Completed
Push — AUTOMATED_TESTING ( 1306ca...0fc006 )
by Gordon
17:27
created

MapAPI::addArrayMarkerByAddress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4286
cc 2
eloc 4
nc 2
nop 3
1
<?php
2
3
/*
4
*
5
* This script is distributed in the hope that it will be useful,
6
* but WITHOUT ANY WARRANTY; without even the implied warranty of
7
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8
* GNU General public License for more details.
9
*
10
* This copyright notice MUST APPEAR in all copies of the script!
11
*
12
*  @author            CERDAN Yohann <[email protected]>
13
*  @copyright      (c) 2009  CERDAN Yohann, All rights reserved
14
*  @ version         18:13 26/05/2009
15
*/
16
17
class MapAPI extends ViewableData
18
{
19
20
	 /** GoogleMap key **/
21
	protected $googleMapKey = '';
22
23
	/** GoogleMap ID for the HTML DIV  **/
24
	protected $googleMapId = 'googlemapapi';
25
26
	/* Additional CSS classes to use when rendering the map */
27
	protected $set_additional_css_classes = '';
28
29
	/** Width of the gmap **/
30
	protected $width = 800;
31
32
	/** Height of the gmap **/
33
	protected $height = 600;
34
35
	/* array of lines to be drawn on the map */
36
	protected $lines = array();
37
38
	/* kml file to be rendered */
39
	protected $kmlFiles = array();
40
41
	/** Default zoom of the gmap **/
42
	protected $zoom = 9;
43
44
	/** Enable the zoom of the Infowindow **/
45
	protected $enableWindowZoom = false;
46
47
	/** Default zoom of the Infowindow **/
48
	protected $infoWindowZoom = 13;
49
50
	/** Lang of the gmap **/
51
	protected $lang = 'en';
52
53
	/**Center of the gmap **/
54
	protected $center = 'Paris, France';
55
56
	/*
57
	 Additional CSS classes to render as a class attribute for the div of the
58
	 map.  Use this if you want more  fine grained control over your map using
59
	 CSS.  If blank it will be ignored
60
	 */
61
	protected $additional_css_classes = '';
62
63
64
	/* Decided whether or not to show the inline map css style on div creation */
65
	protected $show_inline_map_div_style = true;
66
67
	protected $latLongCenter = null;
68
69
	protected $jsonMapStyles = '[]';
70
71
	protected $delayLoadMapFunction = false;
72
73
	/**
74
	 * Type of the gmap, can be:
75
	 *  'road' (roadmap),
76
	 *  'satellite' (sattelite/aerial photographs)
77
	 *  'hybrid' (hybrid of road and satellite)
78
	 *  'terrain' (terrain)
79
	 *  The JavaScript for the mapping service will convert this into a suitable mapping type
80
	 */
81
82
	protected $mapType = 'road';
83
84
85
	/** Content of the HTML generated **/
86
	protected $content = '';
87
88
	protected $mapService = 'google';
89
90
	/** Hide the marker by default **/
91
	protected $defaultHideMarker = false;
92
93
	/** Extra content (marker, etc...) **/
94
	protected $contentMarker = '';
95
96
	// a list of markers, markers being associative arrays
97
	protected $markers = array();
98
99
	/** Use clusterer to display a lot of markers on the gmap **/
100
	protected $useClusterer = false;
101
	protected $gridSize = 50;
102
	protected $maxZoom = 17;
103
	protected $clustererLibraryPath = "/mappable/javascript/google/markerclusterer.js";
104
105
	/** Enable automatic center/zoom **/
106
	protected $enableAutomaticCenterZoom = false;
107
108
	/** maximum longitude of all markers **/
109
	protected $maxLng = -1000000;
110
111
	/** minimum longitude of all markers **/
112
	protected $minLng = 1000000;
113
114
	/** max latitude of all markers **/
115
	protected $maxLat = -1000000;
116
117
	/** min latitude of all markers **/
118
	protected $minLat = 1000000;
119
120
	/** map center latitude (horizontal), calculated automatically as markers
121
	are added to the map **/
122
	protected $centerLat = null;
123
124
	/** map center longitude (vertical),  calculated automatically as markers
125
	are added to the map **/
126
	protected $centerLng = null;
127
128
	/** factor by which to fudge the boundaries so that when we zoom encompass,
129
	the markers aren't too close to the edge **/
130
	protected $coordCoef = 0.01;
131
132
	/* set this to true to render button to maximize / minimize a map */
133
	protected $allowFullScreen = null;
134
135
	/**
136
	 * Class constructor
137
	 *
138
	 * @param string  $googleMapKey the googleMapKey
139
	 */
140
141
	public function __construct($googleMapKey = '') {
142
		$this->googleMapKey = $googleMapKey;
143
	}
144
145
	/**
146
	 * Set the key of the gmap
147
	 *
148
	 * @param string  $googleMapKey the googleMapKey
149
	 *
150
	 * @return MapAPI
151
	 */
152
153
	public function setKey($googleMapKey) {
154
		$this->googleMapKey = $googleMapKey;
155
		return $this;
156
	}
157
158
	public function setShowInlineMapDivStyle($new_show_inline_map_div_style) {
159
		$this->show_inline_map_div_style = $new_show_inline_map_div_style;
160
		return $this;
161
	}
162
163
	public function setAdditionalCSSClasses($new_additional_css_classes) {
164
		$this->additional_css_classes = $new_additional_css_classes;
165
		return $this;
166
	}
167
168
169
	public function setMapStyle($newStyles) {
170
		$this->jsonMapStyles = $newStyles;
171
		return $this;
172
	}
173
174
175
176
	public function setDelayLoadMapFunction($newDelay) {
177
		$this->delayLoadMapFunction = $newDelay;
178
		return $this;
179
	}
180
181
	/**
182
	 * Set the useClusterer parameter (optimization to display a lot of marker)
183
	 *
184
	 * @param boolean $useClusterer     use cluster or not
185
	 * @param int     $gridSize         grid size
186
	 * @param int     $maxZoom 			max zoom to cluster at
187
	 *
188
	 * * @return MapAPI This same object, in order to enable chaining of methods
189
	 */
190
191
	public function setClusterer($useClusterer, $gridSize = 50, $maxZoom = 17,
192
		$clustererLibraryPath = '/mappable/javascript/google/markerclusterer.js') {
193
		$this->useClusterer = $useClusterer;
194
		$this->gridSize = $gridSize;
195
		$this->maxZoom = $maxZoom;
196
		$this->clustererLibraryPath = $clustererLibraryPath;
197
		return $this;
198
	}
199
200
	/**
201
	 * Set the ID of the default gmap DIV
202
	 *
203
	 * @param string  $googleMapId the google div ID
204
	 *
205
	 * @return MapAPI This same object, in order to enable chaining of methods
206
	 */
207
208
	public function setDivId($googleMapId) {
209
		$this->googleMapId = $googleMapId;
210
		return $this;
211
	}
212
213
	/**
214
	 * Set the size of the gmap.  If these values are not provided
215
	 * then CSS is used instead
216
	 *
217
	 * @param int     $width  GoogleMap  width
218
	 * @param int     $height GoogleMap  height
219
	 *
220
	 * @return MapAPI This same object, in order to enable chaining of methods
221
	 */
222
223
	public function setSize($width, $height) {
224
		$this->width = $width;
225
		$this->height = $height;
226
		return $this;
227
	}
228
229
	/**
230
	 * Set the lang of the gmap
231
	 *
232
	 * @param string  $lang GoogleMap  lang : fr,en,..
233
	 *
234
	 * @return MapAPI This same object, in order to enable chaining of methods
235
	 */
236
237
	public function setLang($lang) {
238
		$this->lang = $lang;
239
		return $this;
240
	}
241
242
	/**
243
	 * Set the zoom of the gmap
244
	 *
245
	 * @param int $zoom GoogleMap zoom.
246
	 *
247
	 * @return MapAPI This same object, in order to enable chaining of methods
248
	 */
249
250
	public function setZoom($zoom) {
251
		$this->zoom = $zoom;
252
		return $this;
253
	}
254
255
	/**
256
	 * Set the zoom of the infowindow
257
	 *
258
	 * @param int 	$infoWindowZoom GoogleMap information window zoom.
259
	 *
260
	 * @return MapAPI This same object, in order to enable chaining of methods
261
	 */
262
263
	public function setInfoWindowZoom($infoWindowZoom) {
264
		$this->infoWindowZoom = $infoWindowZoom;
265
		return $this;
266
	}
267
268
	/**
269
	 * Enable the zoom on the marker when you click on it
270
	 *
271
	 * @param int $enableWindowZoom info window enabled zoom.
272
	 *
273
	 * @return MapAPI This same object, in order to enable chaining of methods
274
	 */
275
276
	public function setEnableWindowZoom($enableWindowZoom) {
277
		$this->enableWindowZoom = $enableWindowZoom;
0 ignored issues
show
Documentation Bug introduced by
The property $enableWindowZoom was declared of type boolean, but $enableWindowZoom is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
278
		return $this;
279
	}
280
281
	/**
282
	 * Enable theautomatic center/zoom at the gmap load
283
	 *
284
	 * @param int $enableAutomaticCenterZoom enable automatic centre zoom
285
	 *
286
	 * @return MapAPI This same object, in order to enable chaining of methods
287
	 */
288
289
	public function setEnableAutomaticCenterZoom($enableAutomaticCenterZoom) {
290
		$this->enableAutomaticCenterZoom = $enableAutomaticCenterZoom;
0 ignored issues
show
Documentation Bug introduced by
The property $enableAutomaticCenterZoom was declared of type boolean, but $enableAutomaticCenterZoom is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
291
		return $this;
292
	}
293
294
	/**
295
	 * Set the center of the gmap (an address)
296
	 *
297
	 * @param string  $center GoogleMap  center (an address)
298
	 *
299
	 * @return MapAPI This same object, in order to enable chaining of methods
300
	 */
301
302
	public function setCenter($center) {
303
		$this->center = $center;
304
		return $this;
305
	}
306
307
	/**
308
	 * Set the type of the gmap.  Also takes into account legacy settings
309
	 *
310
	 * FIXME - allow other valid settings in config for map type
311
	 *
312
	 * @param string  $mapType  Can be one of road,satellite,hybrid or terrain. Defaults to road
313
	 *
314
	 * @return MapAPI This same object, in order to enable chaining of methods
315
	 */
316
317
	public function setMapType($mapType) {
318
		$this->mapType = $mapType;
319
320
		// deal with legacy values for backwards compatbility
321
		switch ($mapType) {
322
			case 'google.maps.MapTypeId.SATELLITE':
323
				$this->mapType = "satellite";
324
				break;
325
			case 'google.maps.MapTypeId.G_HYBRID_MAP':
326
				$this->mapType = "hybrid";
327
				break;
328
			case 'google.maps.MapTypeId.G_PHYSICAL_MAP':
329
				$this->mapType = "terrain";
330
				break;
331
			default:
332
				$this->MapType = "road";
0 ignored issues
show
Bug introduced by
The property MapType does not seem to exist. Did you mean mapType?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
333
				break;
334
		}
335
336
		return $this;
337
	}
338
339
	/*
340
	Set whether or not to allow the full screen tools
341
	@return MapAPI This same object, in order to enable chaining of methods
342
	*/
343
	public function setAllowFullScreen($allowed) {
344
		$this->allowFullScreen = $allowed;
345
		return $this;
346
	}
347
348
	/**
349
	* Set the center of the gmap
350
	*
351
	* @return MapAPI This same object, in order to enable chaining of methods
352
	**/
353
	public function setLatLongCenter($center) {
354
		// error check, we want an associative array with lat,lng keys numeric
355
356
		if (!is_array($center)) {
357
			throw new InvalidArgumentException('Center must be an associative array containing lat,lng');
358
		}
359
360
		$keys = array_keys($center);
361
		sort($keys);
362
		if (implode(',', $keys) != 'lat,lng') {
363
			throw new InvalidArgumentException('Keys provided must be lat, lng');
364
		}
365
366
		$this->latLongCenter = $center;
367
		return $this;
368
	}
369
370
	/**
371
	 * Set the defaultHideMarker
372
	 *
373
	 * @param boolean $defaultHideMarker hide all the markers on the map by default
374
	 *
375
	 * @return MapAPI
376
	 */
377
378
	public function setDefaultHideMarker($defaultHideMarker) {
379
		$this->defaultHideMarker = $defaultHideMarker;
380
		return $this;
381
	}
382
383
	/**
384
	 * Get the google map content
385
	 *
386
	 * @return string the google map html code
387
	 */
388
389
	public function getGoogleMap() {
390
		return $this->content;
391
	}
392
393
394
	/**
395
	 * Get URL content using cURL.
396
	 *
397
	 * @param string  $url the url
398
	 *
399
	 * @return string the html code
400
	 *
401
	 * @todo add proxy settings
402
	 */
403
404
	public function getContent($url) {
405
		$curl = curl_init();
406
		curl_setopt($curl, CURLOPT_TIMEOUT, 10);
407
		curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
408
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
409
		curl_setopt($curl, CURLOPT_URL, $url);
410
		$data = curl_exec($curl);
411
		curl_close($curl);
412
		return $data;
413
	}
414
415
	/**
416
	 * Geocoding an address (address -> lat,lng)
417
	 *
418
	 * @param string  $address an address
419
	 *
420
	 * @return string array with precision, lat & lng
421
	 */
422
423
	public function geocoding($address) {
424
		$geocoder = new MappableGoogleGeocoder();
425
		$locations = $geocoder->getLocations($address);
426
		$result = null;
427
		if (!empty($locations)) {
428
			$place = $locations[0];
429
			$location = $place['geometry']['location'];
430
			$result = array(
431
				'lat' => $location['lat'],
432
				'lon' => $location['lng'],
433
				'geocoded' => true
434
			);
435
436
		}
437
		return $result;
438
	}
439
440
	/**
441
	 * Add marker by his coord
442
	 *
443
	 * @param string  $lat      lat
444
	 * @param string  $lng      lngs
445
	 * @param string  $html     html code display in the info window
446
	 * @param string  $category marker category
447
	 * @param string  $icon     an icon url
448
	 *
449
	 * @return MapAPI
450
	 */
451
452
	public function addMarkerByCoords($lat, $lng, $html = '', $category = '', $icon = '') {
453
		$m = array(
454
			'latitude' => $lat,
455
			'longitude' => $lng,
456
			'html' => $html,
457
			'category' => $category,
458
			'icon' => $icon
459
		);
460
		array_push($this->markers, $m);
461
		return $this;
462
	}
463
464
465
	/**
466
	 * Add marker by his address
467
	 *
468
	 * @param string  $address  an ddress
469
	 * @param string  $content  html code display in the info window
470
	 * @param string  $category marker category
471
	 * @param string  $icon     an icon url
472
	 *
473
	 * @return MapAPI
474
	 */
475
476
	public function addMarkerByAddress($address, $content = '', $category = '', $icon = '') {
477
		$point = $this->geocoding($address);
478
		error_log('POINT');
479
		error_log(print_r($point,1));
480
		if ($point !== null) {
481
			$this->addMarkerByCoords($point['lat'], $point['lon'], $content, $category, $icon);
482
		}
483
		return $this;
484
	}
485
486
	/**
487
	 * Add marker by an array of coord
488
	 *
489
	 * @param array  $coordtab an array of lat,lng,content
490
	 * @param string  $category marker category
491
	 * @param string  $icon     an icon url
492
	 *
493
	 * @return MapAPI
494
	 */
495
496
	public function addArrayMarkerByCoords($coordtab, $category = '', $icon = '') {
497
		foreach ($coordtab as $coord) {
498
			$this->addMarkerByCoords($coord[0], $coord[1], $coord[2], $category, $icon);
499
		}
500
		return $this;
501
	}
502
503
504
	/**
505
	 * Adds a {@link ViewableData} object that implements {@link Mappable}
506
	 * to the map.
507
	 * @param   $infowindowtemplateparams Optional array of extra parameters to pass to the map info window
508
	 *
509
	 * @param ViewableData $obj
510
	 */
511
	public function addMarkerAsObject(ViewableData $obj, $infowindowtemplateparams = null) {
512
		$extensionsImplementMappable = false;
513
		$extensions = Object::get_extensions(get_class($obj));
514
		if (is_array($extensions)) {
515
			foreach ($extensions as $extension) {
516
				$class = new ReflectionClass($extension);
517
				if ($class->implementsInterface('Mappable')) {
518
					$extensionsImplementMappable = true;
519
				}
520
521
			}
522
		}
523
524
		if ($extensionsImplementMappable ||
525
			($obj instanceof Mappable) ||
526
			(Object::has_extension($obj->ClassName, 'MapExtension'))
527
		) {
528
			$cat = $obj->hasMethod('getMappableMapCategory') ? $obj->getMappableMapCategory() : "default";
529
			if ($infowindowtemplateparams !== null) {
530
				foreach ($infowindowtemplateparams as $key => $value) {
531
					$obj->{$key} = $value;
532
				}
533
			}
534
			$this->addMarkerByCoords(
535
				$obj->getMappableLatitude(),
536
				$obj->getMappableLongitude(),
537
				$obj->getMappableMapContent(),
538
				$cat,
539
				$obj->getMappableMapPin()
540
			);
541
		}
542
543
		return $this;
544
	}
545
546
547
	/**
548
	 * Draws a line between two {@link ViewableData} objects
549
	 *
550
	 * @param ViewableData $one   The first point
551
	 * @param ViewableData $two   The second point
552
	 * @param string  $color The hexidecimal color of the line
553
	 */
554
	public function connectPoints(ViewableData $one, ViewableData $two, $color = "#FF3300") {
555
		$this->addLine(
556
			array($one->getMappableLatitude(), $one->getMappableLongitude()),
557
			array($two->getMappableLatitude(), $two->getMappableLongitude()),
558
			$color
559
		);
560
	}
561
562
563
	public function forTemplate() {
564
		$this->generate();
565
		return $this->getGoogleMap();
566
	}
567
568
	/**
569
	 * Add a KML file which will be rendered on this map.  Normally used for likes
570
	 * of GPS traces from activities
571
	 *
572
	 * @param string  $url      url of the kml file compatible with gmap and gearth
573
	 *
574
	 * @return MapAPI
575
	 */
576
577
	public function addKML($url) {
578
		array_push($this->kmlFiles, $url);
579
		return $this;
580
	}
581
582
583
	/*
584
	Add a line to the map
585
586
	*/
587
	public function addLine($from = array(), $to = array(), $color = "#FF3300") {
588
		$line = array(
589
			'lat1' => $from[0],
590
			'lon1' => $from[1],
591
			'lat2' => $to[0],
592
			'lon2' => $to[1],
593
			'color' => $color
594
		);
595
596
		array_push($this->lines, $line);
597
		return $this;
598
	}
599
600
601
	/*
602
	For php 5.3
603
	*/
604
	private function jsonRemoveUnicodeSequences($struct) {
605
		 return preg_replace("/\\\\u([a-f0-9]{4})/e",
606
		 					"iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))",
607
		 					json_encode($struct));
608
	}
609
610
611
	/**
612
	 * Generate the gmap
613
	 *
614
	 * @return void
615
	 */
616
617
	public function generate() {
618
		// from http://stackoverflow.com/questions/3586401/cant-decode-json-string-in-php
619
		$jsonMarkers = null;
0 ignored issues
show
Unused Code introduced by
$jsonMarkers is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
620
		$linesJson = null;
0 ignored issues
show
Unused Code introduced by
$linesJson is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
621
		$kmlJson = null;
0 ignored issues
show
Unused Code introduced by
$kmlJson is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
622
623
		// prior to PHP version 5.4, one needs to use regex
624
		if (PHP_VERSION_ID < 50400) {
625
			$jsonMarkers = stripslashes($this->jsonRemoveUnicodeSequences($this->markers));
626
			$linesJson = stripslashes($this->jsonRemoveUnicodeSequences($this->lines));
627
			$kmlJson = stripslashes($this->jsonRemoveUnicodeSequences($this->kmlFiles));
628
		} else {
629
			$jsonMarkers = stripslashes(json_encode($this->markers, JSON_UNESCAPED_UNICODE));
630
			$linesJson = stripslashes(json_encode($this->lines, JSON_UNESCAPED_UNICODE));
631
			$kmlJson = stripslashes(json_encode($this->kmlFiles, JSON_UNESCAPED_UNICODE));
632
		}
633
634
		 // Center of the GMap - text centre takes precedence
635
		$geocodeCentre = ($this->latLongCenter) ?
636
							$this->latLongCenter : $this->geocoding($this->center);
637
638
		// coordinates for centre depending on which method used
639
		if (isset($geocodeCentre['geocoded'] )) {
640
			$latlngCentre = array(
641
				'lat' => $geocodeCentre['lat'],
642
				'lng' => $geocodeCentre['lon']
643
			);
644
		} else if (is_array($this->latLongCenter)) {
645
			$latlngCentre = $this->latLongCenter;
646
		} else { // Paris
647
			$latlngCentre = array('lat'=>48.8792, 'lng' => 2.344444778);
648
		}
649
650
		$this->LatLngCentreJSON = stripslashes(json_encode($latlngCentre));
0 ignored issues
show
Documentation introduced by
The property LatLngCentreJSON does not exist on object<MapAPI>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
651
652
		$lenLng = $this->maxLng - $this->minLng;
653
		$lenLat = $this->maxLat - $this->minLat;
654
		$this->minLng -= $lenLng * $this->coordCoef;
655
		$this->maxLng += $lenLng * $this->coordCoef;
656
		$this->minLat -= $lenLat * $this->coordCoef;
657
		$this->maxLat += $lenLat * $this->coordCoef;
658
659
		// add the css class mappable as a handle onto the map styling
660
		$this->additional_css_classes .= ' mappable';
661
662
		if (!$this->enableAutomaticCenterZoom) {
663
			$this->enableAutomaticCenterZoom = 'false';
0 ignored issues
show
Documentation Bug introduced by
The property $enableAutomaticCenterZoom was declared of type boolean, but 'false' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
664
		}
665
666
		if (!$this->useClusterer) {
667
			$this->useClusterer = 'false';
0 ignored issues
show
Documentation Bug introduced by
The property $useClusterer was declared of type boolean, but 'false' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
668
		}
669
670
		if (!$this->defaultHideMarker) {
671
			$this->defaultHideMarker = 'false';
0 ignored issues
show
Documentation Bug introduced by
The property $defaultHideMarker was declared of type boolean, but 'false' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
672
		}
673
674
		if (!$this->MapTypeId) {
0 ignored issues
show
Bug introduced by
The property MapTypeId does not seem to exist. Did you mean mapType?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
675
			$this->MapTypeId = 'false';
0 ignored issues
show
Bug introduced by
The property MapTypeId does not seem to exist. Did you mean mapType?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
676
		}
677
678
		// initialise full screen as the config value if not already set
679
		if ($this->allowFullScreen === null) {
680
			$this->allowFullScreen = Config::inst()->get('Mappable', 'allow_full_screen');
681
		}
682
683
		if (!$this->allowFullScreen) {
684
			$this->allowFullScreen = 'false';
685
		}
686
687
		if (!$this->enableWindowZoom) {
688
			$this->enableWindowZoom = 'false';
0 ignored issues
show
Documentation Bug introduced by
The property $enableWindowZoom was declared of type boolean, but 'false' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
689
		}
690
691
		$vars = new ArrayData(array(
692
				'JsonMapStyles' => $this->jsonMapStyles,
693
				'AdditionalCssClasses' => $this->additional_css_classes,
694
				'Width' => $this->width,
695
				'Height' => $this->height,
696
				'ShowInlineMapDivStyle' => $this->show_inline_map_div_style,
697
				'InfoWindowZoom' => $this->infoWindowZoom,
698
				'EnableWindowZoom' => $this->enableWindowZoom,
699
				'MapMarkers' => $jsonMarkers,
700
				'DelayLoadMapFunction' => $this->delayLoadMapFunction,
701
				'DefaultHideMarker' => $this->defaultHideMarker,
702
				'LatLngCentre' => $this->LatLngCentreJSON,
0 ignored issues
show
Documentation introduced by
The property LatLngCentreJSON does not exist on object<MapAPI>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
703
				'EnableAutomaticCenterZoom' => $this->enableAutomaticCenterZoom,
704
				'Zoom' => $this->zoom,
705
				'MaxZoom' => $this->maxZoom,
706
				'GridSize' => $this->gridSize,
707
				'MapType' => $this->mapType,
708
				'GoogleMapID' => $this->googleMapId,
709
				'Lang'=>$this->lang,
710
				'UseClusterer'=>$this->useClusterer,
711
				'ClustererLibraryPath' => $this->clustererLibraryPath,
712
				'ClustererMaxZoom' => $this->maxZoom,
713
				'ClustererGridSize' => $this->gridSize,
714
				'Lines' => $linesJson,
715
				'KmlFiles' => $kmlJson,
716
				'AllowFullScreen' => $this->allowFullScreen,
717
				'UseCompressedAssets' => Config::inst()->get('Mappable', 'use_compressed_assets')
718
			)
719
		);
720
721
		// HTML component of the map
722
		$this->content = $this->processTemplateHTML('Map', $vars);
723
	}
724
725
	/**
726
	 * @param string $templateName
727
	 * @param ArrayData $templateVariables
728
	 */
729
	function processTemplateHTML($templateName, $templateVariables = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
730
		if (!$templateVariables) {
731
			$templateVariables = new ArrayList();
732
		}
733
		$mappingService = Config::inst()->get('Mappable', 'mapping_service');
734
		$result = $templateVariables->renderWith($templateName.$mappingService.'HTML');
735
		return $result;
736
	}
737
}
738