Passed
Push — master ( 5aa58a...ca15cf )
by Mark
02:23
created
StaticMap.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
         $this->height = $height;
216 216
         // validate + set maptype
217 217
         $this->maptype = $this->tileDefaultSrc;
218
-        if(array_key_exists($maptype, $this->tileInfo)) {
218
+        if (array_key_exists($maptype, $this->tileInfo)) {
219 219
             $this->maptype = $maptype;
220 220
         }
221 221
         $this->markers          = $markers;
@@ -223,9 +223,9 @@  discard block
 block discarded – undo
223 223
         $this->gpxFileName      = $gpx;
224 224
         $this->geojsonFileName  = $geojson;
225 225
         $this->mediaBaseDir     = $mediaDir;
226
-        $this->tileCacheBaseDir = $tileCacheBaseDir . '/olmaptiles';
226
+        $this->tileCacheBaseDir = $tileCacheBaseDir.'/olmaptiles';
227 227
         $this->useTileCache     = $this->tileCacheBaseDir !== '';
228
-        $this->mapCacheBaseDir  = $mediaDir . '/olmapmaps';
228
+        $this->mapCacheBaseDir  = $mediaDir.'/olmapmaps';
229 229
         $this->autoZoomExtent   = $autoZoomExtent;
230 230
         $this->apikey           = $apikey;
231 231
     }
@@ -237,15 +237,15 @@  discard block
 block discarded – undo
237 237
      */
