1
|
<?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
|
|
20
|
/**
|
21
|
* @todo Please document this function.
|
22
|
* @see http://drupal.org/node/1354
|
23
|
*/
|
24
|
function _add_js_openlayers_map() {
|
25
|
|
26
|
_add_js_openlayers();
|
27
|
|
28
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/openlayers_map.js');
|
29
|
|
30
|
$gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
|
31
|
|
32
|
$baseLayers = variable_get('baselayers', array());
|
33
|
if (!is_array($baseLayers) || count($baseLayers) == 0) {
|
34
|
$baseLayers = array(
|
35
|
'metacarta_vmap0' => 'Metacarta Vmap0',
|
36
|
'PREFERRED' => 'metacarta_vmap0',
|
37
|
);
|
38
|
}
|
39
|
$layerNames = '';
|
40
|
foreach ($baseLayers as $layerName => $layerLabel) {
|
41
|
if ($layerName == 'PREFERRED') {
|
42
|
$preferredLayer = $baseLayers['PREFERRED'];
|
43
|
}
|
44
|
else {
|
45
|
$layerNames .= ($layerNames ? ', ' : '') . "'$layerName'";
|
46
|
}
|
47
|
}
|
48
|
|
49
|
if (isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb'])) {
|
50
|
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. */);
|
51
|
drupal_add_js('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1', array('type' => 'external'));
|
52
|
}
|
53
|
|
54
|
$edit_map_service = get_edit_map_service_settings();
|
55
|
// window.onload - is executed when the document and images etc is fully loaded
|
56
|
// Query(document).ready - is executed much earlier, when the DOM is loaded
|
57
|
drupal_add_js("
|
58
|
jQuery(document).ready(function() {
|
59
|
|
60
|
window.onload = function () {
|
61
|
// ---
|
62
|
jQuery('#openlayers_map').cdm_openlayers_map(
|
63
|
'" . $edit_map_service['base_uri'] . "',
|
64
|
'" . $edit_map_service['version'] . "',
|
65
|
{
|
66
|
legendPosition: 3,
|
67
|
displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', FALSE) . "',
|
68
|
boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', FALSE) . "',
|
69
|
distributionOpacity: '" . variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5') . "',
|
70
|
legendOpacity: '" . variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5') . "',
|
71
|
showLayerSwitcher: " . (variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE) ? 'true' : 'false') . ",
|
72
|
baseLayerNames: [" . $layerNames . "],
|
73
|
defaultBaseLayerName: '" . $preferredLayer . "'
|
74
|
}
|
75
|
);
|
76
|
// ---
|
77
|
};
|
78
|
});
|
79
|
", array('type' => 'inline'));
|
80
|
|
81
|
}
|
82
|
|
83
|
|
84
|
/**
|
85
|
* @todo Enter description here ...
|
86
|
*
|
87
|
* @param unknown_type $width
|
88
|
* @param unknown_type $bounding_box
|
89
|
* @param unknown_type $occurrenceQuery
|
90
|
* @param unknown_type $distributionQuery
|
91
|
* @param unknown_type $legendFormatQuery
|
92
|
* @param unknown_type $map_caption
|
93
|
*
|
94
|
* @return unknown
|
95
|
*/
|
96
|
function get_openlayers_map($width, $bounding_box = FALSE, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE) {
|
97
|
|
98
|
_add_js_openlayers_map();
|
99
|
|
100
|
$out = '<div id="openlayers">';
|
101
|
$out .= '<div id="openlayers_map" class="smallmap"';
|
102
|
if($width) {
|
103
|
$out .= ' style="width: ' . $width . 'px; height:' . ($width / 2) . 'px"';
|
104
|
}
|
105
|
|
106
|
// Additional query parameters as set in the data portal admin section.
|
107
|
$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
|
108
|
|
109
|
$openlayers_map_query_string = '&img=false&ms=' . $width
|
110
|
. ($bounding_box ? '&bbox=' . $bounding_box : '')
|
111
|
. ($labels_on ? '&label=' . $labels_on : '');
|
112
|
|
113
|
if ($occurrenceQuery) {
|
114
|
// @todo Fix $occurrenceQuery.
|
115
|
// $occurrenceQuery .= '&bbox=-180,-90,180,90';
|
116
|
$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
|
117
|
// $occurrenceQuery .= '&l=v:e_w_0';
|
118
|
// TODO add to cdm service?
|
119
|
$occurrenceQuery .= '&legend=0';
|
120
|
|
121
|
$out .= ' occurrenceQuery="' . $occurrenceQuery . '&' . $openlayers_map_query_string . '"';
|
122
|
}
|
123
|
|
124
|
if ($distributionQuery) {
|
125
|
$out .= ' distributionQuery="' . $distributionQuery . '&' . $openlayers_map_query_string . '"';
|
126
|
}
|
127
|
|
128
|
if ($legendFormatQuery) {
|
129
|
$out .= ' legendFormatQuery="' . $legendFormatQuery . '"';
|
130
|
}
|
131
|
|
132
|
$out .= '></div></div>';
|
133
|
|
134
|
// Showing map caption.
|
135
|
if ($map_caption) {
|
136
|
// FIXME: replace <br> by according css style.
|
137
|
$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />';
|
138
|
$out .= '</div>';
|
139
|
}
|
140
|
return $out;
|
141
|
}
|
142
|
|
143
|
|
144
|
|
145
|
/**
|
146
|
* @todo Enter description here ...
|
147
|
*
|
148
|
* @param unknown_type $width
|
149
|
* @param unknown_type $bounding_box
|
150
|
* @param unknown_type $occurrenceQuery
|
151
|
* @param unknown_type $distributionQuery
|
152
|
* @param unknown_type $legendFormatQuery
|
153
|
* @param unknown_type $map_caption
|
154
|
*
|
155
|
* @return unknown
|
156
|
*/
|
157
|
function get_image_map($width, $bounding_box = FALSE, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE) {
|
158
|
|
159
|
// Additional query parameters as set in the data portal admin section.
|
160
|
$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
|
161
|
|
162
|
$query_string = '&image=true&recalculate=false&legend=1&ms=' . $width
|
163
|
. ($bounding_box ? '&bbox=' . $bounding_box : '')
|
164
|
. ($labels_on ? '&label=' . $labels_on : '');
|
165
|
|
166
|
if ($map_caption) {
|
167
|
$query_string .= '&mlp=3&mc_s=Georgia,15,blue&mc=' . $map_caption;
|
168
|
}
|
169
|
|
170
|
if (get_edit_map_service_version_number() >= 1.1) {
|
171
|
|
172
|
// Either occurrence or distribution - combined maps will be possible
|
173
|
// in the future.
|
174
|
if ($occurrenceQuery) {
|
175
|
// @todo Fix $occurrenceQuery.
|
176
|
$occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
|
177
|
// $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
|
178
|
// Will be replaced below.. HACK!!!
|
179
|
$occurrenceQuery .= '&l=tdwg4&as=';
|
180
|
|
181
|
$query_string .= "&" . $occurrenceQuery;
|
182
|
}
|
183
|
elseif ($distributionQuery) {
|
184
|
$query_string .= "&" . $distributionQuery;
|
185
|
}
|
186
|
|
187
|
// Apply Plain Image map settings special for version >= 1.1.
|
188
|
/*
|
189
|
example : title=a:Naturalized++non-invasive
|
190
|
&ad=cyprusdivs:bdcode:a:5&as=a:ff9900,,0.1,&l=tdwg4
|
191
|
&ms=500&bbox=32,34,35,36&img=true&legend=1&mlp=3
|
192
|
&mc_s=Georgia,15,blue&mc=&recalculate=false
|
193
|
|
194
|
http://edit.br.fgov.be/edit_wp5/v1/rest_gen.php?
|
195
|
l=background_gis:b,cyprusdivs&ad=cyprusdivs%3Abdcode%3Aa%3A8%2C4
|
196
|
&as=a%3A339966%2C%2C0.1%2C|b:0000ff,,
|
197
|
&bbox=32%2C34%2C35%2C36&img=true&legend=1&mc=&mc_s=Georgia%2C15%2Cblue
|
198
|
&mlp=3&ms=500&recalculate=false&title=a%3Aindigenous
|
199
|
*/
|
200
|
|
201
|
$map_service_script_name = "rest_gen.php";
|
202
|
|
203
|
$bgcolor_areaStyleId = "y";
|
204
|
$baselayer_areaStyleId = "z";
|
205
|
$bgcolor_layer = '';
|
206
|
$additional_area_styles = array();
|
207
|
|
208
|
// Background color:
|
209
|
if (variable_get('map_bg_color', '')) {
|
210
|
$bgcolor_layer = "background_gis:" . $bgcolor_areaStyleId;
|
211
|
$additional_area_styles[] = $bgcolor_areaStyleId . ":" . variable_get('map_bg_color', '') . ",,";
|
212
|
}
|
213
|
|
214
|
// TODO HACK to replace the default base layer which currently is tdwg4 !!!
|
215
|
// only needed for distribution maps.
|
216
|
if (strpos($query_string, "?l=") !== FALSE) {
|
217
|
$layer_param_token = "?l=";
|
218
|
}
|
219
|
else {
|
220
|
$layer_param_token = "&l=";
|
221
|
}
|
222
|
if (strpos($query_string, "?as=") !== FALSE) {
|
223
|
$areystyle_param_token = "?as=";
|
224
|
}
|
225
|
else {
|
226
|
$areystyle_param_token = "&as=";
|
227
|
}
|
228
|
if (variable_get('map_base_layer', '')) {
|
229
|
$query_string = str_replace($layer_param_token . "tdwg4", "$layer_param_token" . variable_get('map_base_layer', '') . ":" . $baselayer_areaStyleId, $query_string);
|
230
|
}
|
231
|
else {
|
232
|
$query_string = str_replace($layer_param_token . "tdwg4", $layer_param_token . "tdwg4:" . $baselayer_areaStyleId . ",", $query_string);
|
233
|
}
|
234
|
|
235
|
if ($bgcolor_layer) {
|
236
|
$query_string = str_replace($layer_param_token, $layer_param_token . $bgcolor_layer . ",", $query_string);
|
237
|
}
|
238
|
|
239
|
if (variable_get('map_base_layer_style', '')) {
|
240
|
$additional_area_styles[] = $baselayer_areaStyleId . ":" . variable_get('map_base_layer_style', '');
|
241
|
}
|
242
|
|
243
|
foreach ($additional_area_styles as $as) {
|
244
|
$query_string = str_replace($areystyle_param_token, $areystyle_param_token . $as . "|", $query_string);
|
245
|
}
|
246
|
|
247
|
}
|
248
|
else {
|
249
|
// Pre 1.1. version of map service.
|
250
|
if ($occurrenceQuery) {
|
251
|
|
252
|
$map_service_script_name = "point.php";
|
253
|
|
254
|
// Fix $occurrenceQuery.
|
255
|
$occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
|
256
|
// $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
|
257
|
$occurrenceQuery .= '&l=v:e_w_0';
|
258
|
$query_string .= "&" . $occurrenceQuery;
|
259
|
}
|
260
|
elseif ($distributionQuery) {
|
261
|
$query_string .= "&" . $distributionQuery;
|
262
|
$map_service_script_name = "areas.php";
|
263
|
}
|
264
|
}
|
265
|
|
266
|
$mapUri = url(get_edit_map_service_full_uri() . '/' . $map_service_script_name . '?' . $query_string);
|
267
|
$out = '<img class="distribution_map" src="' . $mapUri . '" alt="Map" />';
|
268
|
// Showing map caption.
|
269
|
if ($map_caption) {
|
270
|
// FIXME: replace <br> by according css style.
|
271
|
$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />';
|
272
|
$out .= '</div>';
|
273
|
}
|
274
|
|
275
|
return $out;
|
276
|
}
|
277
|
|
278
|
|