@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | // phpcs:disable PSR1.Files.SideEffects |
23 | 23 | // TODO resolve side effect |
24 | -include_once(realpath(__DIR__) . '/../geophp/geoPHP/geoPHP.inc'); |
|
24 | +include_once(realpath(__DIR__).'/../geophp/geoPHP/geoPHP.inc'); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | $this->height = $height; |
206 | 206 | // validate + set maptype |
207 | 207 | $this->maptype = $this->tileDefaultSrc; |
208 | - if(array_key_exists($maptype, $this->tileInfo)) { |
|
208 | + if (array_key_exists($maptype, $this->tileInfo)) { |
|
209 | 209 | $this->maptype = $maptype; |
210 | 210 | } |
211 | 211 | $this->markers = $markers; |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | $this->gpxFileName = $gpx; |
214 | 214 | $this->geojsonFileName = $geojson; |
215 | 215 | $this->mediaBaseDir = $mediaDir; |
216 | - $this->tileCacheBaseDir = $tileCacheBaseDir . '/olmaptiles'; |
|
216 | + $this->tileCacheBaseDir = $tileCacheBaseDir.'/olmaptiles'; |
|
217 | 217 | $this->useTileCache = $this->tileCacheBaseDir !== ''; |
218 | - $this->mapCacheBaseDir = $mediaDir . '/olmapmaps'; |
|
218 | + $this->mapCacheBaseDir = $mediaDir.'/olmapmaps'; |
|
219 | 219 | $this->autoZoomExtent = $autoZoomExtent; |
220 | 220 | $this->apikey = $apikey; |
221 | 221 | } |
@@ -227,15 +227,15 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function getMap(): string { |
229 | 229 | try { |
230 | - if($this->autoZoomExtent) { |
|
230 | + if ($this->autoZoomExtent) { |
|
231 | 231 | $this->autoZoom(); |
232 | 232 | } |
233 | - } catch(Exception $e) { |
|
233 | + } catch (Exception $e) { |
|
234 | 234 | dbglog($e); |
235 | 235 | } |
236 | 236 | |
237 | 237 | // use map cache, so check cache for map |
238 | - if(!$this->checkMapCache()) { |
|
238 | + if (!$this->checkMapCache()) { |
|
239 | 239 | // map is not in cache, needs to be build |
240 | 240 | $this->makeMap(); |
241 | 241 | $this->mkdirRecursive(dirname($this->mapCacheIDToFilename()), 0777); |
@@ -258,37 +258,37 @@ discard block |
||
258 | 258 | */ |
259 | 259 | private function autoZoom(float $paddingFactor = 1.0): void { |
260 | 260 | $geoms = array(); |
261 | - $geoms [] = new Point ($this->lon, $this->lat); |
|
262 | - if(!empty ($this->markers)) { |
|
263 | - foreach($this->markers as $marker) { |
|
264 | - $geoms [] = new Point ($marker ['lon'], $marker ['lat']); |
|
261 | + $geoms [] = new Point($this->lon, $this->lat); |
|
262 | + if (!empty ($this->markers)) { |
|
263 | + foreach ($this->markers as $marker) { |
|
264 | + $geoms [] = new Point($marker ['lon'], $marker ['lat']); |
|
265 | 265 | } |
266 | 266 | } |
267 | - if(file_exists($this->kmlFileName)) { |
|
267 | + if (file_exists($this->kmlFileName)) { |
|
268 | 268 | $g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml'); |
269 | - if($g !== false) { |
|
269 | + if ($g !== false) { |
|
270 | 270 | $geoms [] = $g; |
271 | 271 | } |
272 | 272 | } |
273 | - if(file_exists($this->gpxFileName)) { |
|
273 | + if (file_exists($this->gpxFileName)) { |
|
274 | 274 | $g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx'); |
275 | - if($g !== false) { |
|
275 | + if ($g !== false) { |
|
276 | 276 | $geoms [] = $g; |
277 | 277 | } |
278 | 278 | } |
279 | - if(file_exists($this->geojsonFileName)) { |
|
279 | + if (file_exists($this->geojsonFileName)) { |
|
280 | 280 | $g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson'); |
281 | - if($g !== false) { |
|
281 | + if ($g !== false) { |
|
282 | 282 | $geoms [] = $g; |
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - if(count($geoms) <= 1) { |
|
286 | + if (count($geoms) <= 1) { |
|
287 | 287 | dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options"); |
288 | 288 | return; |
289 | 289 | } |
290 | 290 | |
291 | - $geom = new GeometryCollection ($geoms); |
|
291 | + $geom = new GeometryCollection($geoms); |
|
292 | 292 | $centroid = $geom->centroid(); |
293 | 293 | $bbox = $geom->getBBox(); |
294 | 294 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | $vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360))); |
298 | 298 | $vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360))); |
299 | 299 | dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1"); |
300 | - if ($vy1 - $vy0 === 0.0){ |
|
300 | + if ($vy1 - $vy0 === 0.0) { |
|
301 | 301 | $resolutionVertical = 0; |
302 | 302 | dbglog("StaticMap::autoZoom: using $resolutionVertical"); |
303 | 303 | } else { |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | dbglog("StaticMap::autoZoom: using $resolutionHorizontal"); |
310 | 310 | $resolution = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor; |
311 | 311 | $zoom = $this->zoom; |
312 | - if ($resolution > 0){ |
|
312 | + if ($resolution > 0) { |
|
313 | 313 | $zoom = log(360 / ($resolution * $this->tileSize), 2); |
314 | 314 | } |
315 | 315 | |
316 | - if(is_finite($zoom) && $zoom < 15 && $zoom > 2) { |
|
316 | + if (is_finite($zoom) && $zoom < 15 && $zoom > 2) { |
|
317 | 317 | $this->zoom = floor($zoom); |
318 | 318 | } |
319 | 319 | $this->lon = $centroid->getX(); |
@@ -346,12 +346,12 @@ discard block |
||
346 | 346 | } |
347 | 347 | |
348 | 348 | public function mapCacheIDToFilename(): string { |
349 | - if(!$this->mapCacheFile) { |
|
350 | - $this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_" |
|
351 | - . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2) |
|
352 | - . "/" . substr($this->mapCacheID, 4); |
|
349 | + if (!$this->mapCacheFile) { |
|
350 | + $this->mapCacheFile = $this->mapCacheBaseDir."/".$this->maptype."/".$this->zoom."/cache_" |
|
351 | + . substr($this->mapCacheID, 0, 2)."/".substr($this->mapCacheID, 2, 2) |
|
352 | + . "/".substr($this->mapCacheID, 4); |
|
353 | 353 | } |
354 | - return $this->mapCacheFile . "." . $this->mapCacheExtension; |
|
354 | + return $this->mapCacheFile.".".$this->mapCacheExtension; |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | public function makeMap(): void { |
361 | 361 | $this->initCoords(); |
362 | 362 | $this->createBaseMap(); |
363 | - if(!empty ($this->markers)) { |
|
363 | + if (!empty ($this->markers)) { |
|
364 | 364 | $this->placeMarkers(); |
365 | 365 | } |
366 | 366 | if (file_exists($this->kmlFileName)) { |
@@ -433,8 +433,8 @@ discard block |
||
433 | 433 | $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize; |
434 | 434 | $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize; |
435 | 435 | |
436 | - for($x = $startX; $x <= $endX; $x++) { |
|
437 | - for($y = $startY; $y <= $endY; $y++) { |
|
436 | + for ($x = $startX; $x <= $endX; $x++) { |
|
437 | + for ($y = $startY; $y <= $endY; $y++) { |
|
438 | 438 | $url = str_replace( |
439 | 439 | array( |
440 | 440 | '{Z}', |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | ); |
449 | 449 | |
450 | 450 | $tileData = $this->fetchTile($url); |
451 | - if($tileData) { |
|
451 | + if ($tileData) { |
|
452 | 452 | $tileImage = imagecreatefromstring($tileData); |
453 | 453 | } else { |
454 | 454 | $tileImage = imagecreate($this->tileSize, $this->tileSize); |
@@ -474,17 +474,17 @@ discard block |
||
474 | 474 | * for better proxy handling... |
475 | 475 | */ |
476 | 476 | public function fetchTile(string $url) { |
477 | - if($this->useTileCache && ($cached = $this->checkTileCache($url))) |
|
477 | + if ($this->useTileCache && ($cached = $this->checkTileCache($url))) |
|
478 | 478 | return $cached; |
479 | 479 | |
480 | - $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')'; |
|
481 | - if(function_exists("curl_init")) { |
|
480 | + $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; '.PHP_OS.')'; |
|
481 | + if (function_exists("curl_init")) { |
|
482 | 482 | // use cUrl |
483 | 483 | $ch = curl_init(); |
484 | 484 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
485 | 485 | curl_setopt($ch, CURLOPT_USERAGENT, $_UA); |
486 | 486 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
487 | - curl_setopt($ch, CURLOPT_URL, $url . $this->apikey); |
|
487 | + curl_setopt($ch, CURLOPT_URL, $url.$this->apikey); |
|
488 | 488 | dbglog("StaticMap::fetchTile: getting: $url using curl_exec"); |
489 | 489 | $tile = curl_exec($ch); |
490 | 490 | curl_close($ch); |
@@ -494,21 +494,21 @@ discard block |
||
494 | 494 | $opts = array( |
495 | 495 | 'http' => array( |
496 | 496 | 'method' => "GET", |
497 | - 'header' => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n", |
|
497 | + 'header' => "Accept-language: en\r\n"."User-Agent: $_UA\r\n"."accept: image/png\r\n", |
|
498 | 498 | 'request_fulluri' => true |
499 | 499 | ) |
500 | 500 | ); |
501 | - if(isset($conf['proxy']['host'], $conf['proxy']['port']) |
|
501 | + if (isset($conf['proxy']['host'], $conf['proxy']['port']) |
|
502 | 502 | && $conf['proxy']['host'] !== '' |
503 | 503 | && $conf['proxy']['port'] !== '') { |
504 | - $opts['http'] += ['proxy' => "tcp://" . $conf['proxy']['host'] . ":" . $conf['proxy']['port']]; |
|
504 | + $opts['http'] += ['proxy' => "tcp://".$conf['proxy']['host'].":".$conf['proxy']['port']]; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | $context = stream_context_create($opts); |
508 | 508 | dbglog("StaticMap::fetchTile: getting: $url . $this->apikey using file_get_contents and options $opts"); |
509 | - $tile = file_get_contents($url . $this->apikey, false, $context); |
|
509 | + $tile = file_get_contents($url.$this->apikey, false, $context); |
|
510 | 510 | } |
511 | - if($tile && $this->useTileCache) { |
|
511 | + if ($tile && $this->useTileCache) { |
|
512 | 512 | $this->writeTileToCache($url, $tile); |
513 | 513 | } |
514 | 514 | return $tile; |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | */ |
522 | 522 | public function checkTileCache(string $url) { |
523 | 523 | $filename = $this->tileUrlToFilename($url); |
524 | - if(file_exists($filename)) { |
|
524 | + if (file_exists($filename)) { |
|
525 | 525 | return file_get_contents($filename); |
526 | 526 | } |
527 | 527 | return false; |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | * @return string |
534 | 534 | */ |
535 | 535 | public function tileUrlToFilename(string $url): string { |
536 | - return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1); |
|
536 | + return $this->tileCacheBaseDir."/".substr($url, strpos($url, '/') + 1); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -568,14 +568,14 @@ discard block |
||
568 | 568 | $count = 0; |
569 | 569 | $color = imagecolorallocate($this->image, 0, 0, 0); |
570 | 570 | $bgcolor = imagecolorallocate($this->image, 200, 200, 200); |
571 | - $markerBaseDir = __DIR__ . '/icons'; |
|
571 | + $markerBaseDir = __DIR__.'/icons'; |
|
572 | 572 | $markerImageOffsetX = 0; |
573 | 573 | $markerImageOffsetY = 0; |
574 | 574 | $markerShadowOffsetX = 0; |
575 | 575 | $markerShadowOffsetY = 0; |
576 | 576 | $markerShadowImg = null; |
577 | 577 | // loop thru marker array |
578 | - foreach($this->markers as $marker) { |
|
578 | + foreach ($this->markers as $marker) { |
|
579 | 579 | // set some local variables |
580 | 580 | $markerLat = $marker ['lat']; |
581 | 581 | $markerLon = $marker ['lon']; |
@@ -585,18 +585,18 @@ discard block |
||
585 | 585 | $markerShadow = ''; |
586 | 586 | $matches = false; |
587 | 587 | // check for marker type, get settings from markerPrototypes |
588 | - if($markerType) { |
|
589 | - foreach($this->markerPrototypes as $markerPrototype) { |
|
590 | - if(preg_match($markerPrototype ['regex'], $markerType, $matches)) { |
|
591 | - $markerFilename = $matches [0] . $markerPrototype ['extension']; |
|
592 | - if($markerPrototype ['offsetImage']) { |
|
588 | + if ($markerType) { |
|
589 | + foreach ($this->markerPrototypes as $markerPrototype) { |
|
590 | + if (preg_match($markerPrototype ['regex'], $markerType, $matches)) { |
|
591 | + $markerFilename = $matches [0].$markerPrototype ['extension']; |
|
592 | + if ($markerPrototype ['offsetImage']) { |
|
593 | 593 | list ($markerImageOffsetX, $markerImageOffsetY) = explode( |
594 | 594 | ",", |
595 | 595 | $markerPrototype ['offsetImage'] |
596 | 596 | ); |
597 | 597 | } |
598 | 598 | $markerShadow = $markerPrototype ['shadow']; |
599 | - if($markerShadow) { |
|
599 | + if ($markerShadow) { |
|
600 | 600 | list ($markerShadowOffsetX, $markerShadowOffsetY) = explode( |
601 | 601 | ",", |
602 | 602 | $markerPrototype ['offsetShadow'] |
@@ -606,14 +606,14 @@ discard block |
||
606 | 606 | } |
607 | 607 | } |
608 | 608 | // create img resource |
609 | - if(file_exists($markerBaseDir . '/' . $markerFilename)) { |
|
610 | - $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename); |
|
609 | + if (file_exists($markerBaseDir.'/'.$markerFilename)) { |
|
610 | + $markerImg = imagecreatefrompng($markerBaseDir.'/'.$markerFilename); |
|
611 | 611 | } else { |
612 | - $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png'); |
|
612 | + $markerImg = imagecreatefrompng($markerBaseDir.'/marker.png'); |
|
613 | 613 | } |
614 | 614 | // check for shadow + create shadow recource |
615 | - if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) { |
|
616 | - $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow); |
|
615 | + if ($markerShadow && file_exists($markerBaseDir.'/'.$markerShadow)) { |
|
616 | + $markerShadowImg = imagecreatefrompng($markerBaseDir.'/'.$markerShadow); |
|
617 | 617 | } |
618 | 618 | // calc position |
619 | 619 | $destX = floor( |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom)) |
626 | 626 | ); |
627 | 627 | // copy shadow on basemap |
628 | - if($markerShadow && $markerShadowImg) { |
|
628 | + if ($markerShadow && $markerShadowImg) { |
|
629 | 629 | imagecopy( |
630 | 630 | $this->image, |
631 | 631 | $markerShadowImg, |
@@ -687,14 +687,14 @@ discard block |
||
687 | 687 | * drawing colour |
688 | 688 | */ |
689 | 689 | private function drawGeometry(Geometry $geom, int $colour): void { |
690 | - if(empty($geom)) { |
|
690 | + if (empty($geom)) { |
|
691 | 691 | return; |
692 | 692 | } |
693 | 693 | |
694 | - switch($geom->geometryType()) { |
|
694 | + switch ($geom->geometryType()) { |
|
695 | 695 | case 'GeometryCollection' : |
696 | 696 | // recursively draw part of the collection |
697 | - for($i = 1; $i < $geom->numGeometries() + 1; $i++) { |
|
697 | + for ($i = 1; $i < $geom->numGeometries() + 1; $i++) { |
|
698 | 698 | $_geom = $geom->geometryN($i); |
699 | 699 | $this->drawGeometry($_geom, $colour); |
700 | 700 | } |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | // extring is a linestring actually.. |
737 | 737 | $extRing = $polygon->exteriorRing(); |
738 | 738 | |
739 | - for($i = 1; $i < $extRing->numGeometries(); $i++) { |
|
739 | + for ($i = 1; $i < $extRing->numGeometries(); $i++) { |
|
740 | 740 | $p1 = $extRing->geometryN($i); |
741 | 741 | $x = floor( |
742 | 742 | ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom)) |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | */ |
763 | 763 | private function drawLineString($line, $colour) { |
764 | 764 | imagesetthickness($this->image, 2); |
765 | - for($p = 1; $p < $line->numGeometries(); $p++) { |
|
765 | + for ($p = 1; $p < $line->numGeometries(); $p++) { |
|
766 | 766 | // get first pair of points |
767 | 767 | $p1 = $line->geometryN($p); |
768 | 768 | $p2 = $line->geometryN($p + 1); |
@@ -835,8 +835,8 @@ discard block |
||
835 | 835 | * add copyright and origin notice and icons to the map. |
836 | 836 | */ |
837 | 837 | public function drawCopyright() { |
838 | - $logoBaseDir = dirname(__FILE__) . '/' . 'logo/'; |
|
839 | - $logoImg = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']); |
|
838 | + $logoBaseDir = dirname(__FILE__).'/'.'logo/'; |
|
839 | + $logoImg = imagecreatefrompng($logoBaseDir.$this->tileInfo ['openstreetmap'] ['logo']); |
|
840 | 840 | $textcolor = imagecolorallocate($this->image, 0, 0, 0); |
841 | 841 | $bgcolor = imagecolorallocate($this->image, 200, 200, 200); |
842 | 842 | |
@@ -869,11 +869,11 @@ discard block |
||
869 | 869 | |
870 | 870 | // additional tile source info, ie. who created/hosted the tiles |
871 | 871 | $xIconOffset = 0; |
872 | - if($this->maptype === 'openstreetmap') { |
|
872 | + if ($this->maptype === 'openstreetmap') { |
|
873 | 873 | $mapAuthor = "(c) OpenStreetMap maps/CC BY-SA"; |
874 | 874 | } else { |
875 | 875 | $mapAuthor = $this->tileInfo [$this->maptype] ['txt']; |
876 | - $iconImg = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']); |
|
876 | + $iconImg = imagecreatefrompng($logoBaseDir.$this->tileInfo [$this->maptype] ['logo']); |
|
877 | 877 | $xIconOffset = imagesx($iconImg); |
878 | 878 | imagecopy( |
879 | 879 | $this->image, |