1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This is the basic engine for the Google Map |
4
|
|
|
* |
5
|
|
|
* There are three options |
6
|
|
|
* 1. setAddress: set address |
7
|
|
|
* 2. setPageDataObjectSet: set Page Data List (who have geo points as children) |
8
|
|
|
* 3. setPoints: set Points Directly Class = GoogleMapLocationsObject |
9
|
|
|
* |
10
|
|
|
* Extras include: |
11
|
|
|
* 1. setTitleOfMap: set title |
12
|
|
|
* 2. setWhereStatementDescription: set where statement |
13
|
|
|
* 3. setFilteredClassNameArray: set an array of classnames |
14
|
|
|
* |
15
|
|
|
* The static configs are explained in googlemap/_config/googlemap.yml.example |
16
|
|
|
* |
17
|
|
|
* |
18
|
|
|
**/ |
19
|
|
|
class GoogleMap extends ViewableData |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
|
24
|
|
|
################################ |
25
|
|
|
# SETTINGS |
26
|
|
|
################################ |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/* BASIC MAP SETTINGS */ |
30
|
|
|
private static $api_version = '3'; |
|
|
|
|
31
|
|
|
private static $google_map_api_key = ""; |
|
|
|
|
32
|
|
|
private static $default_latitude = 0.000000001; //MOVE TO SITECONFIG |
|
|
|
|
33
|
|
|
private static $default_longitude = 0.0000000001; //MOVE TO SITECONFIG |
|
|
|
|
34
|
|
|
private static $default_zoom = 2; //MOVE TO SITECONFIG |
|
|
|
|
35
|
|
|
private static $google_map_width = 0; |
|
|
|
|
36
|
|
|
private static $google_map_height = 0; |
|
|
|
|
37
|
|
|
|
38
|
|
|
/* MAP CONTROLS*/ |
39
|
|
|
private static $map_type_default = 0; //MOVE TO SITECONFIG |
|
|
|
|
40
|
|
|
private static $view_finder_size = 100; //MOVE TO SITECONFIG |
|
|
|
|
41
|
|
|
private static $map_add_type_control = false; //MOVE TO SITECONFIG |
|
|
|
|
42
|
|
|
private static $map_control_size_one_to_three = 3; //MOVE TO SITECONFIG |
|
|
|
|
43
|
|
|
private static $map_scale_info_size_in_pixels = 100; //MOVE TO SITECONFIG |
|
|
|
|
44
|
|
|
|
45
|
|
|
/* INFORMATION AROUND THE MAP */ |
46
|
|
|
private static $default_title = ""; //MOVE TO SITECONFIG |
|
|
|
|
47
|
|
|
private static $default_where_statement_description = ""; //MOVE TO SITECONFIG |
|
|
|
|
48
|
|
|
private static $no_status_at_all = true; //MOVE TO SITECONFIG |
|
|
|
|
49
|
|
|
private static $add_kml_link = false; //MOVE TO SITECONFIG |
|
|
|
|
50
|
|
|
private static $hidden_layers_removed_from_list = false; |
|
|
|
|
51
|
|
|
private static $change_page_title = false; //MOVE TO SITECONFIG |
|
|
|
|
52
|
|
|
private static $number_of_items_before_showing_list = 1; //MOVE TO SITECONFIG |
|
|
|
|
53
|
|
|
private static $main_div_id = "GoogleMapDiv"; |
|
|
|
|
54
|
|
|
private static $title_div_id = ""; |
|
|
|
|
55
|
|
|
private static $side_bar_div_id = ""; |
|
|
|
|
56
|
|
|
private static $drop_down_div_id =""; |
|
|
|
|
57
|
|
|
private static $layer_list_div_id = ""; |
|
|
|
|
58
|
|
|
private static $directions_div_id = ""; |
|
|
|
|
59
|
|
|
private static $status_div_id = ""; |
|
|
|
|
60
|
|
|
|
61
|
|
|
/* INFOWINDOW*/ |
62
|
|
|
private static $info_window_options = "{maxWidth:280, zoomLevel:17, mapTypeId: google.maps.MapTypeId.HYBRID}"; |
|
|
|
|
63
|
|
|
private static $add_antipodean = false; //MOVE TO SITECONFIG |
|
|
|
|
64
|
|
|
private static $add_directions = false; //MOVE TO SITECONFIG |
|
|
|
|
65
|
|
|
private static $add_current_address_finder_in_marker = false; //MOVE TO SITECONFIG |
|
|
|
|
66
|
|
|
private static $add_zoom_in_button = true; //MOVE TO SITECONFIG |
|
|
|
|
67
|
|
|
private static $ajax_info_window_text = "View Details"; //MOVE TO SITECONFIG |
|
|
|
|
68
|
|
|
|
69
|
|
|
/* MARKERS */ |
70
|
|
|
private static $add_points_to_map = false; |
|
|
|
|
71
|
|
|
private static $add_delete_marker_button = ""; |
|
|
|
|
72
|
|
|
private static $marker_options = "{bouncy:true,title: \"click me\"}"; |
|
|
|
|
73
|
|
|
private static $preload_images = false; |
|
|
|
|
74
|
|
|
|
75
|
|
|
/* ICONS */ |
76
|
|
|
private static $default_icon_url = ""; |
|
|
|
|
77
|
|
|
private static $icon_folder = "/googlemap/images/icons/"; |
|
|
|
|
78
|
|
|
private static $icon_width = 20; |
|
|
|
|
79
|
|
|
private static $icon_height = 34; |
|
|
|
|
80
|
|
|
private static $icon_extension = "png"; |
|
|
|
|
81
|
|
|
private static $icon_max_count = 12; |
|
|
|
|
82
|
|
|
|
83
|
|
|
/* POLYS */ |
84
|
|
|
private static $line_colour = "#000"; |
|
|
|
|
85
|
|
|
private static $line_width = 12; |
|
|
|
|
86
|
|
|
private static $line_opacity = 0.5; |
|
|
|
|
87
|
|
|
private static $fill_colour = "#ffccff"; |
|
|
|
|
88
|
|
|
private static $fill_opacity = 0.5; |
|
|
|
|
89
|
|
|
private static $poly_icon = ""; |
|
|
|
|
90
|
|
|
|
91
|
|
|
/* STATIC MAP */ |
92
|
|
|
private static $static_map_settings = "maptype=roadmap"; |
|
|
|
|
93
|
|
|
private static $static_icon = ""; |
|
|
|
|
94
|
|
|
private static $save_static_map_locally = false; |
|
|
|
|
95
|
|
|
|
96
|
|
|
/* ADDRESS FINDER */ |
97
|
|
|
private static $add_address_finder = false; //MOVE TO SITECONFIG |
|
|
|
|
98
|
|
|
private static $default_country_code = "nz"; // see https://developers.google.com/maps/documentation/geocoding/#RegionCodes |
|
|
|
|
99
|
|
|
private static $number_shown_in_around_me = 7; //MOVE TO SITECONFIG |
|
|
|
|
100
|
|
|
private static $max_radius_for_show_around_me = 20000; |
|
|
|
|
101
|
|
|
|
102
|
|
|
/* DIRECTIONS SETTINGS */ |
103
|
|
|
private static $style_sheet_url = ""; |
|
|
|
|
104
|
|
|
private static $locale_for_results = "en_NZ"; |
|
|
|
|
105
|
|
|
|
106
|
|
|
/* SERVER SETTINGS */ |
107
|
|
|
private static $lng_form_field_id = ""; |
|
|
|
|
108
|
|
|
private static $lat_form_field_id = ""; |
|
|
|
|
109
|
|
|
|
110
|
|
|
|
111
|
|
|
|
112
|
|
|
|
113
|
|
|
|
114
|
|
|
|
115
|
|
|
|
116
|
|
|
|
117
|
|
|
|
118
|
|
|
|
119
|
|
|
################################ |
120
|
|
|
# TEMPATE METHODS |
121
|
|
|
################################ |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return String |
|
|
|
|
125
|
|
|
*/ |
126
|
|
|
public function Link() |
127
|
|
|
{ |
128
|
|
|
$page = Controller::curr(); |
129
|
|
|
if ($page) { |
130
|
|
|
return $page->Link(); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* function name for map... |
137
|
|
|
* @var String |
138
|
|
|
*/ |
139
|
|
|
protected $myMapFunctionName = "GMO"; |
140
|
|
|
public function setMyMapFunctionName($a) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
$this->myMapFunctionName = $s; |
|
|
|
|
143
|
|
|
} |
144
|
|
|
public function MyMapFunctionName() |
145
|
|
|
{ |
146
|
|
|
return $this->getMyMapFunctionName(false); |
147
|
|
|
} |
148
|
|
|
public function MyInstanceName() |
149
|
|
|
{ |
150
|
|
|
return $this->getMyMapFunctionName(true); |
151
|
|
|
} |
152
|
|
|
public function getMyMapFunctionName($instanceName = false) |
153
|
|
|
{ |
154
|
|
|
if ($instanceName) { |
155
|
|
|
$var = 'load_my_map_'.$this->myMapFunctionName; |
156
|
|
|
} else { |
157
|
|
|
$var = $this->myMapFunctionName; |
158
|
|
|
} |
159
|
|
|
return $var; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* title of map |
164
|
|
|
* @var string |
165
|
|
|
*/ |
166
|
|
|
protected $titleOfMap = ""; |
167
|
|
|
|
168
|
|
|
public function setTitleOfMap($s) |
169
|
|
|
{ |
170
|
|
|
$this->titleOfMap = $s; |
171
|
|
|
} |
172
|
|
|
public function TitleOfMap() |
173
|
|
|
{ |
174
|
|
|
return $this->getTitleOfMap(); |
175
|
|
|
} |
176
|
|
|
public function getTitleOfMap() |
177
|
|
|
{ |
178
|
|
|
return $this->titleOfMap; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* title of map |
183
|
|
|
* @var string |
184
|
|
|
*/ |
185
|
|
|
protected $noDataPointsMessage = ""; |
186
|
|
|
|
187
|
|
|
public function setNoDataPointsMessage($s) |
188
|
|
|
{ |
189
|
|
|
$this->noDataPointsMessage = $s; |
190
|
|
|
} |
191
|
|
|
public function NoDataPointsMessage() |
192
|
|
|
{ |
193
|
|
|
return $this->getNoDataPointsMessage(); |
194
|
|
|
} |
195
|
|
|
public function getNoDataPointsMessage() |
196
|
|
|
{ |
197
|
|
|
return $this->noDataPointsMessage; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* used for static and non-static maps, hence defined only once. |
203
|
|
|
* @return Int |
|
|
|
|
204
|
|
|
*/ |
205
|
|
|
public function GoogleMapWidth() |
206
|
|
|
{ |
207
|
|
|
return Config::inst()->get("GoogleMap", "google_map_width"); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* used for static and non-static maps, hence defined only once. |
212
|
|
|
* @return Int |
|
|
|
|
213
|
|
|
*/ |
214
|
|
|
public function GoogleMapHeight() |
215
|
|
|
{ |
216
|
|
|
return Config::inst()->get("GoogleMap", "google_map_height"); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return Boolean |
|
|
|
|
221
|
|
|
*/ |
222
|
|
|
public function AddAddressFinder() |
223
|
|
|
{ |
224
|
|
|
return Config::inst()->get("GoogleMap", "add_address_finder"); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return Boolean |
|
|
|
|
229
|
|
|
*/ |
230
|
|
|
public function CanEdit($member = null) |
231
|
|
|
{ |
232
|
|
|
if ($this->getUpdateServerUrlDragend()) { |
233
|
|
|
if (Injector::inst()->get("GoogleMapLocationsObject")->canEdit($member)) { |
234
|
|
|
return true; |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @return String |
|
|
|
|
241
|
|
|
*/ |
242
|
|
|
public function TitleDivID() |
243
|
|
|
{ |
244
|
|
|
return Config::inst()->get("GoogleMap", "title_div_id"); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @return String |
|
|
|
|
249
|
|
|
*/ |
250
|
|
|
public function SideBarDivId() |
251
|
|
|
{ |
252
|
|
|
return Config::inst()->get("GoogleMap", "side_bar_div_id"); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @return String |
|
|
|
|
257
|
|
|
*/ |
258
|
|
|
public function DropDownDivId() |
259
|
|
|
{ |
260
|
|
|
return Config::inst()->get("GoogleMap", "drop_down_div_id"); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return String |
|
|
|
|
265
|
|
|
*/ |
266
|
|
|
public function LayerListDivId() |
267
|
|
|
{ |
268
|
|
|
return Config::inst()->get("GoogleMap", "layer_list_div_id"); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @return String |
|
|
|
|
273
|
|
|
*/ |
274
|
|
|
public function DirectionsDivId() |
275
|
|
|
{ |
276
|
|
|
return Config::inst()->get("GoogleMap", "directions_div_id"); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @return String |
|
|
|
|
281
|
|
|
*/ |
282
|
|
|
public function StatusDivId() |
283
|
|
|
{ |
284
|
|
|
return Config::inst()->get("GoogleMap", "status_div_id"); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* |
289
|
|
|
* @var Boolean |
290
|
|
|
*/ |
291
|
|
|
public function AllowAddPointsToMap() |
292
|
|
|
{ |
293
|
|
|
$this->Config()->update("add_points_to_map", true); |
|
|
|
|
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @var ArrayList |
298
|
|
|
*/ |
299
|
|
|
protected $processedDataPointsForTemplate = null; |
300
|
|
|
public function setProcessedDataPointsForTemplate($s) |
301
|
|
|
{ |
302
|
|
|
$this->processedDataPointsForTemplate = $s; |
303
|
|
|
} |
304
|
|
|
public function ProcessedDataPointsForTemplate() |
305
|
|
|
{ |
306
|
|
|
return $this->getProcessedDataPointsForTemplate(); |
307
|
|
|
} |
308
|
|
|
public function getProcessedDataPointsForTemplate() |
309
|
|
|
{ |
310
|
|
|
return $this->processedDataPointsForTemplate; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @var string |
315
|
|
|
*/ |
316
|
|
|
protected $dataPointsXML = ''; |
317
|
|
|
protected function DataPointsXML() |
318
|
|
|
{ |
319
|
|
|
return $this->getDataPointsXML(); |
320
|
|
|
} |
321
|
|
|
protected function getDataPointsXML() |
322
|
|
|
{ |
323
|
|
|
$this->createDataPoints(); |
324
|
|
|
return $this->dataPointsXML; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
|
328
|
|
|
|
329
|
|
|
|
330
|
|
|
|
331
|
|
|
|
332
|
|
|
|
333
|
|
|
|
334
|
|
|
|
335
|
|
|
|
336
|
|
|
|
337
|
|
|
################################ |
338
|
|
|
# SETUP: LAYER MANAGEMENT |
339
|
|
|
################################ |
340
|
|
|
|
341
|
|
|
|
342
|
|
|
|
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @var ArrayList |
346
|
|
|
*/ |
347
|
|
|
protected $extraLayers = null; |
348
|
|
|
public function setExtraLayer($a) |
349
|
|
|
{ |
350
|
|
|
$this->extraLayers = $a; |
351
|
|
|
} |
352
|
|
|
public function getExtraLayers() |
353
|
|
|
{ |
354
|
|
|
return $this->extraLayers; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* @param String $title |
359
|
|
|
* @param String $link |
360
|
|
|
*/ |
361
|
|
|
public function addExtraLayer($title, $link) |
362
|
|
|
{ |
363
|
|
|
if (!$this->getExtraLayers()) { |
364
|
|
|
$this->extraLayers = new ArrayList(); |
365
|
|
|
} |
366
|
|
|
$this->extraLayers->push( |
367
|
|
|
new ArrayData( |
368
|
|
|
array( |
369
|
|
|
"Title" => $title, |
370
|
|
|
"Link" => $link, |
371
|
|
|
"MyInstanceName" => $this->MyInstanceName() |
372
|
|
|
) |
373
|
|
|
) |
374
|
|
|
); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* |
379
|
|
|
* @return ArrayList |
380
|
|
|
*/ |
381
|
|
|
public function AllExtraLayers() |
382
|
|
|
{ |
383
|
|
|
return $this->getExtraLayers(); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @var Array |
388
|
|
|
* Link => Title |
389
|
|
|
*/ |
390
|
|
|
protected $linksForData = array(); |
391
|
|
|
public function setLinksForData($a) |
392
|
|
|
{ |
393
|
|
|
$this->linksForData = $a; |
394
|
|
|
} |
395
|
|
|
public function getLinksForData() |
396
|
|
|
{ |
397
|
|
|
return $this->linksForData; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* @param string $linkForData |
402
|
|
|
* @param string $title |
403
|
|
|
*/ |
404
|
|
|
public function addLayer($linkForData, $title) |
405
|
|
|
{ |
406
|
|
|
$this->linksForData[$linkForData] = $title; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
|
410
|
|
|
|
411
|
|
|
|
412
|
|
|
|
413
|
|
|
|
414
|
|
|
|
415
|
|
|
################################ |
416
|
|
|
# SETUP: FILTERS AND POINTS PROVIDERS |
417
|
|
|
################################ |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* address being searched for |
421
|
|
|
* @var String |
422
|
|
|
*/ |
423
|
|
|
protected $address = ""; |
424
|
|
|
public function setAddress($v) |
425
|
|
|
{ |
426
|
|
|
$this->address = Convert::raw2js($v); |
|
|
|
|
427
|
|
|
} |
428
|
|
|
public function getAddress($v) |
|
|
|
|
429
|
|
|
{ |
430
|
|
|
return $this->address; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* sets the list of points through a list of parent pages |
435
|
|
|
* affected variable is: points |
436
|
|
|
* @param DataList | ArrayList $pageDataList |
437
|
|
|
*/ |
438
|
|
|
public function setPageDataObjectSet($pageDataList) |
439
|
|
|
{ |
440
|
|
|
if ($pageDataList->count()) { |
441
|
|
|
if ($pageDataList instanceof ArrayList) { |
442
|
|
|
$array = $pageDataList->map("ID", "ID"); |
443
|
|
|
} elseif ($pageDataList instanceof DataList) { |
444
|
|
|
$array = $pageDataList->map("ID", "ID")->toArray(); |
445
|
|
|
} else { |
446
|
|
|
user_error("Wrong format for pageDataList"); |
447
|
|
|
} |
448
|
|
|
$this->points = GoogleMapLocationsObject::get()->filter(array("ParentID" => $array)); |
|
|
|
|
449
|
|
|
$pageDataList = null; |
|
|
|
|
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* @var DataList |
456
|
|
|
*/ |
457
|
|
|
protected $points = null; |
458
|
|
|
public function setPoints($s) |
459
|
|
|
{ |
460
|
|
|
$this->points = $s; |
461
|
|
|
} |
462
|
|
|
public function getPoints() |
463
|
|
|
{ |
464
|
|
|
return $this->points; |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
|
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* a description of how the points were selected ... |
471
|
|
|
* @var String |
472
|
|
|
*/ |
473
|
|
|
protected $whereStatementDescription = ""; |
474
|
|
|
public function setWhereStatementDescription($s) |
475
|
|
|
{ |
476
|
|
|
$this->whereStatementDescription = $s; |
477
|
|
|
} |
478
|
|
|
public function getWhereStatementDescription() |
479
|
|
|
{ |
480
|
|
|
return $this->whereStatementDescription; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* filter for class names |
485
|
|
|
* @var Array |
486
|
|
|
*/ |
487
|
|
|
protected $filteredClassNameArray = array(); |
488
|
|
|
public function setFilteredClassNameArray($a) |
|
|
|
|
489
|
|
|
{ |
490
|
|
|
$this->filteredClassNameArray = $s; |
|
|
|
|
491
|
|
|
} |
492
|
|
|
public function getFilteredClassNameArray() |
493
|
|
|
{ |
494
|
|
|
return $this->filteredClassNameArray; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
|
498
|
|
|
|
499
|
|
|
|
500
|
|
|
|
501
|
|
|
|
502
|
|
|
|
503
|
|
|
################################ |
504
|
|
|
# MAP CHANGES |
505
|
|
|
################################ |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* @var String |
509
|
|
|
*/ |
510
|
|
|
protected $updateServerUrlAddressSearchPoint = "/googlemap/showaroundmexml/"; |
511
|
|
|
public function setUpdateServerUrlAddressSearchPoint($v) |
512
|
|
|
{ |
513
|
|
|
$this->updateServerUrlAddressSearchPoint = Director::absoluteBaseURL().$v; |
514
|
|
|
} |
515
|
|
|
public function getUpdateServerURLAddressSearchPoint() |
516
|
|
|
{ |
517
|
|
|
return $this->updateServerUrlAddressSearchPoint; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* @var String |
522
|
|
|
*/ |
523
|
|
|
protected $updateServerUrlDragend = ""; |
524
|
|
|
public function setUpdateServerUrlDragend($v) |
525
|
|
|
{ |
526
|
|
|
$this->updateServerUrlDragend = Director::absoluteBaseURL().$v; |
527
|
|
|
} |
528
|
|
|
public function getUpdateServerUrlDragend() |
529
|
|
|
{ |
530
|
|
|
return $this->updateServerUrlDragend; |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
|
534
|
|
|
|
535
|
|
|
|
536
|
|
|
|
537
|
|
|
|
538
|
|
|
|
539
|
|
|
|
540
|
|
|
|
541
|
|
|
|
542
|
|
|
################################ |
543
|
|
|
# LOADING |
544
|
|
|
################################ |
545
|
|
|
/** |
546
|
|
|
* this is a hack to avoid having multiple includes |
547
|
|
|
* @var Boolean |
548
|
|
|
*/ |
549
|
|
|
private static $_includes_are_done = false; |
550
|
|
|
|
551
|
|
|
public function loadGoogleMap() |
552
|
|
|
{ |
553
|
|
|
$js = ''; |
554
|
|
|
$this->loadDefaults(); |
555
|
|
|
if (!self::$_includes_are_done) { |
556
|
|
|
Requirements::themedCSS("googleMap", 'googlemap'); |
557
|
|
|
Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
558
|
|
|
$variableName = $this->getMyMapFunctionName(false); |
|
|
|
|
559
|
|
|
$instanceName = $this->getMyMapFunctionName(true); |
|
|
|
|
560
|
|
|
Requirements::javascript("googlemap/javascript/loadAjaxInfoWindow.js"); |
561
|
|
|
Requirements::insertHeadTags('<style type="text/css">v\:* {behavior:url(#default#VML);}</style>', "GoogleMapCustomHeadTag"); |
562
|
|
|
Requirements::javascript( |
563
|
|
|
"//maps.googleapis.com/maps/api/js" |
564
|
|
|
."?v=".Config::inst()->get("GoogleMap", "api_version") |
565
|
|
|
."&libraries=places" |
566
|
|
|
."&key=".Config::inst()->get('GoogleMap', 'google_map_api_key') |
567
|
|
|
); |
568
|
|
|
Requirements::javascript(THIRDPARTY_DIR.'/jquery-form/jquery.form.js'); |
569
|
|
|
Requirements::javascript("googlemap/javascript/googleMaps.js"); |
570
|
|
|
$js .= $this->createJavascript(); |
571
|
|
|
Requirements::customScript($js, "GoogleMapCustomScript"); |
572
|
|
|
self::$_includes_are_done = true; |
573
|
|
|
} |
574
|
|
|
return $this; |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
|
578
|
|
|
|
579
|
|
|
|
580
|
|
|
|
581
|
|
|
|
582
|
|
|
|
583
|
|
|
################################ |
584
|
|
|
# DATA POINTS MASSAGE |
585
|
|
|
################################ |
586
|
|
|
|
587
|
|
|
/** |
588
|
|
|
* sorts points by Latitude |
589
|
|
|
* @param boolean $reverse |
590
|
|
|
* |
591
|
|
|
* @return ArrayList |
592
|
|
|
*/ |
593
|
|
|
protected function orderItemsByLatitude($reverse = false) |
594
|
|
|
{ |
595
|
|
|
$unsortedSet = $this->getProcessedDataPointsForTemplate(); |
596
|
|
|
$sortedSet = new ArrayList(); |
597
|
|
|
if ($unsortedSet->count()) { |
598
|
|
|
foreach ($unsortedSet as $item) { |
599
|
|
|
$tempArray[$item->Latitude] = $item; |
|
|
|
|
600
|
|
|
} |
601
|
|
|
} |
602
|
|
|
ksort($tempArray); |
603
|
|
|
//not sure why this is a bit counter intuitive. |
604
|
|
|
//north to south is from high to low ... |
605
|
|
|
if (!$reverse) { |
606
|
|
|
$tempArray = array_reverse($tempArray); |
607
|
|
|
} |
608
|
|
|
foreach ($tempArray as $item) { |
609
|
|
|
$sortedSet->push($item); |
610
|
|
|
} |
611
|
|
|
return $sortedSet; |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
/** |
615
|
|
|
* |
616
|
|
|
* @return Int |
617
|
|
|
*/ |
618
|
|
|
public function getPointCount() |
619
|
|
|
{ |
620
|
|
|
if ($processedPoints = $this->getProcessedDataPointsForTemplate()) { |
621
|
|
|
return $processedPoints->count(); |
622
|
|
|
} elseif ($points = $this->getPoints()) { |
623
|
|
|
return $points->count(); |
624
|
|
|
} |
625
|
|
|
return 0; |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* @return Boolean |
630
|
|
|
*/ |
631
|
|
|
public function EnoughPointsForAList() |
632
|
|
|
{ |
633
|
|
|
return $this->getPointCount() >= $this->Config()->get("number_of_items_before_showing_list") ? true : false; |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* must be public |
639
|
|
|
* does not return the datapoints XML |
640
|
|
|
* but loads it into variables... |
641
|
|
|
* @return Boolean |
642
|
|
|
*/ |
643
|
|
|
public function createDataPoints() |
644
|
|
|
{ |
645
|
|
|
if($this->dataPointsXML === '') { |
646
|
|
|
$this->loadDefaults(); |
647
|
|
|
$idArray = array(); |
648
|
|
|
$bestZoom = $this->Config()->get("default_zoom"); |
649
|
|
|
$averageLatitude = 0; |
650
|
|
|
$averageLongitude = 0; |
651
|
|
|
$count = 0; |
652
|
|
|
$pointsXml = ''; |
653
|
|
|
//width |
654
|
|
|
$totalCount = $this->getPointCount(); |
655
|
|
|
$filterFree = count($this->filteredClassNameArray) ? false : true; |
656
|
|
|
$averageLongitudeArray = array(); |
657
|
|
|
$averageLatitudeArray = array(); |
658
|
|
|
if ($totalCount > 0 && $totalCount < 10000) { |
659
|
|
|
$this->processedDataPointsForTemplate = new ArrayList(); |
660
|
|
|
foreach ($this->getPoints() as $dataPoint) { |
661
|
|
|
$dataPoint->addParentData(); |
662
|
|
|
if ($filterFree || in_array($dataPoint->ClassName, $this->filteredClassNameArray)) { |
663
|
|
|
if (! in_array($dataPoint->ID, $idArray)) { |
664
|
|
|
if ($dataPoint->Longitude && $dataPoint->Latitude) { |
665
|
|
|
$dataLine = '<Point><coordinates>'.$dataPoint->Longitude.','.$dataPoint->Latitude.'</coordinates></Point>'; |
666
|
|
|
$link = ''; |
|
|
|
|
667
|
|
|
if ($dataPoint->Link) { |
668
|
|
|
$link = $dataPoint->getAjaxInfoWindowLink(); |
|
|
|
|
669
|
|
|
} |
670
|
|
|
$staticIcon = ''; |
|
|
|
|
671
|
|
|
if ($dataPoint->staticIcon) { |
672
|
|
|
$staticIcon = $dataPoint->staticIcon; |
|
|
|
|
673
|
|
|
} else { |
674
|
|
|
$staticIcon = $this->Config()->get("static_icon"); |
|
|
|
|
675
|
|
|
} |
676
|
|
|
$center = round($dataPoint->Latitude, 6).",".round($dataPoint->Longitude, 6); |
677
|
|
|
//get the center IF there is only one point... |
678
|
|
|
if (!$count) { |
679
|
|
|
$defaultCenter = $center; |
|
|
|
|
680
|
|
|
} |
681
|
|
|
if (!$dataPoint->Name) { |
682
|
|
|
$dataPoint->Name = "no name"; |
683
|
|
|
} |
684
|
|
|
$pointsXml .= |
685
|
|
|
'<Placemark>'. |
686
|
|
|
'<id>'.$dataPoint->ID.'</id>'. |
687
|
|
|
'<name>'.Convert::raw2xml($dataPoint->Name).'</name>'. |
688
|
|
|
$dataLine. |
689
|
|
|
'<description><![CDATA[ '.$dataPoint->getAjaxInfoWindowLink().']]></description>'. |
690
|
|
|
'</Placemark>'; |
691
|
|
|
$this->processedDataPointsForTemplate->push($dataPoint); |
692
|
|
|
$averageLatitudeArray[] = $dataPoint->Longitude; |
693
|
|
|
$averageLongitudeArray[] = $dataPoint->Latitude; |
694
|
|
|
$count++; |
695
|
|
|
} |
696
|
|
|
} |
697
|
|
|
} |
698
|
|
|
$idArray[$dataPoint->ID] = $dataPoint->ID; |
699
|
|
|
} |
700
|
|
|
$averageLongitude = array_sum($averageLongitudeArray) / count($averageLongitudeArray); |
701
|
|
|
$averageLatitude = array_sum($averageLatitudeArray) / count($averageLatitudeArray); |
702
|
|
|
|
703
|
|
|
$this->processedDataPointsForTemplate = $this->orderItemsByLatitude($this->processedDataPointsForTemplate); |
|
|
|
|
704
|
|
|
} |
705
|
|
|
if(! $pointsXml) { |
706
|
|
|
$pointsXml = '<errormessage>'.$this->getNoDataPointsMessage().'</errormessage>'; |
707
|
|
|
} |
708
|
|
|
if (!$averageLongitude) { |
709
|
|
|
$averageLongitude = $this->config()->get("default_longitude"); |
710
|
|
|
} |
711
|
|
|
if (!$averageLatitude) { |
712
|
|
|
$averageLatitude = $this->config()->get("default_latitude"); |
713
|
|
|
} |
714
|
|
|
$this->dataPointsXML = |
715
|
|
|
'<mapinfo>'.'<title>'.$this->getTitleOfMap().'</title>' |
716
|
|
|
.'<longitude>'.number_format($averageLongitude - 0, 12, ".", "").'</longitude>' |
717
|
|
|
.'<latitude>'.number_format($averageLatitude - 0, 9, ".", "").'</latitude>' |
718
|
|
|
.'<zoom>'.$bestZoom.'</zoom>' |
719
|
|
|
.'<pointcount>'.$count.'</pointcount>' |
720
|
|
|
.'<info>'.$this->getWhereStatementDescription().'</info>' |
721
|
|
|
.'</mapinfo>' |
722
|
|
|
.$pointsXml; |
723
|
|
|
} |
724
|
|
|
|
725
|
|
|
return true; |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
/** |
729
|
|
|
* @param String staticVariablename |
730
|
|
|
* @return String (Javascript) |
731
|
|
|
*/ |
732
|
|
|
protected function createJavascript() |
733
|
|
|
{ |
734
|
|
|
$variableName = $this->getMyMapFunctionName(false); |
|
|
|
|
735
|
|
|
$instanceName = $this->getMyMapFunctionName(true); |
|
|
|
|
736
|
|
|
$js = ' |
737
|
|
|
if(typeof GoogleMapConstructors === "undefined"){ |
738
|
|
|
GoogleMapConstructors = []; |
739
|
|
|
} |
740
|
|
|
GoogleMapConstructors.push( |
741
|
|
|
{ |
742
|
|
|
divID: "'.$this->config()->get("main_div_id").'", |
743
|
|
|
layers: [], |
744
|
|
|
address: "", |
745
|
|
|
options: { |
746
|
|
|
/* HELPDIVS */ |
747
|
|
|
sideBarId:"'.$this->config()->get("side_bar_div_id").'", |
748
|
|
|
dropBoxId:"'.$this->config()->get("drop_down_div_id").'", |
749
|
|
|
titleId:"'.$this->config()->get("title_div_id").'", |
750
|
|
|
layerListId:"'.$this->config()->get("layer_list_div_id").'", |
751
|
|
|
directionsDivId:"'.$this->config()->get("directions_div_id").'", |
752
|
|
|
statusDivId:"'.$this->config()->get("status_div_id").'", |
753
|
|
|
noStatusAtAll:'.$this->showFalseOrTrue($this->config()->get("no_status_at_all")).', |
754
|
|
|
addKmlLink:'.$this->showFalseOrTrue($this->config()->get("add_kml_link")).', |
755
|
|
|
hiddenLayersRemovedFromList:'.$this->showFalseOrTrue($this->config()->get("hidden_layers_removed_from_list")).', |
756
|
|
|
|
757
|
|
|
/* PAGE*/ |
758
|
|
|
changePageTitle:'.$this->showFalseOrTrue($this->config()->get("change_page_title")).', |
759
|
|
|
defaultTitle:"'.$this->config()->get("default_title").'", |
760
|
|
|
|
761
|
|
|
/* INFOWINDOW*/ |
762
|
|
|
infoWindowOptions:'.$this->config()->get("info_window_options").', |
763
|
|
|
addAntipodean:'.$this->showFalseOrTrue($this->config()->get("add_antipodean")).', |
764
|
|
|
addDirections:'.$this->showFalseOrTrue($this->config()->get("add_directions")).', |
765
|
|
|
addCurrentAddressFinder:'.$this->showFalseOrTrue($this->config()->get("add_current_address_finder_in_marker")).', |
766
|
|
|
addZoomInButton:"'.$this->config()->get("add_zoom_in_button").'", |
767
|
|
|
|
768
|
|
|
/* MARKER */ |
769
|
|
|
addPointsToMap:'.$this->showFalseOrTrue($this->config()->get("add_points_to_map")).', |
770
|
|
|
addDeleteMarkerButton:"'.$this->config()->get("add_delete_marker_button").'", |
771
|
|
|
markerOptions: '.$this->config()->get("marker_options").', |
772
|
|
|
preloadImages:'.$this->showFalseOrTrue($this->config()->get("preload_images")).', |
773
|
|
|
|
774
|
|
|
/* ICONS */ |
775
|
|
|
defaultIconUrl: "'.$this->config()->get("default_icon_url").'", |
776
|
|
|
iconFolder: "'.$this->config()->get("icon_folder").'", |
777
|
|
|
iconWidth:'.$this->config()->get("icon_width").', |
778
|
|
|
iconHeight:'.$this->config()->get("icon_height").', |
779
|
|
|
iconExtension:"'.$this->config()->get("icon_extension").'", |
780
|
|
|
iconMaxCount:'.$this->config()->get("icon_max_count").', |
781
|
|
|
|
782
|
|
|
/* POLYS */ |
783
|
|
|
lineColour: "'.$this->config()->get("line_colour").'", |
784
|
|
|
lineWidth: "'.$this->config()->get("line_width").'", |
785
|
|
|
lineOpacity: "'.$this->config()->get("line_opacity").'", |
786
|
|
|
fillColour: "'.$this->config()->get("fill_colour").'", |
787
|
|
|
fillOpacity: "'.$this->config()->get("fill_opacity").'", |
788
|
|
|
polyIcon: "'.$this->config()->get("poly_icon").'", |
789
|
|
|
|
790
|
|
|
/* MAP*/ |
791
|
|
|
mapTypeDefault: '.intval($this->config()->get("map_type_default")-0).', |
792
|
|
|
viewFinderSize:'.intval($this->config()->get("view_finder_size") - 0).', |
793
|
|
|
mapAddTypeControl:'.$this->showFalseOrTrue($this->config()->get("map_add_type_control")).', |
794
|
|
|
mapControlSizeOneToThree:'.$this->config()->get("map_control_size_one_to_three").', |
795
|
|
|
mapScaleInfoSizeInPixels:'.intval($this->config()->get("map_scale_info_size_in_pixels") - 0).', |
796
|
|
|
|
797
|
|
|
/* START POSITION */ |
798
|
|
|
defaultLatitude:'.number_format($this->config()->get("default_latitude") - 0, 9, ".", "").', |
799
|
|
|
defaultLongitude:'.number_format($this->config()->get("default_longitude") - 0, 12, ".", "").', |
800
|
|
|
defaultZoom:'.intval($this->config()->get("default_zoom") - 0).', |
801
|
|
|
|
802
|
|
|
/* SERVER INTERACTION */ |
803
|
|
|
updateServerUrlAddressSearchPoint: "'.$this->getUpdateServerUrlAddressSearchPoint(). '", |
804
|
|
|
updateServerUrlDragend: "'.$this->getUpdateServerUrlDragend().'", |
805
|
|
|
latFormFieldId:"'.$this->config()->get("lat_form_field_id").'", |
806
|
|
|
lngFormFieldId:"'.$this->config()->get("lng_form_field_id").'", |
807
|
|
|
|
808
|
|
|
/* ADDRESS FORM */ |
809
|
|
|
addAddressFinder:'.$this->showFalseOrTrue($this->config()->get("add_address_finder")).', |
810
|
|
|
defaultCountryCode:"'.$this->config()->get("default_country_code").'", |
811
|
|
|
|
812
|
|
|
/* DIRECTIONS */ |
813
|
|
|
styleSheetUrl: "'.$this->config()->get("style_sheet_url").'", |
814
|
|
|
localeForResults: "'.$this->config()->get("locale_for_results").'" |
815
|
|
|
} |
816
|
|
|
} |
817
|
|
|
);'; |
818
|
|
|
if ($this->linksForData && count($this->linksForData)) { |
|
|
|
|
819
|
|
|
foreach ($this->linksForData as $link => $title) { |
820
|
|
|
$js .= ' |
821
|
|
|
GoogleMapConstructors[GoogleMapConstructors.length-1].layers.push( |
822
|
|
|
{ |
823
|
|
|
link: '.Convert::raw2json(Director::absoluteURL($link)).', |
824
|
|
|
title: '.Convert::raw2json($title).' |
825
|
|
|
} |
826
|
|
|
);'; |
827
|
|
|
} |
828
|
|
|
} elseif ($this->address) { |
829
|
|
|
$js .= ' |
830
|
|
|
GoogleMapConstructors[GoogleMapConstructors.length-1].address = \''.$this->address.'\''; |
831
|
|
|
} |
832
|
|
|
return $js; |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* turns 0 into false and 1 into true |
837
|
|
|
* @param Mixed |
838
|
|
|
* @return string (true|false) |
839
|
|
|
*/ |
840
|
|
|
protected function showFalseOrTrue($v) |
841
|
|
|
{ |
842
|
|
|
if ($v && $v !== "false" && $v !== "0" && $v !== 0) { |
843
|
|
|
return "true"; |
844
|
|
|
} else { |
845
|
|
|
return "false"; |
846
|
|
|
} |
847
|
|
|
} |
848
|
|
|
|
849
|
|
|
/** |
850
|
|
|
* load some defaults |
851
|
|
|
*/ |
852
|
|
|
protected function loadDefaults() |
853
|
|
|
{ |
854
|
|
|
if (!isset($this->whereStatementDescription)) { |
855
|
|
|
$this->whereStatementDescription = $this->Config()->get("default_where_statement_description"); |
856
|
|
|
} |
857
|
|
|
if (!isset($this->titleOfMap) || !$this->titleOfMap) { |
858
|
|
|
$this->titleOfMap = $this->Config()->get("default_title"); |
859
|
|
|
} |
860
|
|
|
} |
861
|
|
|
} |
862
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.