gordonbanderson /
Mappable
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 | /** GoogleMap key **/ |
||
| 20 | protected $googleMapKey = ''; |
||
| 21 | |||
| 22 | /** GoogleMap ID for the HTML DIV **/ |
||
| 23 | protected $googleMapId = 'googlemapapi'; |
||
| 24 | |||
| 25 | /* Additional CSS classes to use when rendering the map */ |
||
| 26 | protected $set_additional_css_classes = ''; |
||
| 27 | |||
| 28 | /** Width of the gmap **/ |
||
| 29 | protected $width = 800; |
||
| 30 | |||
| 31 | /** Height of the gmap **/ |
||
| 32 | protected $height = 600; |
||
| 33 | |||
| 34 | /* array of lines to be drawn on the map */ |
||
| 35 | protected $lines = array(); |
||
| 36 | |||
| 37 | /* kml file to be rendered */ |
||
| 38 | protected $kmlFiles = array(); |
||
| 39 | |||
| 40 | /** Default zoom of the gmap **/ |
||
| 41 | protected $zoom = 9; |
||
| 42 | |||
| 43 | /** Enable the zoom of the Infowindow **/ |
||
| 44 | protected $enableWindowZoom = false; |
||
| 45 | |||
| 46 | /** Default zoom of the Infowindow **/ |
||
| 47 | protected $infoWindowZoom = 13; |
||
| 48 | |||
| 49 | /** Lang of the gmap **/ |
||
| 50 | protected $lang = 'en'; |
||
| 51 | |||
| 52 | /**Center of the gmap **/ |
||
| 53 | protected $center = 'Paris, France'; |
||
| 54 | |||
| 55 | /* |
||
| 56 | Additional CSS classes to render as a class attribute for the div of the |
||
| 57 | map. Use this if you want more fine grained control over your map using |
||
| 58 | CSS. If blank it will be ignored |
||
| 59 | */ |
||
| 60 | protected $additional_css_classes = ''; |
||
| 61 | |||
| 62 | /* Decided whether or not to show the inline map css style on div creation */ |
||
| 63 | protected $show_inline_map_div_style = true; |
||
| 64 | |||
| 65 | protected $latLongCenter = null; |
||
| 66 | |||
| 67 | protected $jsonMapStyles = '[]'; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Type of the gmap, can be: |
||
| 71 | * 'road' (roadmap), |
||
| 72 | * 'satellite' (sattelite/aerial photographs) |
||
| 73 | * 'hybrid' (hybrid of road and satellite) |
||
| 74 | * 'terrain' (terrain) |
||
| 75 | * The JavaScript for the mapping service will convert this into a suitable mapping type. |
||
| 76 | */ |
||
| 77 | protected $mapType = 'road'; |
||
| 78 | |||
| 79 | /** Content of the HTML generated **/ |
||
| 80 | protected $content = ''; |
||
| 81 | |||
| 82 | protected $mapService = 'google'; |
||
| 83 | |||
| 84 | /** Hide the marker by default **/ |
||
| 85 | protected $defaultHideMarker = false; |
||
| 86 | |||
| 87 | /** Extra content (marker, etc...) **/ |
||
| 88 | protected $contentMarker = ''; |
||
| 89 | |||
| 90 | // a list of markers, markers being associative arrays |
||
| 91 | protected $markers = array(); |
||
| 92 | |||
| 93 | /** Use clusterer to display a lot of markers on the gmap **/ |
||
| 94 | protected $useClusterer = false; |
||
| 95 | protected $gridSize = 50; |
||
| 96 | protected $maxZoom = 17; |
||
| 97 | protected $clustererLibraryPath = '/mappable/javascript/google/markerclusterer.js'; |
||
| 98 | |||
| 99 | /** Enable automatic center/zoom **/ |
||
| 100 | protected $enableAutomaticCenterZoom = false; |
||
| 101 | |||
| 102 | /** maximum longitude of all markers **/ |
||
| 103 | protected $maxLng = -1000000; |
||
| 104 | |||
| 105 | /** minimum longitude of all markers **/ |
||
| 106 | protected $minLng = 1000000; |
||
| 107 | |||
| 108 | /** max latitude of all markers **/ |
||
| 109 | protected $maxLat = -1000000; |
||
| 110 | |||
| 111 | /** min latitude of all markers **/ |
||
| 112 | protected $minLat = 1000000; |
||
| 113 | |||
| 114 | /** map center latitude (horizontal), calculated automatically as markers |
||
| 115 | are added to the map **/ |
||
| 116 | protected $centerLat = null; |
||
| 117 | |||
| 118 | /** map center longitude (vertical), calculated automatically as markers |
||
| 119 | are added to the map **/ |
||
| 120 | protected $centerLng = null; |
||
| 121 | |||
| 122 | /** factor by which to fudge the boundaries so that when we zoom encompass, |
||
| 123 | the markers aren't too close to the edge **/ |
||
| 124 | protected $coordCoef = 0.01; |
||
| 125 | |||
| 126 | /* set this to true to render button to maximize / minimize a map */ |
||
| 127 | protected $allowFullScreen = null; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Class constructor. |
||
| 131 | * |
||
| 132 | * @param string $googleMapKey the googleMapKey |
||
| 133 | */ |
||
| 134 | 41 | public function __construct($googleMapKey = '') |
|
| 135 | { |
||
| 136 | 41 | $this->googleMapKey = $googleMapKey; |
|
| 137 | 41 | } |
|
| 138 | |||
| 139 | 3 | public function setShowInlineMapDivStyle($new_show_inline_map_div_style) |
|
| 140 | { |
||
| 141 | 3 | $this->show_inline_map_div_style = $new_show_inline_map_div_style; |
|
| 142 | |||
| 143 | 3 | return $this; |
|
| 144 | } |
||
| 145 | |||
| 146 | 3 | public function setAdditionalCSSClasses($new_additional_css_classes) |
|
| 147 | { |
||
| 148 | 3 | $this->additional_css_classes = $new_additional_css_classes; |
|
| 149 | |||
| 150 | 3 | return $this; |
|
| 151 | } |
||
| 152 | |||
| 153 | 1 | public function setMapStyle($newStyles) |
|
| 154 | { |
||
| 155 | 1 | $this->jsonMapStyles = $newStyles; |
|
| 156 | |||
| 157 | 1 | return $this; |
|
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Set the useClusterer parameter (optimization to display a lot of marker). |
||
| 162 | * |
||
| 163 | * @param bool $useClusterer use cluster or not |
||
| 164 | * @param int $gridSize grid size |
||
| 165 | * @param int $maxZoom max zoom to cluster at |
||
| 166 | * |
||
| 167 | * * @return MapAPI This same object, in order to enable chaining of methods |
||
| 168 | */ |
||
| 169 | 1 | public function setClusterer( |
|
| 170 | $useClusterer, |
||
| 171 | $gridSize = 50, |
||
| 172 | 1 | $maxZoom = 17, |
|
| 173 | 1 | $clustererLibraryPath = '/mappable/javascript/google/markerclusterer.js' |
|
| 174 | 1 | ) { |
|
| 175 | 1 | $this->useClusterer = $useClusterer; |
|
| 176 | $this->gridSize = $gridSize; |
||
| 177 | 1 | $this->maxZoom = $maxZoom; |
|
| 178 | $this->clustererLibraryPath = $clustererLibraryPath; |
||
| 179 | |||
| 180 | return $this; |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Set the ID of the default gmap DIV. |
||
| 185 | * |
||
| 186 | * @param string $googleMapId the google div ID |
||
| 187 | 41 | * |
|
| 188 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 189 | 41 | */ |
|
| 190 | public function setDivId($googleMapId) |
||
| 191 | 41 | { |
|
| 192 | $this->googleMapId = $googleMapId; |
||
| 193 | |||
| 194 | return $this; |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Set the size of the gmap. If these values are not provided |
||
| 199 | * then CSS is used instead. |
||
| 200 | * |
||
| 201 | * @param int $width GoogleMap width |
||
| 202 | * @param int $height GoogleMap height |
||
| 203 | 41 | * |
|
| 204 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 205 | 41 | */ |
|
| 206 | 41 | public function setSize($width, $height) |
|
| 207 | { |
||
| 208 | 41 | $this->width = $width; |
|
| 209 | $this->height = $height; |
||
| 210 | |||
| 211 | return $this; |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Set the lang of the gmap. |
||
| 216 | * |
||
| 217 | * @param string $lang GoogleMap lang : fr,en,.. |
||
| 218 | 41 | * |
|
| 219 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 220 | 41 | */ |
|
| 221 | public function setLang($lang) |
||
| 222 | 41 | { |
|
| 223 | $this->lang = $lang; |
||
| 224 | |||
| 225 | return $this; |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Set the zoom of the gmap. |
||
| 230 | * |
||
| 231 | * @param int $zoom GoogleMap zoom. |
||
| 232 | 32 | * |
|
| 233 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 234 | 32 | */ |
|
| 235 | public function setZoom($zoom) |
||
| 236 | 32 | { |
|
| 237 | $this->zoom = $zoom; |
||
| 238 | |||
| 239 | return $this; |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Set the zoom of the infowindow. |
||
| 244 | * |
||
| 245 | * @param int $infoWindowZoom GoogleMap information window zoom. |
||
| 246 | 1 | * |
|
| 247 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 248 | 1 | */ |
|
| 249 | public function setInfoWindowZoom($infoWindowZoom) |
||
| 250 | 1 | { |
|
| 251 | $this->infoWindowZoom = $infoWindowZoom; |
||
| 252 | |||
| 253 | return $this; |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Enable the zoom on the marker when you click on it. |
||
| 258 | * |
||
| 259 | * @param bool $enableWindowZoom info window enabled zoom. |
||
| 260 | 1 | * |
|
| 261 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 262 | 1 | */ |
|
| 263 | public function setEnableWindowZoom($enableWindowZoom) |
||
| 264 | 1 | { |
|
| 265 | $this->enableWindowZoom = $enableWindowZoom; |
||
| 266 | |||
| 267 | return $this; |
||
| 268 | } |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Enable theautomatic center/zoom at the gmap load. |
||
| 272 | * |
||
| 273 | * @param bool $enableAutomaticCenterZoom enable automatic centre zoom |
||
| 274 | 41 | * |
|
| 275 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 276 | 41 | */ |
|
| 277 | public function setEnableAutomaticCenterZoom($enableAutomaticCenterZoom) |
||
| 278 | 41 | { |
|
| 279 | $this->enableAutomaticCenterZoom = $enableAutomaticCenterZoom; |
||
| 280 | |||
| 281 | return $this; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Set the center of the gmap (an address). |
||
| 286 | * |
||
| 287 | * @param string $center GoogleMap center (an address) |
||
| 288 | 41 | * |
|
| 289 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 290 | 41 | */ |
|
| 291 | public function setCenter($center) |
||
| 292 | 41 | { |
|
| 293 | $this->center = $center; |
||
| 294 | |||
| 295 | return $this; |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Set the type of the gmap. Also takes into account legacy settings. |
||
| 300 | * |
||
| 301 | * FIXME - allow other valid settings in config for map type |
||
| 302 | * |
||
| 303 | * @param string $mapType Can be one of road,satellite,hybrid or terrain. Defaults to road |
||
| 304 | 41 | * |
|
| 305 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 306 | 41 | */ |
|
| 307 | public function setMapType($mapType) |
||
| 308 | { |
||
| 309 | $this->mapType = $mapType; |
||
| 310 | 41 | ||
| 311 | 2 | // deal with legacy values for backwards compatbility |
|
| 312 | 2 | switch ($mapType) { |
|
| 313 | 41 | case 'google.maps.MapTypeId.SATELLITE': |
|
| 314 | 2 | $this->mapType = 'satellite'; |
|
| 315 | 2 | break; |
|
| 316 | 41 | case 'google.maps.MapTypeId.G_HYBRID_MAP': |
|
| 317 | 2 | $this->mapType = 'hybrid'; |
|
| 318 | 2 | break; |
|
| 319 | 41 | case 'google.maps.MapTypeId.G_PHYSICAL_MAP': |
|
| 320 | 41 | $this->mapType = 'terrain'; |
|
| 321 | 41 | break; |
|
| 322 | case 'google.maps.MapTypeId.ROADMAP': |
||
| 323 | $this->mapType = 'road'; |
||
| 324 | 41 | break; |
|
| 325 | } |
||
| 326 | |||
| 327 | return $this; |
||
| 328 | } |
||
| 329 | |||
| 330 | /* |
||
| 331 | 41 | Set whether or not to allow the full screen tools |
|
| 332 | @return MapAPI This same object, in order to enable chaining of methods |
||
| 333 | 41 | */ |
|
| 334 | public function setAllowFullScreen($allowed) |
||
| 335 | 41 | { |
|
| 336 | $this->allowFullScreen = $allowed; |
||
| 337 | |||
| 338 | return $this; |
||
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Set the center of the gmap. |
||
| 343 | 5 | * |
|
| 344 | * @return MapAPI This same object, in order to enable chaining of methods |
||
| 345 | **/ |
||
| 346 | public function setLatLongCenter($center) |
||
| 347 | 5 | { |
|
| 348 | 1 | // error check, we want an associative array with lat,lng keys numeric |
|
| 349 | |||
| 350 | if (!is_array($center)) { |
||
| 351 | 5 | throw new InvalidArgumentException('Center must be an associative array containing lat,lng'); |
|
| 352 | 5 | } |
|
| 353 | 5 | ||
| 354 | 1 | $keys = array_keys($center); |
|
| 355 | sort($keys); |
||
| 356 | if (implode(',', $keys) != 'lat,lng') { |
||
| 357 | 5 | throw new InvalidArgumentException('Keys provided must be lat, lng'); |
|
| 358 | } |
||
| 359 | 5 | ||
| 360 | $this->latLongCenter = $center; |
||
| 361 | |||
| 362 | return $this; |
||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Set the defaultHideMarker. |
||
| 367 | * |
||
| 368 | * @param bool $defaultHideMarker hide all the markers on the map by default |
||
| 369 | 41 | * |
|
| 370 | * @return MapAPI |
||
| 371 | 41 | */ |
|
| 372 | public function setDefaultHideMarker($defaultHideMarker) |
||
| 373 | 41 | { |
|
| 374 | $this->defaultHideMarker = $defaultHideMarker; |
||
| 375 | |||
| 376 | return $this; |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Get the google map content. |
||
| 381 | 37 | * |
|
| 382 | * @return string the google map html code |
||
| 383 | 37 | */ |
|
| 384 | public function getGoogleMap() |
||
| 385 | { |
||
| 386 | return $this->content; |
||
| 387 | } |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Get URL content using cURL. |
||
| 391 | * |
||
| 392 | * @param string $url the url |
||
| 393 | * |
||
| 394 | * @return string the html code |
||
| 395 | 1 | * |
|
| 396 | * @todo add proxy settings |
||
| 397 | 1 | */ |
|
| 398 | 1 | public function getContent($url) |
|
| 399 | 1 | { |
|
| 400 | 1 | $curl = curl_init(); |
|
| 401 | 1 | curl_setopt($curl, CURLOPT_TIMEOUT, 10); |
|
| 402 | 1 | curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); |
|
| 403 | 1 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 404 | curl_setopt($curl, CURLOPT_URL, $url); |
||
| 405 | 1 | $data = curl_exec($curl); |
|
| 406 | curl_close($curl); |
||
| 407 | |||
| 408 | return $data; |
||
| 409 | } |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Geocoding an address (address -> lat,lng). |
||
| 413 | * |
||
| 414 | * @param string $address an address |
||
| 415 | 34 | * |
|
| 416 | * @return string array with precision, lat & lng |
||
| 417 | 34 | */ |
|
| 418 | 34 | public function geocoding($address) |
|
| 419 | 34 | { |
|
| 420 | 34 | $geocoder = new MappableGoogleGeocoder(); |
|
| 421 | 33 | $locations = $geocoder->getLocations($address); |
|
| 422 | 33 | $result = null; |
|
|
0 ignored issues
–
show
|
|||
| 423 | if (!empty($locations)) { |
||
| 424 | 33 | $place = $locations[0]; |
|
| 425 | 33 | $location = $place['geometry']['location']; |
|
| 426 | 33 | $result = array( |
|
| 427 | 33 | 'lat' => $location['lat'], |
|
| 428 | 33 | 'lon' => $location['lng'], |
|
| 429 | 1 | 'geocoded' => true, |
|
| 430 | ); |
||
| 431 | } else { |
||
| 432 | 34 | $result = array(); // no results |
|
| 433 | } |
||
| 434 | |||
| 435 | return $result; |
||
| 436 | } |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Add marker by his coord. |
||
| 440 | * |
||
| 441 | * @param string $lat lat |
||
| 442 | * @param string $lng lngs |
||
| 443 | * @param string $html html code display in the info window |
||
| 444 | * @param string $category marker category |
||
| 445 | * @param string $icon an icon url |
||
| 446 | 13 | * |
|
| 447 | * @return MapAPI |
||
| 448 | */ |
||
| 449 | 13 | public function addMarkerByCoords($lat, $lng, $html = '', $category = '', $icon = '') |
|
| 450 | 13 | { |
|
| 451 | 13 | $m = array( |
|
| 452 | 13 | 'latitude' => $lat, |
|
| 453 | 13 | 'longitude' => $lng, |
|
| 454 | 13 | 'html' => $html, |
|
| 455 | 13 | 'category' => $category, |
|
| 456 | 'icon' => $icon, |
||
| 457 | 13 | ); |
|
| 458 | array_push($this->markers, $m); |
||
| 459 | |||
| 460 | return $this; |
||
| 461 | } |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Add marker by his address. |
||
| 465 | * |
||
| 466 | * @param string $address an ddress |
||
| 467 | * @param string $content html code display in the info window |
||
| 468 | * @param string $category marker category |
||
| 469 | * @param string $icon an icon url |
||
| 470 | 1 | * |
|
| 471 | * @return MapAPI |
||
| 472 | 1 | */ |
|
| 473 | 1 | public function addMarkerByAddress($address, $content = '', $category = '', $icon = '') |
|
| 474 | 1 | { |
|
| 475 | 1 | $point = $this->geocoding($address); |
|
| 476 | if ($point !== null) { |
||
| 477 | 1 | $this->addMarkerByCoords($point['lat'], $point['lon'], $content, $category, $icon); |
|
| 478 | } |
||
| 479 | |||
| 480 | return $this; |
||
| 481 | } |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Add marker by an array of coord. |
||
| 485 | * |
||
| 486 | * @param array $coordtab an array of lat,lng,content |
||
| 487 | * @param string $category marker category |
||
| 488 | * @param string $icon an icon url |
||
| 489 | 1 | * |
|
| 490 | * @return MapAPI |
||
| 491 | 1 | */ |
|
| 492 | 1 | public function addArrayMarkerByCoords($coordtab, $category = '', $icon = '') |
|
| 493 | 1 | { |
|
| 494 | foreach ($coordtab as $coord) { |
||
| 495 | 1 | $this->addMarkerByCoords($coord[0], $coord[1], $coord[2], $category, $icon); |
|
| 496 | } |
||
| 497 | |||
| 498 | return $this; |
||
| 499 | } |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Adds a {@link ViewableData} object that implements {@link Mappable} |
||
| 503 | * to the map. |
||
| 504 | * |
||
| 505 | 10 | * @param $infowindowtemplateparams Optional array of extra parameters to pass to the map info window |
|
| 506 | * @param ViewableData $obj |
||
| 507 | 10 | */ |
|
| 508 | 10 | public function addMarkerAsObject(ViewableData $obj, $infowindowtemplateparams = null) |
|
| 509 | 10 | { |
|
| 510 | 10 | $extensionsImplementMappable = false; |
|
| 511 | 9 | $extensions = Object::get_extensions(get_class($obj)); |
|
| 512 | 9 | if (is_array($extensions)) { |
|
| 513 | 9 | foreach ($extensions as $extension) { |
|
| 514 | 9 | $class = new ReflectionClass($extension); |
|
| 515 | 10 | if ($class->implementsInterface('Mappable')) { |
|
| 516 | 10 | $extensionsImplementMappable = true; |
|
| 517 | } |
||
| 518 | 10 | } |
|
| 519 | 1 | } |
|
| 520 | |||
| 521 | 10 | if ($extensionsImplementMappable || |
|
| 522 | 10 | ($obj instanceof Mappable) || |
|
| 523 | 10 | (Object::has_extension($obj->ClassName, 'MapExtension')) |
|
| 524 | 5 | ) { |
|
| 525 | 2 | $cat = $obj->hasMethod('getMappableMapCategory') ? $obj->getMappableMapCategory() : 'default'; |
|
| 526 | 5 | if ($infowindowtemplateparams !== null) { |
|
| 527 | 5 | foreach ($infowindowtemplateparams as $key => $value) { |
|
| 528 | 10 | $obj->{$key} = $value; |
|
| 529 | 10 | } |
|
| 530 | 10 | } |
|
| 531 | 10 | $this->addMarkerByCoords( |
|
| 532 | 10 | $obj->getMappableLatitude(), |
|
| 533 | 10 | $obj->getMappableLongitude(), |
|
| 534 | 10 | $obj->getMappableMapContent(), |
|
| 535 | 10 | $cat, |
|
| 536 | $obj->getMappableMapPin() |
||
| 537 | 10 | ); |
|
| 538 | } |
||
| 539 | |||
| 540 | return $this; |
||
| 541 | } |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Draws a line between two {@link ViewableData} objects. |
||
| 545 | * |
||
| 546 | * @param ViewableData $one The first point |
||
| 547 | 1 | * @param ViewableData $two The second point |
|
| 548 | * @param string $color The hexidecimal color of the line |
||
| 549 | 1 | */ |
|
| 550 | 1 | public function connectPoints(ViewableData $one, ViewableData $two, $color = '#FF3300') |
|
| 551 | 1 | { |
|
| 552 | $this->addLine( |
||
| 553 | 1 | array($one->getMappableLatitude(), $one->getMappableLongitude()), |
|
| 554 | 1 | array($two->getMappableLatitude(), $two->getMappableLongitude()), |
|
| 555 | $color |
||
| 556 | 37 | ); |
|
| 557 | } |
||
| 558 | 37 | ||
| 559 | 37 | public function forTemplate() |
|
| 560 | { |
||
| 561 | 37 | $this->generate(); |
|
| 562 | MapUtil::set_map_already_rendered(true); |
||
| 563 | |||
| 564 | return $this->getGoogleMap(); |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Add a KML file which will be rendered on this map. Normally used for likes |
||
| 569 | * of GPS traces from activities. |
||
| 570 | * |
||
| 571 | * @param string $url url of the kml file compatible with gmap and gearth |
||
| 572 | 2 | * |
|
| 573 | * @return MapAPI |
||
| 574 | 2 | */ |
|
| 575 | public function addKML($url) |
||
| 576 | 2 | { |
|
| 577 | array_push($this->kmlFiles, $url); |
||
| 578 | |||
| 579 | return $this; |
||
| 580 | } |
||
| 581 | |||
| 582 | /* |
||
| 583 | 2 | Add a line to the map |
|
| 584 | |||
| 585 | */ |
||
| 586 | 2 | public function addLine($from = array(), $to = array(), $color = '#FF3300') |
|
| 587 | 2 | { |
|
| 588 | 2 | $line = array( |
|
| 589 | 2 | 'lat1' => $from[0], |
|
| 590 | 2 | 'lon1' => $from[1], |
|
| 591 | 2 | 'lat2' => $to[0], |
|
| 592 | 'lon2' => $to[1], |
||
| 593 | 2 | 'color' => $color, |
|
| 594 | ); |
||
| 595 | 2 | ||
| 596 | array_push($this->lines, $line); |
||
| 597 | |||
| 598 | return $this; |
||
| 599 | } |
||
| 600 | |||
| 601 | /* |
||
| 602 | For php 5.3 |
||
| 603 | */ |
||
| 604 | public static function jsonRemoveUnicodeSequences($struct) |
||
| 605 | { |
||
| 606 | return preg_replace( |
||
| 607 | '/\\\\u([a-f0-9]{4})/e', |
||
| 608 | "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", |
||
| 609 | json_encode($struct) |
||
| 610 | ); |
||
| 611 | 37 | } |
|
| 612 | |||
| 613 | /** |
||
| 614 | 37 | * Generate the gmap. |
|
| 615 | 37 | */ |
|
| 616 | 37 | public function generate() |
|
| 617 | { |
||
| 618 | // from http://stackoverflow.com/questions/3586401/cant-decode-json-string-in-php |
||
| 619 | 37 | $jsonMarkers = null; |
|
|
0 ignored issues
–
show
$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 Loading history...
|
|||
| 620 | $linesJson = null; |
||
|
0 ignored issues
–
show
$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 Loading history...
|
|||
| 621 | $kmlJson = null; |
||
|
0 ignored issues
–
show
$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 Loading history...
|
|||
| 622 | |||
| 623 | // prior to PHP version 5.4, one needs to use regex |
||
| 624 | 37 | if (PHP_VERSION_ID < 50400) { |
|
| 625 | 37 | $jsonMarkers = stripslashes(self::jsonRemoveUnicodeSequences($this->markers)); |
|
| 626 | 37 | $linesJson = stripslashes(self::jsonRemoveUnicodeSequences($this->lines)); |
|
| 627 | $kmlJson = stripslashes(self::jsonRemoveUnicodeSequences($this->kmlFiles)); |
||
| 628 | } else { |
||
| 629 | $jsonMarkers = stripslashes(json_encode($this->markers, JSON_UNESCAPED_UNICODE)); |
||
| 630 | 37 | $linesJson = stripslashes(json_encode($this->lines, JSON_UNESCAPED_UNICODE)); |
|
| 631 | 37 | $kmlJson = stripslashes(json_encode($this->kmlFiles, JSON_UNESCAPED_UNICODE)); |
|
| 632 | } |
||
| 633 | 37 | ||
| 634 | // Center of the GMap - text centre takes precedence |
||
| 635 | 37 | $geocodeCentre = ($this->latLongCenter) ? |
|
| 636 | $this->latLongCenter : $this->geocoding($this->center); |
||
| 637 | 32 | ||
| 638 | 32 | $latlngCentre = null; |
|
| 639 | 32 | // coordinates for centre depending on which method used |
|
| 640 | 37 | if (isset($geocodeCentre['geocoded'])) { |
|
| 641 | 5 | $latlngCentre = array( |
|
| 642 | 5 | 'lat' => $geocodeCentre['lat'], |
|
| 643 | 'lng' => $geocodeCentre['lon'], |
||
| 644 | 37 | ); |
|
| 645 | } elseif (is_array($this->latLongCenter)) { |
||
| 646 | 37 | $latlngCentre = $this->latLongCenter; |
|
| 647 | 37 | } |
|
| 648 | 37 | ||
| 649 | 37 | $this->LatLngCentreJSON = stripslashes(json_encode($latlngCentre)); |
|
|
0 ignored issues
–
show
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 <?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...
|
|||
| 650 | 37 | ||
| 651 | 37 | $lenLng = $this->maxLng - $this->minLng; |
|
| 652 | $lenLat = $this->maxLat - $this->minLat; |
||
| 653 | $this->minLng -= $lenLng * $this->coordCoef; |
||
| 654 | 37 | $this->maxLng += $lenLng * $this->coordCoef; |
|
| 655 | $this->minLat -= $lenLat * $this->coordCoef; |
||
| 656 | 37 | $this->maxLat += $lenLat * $this->coordCoef; |
|
| 657 | 26 | ||
| 658 | 26 | // add the css class mappable as a handle onto the map styling |
|
| 659 | $this->additional_css_classes .= ' mappable'; |
||
| 660 | 37 | ||
| 661 | 37 | if (!$this->enableAutomaticCenterZoom) { |
|
| 662 | 37 | $this->enableAutomaticCenterZoom = 'false'; |
|
|
0 ignored issues
–
show
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...
|
|||
| 663 | } |
||
| 664 | 37 | ||
| 665 | 37 | if (!$this->useClusterer) { |
|
| 666 | 37 | $this->useClusterer = 'false'; |
|
|
0 ignored issues
–
show
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...
|
|||
| 667 | } |
||
| 668 | |||
| 669 | 37 | if (!$this->defaultHideMarker) { |
|
| 670 | 1 | $this->defaultHideMarker = 'false'; |
|
|
0 ignored issues
–
show
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...
|
|||
| 671 | 1 | } |
|
| 672 | |||
| 673 | 37 | // initialise full screen as the config value if not already set |
|
| 674 | 1 | if ($this->allowFullScreen === null) { |
|
| 675 | 1 | $this->allowFullScreen = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
| 676 | } |
||
| 677 | 37 | ||
| 678 | 37 | if (!$this->allowFullScreen) { |
|
| 679 | 37 | $this->allowFullScreen = 'false'; |
|
| 680 | } |
||
| 681 | 37 | ||
| 682 | if (!$this->enableWindowZoom) { |
||
| 683 | 37 | $this->enableWindowZoom = 'false'; |
|
|
0 ignored issues
–
show
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...
|
|||
| 684 | 37 | } |
|
| 685 | 37 | ||
| 686 | 37 | $vars = new ArrayData( |
|
| 687 | 37 | array( |
|
| 688 | 37 | ||
| 689 | 37 | 'JsonMapStyles' => $this->jsonMapStyles, |
|
| 690 | 37 | 'AdditionalCssClasses' => $this->additional_css_classes, |
|
| 691 | 37 | 'Width' => $this->width, |
|
| 692 | 37 | 'Height' => $this->height, |
|
| 693 | 37 | 'ShowInlineMapDivStyle' => $this->show_inline_map_div_style, |
|
| 694 | 37 | 'InfoWindowZoom' => $this->infoWindowZoom, |
|
| 695 | 37 | 'EnableWindowZoom' => $this->enableWindowZoom, |
|
| 696 | 37 | 'MapMarkers' => $jsonMarkers, |
|
| 697 | 37 | 'DefaultHideMarker' => $this->defaultHideMarker, |
|
| 698 | 37 | 'LatLngCentre' => $this->LatLngCentreJSON, |
|
|
0 ignored issues
–
show
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 <?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...
|
|||
| 699 | 37 | 'EnableAutomaticCenterZoom' => $this->enableAutomaticCenterZoom, |
|
| 700 | 37 | 'Zoom' => $this->zoom, |
|
| 701 | 37 | 'MaxZoom' => $this->maxZoom, |
|
| 702 | 37 | 'GridSize' => $this->gridSize, |
|
| 703 | 37 | 'MapType' => $this->mapType, |
|
| 704 | 37 | 'GoogleMapID' => $this->googleMapId, |
|
| 705 | 37 | 'Lang' => $this->lang, |
|
| 706 | 37 | 'UseClusterer' => $this->useClusterer, |
|
| 707 | 37 | 'ClustererLibraryPath' => $this->clustererLibraryPath, |
|
| 708 | 'ClustererMaxZoom' => $this->maxZoom, |
||
| 709 | 37 | 'ClustererGridSize' => $this->gridSize, |
|
| 710 | 'Lines' => $linesJson, |
||
| 711 | 37 | 'KmlFiles' => $kmlJson, |
|
| 712 | 36 | 'AllowFullScreen' => $this->allowFullScreen, |
|
| 713 | 36 | 'UseCompressedAssets' => Config::inst()->get('Mappable', 'use_compressed_assets'), |
|
| 714 | 36 | ) |
|
| 715 | ); |
||
| 716 | |||
| 717 | 37 | if (!MapUtil::get_map_already_rendered()) { |
|
| 718 | 37 | $vars->setField('GoogleMapKey', $this->googleMapKey); |
|
| 719 | $vars->setField('GoogleMapLang', $this->lang); |
||
| 720 | } |
||
| 721 | |||
| 722 | // HTML component of the map |
||
| 723 | $this->content = $this->processTemplateHTML('Map', $vars); |
||
| 724 | 38 | } |
|
| 725 | |||
| 726 | 38 | /** |
|
| 727 | 1 | * @param string $templateName |
|
| 728 | 1 | * @param ArrayData $templateVariables |
|
| 729 | 38 | */ |
|
| 730 | 38 | public function processTemplateHTML($templateName, $templateVariables = null) |
|
| 731 | { |
||
| 732 | 38 | if (!$templateVariables) { |
|
| 733 | $templateVariables = new ArrayList(); |
||
| 734 | } |
||
| 735 | 1 | $mappingService = Config::inst()->get('Mappable', 'mapping_service'); |
|
| 736 | $result = $templateVariables->renderWith($templateName.$mappingService.'HTML'); |
||
| 737 | |||
| 738 | return $result; |
||
| 739 | } |
||
| 740 | } |
||
| 741 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.