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 string |
|
|
|
|
204
|
|
|
*/ |
205
|
|
|
public function GoogleMapDivID() |
206
|
|
|
{ |
207
|
|
|
return Config::inst()->get("GoogleMap", "main_div_id"); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* used for static and non-static maps, hence defined only once. |
212
|
|
|
* @return Int |
|
|
|
|
213
|
|
|
*/ |
214
|
|
|
public function GoogleMapWidth() |
215
|
|
|
{ |
216
|
|
|
return Config::inst()->get("GoogleMap", "google_map_width"); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* used for static and non-static maps, hence defined only once. |
221
|
|
|
* @return Int |
|
|
|
|
222
|
|
|
*/ |
223
|
|
|
public function GoogleMapHeight() |
224
|
|
|
{ |
225
|
|
|
return Config::inst()->get("GoogleMap", "google_map_height"); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @return Boolean |
|
|
|
|
230
|
|
|
*/ |
231
|
|
|
public function AddAddressFinder() |
232
|
|
|
{ |
233
|
|
|
return Config::inst()->get("GoogleMap", "add_address_finder"); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @return Boolean |
|
|
|
|
238
|
|
|
*/ |
239
|
|
|
public function CanEdit($member = null) |
240
|
|
|
{ |
241
|
|
|
if ($this->getUpdateServerUrlDragend()) { |
242
|
|
|
if (Injector::inst()->get("GoogleMapLocationsObject")->canEdit($member)) { |
243
|
|
|
return true; |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return String |
|
|
|
|
250
|
|
|
*/ |
251
|
|
|
public function TitleDivID() |
252
|
|
|
{ |
253
|
|
|
return Config::inst()->get("GoogleMap", "title_div_id"); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @return String |
|
|
|
|
258
|
|
|
*/ |
259
|
|
|
public function SideBarDivId() |
260
|
|
|
{ |
261
|
|
|
return Config::inst()->get("GoogleMap", "side_bar_div_id"); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @return String |
|
|
|
|
266
|
|
|
*/ |
267
|
|
|
public function DropDownDivId() |
268
|
|
|
{ |
269
|
|
|
return Config::inst()->get("GoogleMap", "drop_down_div_id"); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @return String |
|
|
|
|
274
|
|
|
*/ |
275
|
|
|
public function LayerListDivId() |
276
|
|
|
{ |
277
|
|
|
return Config::inst()->get("GoogleMap", "layer_list_div_id"); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @return String |
|
|
|
|
282
|
|
|
*/ |
283
|
|
|
public function DirectionsDivId() |
284
|
|
|
{ |
285
|
|
|
return Config::inst()->get("GoogleMap", "directions_div_id"); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @return String |
|
|
|
|
290
|
|
|
*/ |
291
|
|
|
public function StatusDivId() |
292
|
|
|
{ |
293
|
|
|
return Config::inst()->get("GoogleMap", "status_div_id"); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* |
298
|
|
|
* @var Boolean |
299
|
|
|
*/ |
300
|
|
|
public function AllowAddPointsToMap() |
301
|
|
|
{ |
302
|
|
|
$this->Config()->update("add_points_to_map", true); |
|
|
|
|
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @var ArrayList |
307
|
|
|
*/ |
308
|
|
|
protected $processedDataPointsForTemplate = null; |
309
|
|
|
public function setProcessedDataPointsForTemplate($s) |
310
|
|
|
{ |
311
|
|
|
$this->processedDataPointsForTemplate = $s; |
312
|
|
|
} |
313
|
|
|
public function ProcessedDataPointsForTemplate() |
314
|
|
|
{ |
315
|
|
|
return $this->getProcessedDataPointsForTemplate(); |
316
|
|
|
} |
317
|
|
|
public function getProcessedDataPointsForTemplate() |
318
|
|
|
{ |
319
|
|
|
return $this->processedDataPointsForTemplate; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @var string |
324
|
|
|
*/ |
325
|
|
|
protected $dataPointsXML = ''; |
326
|
|
|
protected function DataPointsXML() |
327
|
|
|
{ |
328
|
|
|
return $this->getDataPointsXML(); |
329
|
|
|
} |
330
|
|
|
protected function getDataPointsXML() |
331
|
|
|
{ |
332
|
|
|
$this->createDataPoints(); |
333
|
|
|
return $this->dataPointsXML; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
|
337
|
|
|
|
338
|
|
|
|
339
|
|
|
|
340
|
|
|
|
341
|
|
|
|
342
|
|
|
|
343
|
|
|
|
344
|
|
|
|
345
|
|
|
|
346
|
|
|
################################ |
347
|
|
|
# SETUP: LAYER MANAGEMENT |
348
|
|
|
################################ |
349
|
|
|
|
350
|
|
|
|
351
|
|
|
|
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @var ArrayList |
355
|
|
|
*/ |
356
|
|
|
protected $extraLayers = null; |
357
|
|
|
public function setExtraLayer($a) |
358
|
|
|
{ |
359
|
|
|
$this->extraLayers = $a; |
360
|
|
|
} |
361
|
|
|
public function getExtraLayers() |
362
|
|
|
{ |
363
|
|
|
return $this->extraLayers; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* @param String $title |
368
|
|
|
* @param String $link |
369
|
|
|
*/ |
370
|
|
|
public function addExtraLayer($title, $link) |
371
|
|
|
{ |
372
|
|
|
if (!$this->getExtraLayers()) { |
373
|
|
|
$this->extraLayers = new ArrayList(); |
374
|
|
|
} |
375
|
|
|
$this->extraLayers->push( |
376
|
|
|
new ArrayData( |
377
|
|
|
array( |
378
|
|
|
"Title" => $title, |
379
|
|
|
"Link" => $link, |
380
|
|
|
"MyInstanceName" => $this->MyInstanceName() |
381
|
|
|
) |
382
|
|
|
) |
383
|
|
|
); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* |
388
|
|
|
* @return ArrayList |
389
|
|
|
*/ |
390
|
|
|
public function AllExtraLayers() |
391
|
|
|
{ |
392
|
|
|
return $this->getExtraLayers(); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* @var Array |
397
|
|
|
* Link => Title |
398
|
|
|
*/ |
399
|
|
|
protected $linksForData = array(); |
400
|
|
|
public function setLinksForData($a) |
401
|
|
|
{ |
402
|
|
|
$this->linksForData = $a; |
403
|
|
|
} |
404
|
|
|
public function getLinksForData() |
405
|
|
|
{ |
406
|
|
|
return $this->linksForData; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* @param string $linkForData |
411
|
|
|
* @param string $title |
412
|
|
|
*/ |
413
|
|
|
public function addLayer($linkForData, $title) |
414
|
|
|
{ |
415
|
|
|
$this->linksForData[$linkForData] = $title; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
|
419
|
|
|
|
420
|
|
|
|
421
|
|
|
|
422
|
|
|
|
423
|
|
|
|
424
|
|
|
################################ |
425
|
|
|
# SETUP: FILTERS AND POINTS PROVIDERS |
426
|
|
|
################################ |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* address being searched for |
430
|
|
|
* @var String |
431
|
|
|
*/ |
432
|
|
|
protected $address = ""; |
433
|
|
|
public function setAddress($v) |
434
|
|
|
{ |
435
|
|
|
$this->address = Convert::raw2js($v); |
|
|
|
|
436
|
|
|
} |
437
|
|
|
public function getAddress($v) |
|
|
|
|
438
|
|
|
{ |
439
|
|
|
return $this->address; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* sets the list of points through a list of parent pages |
444
|
|
|
* affected variable is: points |
445
|
|
|
* @param DataList | ArrayList $pageDataList |
446
|
|
|
*/ |
447
|
|
|
public function setPageDataObjectSet($pageDataList) |
448
|
|
|
{ |
449
|
|
|
if ($pageDataList->count()) { |
450
|
|
|
if ($pageDataList instanceof SS_List) { |
451
|
|
|
$array = $pageDataList->map("ID", "ID"); |
452
|
|
|
} elseif ($pageDataList instanceof DataList) { |
453
|
|
|
$array = $pageDataList->map("ID", "ID")->toArray(); |
454
|
|
|
} else { |
455
|
|
|
user_error("Wrong format for pageDataList"); |
456
|
|
|
} |
457
|
|
|
$this->points = GoogleMapLocationsObject::get()->filter(array("ParentID" => $array)); |
|
|
|
|
458
|
|
|
$pageDataList = null; |
|
|
|
|
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* @var DataList |
465
|
|
|
*/ |
466
|
|
|
protected $points = null; |
467
|
|
|
public function setPoints($s) |
468
|
|
|
{ |
469
|
|
|
$this->points = $s; |
470
|
|
|
} |
471
|
|
|
public function getPoints() |
472
|
|
|
{ |
473
|
|
|
return $this->points; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
|
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* a description of how the points were selected ... |
480
|
|
|
* @var String |
481
|
|
|
*/ |
482
|
|
|
protected $whereStatementDescription = ""; |
483
|
|
|
public function setWhereStatementDescription($s) |
484
|
|
|
{ |
485
|
|
|
$this->whereStatementDescription = $s; |
486
|
|
|
} |
487
|
|
|
public function getWhereStatementDescription() |
488
|
|
|
{ |
489
|
|
|
return $this->whereStatementDescription; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* filter for class names |
494
|
|
|
* @var Array |
495
|
|
|
*/ |
496
|
|
|
protected $filteredClassNameArray = array(); |
497
|
|
|
public function setFilteredClassNameArray($a) |
|
|
|
|
498
|
|
|
{ |
499
|
|
|
$this->filteredClassNameArray = $s; |
|
|
|
|
500
|
|
|
} |
501
|
|
|
public function getFilteredClassNameArray() |
502
|
|
|
{ |
503
|
|
|
return $this->filteredClassNameArray; |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
|
507
|
|
|
|
508
|
|
|
|
509
|
|
|
|
510
|
|
|
|
511
|
|
|
|
512
|
|
|
################################ |
513
|
|
|
# MAP CHANGES |
514
|
|
|
################################ |
515
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* @var String |
518
|
|
|
*/ |
519
|
|
|
protected $updateServerUrlAddressSearchPoint = "/googlemap/showaroundmexml/"; |
520
|
|
|
public function setUpdateServerUrlAddressSearchPoint($v) |
521
|
|
|
{ |
522
|
|
|
$this->updateServerUrlAddressSearchPoint = Director::absoluteBaseURL().$v; |
523
|
|
|
} |
524
|
|
|
public function getUpdateServerURLAddressSearchPoint() |
525
|
|
|
{ |
526
|
|
|
return $this->updateServerUrlAddressSearchPoint; |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* @var String |
531
|
|
|
*/ |
532
|
|
|
protected $updateServerUrlDragend = ""; |
533
|
|
|
public function setUpdateServerUrlDragend($v) |
534
|
|
|
{ |
535
|
|
|
$this->updateServerUrlDragend = Director::absoluteBaseURL().$v; |
536
|
|
|
} |
537
|
|
|
public function getUpdateServerUrlDragend() |
538
|
|
|
{ |
539
|
|
|
return $this->updateServerUrlDragend; |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
|
543
|
|
|
|
544
|
|
|
|
545
|
|
|
|
546
|
|
|
|
547
|
|
|
|
548
|
|
|
|
549
|
|
|
|
550
|
|
|
|
551
|
|
|
################################ |
552
|
|
|
# LOADING |
553
|
|
|
################################ |
554
|
|
|
/** |
555
|
|
|
* this is a hack to avoid having multiple includes |
556
|
|
|
* @var Boolean |
557
|
|
|
*/ |
558
|
|
|
private static $_includes_are_done = false; |
559
|
|
|
|
560
|
|
|
public function loadGoogleMap() |
561
|
|
|
{ |
562
|
|
|
$js = ''; |
563
|
|
|
$this->loadDefaults(); |
564
|
|
|
if (!self::$_includes_are_done) { |
565
|
|
|
Requirements::themedCSS("googleMap", 'googlemap'); |
566
|
|
|
Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
567
|
|
|
$variableName = $this->getMyMapFunctionName(false); |
|
|
|
|
568
|
|
|
$instanceName = $this->getMyMapFunctionName(true); |
|
|
|
|
569
|
|
|
Requirements::javascript("googlemap/javascript/loadAjaxInfoWindow.js"); |
570
|
|
|
Requirements::insertHeadTags('<style type="text/css">v\:* {behavior:url(#default#VML);}</style>', "GoogleMapCustomHeadTag"); |
571
|
|
|
Requirements::javascript( |
572
|
|
|
"//maps.googleapis.com/maps/api/js" |
573
|
|
|
."?v=".Config::inst()->get("GoogleMap", "api_version") |
574
|
|
|
."&libraries=places" |
575
|
|
|
."&key=".Config::inst()->get('GoogleMap', 'google_map_api_key') |
576
|
|
|
); |
577
|
|
|
Requirements::javascript(THIRDPARTY_DIR.'/jquery-form/jquery.form.js'); |
578
|
|
|
Requirements::javascript("googlemap/javascript/googleMaps.js"); |
579
|
|
|
$js .= $this->createJavascript(); |
580
|
|
|
Requirements::customScript($js, "GoogleMapCustomScript"); |
581
|
|
|
self::$_includes_are_done = true; |
582
|
|
|
} |
583
|
|
|
return $this; |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
|
587
|
|
|
|
588
|
|
|
|
589
|
|
|
|
590
|
|
|
|
591
|
|
|
|
592
|
|
|
################################ |
593
|
|
|
# DATA POINTS MASSAGE |
594
|
|
|
################################ |
595
|
|
|
|
596
|
|
|
/** |
597
|
|
|
* sorts points by Latitude |
598
|
|
|
* @param boolean $reverse |
599
|
|
|
* |
600
|
|
|
* @return ArrayList |
601
|
|
|
*/ |
602
|
|
|
protected function orderItemsByLatitude($reverse = false) |
603
|
|
|
{ |
604
|
|
|
$unsortedSet = $this->getProcessedDataPointsForTemplate(); |
605
|
|
|
$sortedSet = new ArrayList(); |
606
|
|
|
if ($unsortedSet->count()) { |
607
|
|
|
foreach ($unsortedSet as $item) { |
608
|
|
|
$tempArray[$item->Latitude] = $item; |
|
|
|
|
609
|
|
|
} |
610
|
|
|
} |
611
|
|
|
ksort($tempArray); |
612
|
|
|
//not sure why this is a bit counter intuitive. |
613
|
|
|
//north to south is from high to low ... |
614
|
|
|
if (!$reverse) { |
615
|
|
|
$tempArray = array_reverse($tempArray); |
616
|
|
|
} |
617
|
|
|
foreach ($tempArray as $item) { |
618
|
|
|
$sortedSet->push($item); |
619
|
|
|
} |
620
|
|
|
return $sortedSet; |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
/** |
624
|
|
|
* |
625
|
|
|
* @return Int |
626
|
|
|
*/ |
627
|
|
|
public function getPointCount() |
628
|
|
|
{ |
629
|
|
|
if ($processedPoints = $this->getProcessedDataPointsForTemplate()) { |
630
|
|
|
return $processedPoints->count(); |
631
|
|
|
} elseif ($points = $this->getPoints()) { |
632
|
|
|
return $points->count(); |
633
|
|
|
} |
634
|
|
|
return 0; |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* @return Boolean |
639
|
|
|
*/ |
640
|
|
|
public function EnoughPointsForAList() |
641
|
|
|
{ |
642
|
|
|
return $this->getPointCount() >= $this->Config()->get("number_of_items_before_showing_list") ? true : false; |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
|
646
|
|
|
/** |
647
|
|
|
* must be public |
648
|
|
|
* does not return the datapoints XML |
649
|
|
|
* but loads it into variables... |
650
|
|
|
* @return Boolean |
651
|
|
|
*/ |
652
|
|
|
public function createDataPoints() |
653
|
|
|
{ |
654
|
|
|
if ($this->dataPointsXML === '') { |
655
|
|
|
$this->loadDefaults(); |
656
|
|
|
$idArray = array(); |
657
|
|
|
$bestZoom = $this->Config()->get("default_zoom"); |
658
|
|
|
$averageLatitude = 0; |
659
|
|
|
$averageLongitude = 0; |
660
|
|
|
$count = 0; |
661
|
|
|
$pointsXml = ''; |
662
|
|
|
//width |
663
|
|
|
$totalCount = $this->getPointCount(); |
664
|
|
|
$filterFree = count($this->filteredClassNameArray) ? false : true; |
665
|
|
|
$averageLongitudeArray = array(); |
666
|
|
|
$averageLatitudeArray = array(); |
667
|
|
|
if ($totalCount > 0 && $totalCount < 10000) { |
668
|
|
|
$this->processedDataPointsForTemplate = new ArrayList(); |
669
|
|
|
foreach ($this->getPoints() as $dataPoint) { |
670
|
|
|
$dataPoint->addParentData(); |
671
|
|
|
if ($filterFree || in_array($dataPoint->ClassName, $this->filteredClassNameArray)) { |
672
|
|
|
if (! in_array($dataPoint->ID, $idArray)) { |
673
|
|
|
if ($dataPoint->Longitude && $dataPoint->Latitude) { |
674
|
|
|
$dataLine = '<Point><coordinates>'.$dataPoint->Longitude.','.$dataPoint->Latitude.'</coordinates></Point>'; |
675
|
|
|
$link = ''; |
|
|
|
|
676
|
|
|
if ($dataPoint->Link) { |
677
|
|
|
$link = $dataPoint->getAjaxInfoWindowLink(); |
|
|
|
|
678
|
|
|
} |
679
|
|
|
$staticIcon = ''; |
|
|
|
|
680
|
|
|
if ($dataPoint->staticIcon) { |
681
|
|
|
$staticIcon = $dataPoint->staticIcon; |
|
|
|
|
682
|
|
|
} else { |
683
|
|
|
$staticIcon = $this->Config()->get("static_icon"); |
|
|
|
|
684
|
|
|
} |
685
|
|
|
$center = round($dataPoint->Latitude, 6).",".round($dataPoint->Longitude, 6); |
686
|
|
|
//get the center IF there is only one point... |
687
|
|
|
if (!$count) { |
688
|
|
|
$defaultCenter = $center; |
|
|
|
|
689
|
|
|
} |
690
|
|
|
if (!$dataPoint->Name) { |
691
|
|
|
$dataPoint->Name = "no name"; |
692
|
|
|
} |
693
|
|
|
$pointsXml .= |
694
|
|
|
'<Placemark>'. |
695
|
|
|
'<id>'.$dataPoint->ID.'</id>'. |
696
|
|
|
'<name>'.Convert::raw2xml($dataPoint->Name).'</name>'. |
697
|
|
|
$dataLine. |
698
|
|
|
'<description><![CDATA[ '.$dataPoint->getAjaxInfoWindowLink().']]></description>'. |
699
|
|
|
'</Placemark>'; |
700
|
|
|
$this->processedDataPointsForTemplate->push($dataPoint); |
701
|
|
|
$averageLatitudeArray[] = $dataPoint->Longitude; |
702
|
|
|
$averageLongitudeArray[] = $dataPoint->Latitude; |
703
|
|
|
$count++; |
704
|
|
|
} |
705
|
|
|
} |
706
|
|
|
} |
707
|
|
|
$idArray[$dataPoint->ID] = $dataPoint->ID; |
708
|
|
|
} |
709
|
|
|
$averageLongitude = array_sum($averageLongitudeArray) / count($averageLongitudeArray); |
710
|
|
|
$averageLatitude = array_sum($averageLatitudeArray) / count($averageLatitudeArray); |
711
|
|
|
|
712
|
|
|
$this->processedDataPointsForTemplate = $this->orderItemsByLatitude($this->processedDataPointsForTemplate); |
|
|
|
|
713
|
|
|
} |
714
|
|
|
if (! $pointsXml) { |
715
|
|
|
$pointsXml = '<errormessage>'.$this->getNoDataPointsMessage().'</errormessage>'; |
716
|
|
|
} |
717
|
|
|
if (!$averageLongitude) { |
718
|
|
|
$averageLongitude = $this->config()->get("default_longitude"); |
719
|
|
|
} |
720
|
|
|
if (!$averageLatitude) { |
721
|
|
|
$averageLatitude = $this->config()->get("default_latitude"); |
722
|
|
|
} |
723
|
|
|
$this->dataPointsXML = |
724
|
|
|
'<mapinfo>'.'<title>'.$this->getTitleOfMap().'</title>' |
725
|
|
|
.'<longitude>'.number_format($averageLongitude - 0, 12, ".", "").'</longitude>' |
726
|
|
|
.'<latitude>'.number_format($averageLatitude - 0, 9, ".", "").'</latitude>' |
727
|
|
|
.'<zoom>'.$bestZoom.'</zoom>' |
728
|
|
|
.'<pointcount>'.$count.'</pointcount>' |
729
|
|
|
.'<info>'.$this->getWhereStatementDescription().'</info>' |
730
|
|
|
.'</mapinfo>' |
731
|
|
|
.$pointsXml; |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
return true; |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
/** |
738
|
|
|
* @param String staticVariablename |
739
|
|
|
* @return String (Javascript) |
740
|
|
|
*/ |
741
|
|
|
protected function createJavascript() |
742
|
|
|
{ |
743
|
|
|
$variableName = $this->getMyMapFunctionName(false); |
|
|
|
|
744
|
|
|
$instanceName = $this->getMyMapFunctionName(true); |
|
|
|
|
745
|
|
|
$js = ' |
746
|
|
|
if(typeof GoogleMapConstructors === "undefined"){ |
747
|
|
|
GoogleMapConstructors = []; |
748
|
|
|
} |
749
|
|
|
GoogleMapConstructors.push( |
750
|
|
|
{ |
751
|
|
|
divID: "'.$this->GoogleMapDivID().'", |
752
|
|
|
layers: [], |
753
|
|
|
address: "", |
754
|
|
|
options: { |
755
|
|
|
/* HELPDIVS */ |
756
|
|
|
sideBarId:"'.$this->config()->get("side_bar_div_id").'", |
757
|
|
|
dropBoxId:"'.$this->config()->get("drop_down_div_id").'", |
758
|
|
|
titleId:"'.$this->config()->get("title_div_id").'", |
759
|
|
|
layerListId:"'.$this->config()->get("layer_list_div_id").'", |
760
|
|
|
directionsDivId:"'.$this->config()->get("directions_div_id").'", |
761
|
|
|
statusDivId:"'.$this->config()->get("status_div_id").'", |
762
|
|
|
noStatusAtAll:'.$this->showFalseOrTrue($this->config()->get("no_status_at_all")).', |
763
|
|
|
addKmlLink:'.$this->showFalseOrTrue($this->config()->get("add_kml_link")).', |
764
|
|
|
hiddenLayersRemovedFromList:'.$this->showFalseOrTrue($this->config()->get("hidden_layers_removed_from_list")).', |
765
|
|
|
|
766
|
|
|
/* PAGE*/ |
767
|
|
|
changePageTitle:'.$this->showFalseOrTrue($this->config()->get("change_page_title")).', |
768
|
|
|
defaultTitle:"'.$this->config()->get("default_title").'", |
769
|
|
|
|
770
|
|
|
/* INFOWINDOW*/ |
771
|
|
|
infoWindowOptions:'.$this->config()->get("info_window_options").', |
772
|
|
|
addAntipodean:'.$this->showFalseOrTrue($this->config()->get("add_antipodean")).', |
773
|
|
|
addDirections:'.$this->showFalseOrTrue($this->config()->get("add_directions")).', |
774
|
|
|
addCurrentAddressFinder:'.$this->showFalseOrTrue($this->config()->get("add_current_address_finder_in_marker")).', |
775
|
|
|
addZoomInButton:"'.$this->config()->get("add_zoom_in_button").'", |
776
|
|
|
|
777
|
|
|
/* MARKER */ |
778
|
|
|
addPointsToMap:'.$this->showFalseOrTrue($this->config()->get("add_points_to_map")).', |
779
|
|
|
addDeleteMarkerButton:"'.$this->config()->get("add_delete_marker_button").'", |
780
|
|
|
markerOptions: '.$this->config()->get("marker_options").', |
781
|
|
|
preloadImages:'.$this->showFalseOrTrue($this->config()->get("preload_images")).', |
782
|
|
|
|
783
|
|
|
/* ICONS */ |
784
|
|
|
defaultIconUrl: "'.$this->config()->get("default_icon_url").'", |
785
|
|
|
iconFolder: "'.$this->config()->get("icon_folder").'", |
786
|
|
|
iconWidth:'.$this->config()->get("icon_width").', |
787
|
|
|
iconHeight:'.$this->config()->get("icon_height").', |
788
|
|
|
iconExtension:"'.$this->config()->get("icon_extension").'", |
789
|
|
|
iconMaxCount:'.$this->config()->get("icon_max_count").', |
790
|
|
|
|
791
|
|
|
/* POLYS */ |
792
|
|
|
lineColour: "'.$this->config()->get("line_colour").'", |
793
|
|
|
lineWidth: "'.$this->config()->get("line_width").'", |
794
|
|
|
lineOpacity: "'.$this->config()->get("line_opacity").'", |
795
|
|
|
fillColour: "'.$this->config()->get("fill_colour").'", |
796
|
|
|
fillOpacity: "'.$this->config()->get("fill_opacity").'", |
797
|
|
|
polyIcon: "'.$this->config()->get("poly_icon").'", |
798
|
|
|
|
799
|
|
|
/* MAP*/ |
800
|
|
|
mapTypeDefault: '.intval($this->config()->get("map_type_default")-0).', |
801
|
|
|
viewFinderSize:'.intval($this->config()->get("view_finder_size") - 0).', |
802
|
|
|
mapAddTypeControl:'.$this->showFalseOrTrue($this->config()->get("map_add_type_control")).', |
803
|
|
|
mapControlSizeOneToThree:'.$this->config()->get("map_control_size_one_to_three").', |
804
|
|
|
mapScaleInfoSizeInPixels:'.intval($this->config()->get("map_scale_info_size_in_pixels") - 0).', |
805
|
|
|
|
806
|
|
|
/* START POSITION */ |
807
|
|
|
defaultLatitude:'.number_format($this->config()->get("default_latitude") - 0, 9, ".", "").', |
808
|
|
|
defaultLongitude:'.number_format($this->config()->get("default_longitude") - 0, 12, ".", "").', |
809
|
|
|
defaultZoom:'.intval($this->config()->get("default_zoom") - 0).', |
810
|
|
|
|
811
|
|
|
/* SERVER INTERACTION */ |
812
|
|
|
updateServerUrlAddressSearchPoint: "'.$this->getUpdateServerUrlAddressSearchPoint(). '", |
813
|
|
|
updateServerUrlDragend: "'.$this->getUpdateServerUrlDragend().'", |
814
|
|
|
latFormFieldId:"'.$this->config()->get("lat_form_field_id").'", |
815
|
|
|
lngFormFieldId:"'.$this->config()->get("lng_form_field_id").'", |
816
|
|
|
|
817
|
|
|
/* ADDRESS FORM */ |
818
|
|
|
addAddressFinder:'.$this->showFalseOrTrue($this->config()->get("add_address_finder")).', |
819
|
|
|
defaultCountryCode:"'.$this->config()->get("default_country_code").'", |
820
|
|
|
|
821
|
|
|
/* DIRECTIONS */ |
822
|
|
|
styleSheetUrl: "'.$this->config()->get("style_sheet_url").'", |
823
|
|
|
localeForResults: "'.$this->config()->get("locale_for_results").'" |
824
|
|
|
} |
825
|
|
|
} |
826
|
|
|
);'; |
827
|
|
|
if ($this->linksForData && count($this->linksForData)) { |
|
|
|
|
828
|
|
|
foreach ($this->linksForData as $link => $title) { |
829
|
|
|
$js .= ' |
830
|
|
|
GoogleMapConstructors[GoogleMapConstructors.length-1].layers.push( |
831
|
|
|
{ |
832
|
|
|
link: '.Convert::raw2json(Director::absoluteURL($link)).', |
833
|
|
|
title: '.Convert::raw2json($title).' |
834
|
|
|
} |
835
|
|
|
);'; |
836
|
|
|
} |
837
|
|
|
} elseif ($this->address) { |
838
|
|
|
$js .= ' |
839
|
|
|
GoogleMapConstructors[GoogleMapConstructors.length-1].address = \''.$this->address.'\''; |
840
|
|
|
} |
841
|
|
|
return $js; |
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
/** |
845
|
|
|
* turns 0 into false and 1 into true |
846
|
|
|
* @param Mixed |
847
|
|
|
* @return string (true|false) |
848
|
|
|
*/ |
849
|
|
|
protected function showFalseOrTrue($v) |
850
|
|
|
{ |
851
|
|
|
if ($v && $v !== "false" && $v !== "0" && $v !== 0) { |
852
|
|
|
return "true"; |
853
|
|
|
} else { |
854
|
|
|
return "false"; |
855
|
|
|
} |
856
|
|
|
} |
857
|
|
|
|
858
|
|
|
/** |
859
|
|
|
* load some defaults |
860
|
|
|
*/ |
861
|
|
|
protected function loadDefaults() |
862
|
|
|
{ |
863
|
|
|
if (!isset($this->whereStatementDescription)) { |
864
|
|
|
$this->whereStatementDescription = $this->Config()->get("default_where_statement_description"); |
865
|
|
|
} |
866
|
|
|
if (!isset($this->titleOfMap) || !$this->titleOfMap) { |
867
|
|
|
$this->titleOfMap = $this->Config()->get("default_title"); |
868
|
|
|
} |
869
|
|
|
} |
870
|
|
|
} |
871
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.