1 |
3eb8fbfb
|
Andreas Kohlbecker
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Functions for dealing maps
|
5 |
|
|
*
|
6 |
|
|
* @copyright
|
7 |
|
|
* (C) 2007-2013 EDIT
|
8 |
|
|
* European Distributed Institute of Taxonomy
|
9 |
|
|
* http://www.e-taxonomy.eu
|
10 |
|
|
*
|
11 |
|
|
* The contents of this module are subject to the Mozilla
|
12 |
|
|
* Public License Version 1.1.
|
13 |
|
|
* @see http://www.mozilla.org/MPL/MPL-1.1.html
|
14 |
|
|
*
|
15 |
|
|
* @author
|
16 |
|
|
* - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
d2fd2a4c
|
Andreas Kohlbecker
|
/**
|
20 |
|
|
* Compose an render array for distribution and occurrence
|
21 |
|
|
* maps.
|
22 |
|
|
*
|
23 |
|
|
* The map can either be a plain image or a dynamic open layers map
|
24 |
|
|
* depending on the settings
|
25 |
|
|
*
|
26 |
|
|
* compose_hook() implementation
|
27 |
|
|
*
|
28 |
|
|
* @param string $occurrence_query
|
29 |
|
|
* @param string $distribution_query
|
30 |
|
|
* @param string $legend_format_query
|
31 |
|
|
* @param array $event_listeners
|
32 |
|
|
* An associative array of with OpenLayers.Map event names as key and corresponding js callbacks.
|
33 |
|
|
* In addition to the event names '#execute' as key is also allowed.
|
34 |
|
|
* Valid events are:
|
35 |
|
|
* - move
|
36 |
|
|
* - moveend
|
37 |
|
|
* - zoomend
|
38 |
|
|
* - changelayer
|
39 |
|
|
* - changebaselayer
|
40 |
|
|
* - #execute:
|
41 |
|
|
* force execution of the given callback after registration of the event handlers
|
42 |
|
|
* see http://dev.openlayers.org/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.events for more
|
43 |
087bb473
|
Andreas Kohlbecker
|
* @param bool $resizable
|
44 |
|
|
* only possible for openlayers_map
|
45 |
6f718d1b
|
Andreas Kohlbecker
|
* @param string $force_map_type
|
46 |
|
|
* Can be used to override the map_type setting stored in the settings variable CDM_MAP_DISTRIBUTION
|
47 |
|
|
* - 1: openlayers_map
|
48 |
|
|
* - 0: image_map
|
49 |
d2fd2a4c
|
Andreas Kohlbecker
|
*
|
50 |
|
|
* @return array
|
51 |
|
|
* A drupal render array
|
52 |
|
|
*
|
53 |
cc3c9807
|
Andreas Kohlbecker
|
* Similar compose function compose_distribution_map()
|
54 |
|
|
*
|
55 |
d2fd2a4c
|
Andreas Kohlbecker
|
* @ingroup compose
|
56 |
|
|
*/
|
57 |
6f718d1b
|
Andreas Kohlbecker
|
function compose_map($occurrence_query = NULL, $distribution_query = NULL,
|
58 |
087bb473
|
Andreas Kohlbecker
|
$legend_format_query = NULL, array $event_listeners = array(), $resizable = false,
|
59 |
6f718d1b
|
Andreas Kohlbecker
|
$force_map_type = NULL) {
|
60 |
d2fd2a4c
|
Andreas Kohlbecker
|
|
61 |
62cd8253
|
Patric Plitzner
|
$map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
|
62 |
50791e51
|
Andreas Kohlbecker
|
|
63 |
6f718d1b
|
Andreas Kohlbecker
|
if($force_map_type === NULL){
|
64 |
|
|
$force_map_type = $map_settings['map_type'];
|
65 |
ff965d76
|
Andreas Kohlbecker
|
}
|
66 |
50791e51
|
Andreas Kohlbecker
|
|
67 |
6f718d1b
|
Andreas Kohlbecker
|
if ($force_map_type == 1) {
|
68 |
087bb473
|
Andreas Kohlbecker
|
_add_jquery_ui();
|
69 |
d2fd2a4c
|
Andreas Kohlbecker
|
$map_html = get_openlayers_map(
|
70 |
|
|
$occurrence_query,
|
71 |
|
|
$distribution_query,
|
72 |
|
|
$legend_format_query,
|
73 |
cc3c9807
|
Andreas Kohlbecker
|
$map_settings['caption'],
|
74 |
087bb473
|
Andreas Kohlbecker
|
$event_listeners,
|
75 |
|
|
$resizable
|
76 |
d2fd2a4c
|
Andreas Kohlbecker
|
);
|
77 |
62cd8253
|
Patric Plitzner
|
}
|
78 |
|
|
else {
|
79 |
50791e51
|
Andreas Kohlbecker
|
$map_height = round($map_settings['image_map']['width'] / (float)$map_settings['aspect_ratio']);
|
80 |
62cd8253
|
Patric Plitzner
|
$map_html = get_image_map(
|
81 |
b4503332
|
Andreas Kohlbecker
|
$map_settings['image_map']['width'],
|
82 |
50791e51
|
Andreas Kohlbecker
|
$map_height,
|
83 |
d2fd2a4c
|
Andreas Kohlbecker
|
$occurrence_query,
|
84 |
|
|
$distribution_query,
|
85 |
|
|
$legend_format_query,
|
86 |
cc3c9807
|
Andreas Kohlbecker
|
$map_settings['caption']
|
87 |
50791e51
|
Andreas Kohlbecker
|
);
|
88 |
62cd8253
|
Patric Plitzner
|
}
|
89 |
50791e51
|
Andreas Kohlbecker
|
return markup_to_render_array($map_html);
|
90 |
d2fd2a4c
|
Andreas Kohlbecker
|
}
|
91 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
92 |
|
|
/**
|
93 |
2bbc28c8
|
Andreas Kohlbecker
|
* @param $map_settings
|
94 |
|
|
* The map settings array as retrieved by e.g. get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
|
95 |
d2fd2a4c
|
Andreas Kohlbecker
|
* @param array $event_listeners
|
96 |
|
|
* An associative array of with OpenLayers.Map event names as key and corresponding js callbacks.
|
97 |
|
|
* In addition to the event names '#execute' as key is also allowed.
|
98 |
|
|
* Valid events are:
|
99 |
|
|
* - move
|
100 |
|
|
* - moveend
|
101 |
|
|
* - zoomend
|
102 |
|
|
* - changelayer
|
103 |
|
|
* - changebaselayer
|
104 |
|
|
* - #execute:
|
105 |
|
|
* force execution of the given callback after registration of the event handlers
|
106 |
|
|
* see http://dev.openlayers.org/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.events for more
|
107 |
087bb473
|
Andreas Kohlbecker
|
* @param bool $resizable
|
108 |
|
|
* The map is made resizable when set to true
|
109 |
3eb8fbfb
|
Andreas Kohlbecker
|
*/
|
110 |
087bb473
|
Andreas Kohlbecker
|
function _add_js_openlayers_map($map_settings, array $event_listeners = array(), $resizable = false) {
|
111 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
112 |
5053f04f
|
Andreas Kohlbecker
|
font_awesome_icon_markup(); // no icon specified, only used to add the font and styles
|
113 |
|
|
|
114 |
3eb8fbfb
|
Andreas Kohlbecker
|
_add_js_openlayers();
|
115 |
|
|
|
116 |
2bbc28c8
|
Andreas Kohlbecker
|
$edit_map_service = get_edit_map_service_settings();
|
117 |
|
|
|
118 |
d2fd2a4c
|
Andreas Kohlbecker
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/map/openlayers_map.js');
|
119 |
|
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/map/openlayers_layers.js');
|
120 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
121 |
2bbc28c8
|
Andreas Kohlbecker
|
$cdm_openlayers_options = array(
|
122 |
|
|
'legendPosition' => '3',
|
123 |
d5661a4c
|
Andreas Kohlbecker
|
'boundingBox' => $map_settings['bbox'],
|
124 |
b4503332
|
Andreas Kohlbecker
|
'aspectRatio' => $map_settings['aspect_ratio'],
|
125 |
d5661a4c
|
Andreas Kohlbecker
|
'distributionOpacity' => $map_settings['distribution_opacity'],
|
126 |
|
|
'legendOpacity' => $map_settings['legend']['opacity'],
|
127 |
2bbc28c8
|
Andreas Kohlbecker
|
'showLayerSwitcher' => $map_settings['openlayers']['show_layer_switcher'] == 1,
|
128 |
10f6aa4b
|
Andreas Kohlbecker
|
'displayOutsideMaxExtent' => $map_settings['openlayers']['display_outside_max_extent'] == 1,
|
129 |
087bb473
|
Andreas Kohlbecker
|
'resizable' => $resizable
|
130 |
10f6aa4b
|
Andreas Kohlbecker
|
// 'imgPath' => drupal_get_path('module', 'cdm_dataportal') . '/js/map/OpenLayers-2.13.1/img/' // path to the control icons
|
131 |
2bbc28c8
|
Andreas Kohlbecker
|
// if no baseLayerNames or defaultBaseLayerName are not defined
|
132 |
|
|
// the defaults in cdm_openlayers.js will be used
|
133 |
|
|
);
|
134 |
|
|
|
135 |
|
|
// --- setting the base layer options
|
136 |
|
|
if (is_array($map_settings['openlayers']['base_layers']) && count($map_settings['openlayers']['base_layers']) > 0) {
|
137 |
|
|
|
138 |
|
|
$layer_names = $map_settings['openlayers']['base_layers'];
|
139 |
|
|
|
140 |
a5ab2641
|
Andreas Kohlbecker
|
$cdm_openlayers_options['baseLayerNames'] = array_values($layer_names);
|
141 |
|
|
|
142 |
d5f29731
|
Andreas Kohlbecker
|
if($layer_names['PREFERRED']){
|
143 |
2bbc28c8
|
Andreas Kohlbecker
|
$cdm_openlayers_options['defaultBaseLayerName'] = $layer_names['PREFERRED'];
|
144 |
d5f29731
|
Andreas Kohlbecker
|
unset($layer_names['PREFERRED']); // why is this needed?
|
145 |
a5ab2641
|
Andreas Kohlbecker
|
if(!array_search($cdm_openlayers_options['defaultBaseLayerName'], $cdm_openlayers_options['baseLayerNames'])){
|
146 |
d5f29731
|
Andreas Kohlbecker
|
// the default layer must also be in the list of base layers
|
147 |
a5ab2641
|
Andreas Kohlbecker
|
$cdm_openlayers_options['baseLayerNames'][] = $cdm_openlayers_options['defaultBaseLayerName'];
|
148 |
|
|
}
|
149 |
3eb8fbfb
|
Andreas Kohlbecker
|
}
|
150 |
2bbc28c8
|
Andreas Kohlbecker
|
|
151 |
|
|
|
152 |
3eb8fbfb
|
Andreas Kohlbecker
|
}
|
153 |
|
|
|
154 |
2bbc28c8
|
Andreas Kohlbecker
|
// --- custom wms base layer
|
155 |
|
|
$map_settings['openlayers']['custom_wms_base_layer']['params'] = json_decode($map_settings['openlayers']['custom_wms_base_layer']['params']);
|
156 |
|
|
$cdm_openlayers_options['customWMSBaseLayerData'] = $map_settings['openlayers']['custom_wms_base_layer'];
|
157 |
|
|
|
158 |
|
|
// --- eventhandlers
|
159 |
d2fd2a4c
|
Andreas Kohlbecker
|
$event_listeners_js = '';
|
160 |
|
|
$execute_handler = '';
|
161 |
|
|
foreach($event_listeners as $event=>$js_callback){
|
162 |
|
|
if($event == '#execute'){
|
163 |
|
|
$execute_handler = 'map_container.each(function(){' . $js_callback . '();});';
|
164 |
|
|
} else {
|
165 |
|
|
$event_listeners_js .= ($event_listeners_js ? ",\n": "\n") .'"' . $event . '": ' . $js_callback;
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
|
169 |
0b554b40
|
Andreas Kohlbecker
|
$mapserver_base_uri = $edit_map_service['base_uri'];
|
170 |
|
|
$is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
|
171 |
|
|
$http_protocol = $is_https ? 'https' : 'http';
|
172 |
|
|
$mapserver_base_uri = preg_replace('/^https?:/', $http_protocol . ':', $mapserver_base_uri);
|
173 |
2bbc28c8
|
Andreas Kohlbecker
|
|
174 |
3eb8fbfb
|
Andreas Kohlbecker
|
// window.onload - is executed when the document and images etc is fully loaded
|
175 |
|
|
// Query(document).ready - is executed much earlier, when the DOM is loaded
|
176 |
|
|
drupal_add_js("
|
177 |
|
|
jQuery(document).ready(function() {
|
178 |
087bb473
|
Andreas Kohlbecker
|
jQuery(window).load(function () {
|
179 |
d2fd2a4c
|
Andreas Kohlbecker
|
var map_container = jQuery('#openlayers_map').cdm_openlayers_map(
|
180 |
0b554b40
|
Andreas Kohlbecker
|
'" . $mapserver_base_uri . "',
|
181 |
3eb8fbfb
|
Andreas Kohlbecker
|
'" . $edit_map_service['version'] . "',
|
182 |
2bbc28c8
|
Andreas Kohlbecker
|
" . json_encode($cdm_openlayers_options) . "
|
183 |
3eb8fbfb
|
Andreas Kohlbecker
|
);
|
184 |
d2fd2a4c
|
Andreas Kohlbecker
|
map_container.each(function(){
|
185 |
087bb473
|
Andreas Kohlbecker
|
this.cdmOpenlayersMap.registerEvents({" . "
|
186 |
|
|
" . $event_listeners_js . "
|
187 |
|
|
});
|
188 |
d2fd2a4c
|
Andreas Kohlbecker
|
});
|
189 |
|
|
" . $execute_handler . "
|
190 |
087bb473
|
Andreas Kohlbecker
|
});
|
191 |
3eb8fbfb
|
Andreas Kohlbecker
|
});
|
192 |
|
|
", array('type' => 'inline'));
|
193 |
|
|
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
/**
|
198 |
|
|
* @todo Enter description here ...
|
199 |
|
|
*
|
200 |
|
|
* @param unknown_type $bounding_box
|
201 |
|
|
* @param unknown_type $occurrenceQuery
|
202 |
|
|
* @param unknown_type $distributionQuery
|
203 |
|
|
* @param unknown_type $legendFormatQuery
|
204 |
|
|
* @param unknown_type $map_caption
|
205 |
d2fd2a4c
|
Andreas Kohlbecker
|
* @param array $event_listeners
|
206 |
|
|
* An associative array of with OpenLayers.Map event names as key and corresponding js callbacks.
|
207 |
|
|
* In addition to the event names '#execute' as key is also allowed.
|
208 |
|
|
* Valid events are:
|
209 |
|
|
* - move
|
210 |
|
|
* - moveend
|
211 |
|
|
* - zoomend
|
212 |
|
|
* - changelayer
|
213 |
|
|
* - changebaselayer
|
214 |
|
|
* - #execute:
|
215 |
|
|
* force execution of the given callback after registration of the event handlers
|
216 |
|
|
* see http://dev.openlayers.org/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.events for more
|
217 |
3eb8fbfb
|
Andreas Kohlbecker
|
*
|
218 |
d2fd2a4c
|
Andreas Kohlbecker
|
* @return String
|
219 |
|
|
* rendered html
|
220 |
3eb8fbfb
|
Andreas Kohlbecker
|
*/
|
221 |
753d936d
|
Andreas Kohlbecker
|
function get_openlayers_map($occurrenceQuery = FALSE, $distributionQuery = FALSE,
|
222 |
087bb473
|
Andreas Kohlbecker
|
$legendFormatQuery = FALSE, $map_caption = FALSE, array $event_listeners = array(),
|
223 |
|
|
$resizable = false) {
|
224 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
225 |
cc3c9807
|
Andreas Kohlbecker
|
$map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
|
226 |
|
|
|
227 |
087bb473
|
Andreas Kohlbecker
|
_add_js_openlayers_map($map_settings, $event_listeners, $resizable);
|
228 |
2bbc28c8
|
Andreas Kohlbecker
|
|
229 |
087bb473
|
Andreas Kohlbecker
|
$out = '<div id="openlayers_container" class="openlayers_width ui-widget-content" style="width: 100%;">';
|
230 |
|
|
$out .= '<div id="openlayers_map" class="smallmap" style="width:100%; height:100%; margin: 10px;"';
|
231 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
232 |
|
|
// Additional query parameters as set in the data portal admin section.
|
233 |
cc3c9807
|
Andreas Kohlbecker
|
$labels_on = $map_settings['show_labels'];
|
234 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
235 |
b4503332
|
Andreas Kohlbecker
|
// need to set the ms parameter to some value in order to satisfy the
|
236 |
|
|
// map service even if this value should not be required:
|
237 |
|
|
$width = 512;
|
238 |
|
|
|
239 |
3eb8fbfb
|
Andreas Kohlbecker
|
$openlayers_map_query_string = '&img=false&ms=' . $width
|
240 |
|
|
. ($labels_on ? '&label=' . $labels_on : '');
|
241 |
|
|
|
242 |
|
|
if ($occurrenceQuery) {
|
243 |
|
|
// @todo Fix $occurrenceQuery.
|
244 |
|
|
// $occurrenceQuery .= '&bbox=-180,-90,180,90';
|
245 |
8faca2e1
|
Andreas Kohlbecker
|
$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0'; // TODO why are we using v:atbi,e_w_0 as layer ???
|
246 |
3eb8fbfb
|
Andreas Kohlbecker
|
// $occurrenceQuery .= '&l=v:e_w_0';
|
247 |
|
|
// TODO add to cdm service?
|
248 |
|
|
$occurrenceQuery .= '&legend=0';
|
249 |
|
|
|
250 |
|
|
$out .= ' occurrenceQuery="' . $occurrenceQuery . '&' . $openlayers_map_query_string . '"';
|
251 |
|
|
}
|
252 |
|
|
|
253 |
|
|
if ($distributionQuery) {
|
254 |
4bef194f
|
Andreas Kohlbecker
|
//HACK for testing (this must be done in js)
|
255 |
|
|
// $distributionQuery .= "&layer=em_tiny_jan2003&dest_projection_epsg=7777777";
|
256 |
3eb8fbfb
|
Andreas Kohlbecker
|
$out .= ' distributionQuery="' . $distributionQuery . '&' . $openlayers_map_query_string . '"';
|
257 |
|
|
}
|
258 |
|
|
|
259 |
|
|
if ($legendFormatQuery) {
|
260 |
|
|
$out .= ' legendFormatQuery="' . $legendFormatQuery . '"';
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
$out .= '></div></div>';
|
264 |
|
|
|
265 |
|
|
// Showing map caption.
|
266 |
|
|
if ($map_caption) {
|
267 |
24b3a0f0
|
Andreas Kohlbecker
|
$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>';
|
268 |
3eb8fbfb
|
Andreas Kohlbecker
|
}
|
269 |
|
|
return $out;
|
270 |
|
|
}
|
271 |
|
|
|
272 |
|
|
|
273 |
aa63dfb4
|
Andreas Kohlbecker
|
/**
|
274 |
|
|
* Composes the render array for a distribution map of the given taxon.
|
275 |
|
|
*
|
276 |
|
|
* The distribution map can either be a plain image or a dynamic open layers map
|
277 |
|
|
* depending on the settings.
|
278 |
|
|
*
|
279 |
|
|
* compose_hook() implementation
|
280 |
|
|
*
|
281 |
|
|
* @param $taxon
|
282 |
|
|
* The CDM Taxon instance to create the distribution map for.
|
283 |
|
|
* @return array
|
284 |
|
|
* A drupal render array
|
285 |
|
|
*
|
286 |
|
|
* Similar compose function compose_map()
|
287 |
|
|
*
|
288 |
|
|
* @ingroup compose
|
289 |
|
|
*/
|
290 |
092744e1
|
Andreas Kohlbecker
|
function compose_distribution_map($taxon, $query_string) {
|
291 |
aa63dfb4
|
Andreas Kohlbecker
|
|
292 |
|
|
$out = '';
|
293 |
|
|
|
294 |
|
|
$fontStyles = array(
|
295 |
|
|
0 => "plane",
|
296 |
|
|
1 => "italic",
|
297 |
|
|
);
|
298 |
|
|
|
299 |
|
|
if (!$query_string) {
|
300 |
|
|
// The $query_string is empty if there are no distribution areas defined.
|
301 |
0b554b40
|
Andreas Kohlbecker
|
return null;
|
302 |
aa63dfb4
|
Andreas Kohlbecker
|
}
|
303 |
|
|
|
304 |
|
|
/* ------ choose the display mode, either openlayers or static image ------ */
|
305 |
|
|
|
306 |
|
|
$map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
|
307 |
|
|
|
308 |
|
|
if ($map_settings['map_type'] == 1) {
|
309 |
|
|
|
310 |
|
|
/* =========== display distributions using the openlayers map viewer =========== */
|
311 |
|
|
|
312 |
|
|
$legendFormatQueryStr = "format=image" . urlencode('/') . "png"
|
313 |
44d445c0
|
Andreas Kohlbecker
|
. "&TRANSPARENT=TRUE"
|
314 |
|
|
. "&WIDTH=" . $map_settings['legend']['icon_width']
|
315 |
|
|
. "&HEIGHT=" . $map_settings['legend']['icon_height']
|
316 |
|
|
// TODO why is the layer=topp:tdwg_level_4 parameter needed at all here??
|
317 |
|
|
// AK: i think the tdwg_level_4 is used as place holder and will be replaced later on
|
318 |
|
|
// => search for "tdwg_level_4" in the code
|
319 |
|
|
. "&layer=topp" . urlencode(':') . "tdwg_level_4"
|
320 |
|
|
. "&LEGEND_OPTIONS=forceLabels" . urlencode(':') . "on"
|
321 |
|
|
. ";fontStyle" . urlencode(':') . $fontStyles[$map_settings['legend']['font_style']]
|
322 |
|
|
. ";fontSize" . urlencode(':') . $map_settings['legend']['font_size']
|
323 |
|
|
. "&SLD=";
|
324 |
aa63dfb4
|
Andreas Kohlbecker
|
|
325 |
50791e51
|
Andreas Kohlbecker
|
/*$out .= get_openlayers_map(
|
326 |
aa63dfb4
|
Andreas Kohlbecker
|
$map_settings['bbox'],
|
327 |
|
|
NULL,
|
328 |
|
|
$query_string,
|
329 |
|
|
$legendFormatQueryStr,
|
330 |
|
|
$map_settings['caption']
|
331 |
|
|
);
|
332 |
50791e51
|
Andreas Kohlbecker
|
*/
|
333 |
aa63dfb4
|
Andreas Kohlbecker
|
}
|
334 |
|
|
else {
|
335 |
|
|
$legendFormatQueryStr = '';
|
336 |
50791e51
|
Andreas Kohlbecker
|
/*
|
337 |
|
|
get_image_map(
|
338 |
|
|
$map_settings['image_map']['width'],
|
339 |
|
|
$map_settings['image_map']['height'],
|
340 |
|
|
$map_settings['bbox'],
|
341 |
|
|
NULL,
|
342 |
|
|
$query_string,
|
343 |
|
|
$legendFormatQueryStr,
|
344 |
|
|
$map_settings['caption']
|
345 |
|
|
);
|
346 |
|
|
*/
|
347 |
aa63dfb4
|
Andreas Kohlbecker
|
}
|
348 |
50791e51
|
Andreas Kohlbecker
|
$out = compose_map(NULL, $query_string, $legendFormatQueryStr);
|
349 |
|
|
|
350 |
|
|
return $out;
|
351 |
aa63dfb4
|
Andreas Kohlbecker
|
}
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
|
355 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
356 |
|
|
/**
|
357 |
|
|
* @todo Enter description here ...
|
358 |
|
|
*
|
359 |
|
|
* @param unknown_type $width
|
360 |
|
|
* @param unknown_type $occurrenceQuery
|
361 |
|
|
* @param unknown_type $distributionQuery
|
362 |
|
|
* @param unknown_type $legendFormatQuery
|
363 |
|
|
* @param unknown_type $map_caption
|
364 |
|
|
*
|
365 |
d2fd2a4c
|
Andreas Kohlbecker
|
* @return String
|
366 |
|
|
* rendered html
|
367 |
3eb8fbfb
|
Andreas Kohlbecker
|
*/
|
368 |
24b3a0f0
|
Andreas Kohlbecker
|
function get_image_map($width, $height= NULL, $occurrenceQuery = FALSE, $distributionQuery = FALSE,
|
369 |
|
|
$legendFormatQuery = FALSE, $map_caption = FALSE) {
|
370 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
371 |
cc3c9807
|
Andreas Kohlbecker
|
$map_settings = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
|
372 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
373 |
4bef194f
|
Andreas Kohlbecker
|
$baselayer_name = $map_settings['image_map']['base_layer'];
|
374 |
|
|
if(empty($baselayer_name)){
|
375 |
|
|
$baselayer_name = "earth";
|
376 |
|
|
}
|
377 |
|
|
|
378 |
96835579
|
Andreas Kohlbecker
|
$query_string = '&img=true&recalculate=false&ms=' . $width . ($height ? ',' . $height : '')
|
379 |
cc3c9807
|
Andreas Kohlbecker
|
// Additional query parameters as set in the data portal admin section.
|
380 |
753d936d
|
Andreas Kohlbecker
|
. ($map_settings['bbox'] ? '&bbox=' . $map_settings['bbox'] : '')
|
381 |
cc3c9807
|
Andreas Kohlbecker
|
. ($map_settings['show_labels'] ? '&label=' . $map_settings['show_labels'] : '');
|
382 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
383 |
|
|
if ($map_caption) {
|
384 |
|
|
$query_string .= '&mlp=3&mc_s=Georgia,15,blue&mc=' . $map_caption;
|
385 |
|
|
}
|
386 |
|
|
|
387 |
|
|
if (get_edit_map_service_version_number() >= 1.1) {
|
388 |
|
|
|
389 |
|
|
// Either occurrence or distribution - combined maps will be possible
|
390 |
|
|
// in the future.
|
391 |
|
|
if ($occurrenceQuery) {
|
392 |
|
|
// @todo Fix $occurrenceQuery.
|
393 |
|
|
$occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
|
394 |
|
|
// $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
|
395 |
4bef194f
|
Andreas Kohlbecker
|
|
396 |
3eb8fbfb
|
Andreas Kohlbecker
|
// Will be replaced below.. HACK!!!
|
397 |
4bef194f
|
Andreas Kohlbecker
|
$occurrenceQuery .= '&l=' . $baselayer_name . '&as=';
|
398 |
3eb8fbfb
|
Andreas Kohlbecker
|
|
399 |
|
|
$query_string .= "&" . $occurrenceQuery;
|
400 |
|
|
}
|
401 |
|
|
elseif ($distributionQuery) {
|
402 |
4bef194f
|
Andreas Kohlbecker
|
$query_string .= '&l=' . $baselayer_name . "&" .$distributionQuery;
|
403 |
3eb8fbfb
|
Andreas Kohlbecker
|
}
|
404 |
|
|
|
405 |
|
|
// Apply Plain Image map settings special for version >= 1.1.
|
406 |
|
|
/*
|
407 |
|
|
example : title=a:Naturalized++non-invasive
|
408 |
|
|
&ad=cyprusdivs:bdcode:a:5&as=a:ff9900,,0.1,&l=tdwg4
|
409 |
|
|
&ms=500&bbox=32,34,35,36&img=true&legend=1&mlp=3
|
410 |
|
|
&mc_s=Georgia,15,blue&mc=&recalculate=false
|
411 |
|
|
|
412 |
|
|
http://edit.br.fgov.be/edit_wp5/v1/rest_gen.php?
|
413 |
|
|
l=background_gis:b,cyprusdivs&ad=cyprusdivs%3Abdcode%3Aa%3A8%2C4
|
414 |
|
|
&as=a%3A339966%2C%2C0.1%2C|b:0000ff,,
|
415 |
|
|
&bbox=32%2C34%2C35%2C36&img=true&legend=1&mc=&mc_s=Georgia%2C15%2Cblue
|
416 |
|
|
&mlp=3&ms=500&recalculate=false&title=a%3Aindigenous
|
417 |
|
|
*/
|
418 |
|
|
|
419 |
|
|
$map_service_script_name = "rest_gen.php";
|
420 |
|
|
|
421 |
4bef194f
|
Andreas Kohlbecker
|
$bgcolor_areaStyleId = "Y";
|
422 |
|
|
$baselayer_areaStyleId = "Z";
|
423 |
3eb8fbfb
|
Andreas Kohlbecker
|
$bgcolor_layer = '';
|
424 |
|
|
$additional_area_styles = array();
|
425 |
|
|
|
426 |
|
|
// Background color:
|
427 |
cc3c9807
|
Andreas Kohlbecker
|
if ($map_settings['image_map']['bg_color'] ) {
|
428 |
3eb8fbfb
|
Andreas Kohlbecker
|
$bgcolor_layer = "background_gis:" . $bgcolor_areaStyleId;
|
429 |
cc3c9807
|
Andreas Kohlbecker
|
$additional_area_styles[] = $bgcolor_areaStyleId . ":" . $map_settings['image_map']['bg_color'] . ",,";
|
430 |
3eb8fbfb
|
Andreas Kohlbecker
|
}
|
431 |
|
|
|
432 |
|
|
// TODO HACK to replace the default base layer which currently is tdwg4 !!!
|
433 |
|
|
// only needed for distribution maps.
|
434 |
|
|
if (strpos($query_string, "?l=") !== FALSE) {
|
435 |
|
|
$layer_param_token = "?l=";
|
436 |
|
|
}
|
437 |
|
|
else {
|
438 |
|
|
$layer_param_token = "&l=";
|
439 |
|
|
}
|
440 |
|
|
if (strpos($query_string, "?as=") !== FALSE) {
|
441 |
|
|
$areystyle_param_token = "?as=";
|
442 |
|
|
}
|
443 |
|
|
else {
|
444 |
|
|
$areystyle_param_token = "&as=";
|
445 |
|
|
}
|
446 |
cc3c9807
|
Andreas Kohlbecker
|
if ($map_settings['image_map']['base_layer']) {
|
447 |
4bef194f
|
Andreas Kohlbecker
|
$query_string = str_replace($layer_param_token .$baselayer_name, "$layer_param_token" . $map_settings['image_map']['base_layer'] . ":" . $baselayer_areaStyleId, $query_string);
|
448 |
3eb8fbfb
|
Andreas Kohlbecker
|
}
|
449 |
|
|
else {
|
450 |
4bef194f
|
Andreas Kohlbecker
|
$query_string = str_replace($layer_param_token . $baselayer_name, $layer_param_token . $baselayer_name . ":" . $baselayer_areaStyleId . ",", $query_string);
|
451 |
3eb8fbfb
|
Andreas Kohlbecker
|
}
|
452 |
|
|
|
453 |
|
|
if ($bgcolor_layer) {
|
454 |
|
|
$query_string = str_replace($layer_param_token, $layer_param_token . $bgcolor_layer . ",", $query_string);
|
455 |
|
|
}
|
456 |
|
|
|
457 |
cc3c9807
|
Andreas Kohlbecker
|
if ($map_settings['image_map']['layer_style']) {
|
458 |
|
|
$additional_area_styles[] = $baselayer_areaStyleId . ":" . $map_settings['image_map']['layer_style'];
|
459 |
3eb8fbfb
|
Andreas Kohlbecker
|
}
|
460 |
|
|
|
461 |
4bef194f
|
Andreas Kohlbecker
|
if(isset($map_settings['projection'])){
|
462 |
|
|
$query_string .= "&srs=" . $map_settings['projection'];
|
463 |
|
|
}
|
464 |
|
|
|
465 |
|
|
if(isset($map_settings['legend']['show']) && $map_settings['legend']['show']){
|
466 |
|
|
$query_string .= "&legend=1";
|
467 |
|
|
}
|
468 |
|
|
|
469 |
3eb8fbfb
|
Andreas Kohlbecker
|
foreach ($additional_area_styles as $as) {
|
470 |
|
|
$query_string = str_replace($areystyle_param_token, $areystyle_param_token . $as . "|", $query_string);
|
471 |
|
|
}
|
472 |
|
|
|
473 |
|
|
}
|
474 |
|
|
else {
|
475 |
|
|
// Pre 1.1. version of map service.
|
476 |
|
|
if ($occurrenceQuery) {
|
477 |
|
|
|
478 |
|
|
$map_service_script_name = "point.php";
|
479 |
|
|
|
480 |
|
|
// Fix $occurrenceQuery.
|
481 |
|
|
$occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
|
482 |
|
|
// $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
|
483 |
|
|
$occurrenceQuery .= '&l=v:e_w_0';
|
484 |
|
|
$query_string .= "&" . $occurrenceQuery;
|
485 |
|
|
}
|
486 |
|
|
elseif ($distributionQuery) {
|
487 |
|
|
$query_string .= "&" . $distributionQuery;
|
488 |
|
|
$map_service_script_name = "areas.php";
|
489 |
|
|
}
|
490 |
|
|
}
|
491 |
|
|
|
492 |
|
|
$mapUri = url(get_edit_map_service_full_uri() . '/' . $map_service_script_name . '?' . $query_string);
|
493 |
|
|
$out = '<img class="distribution_map" src="' . $mapUri . '" alt="Map" />';
|
494 |
|
|
// Showing map caption.
|
495 |
|
|
if ($map_caption) {
|
496 |
24b3a0f0
|
Andreas Kohlbecker
|
$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>';
|
497 |
3eb8fbfb
|
Andreas Kohlbecker
|
}
|
498 |
|
|
|
499 |
|
|
return $out;
|
500 |
|
|
}
|
501 |
|
|
|