/[drupal]/contributions/modules/nicemap/nicemap_admin.inc
ViewVC logotype

Contents of /contributions/modules/nicemap/nicemap_admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri Dec 12 14:32:48 2008 UTC (11 months, 2 weeks ago) by jmiccolis
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +2 -2 lines
File MIME type: text/x-php
Removed two unnecessary call-time-pass-by-references. Thanks due to spython for pointing out the fix.
1 <?php
2 // $Id: nicemap_admin.inc,v 1.1 2008/11/14 18:03:58 jmiccolis Exp $
3
4 /**
5 * Form for clearing the nicemap cache
6 */
7 function nicemap_cache_clear() {
8 $form = array();
9 $form['info'] = array(
10 '#type' => 'item',
11 '#value' => "<p>". t('Nicemap stores information it retrieves from each WMS server in a cache to eliminate the need to poll the server for information each time a map is generated. You should clear this cache when the server updates its capabilities or the cached information is no longer valid.') ."</p>",
12 );
13 $form['submit'] = array(
14 '#type' => 'submit',
15 '#value' => t('Clear nicemap cache'),
16 );
17 return $form;
18 }
19
20 /**
21 * Submit handler for nicemap cache clearing.
22 */
23 function nicemap_cache_clear_submit($form, &$form_state) {
24 variable_set('nicemap_cache', array());
25 }
26
27 /**
28 * Master settings form and testing page
29 */
30 function nicemap_settings() {
31 $form = array();
32 $form['nicemap_mode'] = array(
33 '#title' => t('Map source'),
34 '#type' => 'select',
35 '#options' => array(0 => '---', 'wms' => t('WMS server'), 'file' => t('Uploaded file')),
36 '#default_value' => variable_get('nicemap_mode', 0),
37 );
38
39 $form = system_settings_form($form);
40 $form['buttons']['#weight'] = 100;
41
42 switch (variable_get('nicemap_mode', '')) {
43 case 'wms':
44 $form['wms'] = array(
45 '#type' => 'fieldset',
46 '#title' => t('WMS server'),
47 );
48 $form['wms']['nicemap_wms_url'] = array(
49 '#title' => t('Map server URL'),
50 '#description' => t('The root URL of the map server you intend to use,
51 please include "http://". This may or may not include
52 certain arguments and filenames.'),
53 '#default_value' => variable_get('nicemap_wms_url', ''),
54 '#type' => 'textfield');
55 if ($wms = variable_get('nicemap_wms_url', '')) {
56 $spec = nicemap_capabilities_cache($wms);
57
58 // projections
59 $crs = array();
60 if (count($spec['crs'])) {
61 foreach ($spec['crs'] as $code) {
62 $crs[$code] = $code;
63 }
64 }
65 $form['wms']['nicemap_wms_crs'] = array(
66 '#type' => 'select',
67 '#title' => t('CRS code'),
68 '#description' => t('Choose the projection mode.'),
69 '#options' => $crs,
70 '#default_value' => variable_get('nicemap_wms_crs', ''),
71 );
72
73 // layers + styles
74 $l = _nicemap_get_layers($spec);
75 $settings = variable_get('nicemap_defaults', array('layers' => array(), 'styles' => array(), 'weights' => array()));
76 $bgcolor = variable_get('nicemap_bgcolor', 'aabbcc');
77 _nicemap_layer_style_form($form, $l, $settings['layers'], $settings['styles'], $settings['weights'], $bgcolor);
78
79 }
80 break;
81 case 'file':
82 $form['file'] = array(
83 '#type' => 'fieldset',
84 '#title' => t('Uploaded file'),
85 );
86 $options = array();
87 foreach (nicemap_projections() as $k => $v) {
88 $options[$k] = $v['name'];
89 }
90 $form['file']['nicemap_file_projection'] = array(
91 '#title' => t('Map file projection'),
92 '#type' => 'select',
93 '#options' => $options,
94 '#default_value' => variable_get('nicemap_file_projection', 'mercator'),
95 );
96 break;
97 }
98 return $form;
99 }
100
101 /**
102 * Layer and style settings form, used also by the view form.
103 */
104 function _nicemap_layer_style_form(&$form, $wms_layers, $default_layers, $default_styles, $default_weights, $default_bg) {
105 $form['display'] = array(
106 '#title' => t('Display options'),
107 '#type' => 'fieldset',
108 );
109 $form['display']['nicemap_bgcolor'] = array(
110 '#title' => t('Background color'),
111 '#type' => 'textfield',
112 '#size' => 6,
113 '#maxlength' => 6,
114 '#description' => t('Enter an RGB hex value or leave blank to use a transparent background.'),
115 '#default_value' => $default_bg,
116 );
117
118 $layers = $styles = array();
119 foreach ($wms_layers as $layer => $info) {
120 $layers[$layer] = $info['title'];
121 $styles[$layer] = $info['styles'];
122 }
123
124 $weight_options = array();
125 for ($i = -5; $i <= 5; $i++) {
126 $weight_options[$i] = $i;
127 }
128
129 $form['nicemap_defaults'] = array(
130 '#tree' => true,
131 '#theme' => 'nicemap_settings_layers',
132 '#type' => 'fieldset',
133 '#title' => t('Layers display options'),
134 'layers' => array(),
135 'styles' => array(),
136 'weights' => array(),
137 );
138
139 foreach ($layers as $layer => $name) {
140 $form['nicemap_defaults']['layers'][$layer] = array(
141 '#type' => 'checkbox',
142 '#title' => $name,
143 '#default_value' => isset($default_layers[$layer]) ? $default_layers[$layer] : 0,
144 );
145 $form['nicemap_defaults']['styles'][$layer] = array(
146 '#type' => 'select',
147 '#options' => $styles[$layer],
148 '#default_value' => isset($default_styles[$layer]) ? $default_styles[$layer] : $styles[$layer][0],
149 );
150 $form['nicemap_defaults']['weights'][$layer] = array(
151 '#type' => 'select',
152 '#options' => $weight_options,
153 '#default_value' => isset($default_weights[$layer]) ? $default_weights[$layer] : 0,
154 '#attributes' => array('class' => 'layer-weight'),
155 );
156 }
157 }
158
159 /**
160 * Style layer settings into a table grid.
161 */
162 function theme_nicemap_settings_layers($form) {
163 uasort($form['weights'], create_function('$a, $b', 'return $a["#default_value"] > $b["#default_value"];'));
164
165 $rows = array();
166 foreach (element_children($form['weights']) as $elem) {
167 $row = array(
168 drupal_render($form['layers'][$elem]),
169 drupal_render($form['styles'][$elem]),
170 drupal_render($form['weights'][$elem]),
171 );
172 $rows[] = array('data' => $row, 'class' => 'draggable');
173 }
174 $output = theme('table', array(t('Layer'), t('Style'), t('Weight')), $rows, array('id' => 'wms-layer-selector'));
175 drupal_add_tabledrag('wms-layer-selector', 'order', 'self', 'layer-weight');
176 $output .= drupal_render($form);
177 return $output;
178 }

  ViewVC Help
Powered by ViewVC 1.1.2