Revision 3eb8fbfb
Added by Andreas Kohlbecker over 10 years ago
7.x/modules/cdm_dataportal/cdm_dataportal.module | ||
---|---|---|
24 | 24 |
|
25 | 25 |
module_load_include('inc', 'cdm_dataportal', 'includes/common'); |
26 | 26 |
module_load_include('inc', 'cdm_dataportal', 'includes/pages'); |
27 |
module_load_include('inc', 'cdm_dataportal', 'includes/media'); |
|
27 |
module_load_include('inc', 'cdm_dataportal', 'includes/media'); |
|
28 |
module_load_include('inc', 'cdm_dataportal', 'includes/maps'); |
|
28 | 29 |
module_load_include('inc', 'cdm_dataportal', 'includes/occurrences'); |
29 | 30 |
module_load_include('inc', 'cdm_dataportal', 'includes/descriptions'); |
30 | 31 |
module_load_include('inc', 'cdm_dataportal', 'includes/pre-drupal8'); |
... | ... | |
110 | 111 |
} |
111 | 112 |
|
112 | 113 |
function _add_js_openlayers() { |
113 |
$openlayers = '/js/OpenLayers-2.11/OpenLayers.js'; |
|
114 |
|
|
115 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . $openlayers, array( |
|
116 |
'type' => 'file', |
|
117 |
'weight' => JS_LIBRARY, |
|
118 |
'cache' => FALSE, |
|
119 |
)); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* @todo Please document this function. |
|
124 |
* @see http://drupal.org/node/1354 |
|
125 |
*/ |
|
126 |
function _add_js_openlayers_map() { |
|
127 |
|
|
128 |
_add_js_openlayers(); |
|
129 |
|
|
130 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/openlayers_map.js'); |
|
131 |
|
|
132 |
$gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ'); |
|
133 |
|
|
134 |
$baseLayers = variable_get('baselayers', array()); |
|
135 |
if (!is_array($baseLayers) || count($baseLayers) == 0) { |
|
136 |
$baseLayers = array( |
|
137 |
'metacarta_vmap0' => 'Metacarta Vmap0', |
|
138 |
'PREFERRED' => 'metacarta_vmap0', |
|
139 |
); |
|
140 |
} |
|
141 |
$layerNames = ''; |
|
142 |
foreach ($baseLayers as $layerName => $layerLabel) { |
|
143 |
if ($layerName == 'PREFERRED') { |
|
144 |
$preferredLayer = $baseLayers['PREFERRED']; |
|
145 |
} |
|
146 |
else { |
|
147 |
$layerNames .= ($layerNames ? ', ' : '') . "'$layerName'"; |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
if (isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb'])) { |
|
152 |
drupal_add_html_head('<script src=http://maps.google.com/maps?file=api&v=2&sensor=false&key=' . $gmap_api_key . '" type="text/javascript"></script>', $key = NULL /* TODO Set this variable. */); |
|
153 |
drupal_add_js('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1', array('type' => 'external')); |
|
154 |
} |
|
155 |
|
|
156 |
$edit_map_service = get_edit_map_service_settings(); |
|
157 |
// window.onload - is executed when the document and images etc is fully loaded |
|
158 |
// Query(document).ready - is executed much earlier, when the DOM is loaded |
|
159 |
drupal_add_js(" |
|
160 |
jQuery(document).ready(function() { |
|
161 |
|
|
162 |
window.onload = function () { |
|
163 |
// --- |
|
164 |
jQuery('#openlayers_map').cdm_openlayers_map( |
|
165 |
'" . $edit_map_service['base_uri'] . "', |
|
166 |
'" . $edit_map_service['version'] . "', |
|
167 |
{ |
|
168 |
legendPosition: 3, |
|
169 |
displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', FALSE) . "', |
|
170 |
boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', FALSE) . "', |
|
171 |
distributionOpacity: '" . variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5') . "', |
|
172 |
legendOpacity: '" . variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5') . "', |
|
173 |
showLayerSwitcher: " . (variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE) ? 'true' : 'false') . ", |
|
174 |
baseLayerNames: [" . $layerNames . "], |
|
175 |
defaultBaseLayerName: '" . $preferredLayer . "' |
|
176 |
} |
|
177 |
); |
|
178 |
// --- |
|
179 |
}; |
|
180 |
}); |
|
181 |
", array('type' => 'inline')); |
|
114 |
$openlayers = '/js/OpenLayers-2.11/OpenLayers.js'; |
|
182 | 115 |
|
116 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . $openlayers, array( |
|
117 |
'type' => 'file', |
|
118 |
'weight' => JS_LIBRARY, |
|
119 |
'cache' => FALSE, |
|
120 |
)); |
|
183 | 121 |
} |
184 | 122 |
|
185 | 123 |
/** |
... | ... | |
290 | 228 |
} |
291 | 229 |
|
292 | 230 |
|
293 |
/** |
|
294 |
* @todo Enter description here ... |
|
295 |
* |
|
296 |
* @param unknown_type $width |
|
297 |
* @param unknown_type $bounding_box |
|
298 |
* @param unknown_type $occurrenceQuery |
|
299 |
* @param unknown_type $distributionQuery |
|
300 |
* @param unknown_type $legendFormatQuery |
|
301 |
* @param unknown_type $map_caption |
|
302 |
* |
|
303 |
* @return unknown |
|
304 |
*/ |
|
305 |
function get_image_map($width, $bounding_box = FALSE, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE) { |
|
306 |
|
|
307 |
// Additional query parameters as set in the data portal admin section. |
|
308 |
$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0); |
|
309 |
|
|
310 |
$query_string = '&image=true&recalculate=false&legend=1&ms=' . $width |
|
311 |
. ($bounding_box ? '&bbox=' . $bounding_box : '') |
|
312 |
. ($labels_on ? '&label=' . $labels_on : ''); |
|
313 |
|
|
314 |
if ($map_caption) { |
|
315 |
$query_string .= '&mlp=3&mc_s=Georgia,15,blue&mc=' . $map_caption; |
|
316 |
} |
|
317 |
|
|
318 |
if (get_edit_map_service_version_number() >= 1.1) { |
|
319 |
|
|
320 |
// Either occurrence or distribution - combined maps will be possible |
|
321 |
// in the future. |
|
322 |
if ($occurrenceQuery) { |
|
323 |
// @todo Fix $occurrenceQuery. |
|
324 |
$occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery); |
|
325 |
// $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0'; |
|
326 |
// Will be replaced below.. HACK!!! |
|
327 |
$occurrenceQuery .= '&l=tdwg4&as='; |
|
328 |
|
|
329 |
$query_string .= "&" . $occurrenceQuery; |
|
330 |
} |
|
331 |
elseif ($distributionQuery) { |
|
332 |
$query_string .= "&" . $distributionQuery; |
|
333 |
} |
|
334 |
|
|
335 |
// Apply Plain Image map settings special for version >= 1.1. |
|
336 |
/* |
|
337 |
example : title=a:Naturalized++non-invasive |
|
338 |
&ad=cyprusdivs:bdcode:a:5&as=a:ff9900,,0.1,&l=tdwg4 |
|
339 |
&ms=500&bbox=32,34,35,36&img=true&legend=1&mlp=3 |
|
340 |
&mc_s=Georgia,15,blue&mc=&recalculate=false |
|
341 |
|
|
342 |
http://edit.br.fgov.be/edit_wp5/v1/rest_gen.php? |
|
343 |
l=background_gis:b,cyprusdivs&ad=cyprusdivs%3Abdcode%3Aa%3A8%2C4 |
|
344 |
&as=a%3A339966%2C%2C0.1%2C|b:0000ff,, |
|
345 |
&bbox=32%2C34%2C35%2C36&img=true&legend=1&mc=&mc_s=Georgia%2C15%2Cblue |
|
346 |
&mlp=3&ms=500&recalculate=false&title=a%3Aindigenous |
|
347 |
*/ |
|
348 |
|
|
349 |
$map_service_script_name = "rest_gen.php"; |
|
350 |
|
|
351 |
$bgcolor_areaStyleId = "y"; |
|
352 |
$baselayer_areaStyleId = "z"; |
|
353 |
$bgcolor_layer = ''; |
|
354 |
$additional_area_styles = array(); |
|
355 |
|
|
356 |
// Background color: |
|
357 |
if (variable_get('map_bg_color', '')) { |
|
358 |
$bgcolor_layer = "background_gis:" . $bgcolor_areaStyleId; |
|
359 |
$additional_area_styles[] = $bgcolor_areaStyleId . ":" . variable_get('map_bg_color', '') . ",,"; |
|
360 |
} |
|
361 |
|
|
362 |
// TODO HACK to replace the default base layer which currently is tdwg4 !!! |
|
363 |
// only needed for distribution maps. |
|
364 |
if (strpos($query_string, "?l=") !== FALSE) { |
|
365 |
$layer_param_token = "?l="; |
|
366 |
} |
|
367 |
else { |
|
368 |
$layer_param_token = "&l="; |
|
369 |
} |
|
370 |
if (strpos($query_string, "?as=") !== FALSE) { |
|
371 |
$areystyle_param_token = "?as="; |
|
372 |
} |
|
373 |
else { |
|
374 |
$areystyle_param_token = "&as="; |
|
375 |
} |
|
376 |
if (variable_get('map_base_layer', '')) { |
|
377 |
$query_string = str_replace($layer_param_token . "tdwg4", "$layer_param_token" . variable_get('map_base_layer', '') . ":" . $baselayer_areaStyleId, $query_string); |
|
378 |
} |
|
379 |
else { |
|
380 |
$query_string = str_replace($layer_param_token . "tdwg4", $layer_param_token . "tdwg4:" . $baselayer_areaStyleId . ",", $query_string); |
|
381 |
} |
|
382 |
|
|
383 |
if ($bgcolor_layer) { |
|
384 |
$query_string = str_replace($layer_param_token, $layer_param_token . $bgcolor_layer . ",", $query_string); |
|
385 |
} |
|
386 |
|
|
387 |
if (variable_get('map_base_layer_style', '')) { |
|
388 |
$additional_area_styles[] = $baselayer_areaStyleId . ":" . variable_get('map_base_layer_style', ''); |
|
389 |
} |
|
390 |
|
|
391 |
foreach ($additional_area_styles as $as) { |
|
392 |
$query_string = str_replace($areystyle_param_token, $areystyle_param_token . $as . "|", $query_string); |
|
393 |
} |
|
394 |
|
|
395 |
} |
|
396 |
else { |
|
397 |
// Pre 1.1. version of map service. |
|
398 |
if ($occurrenceQuery) { |
|
399 |
|
|
400 |
$map_service_script_name = "point.php"; |
|
401 |
|
|
402 |
// Fix $occurrenceQuery. |
|
403 |
$occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery); |
|
404 |
// $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0'; |
|
405 |
$occurrenceQuery .= '&l=v:e_w_0'; |
|
406 |
$query_string .= "&" . $occurrenceQuery; |
|
407 |
} |
|
408 |
elseif ($distributionQuery) { |
|
409 |
$query_string .= "&" . $distributionQuery; |
|
410 |
$map_service_script_name = "areas.php"; |
|
411 |
} |
|
412 |
} |
|
413 |
|
|
414 |
$mapUri = url(get_edit_map_service_full_uri() . '/' . $map_service_script_name . '?' . $query_string); |
|
415 |
$out = '<img class="distribution_map" src="' . $mapUri . '" alt="Map" />'; |
|
416 |
// Showing map caption. |
|
417 |
if ($map_caption) { |
|
418 |
// FIXME: replace <br> by according css style. |
|
419 |
$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; |
|
420 |
$out .= '</div>'; |
|
421 |
} |
|
422 |
|
|
423 |
return $out; |
|
424 |
} |
|
425 |
|
|
426 |
/** |
|
427 |
* @todo Enter description here ... |
|
428 |
* |
|
429 |
* @param unknown_type $width |
|
430 |
* @param unknown_type $bounding_box |
|
431 |
* @param unknown_type $occurrenceQuery |
|
432 |
* @param unknown_type $distributionQuery |
|
433 |
* @param unknown_type $legendFormatQuery |
|
434 |
* @param unknown_type $map_caption |
|
435 |
* |
|
436 |
* @return unknown |
|
437 |
*/ |
|
438 |
function get_openlayers_map($width, $bounding_box = FALSE, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE) { |
|
439 |
|
|
440 |
_add_js_openlayers_map(); |
|
441 |
|
|
442 |
$out = '<div id="openlayers">'; |
|
443 |
$out .= '<div id="openlayers_map" class="smallmap"'; |
|
444 |
if($width) { |
|
445 |
$out .= ' style="width: ' . $width . 'px; height:' . ($width / 2) . 'px"'; |
|
446 |
} |
|
447 |
|
|
448 |
// Additional query parameters as set in the data portal admin section. |
|
449 |
$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0); |
|
450 |
|
|
451 |
$openlayers_map_query_string = '&img=false&ms=' . $width |
|
452 |
. ($bounding_box ? '&bbox=' . $bounding_box : '') |
|
453 |
. ($labels_on ? '&label=' . $labels_on : ''); |
|
454 |
|
|
455 |
if ($occurrenceQuery) { |
|
456 |
// @todo Fix $occurrenceQuery. |
|
457 |
// $occurrenceQuery .= '&bbox=-180,-90,180,90'; |
|
458 |
$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0'; |
|
459 |
// $occurrenceQuery .= '&l=v:e_w_0'; |
|
460 |
// TODO add to cdm service? |
|
461 |
$occurrenceQuery .= '&legend=0'; |
|
462 |
|
|
463 |
$out .= ' occurrenceQuery="' . $occurrenceQuery . '&' . $openlayers_map_query_string . '"'; |
|
464 |
} |
|
465 |
|
|
466 |
if ($distributionQuery) { |
|
467 |
$out .= ' distributionQuery="' . $distributionQuery . '&' . $openlayers_map_query_string . '"'; |
|
468 |
} |
|
469 |
|
|
470 |
if ($legendFormatQuery) { |
|
471 |
$out .= ' legendFormatQuery="' . $legendFormatQuery . '"'; |
|
472 |
} |
|
473 |
|
|
474 |
$out .= '></div></div>'; |
|
475 |
|
|
476 |
// Showing map caption. |
|
477 |
if ($map_caption) { |
|
478 |
// FIXME: replace <br> by according css style. |
|
479 |
$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; |
|
480 |
$out .= '</div>'; |
|
481 |
} |
|
482 |
return $out; |
|
483 |
} |
|
484 |
|
|
485 | 231 |
/* ====================== hook implementations ====================== */ |
486 | 232 |
/** |
487 | 233 |
* Implements hook_permission(). * |
Also available in: Unified diff
separating out map functionality in extra file