238 238
     public function getMap(): string {
239 239
         try {
240
-            if($this->autoZoomExtent) {
240
+            if ($this->autoZoomExtent) {
241 241
                 $this->autoZoom();
242 242
             }
243
-        } catch(Exception $e) {
243
+        } catch (Exception $e) {
244 244
             dbglog($e);
245 245
         }
246 246
 
247 247
         // use map cache, so check cache for map
248
-        if(!$this->checkMapCache()) {
248
+        if (!$this->checkMapCache()) {
249 249
             // map is not in cache, needs to be build
250 250
             $this->makeMap();
251 251
             $this->mkdirRecursive(dirname($this->mapCacheIDToFilename()), 0777);
@@ -265,37 +265,37 @@  discard block
 block discarded – undo
265 265
      */
266 266
     private function autoZoom(float $paddingFactor = 1.0): void {
267 267
         $geoms    = array();
268
-        $geoms [] = new Point ($this->lon, $this->lat);
269
-        if(!empty ($this->markers)) {
270
-            foreach($this->markers as $marker) {
271
-                $geoms [] = new Point ($marker ['lon'], $marker ['lat']);
268
+        $geoms [] = new Point($this->lon, $this->lat);
269
+        if (!empty ($this->markers)) {
270
+            foreach ($this->markers as $marker) {
271
+                $geoms [] = new Point($marker ['lon'], $marker ['lat']);
272 272
             }
273 273
         }
274
-        if(file_exists($this->kmlFileName)) {
274
+        if (file_exists($this->kmlFileName)) {
275 275
             $g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
276
-            if($g !== false) {
276
+            if ($g !== false) {
277 277
                 $geoms [] = $g;
278 278
             }
279 279
         }
280
-        if(file_exists($this->gpxFileName)) {
280
+        if (file_exists($this->gpxFileName)) {
281 281
             $g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
282
-            if($g !== false) {
282
+            if ($g !== false) {
283 283
                 $geoms [] = $g;
284 284
             }
285 285
         }
286
-        if(file_exists($this->geojsonFileName)) {
286
+        if (file_exists($this->geojsonFileName)) {
287 287
             $g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson');
288
-            if($g !== false) {
288
+            if ($g !== false) {
289 289
                 $geoms [] = $g;
290 290
             }
291 291
         }
292 292
 
293
-        if(count($geoms) <= 1) {
293
+        if (count($geoms) <= 1) {
294 294
             dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options");
295 295
             return;
296 296
         }
297 297
 
298
-        $geom     = new GeometryCollection ($geoms);
298
+        $geom     = new GeometryCollection($geoms);
299 299
         $centroid = $geom->centroid();
300 300
         $bbox     = $geom->getBBox();
301 301
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         $vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360)));
305 305
         $vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360)));
306 306
         dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1");
307
-        if ($vy1 - $vy0 === 0.0){
307
+        if ($vy1 - $vy0 === 0.0) {
308 308
             $resolutionVertical = 0;
309 309
             dbglog("StaticMap::autoZoom: using $resolutionVertical");
310 310
         } else {
@@ -316,11 +316,11 @@  discard block
 block discarded – undo
316 316
         dbglog("StaticMap::autoZoom: using $resolutionHorizontal");
317 317
         $resolution           = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
318 318
         $zoom                 = $this->zoom;
319
-        if ($resolution > 0){
319
+        if ($resolution > 0) {
320 320
             $zoom             = log(360 / ($resolution * $this->tileSize), 2);
321 321
         }
322 322
 
323
-        if(is_finite($zoom) && $zoom < 15 && $zoom > 2) {
323
+        if (is_finite($zoom) && $zoom < 15 && $zoom > 2) {
324 324
             $this->zoom = floor($zoom);
325 325
         }
326 326
         $this->lon = $centroid->getX();
@@ -353,12 +353,12 @@  discard block
 block discarded – undo
353 353
     }
354 354
 
355 355
     public function mapCacheIDToFilename(): string {
356
-        if(!$this->mapCacheFile) {
357
-            $this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_"
358
-                . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2)
359
-                . "/" . substr($this->mapCacheID, 4);
356
+        if (!$this->mapCacheFile) {
357
+            $this->mapCacheFile = $this->mapCacheBaseDir."/".$this->maptype."/".$this->zoom."/cache_"
358
+                . substr($this->mapCacheID, 0, 2)."/".substr($this->mapCacheID, 2, 2)
359
+                . "/".substr($this->mapCacheID, 4);
360 360
         }
361
-        return $this->mapCacheFile . "." . $this->mapCacheExtension;
361
+        return $this->mapCacheFile.".".$this->mapCacheExtension;
362 362
     }
363 363
 
364 364
     /**
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
     public function makeMap(): void {
368 368
         $this->initCoords();
369 369
         $this->createBaseMap();
370
-        if(!empty ($this->markers)) {
370
+        if (!empty ($this->markers)) {
371 371
             $this->placeMarkers();
372 372
         }
373 373
         if (file_exists($this->kmlFileName)) {
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
         $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize;
441 441
         $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize;
442 442
 
443
-        for($x = $startX; $x <= $endX; $x++) {
444
-            for($y = $startY; $y <= $endY; $y++) {
443
+        for ($x = $startX; $x <= $endX; $x++) {
444
+            for ($y = $startY; $y <= $endY; $y++) {
445 445
                 $url = str_replace(
446 446
                     array(
447 447
                         '{Z}',
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
                 );
456 456
 
457 457
                 $tileData = $this->fetchTile($url);
458
-                if($tileData) {
458
+                if ($tileData) {
459 459
                     $tileImage = imagecreatefromstring($tileData);
460 460
                 } else {
461 461
                     $tileImage = imagecreate($this->tileSize, $this->tileSize);
@@ -481,17 +481,17 @@  discard block
 block discarded – undo
481 481
      *          for better proxy handling...
482 482
      */
483 483
     public function fetchTile(string $url) {
484
-        if($this->useTileCache && ($cached = $this->checkTileCache($url)))
484
+        if ($this->useTileCache && ($cached = $this->checkTileCache($url)))
485 485
             return $cached;
486 486
 
487
-        $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')';
488
-        if(function_exists("curl_init")) {
487
+        $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; '.PHP_OS.')';
488
+        if (function_exists("curl_init")) {
489 489
             // use cUrl
490 490
             $ch = curl_init();
491 491
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
492 492
             curl_setopt($ch, CURLOPT_USERAGENT, $_UA);
493 493
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
494
-            curl_setopt($ch, CURLOPT_URL, $url . $this->apikey);
494
+            curl_setopt($ch, CURLOPT_URL, $url.$this->apikey);
495 495
             dbglog("StaticMap::fetchTile: getting: $url using curl_exec");
496 496
             $tile = curl_exec($ch);
497 497
             curl_close($ch);
@@ -501,21 +501,21 @@  discard block
 block discarded – undo
501 501
             $opts = array(
502 502
                 'http' => array(
503 503
                     'method'          => "GET",
504
-                    'header'          => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n",
504
+                    'header'          => "Accept-language: en\r\n"."User-Agent: $_UA\r\n"."accept: image/png\r\n",
505 505
                     'request_fulluri' => true
506 506
                 )
507 507
             );
508
-            if(isset($conf['proxy']['host'], $conf['proxy']['port'])
508
+            if (isset($conf['proxy']['host'], $conf['proxy']['port'])
509 509
                 && $conf['proxy']['host'] !== ''
510 510
                 && $conf['proxy']['port'] !== '') {
511
-                $opts['http'] += ['proxy' => "tcp://" . $conf['proxy']['host'] . ":" . $conf['proxy']['port']];
511
+                $opts['http'] += ['proxy' => "tcp://".$conf['proxy']['host'].":".$conf['proxy']['port']];
512 512
             }
513 513
 
514 514
             $context = stream_context_create($opts);
515 515
             // dbglog("StaticMap::fetchTile: getting: $url . $this->apikey using file_get_contents and options $opts");
516
-            $tile = file_get_contents($url . $this->apikey, false, $context);
516
+            $tile = file_get_contents($url.$this->apikey, false, $context);
517 517
         }
518
-        if($tile && $this->useTileCache) {
518
+        if ($tile && $this->useTileCache) {
519 519
             $this->writeTileToCache($url, $tile);
520 520
         }
521 521
         return $tile;
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
      */
529 529
     public function checkTileCache(string $url) {
530 530
         $filename = $this->tileUrlToFilename($url);
531
-        if(file_exists($filename)) {
531
+        if (file_exists($filename)) {
532 532
             return file_get_contents($filename);
533 533
         }
534 534
         return false;
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
      * @return string
541 541
      */
542 542
     public function tileUrlToFilename(string $url): string {
543
-        return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1);
543
+        return $this->tileCacheBaseDir."/".substr($url, strpos($url, '/') + 1);
544 544
     }
545 545
 
546 546
     /**
@@ -575,14 +575,14 @@  discard block
 block discarded – undo
575 575
         $count         = 0;
576 576
         $color         = imagecolorallocate($this->image, 0, 0, 0);
577 577
         $bgcolor       = imagecolorallocate($this->image, 200, 200, 200);
578
-        $markerBaseDir = __DIR__ . '/icons';
578
+        $markerBaseDir = __DIR__.'/icons';
579 579
         $markerImageOffsetX  = 0;
580 580
         $markerImageOffsetY  = 0;
581 581
         $markerShadowOffsetX = 0;
582 582
         $markerShadowOffsetY = 0;
583 583
         $markerShadowImg     = null;
584 584
         // loop thru marker array
585
-        foreach($this->markers as $marker) {
585
+        foreach ($this->markers as $marker) {
586 586
             // set some local variables
587 587
             $markerLat  = $marker ['lat'];
588 588
             $markerLon  = $marker ['lon'];
@@ -592,18 +592,18 @@  discard block
 block discarded – undo
592 592
             $markerShadow   = '';
593 593
             $matches        = false;
594 594
             // check for marker type, get settings from markerPrototypes
595
-            if($markerType) {
596
-                foreach($this->markerPrototypes as $markerPrototype) {
597
-                    if(preg_match($markerPrototype ['regex'], $markerType, $matches)) {
598
-                        $markerFilename = $matches [0] . $markerPrototype ['extension'];
599
-                        if($markerPrototype ['offsetImage']) {
595
+            if ($markerType) {
596
+                foreach ($this->markerPrototypes as $markerPrototype) {
597
+                    if (preg_match($markerPrototype ['regex'], $markerType, $matches)) {
598
+                        $markerFilename = $matches [0].$markerPrototype ['extension'];
599
+                        if ($markerPrototype ['offsetImage']) {
600 600
                             list ($markerImageOffsetX, $markerImageOffsetY) = explode(
601 601
                                 ",",
602 602
                                 $markerPrototype ['offsetImage']
603 603
                             );
604 604
                         }
605 605
                         $markerShadow = $markerPrototype ['shadow'];
606
-                        if($markerShadow) {
606
+                        if ($markerShadow) {
607 607
                             list ($markerShadowOffsetX, $markerShadowOffsetY) = explode(
608 608
                                 ",",
609 609
                                 $markerPrototype ['offsetShadow']
@@ -613,14 +613,14 @@  discard block
 block discarded – undo
613 613
                 }
614 614
             }
615 615
             // create img resource
616
-            if(file_exists($markerBaseDir . '/' . $markerFilename)) {
617
-                $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename);
616
+            if (file_exists($markerBaseDir.'/'.$markerFilename)) {
617
+                $markerImg = imagecreatefrompng($markerBaseDir.'/'.$markerFilename);
618 618
             } else {
619
-                $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png');
619
+                $markerImg = imagecreatefrompng($markerBaseDir.'/marker.png');
620 620
             }
621 621
             // check for shadow + create shadow recource
622
-            if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) {
623
-                $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow);
622
+            if ($markerShadow && file_exists($markerBaseDir.'/'.$markerShadow)) {
623
+                $markerShadowImg = imagecreatefrompng($markerBaseDir.'/'.$markerShadow);
624 624
             }
625 625
             // calc position
626 626
             $destX = floor(
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
                 $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))
633 633
             );
634 634
             // copy shadow on basemap
635
-            if($markerShadow && $markerShadowImg) {
635
+            if ($markerShadow && $markerShadowImg) {
636 636
                 imagecopy(
637 637
                     $this->image,
638 638
                     $markerShadowImg,
@@ -694,14 +694,14 @@  discard block
 block discarded – undo
694 694
      *            drawing colour
695 695
      */
696 696
     private function drawGeometry(Geometry $geom, int $colour): void {
697
-        if(empty($geom)) {
697
+        if (empty($geom)) {
698 698
             return;
699 699
         }
700 700
 
701
-        switch($geom->geometryType()) {
701
+        switch ($geom->geometryType()) {
702 702
             case 'GeometryCollection' :
703 703
                 // recursively draw part of the collection
704
-                for($i = 1; $i < $geom->numGeometries() + 1; $i++) {
704
+                for ($i = 1; $i < $geom->numGeometries() + 1; $i++) {
705 705
                     $_geom = $geom->geometryN($i);
706 706
                     $this->drawGeometry($_geom, $colour);
707 707
                 }
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
         // extring is a linestring actually..
744 744
         $extRing = $polygon->exteriorRing();
745 745
 
746
-        for($i = 1; $i < $extRing->numGeometries(); $i++) {
746
+        for ($i = 1; $i < $extRing->numGeometries(); $i++) {
747 747
             $p1           = $extRing->geometryN($i);
748 748
             $x            = floor(
749 749
                 ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
      */
770 770
     private function drawLineString($line, $colour) {
771 771
         imagesetthickness($this->image, 2);
772
-        for($p = 1; $p < $line->numGeometries(); $p++) {
772
+        for ($p = 1; $p < $line->numGeometries(); $p++) {
773 773
             // get first pair of points
774 774
             $p1 = $line->geometryN($p);
775 775
             $p2 = $line->geometryN($p + 1);
@@ -842,8 +842,8 @@  discard block
 block discarded – undo
842 842
      * add copyright and origin notice and icons to the map.
843 843
      */
844 844
     public function drawCopyright() {
845
-        $logoBaseDir = dirname(__FILE__) . '/' . 'logo/';
846
-        $logoImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']);
845
+        $logoBaseDir = dirname(__FILE__).'/'.'logo/';
846
+        $logoImg     = imagecreatefrompng($logoBaseDir.$this->tileInfo ['openstreetmap'] ['logo']);
847 847
         $textcolor   = imagecolorallocate($this->image, 0, 0, 0);
848 848
         $bgcolor     = imagecolorallocate($this->image, 200, 200, 200);
849 849
 
@@ -876,11 +876,11 @@  discard block
 block discarded – undo
876 876
 
877 877
         // additional tile source info, ie. who created/hosted the tiles
878 878
         $xIconOffset = 0;
879
-        if($this->maptype === 'openstreetmap') {
879
+        if ($this->maptype === 'openstreetmap') {
880 880
             $mapAuthor = "(c) OpenStreetMap maps/CC BY-SA";
881 881
         } else {
882 882
             $mapAuthor   = $this->tileInfo [$this->maptype] ['txt'];
883
-            $iconImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']);
883
+            $iconImg     = imagecreatefrompng($logoBaseDir.$this->tileInfo [$this->maptype] ['logo']);
884 884
             $xIconOffset = imagesx($iconImg);
885 885
             imagecopy(
886 886
                 $this->image,
Please login to merge, or discard this patch.