Passed
Pull Request — master (#14)
by Mark
02:12
created
syntax/searchlayer.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -14,22 +14,22 @@  discard block
 block discarded – undo
14 14
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 15
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16
  */
17
-if (! defined ( 'DOKU_INC' ))
17
+if (!defined('DOKU_INC'))
18 18
 	die ();
19 19
 
20
-if (! defined ( 'DOKU_LF' ))
21
-	define ( 'DOKU_LF', "\n" );
22
-if (! defined ( 'DOKU_TAB' ))
23
-	define ( 'DOKU_TAB', "\t" );
24
-if (! defined ( 'DOKU_PLUGIN' ))
25
-	define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' );
20
+if (!defined('DOKU_LF'))
21
+	define('DOKU_LF', "\n");
22
+if (!defined('DOKU_TAB'))
23
+	define('DOKU_TAB', "\t");
24
+if (!defined('DOKU_PLUGIN'))
25
+	define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
26 26
 
27
-require_once DOKU_PLUGIN . 'syntax.php';
27
+require_once DOKU_PLUGIN.'syntax.php';
28 28
 /**
29 29
  * adds a WMS 1.1.1 layer to your map.
30 30
  */
31 31
 class syntax_plugin_openlayersmapoverlays_searchlayer extends DokuWiki_Syntax_Plugin {
32
-	private $dflt = array (
32
+	private $dflt = array(
33 33
 			'id' => 'olmap',
34 34
 			'name' => '',
35 35
 			'search' => '',
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 	 * @see Doku_Parser_Mode::connectTo()
77 77
 	 */
78 78
 	public function connectTo($mode) {
79
-		$this->Lexer->addSpecialPattern ( '<olmap_searchlayer ?[^>\n]*>.*?</olmap_searchlayer>',
80
-				$mode, 'plugin_openlayersmapoverlays_searchlayer' );
79
+		$this->Lexer->addSpecialPattern('<olmap_searchlayer ?[^>\n]*>.*?</olmap_searchlayer>',
80
+				$mode, 'plugin_openlayersmapoverlays_searchlayer');
81 81
 	}
82 82
 
83 83
 	/**
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
 	 * @see DokuWiki_Syntax_Plugin::handle()
87 87
 	 */
88 88
 	public function handle($match, $state, $pos, Doku_Handler $handler) {
89
-		$param = array ();
89
+		$param = array();
90 90
 		$data = $this->dflt;
91 91
 
92
-		preg_match_all ( '/(\w*)="(.*?)"/us', $match, $param, PREG_SET_ORDER );
92
+		preg_match_all('/(\w*)="(.*?)"/us', $match, $param, PREG_SET_ORDER);
93 93
 
94
-		foreach ( $param as $kvpair ) {
95
-			list ( $matched, $key, $val ) = $kvpair;
96
-			if (isset ( $data [$key] )) {
97
-				$key = strtolower ( $key );
94
+		foreach ($param as $kvpair) {
95
+			list ($matched, $key, $val) = $kvpair;
96
+			if (isset ($data [$key])) {
97
+				$key = strtolower($key);
98 98
 				$data [$key] = $val;
99 99
 			}
100 100
 		}
101
-		dbglog($data,'syntax_plugin_overlayer::handle: parsed data is:');
101
+		dbglog($data, 'syntax_plugin_overlayer::handle: parsed data is:');
102 102
 		return $data;
103 103
 	}
104 104
 
@@ -112,22 +112,22 @@  discard block
 block discarded – undo
112 112
 			return false;
113 113
 
114 114
 		static $loadedOLlib = false;
115
-		if (! $loadedOLlib) {
116
-			$renderer->doc .= DOKU_LF . '<script type="text/javascript" src="' . DOKU_BASE . 'lib/plugins/openlayersmapoverlays/lib/layers.js' . '"></script>';
115
+		if (!$loadedOLlib) {
116
+			$renderer->doc .= DOKU_LF.'<script type="text/javascript" src="'.DOKU_BASE.'lib/plugins/openlayersmapoverlays/lib/layers.js'.'"></script>';
117 117
 			$loadedOLlib = true;
118 118
 		}
119 119
 		// incremented for each olmap_wmslayer tag in the page source
120 120
 		static $overlaynumber = 0;
121 121
 
122
-		list ( $id, $url, $name, $visible ) = $data;
123
-		$renderer->doc .= DOKU_LF . "<script type='text/javascript'><!--//--><![CDATA[//><!--" . DOKU_LF;
122
+		list ($id, $url, $name, $visible) = $data;
123
+		$renderer->doc .= DOKU_LF."<script type='text/javascript'><!--//--><![CDATA[//><!--".DOKU_LF;
124 124
 		$str = '{';
125
-		foreach ( $data as $key => $val ) {
126
-			$str .= "'" . $key . "' : '" . $val . "',";
125
+		foreach ($data as $key => $val) {
126
+			$str .= "'".$key."' : '".$val."',";
127 127
 		}
128 128
 		$str .= "'type':'wms'}";
129
-		$renderer->doc .= "olMapOverlays['wms" . $overlaynumber . "'] = " . $str . ";" . DOKU_LF . "//--><!]]></script>";
130
-		$overlaynumber ++;
129
+		$renderer->doc .= "olMapOverlays['wms".$overlaynumber."'] = ".$str.";".DOKU_LF."//--><!]]></script>";
130
+		$overlaynumber++;
131 131
 		return true;
132 132
 	}
133 133
 }
Please login to merge, or discard this patch.
Braces   +11 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,15 +14,19 @@  discard block
 block discarded – undo
14 14
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 15
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16
  */
17
-if (! defined ( 'DOKU_INC' ))
17
+if (! defined ( 'DOKU_INC' )) {
18 18
 	die ();
19
+}
19 20
 
20
-if (! defined ( 'DOKU_LF' ))
21
+if (! defined ( 'DOKU_LF' )) {
21 22
 	define ( 'DOKU_LF', "\n" );
22
-if (! defined ( 'DOKU_TAB' ))
23
+}
24
+if (! defined ( 'DOKU_TAB' )) {
23 25
 	define ( 'DOKU_TAB', "\t" );
24
-if (! defined ( 'DOKU_PLUGIN' ))
26
+}
27
+if (! defined ( 'DOKU_PLUGIN' )) {
25 28
 	define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' );
29
+}
26 30
 
27 31
 require_once DOKU_PLUGIN . 'syntax.php';
28 32
 /**
@@ -108,8 +112,9 @@  discard block
 block discarded – undo
108 112
 	 * @see DokuWiki_Syntax_Plugin::render()
109 113
 	 */
110 114
 	public function render($mode, Doku_Renderer $renderer, $data) {
111
-		if ($mode != 'xhtml')
112
-			return false;
115
+		if ($mode != 'xhtml') {
116
+					return false;
117
+		}
113 118
 
114 119
 		static $loadedOLlib = false;
115 120
 		if (! $loadedOLlib) {
Please login to merge, or discard this patch.
StaticMap.php 3 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -471,8 +471,9 @@
 block discarded – undo
471 471
      *          for better proxy handling...
472 472
      */
473 473
     public function fetchTile(string $url) {
474
-        if($this->useTileCache && ($cached = $this->checkTileCache($url)))
475
-            return $cached;
474
+        if($this->useTileCache && ($cached = $this->checkTileCache($url))) {
475
+                    return $cached;
476
+        }
476 477
 
477 478
         $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')';
478 479
         if(function_exists("curl_init")) {
Please login to merge, or discard this patch.
Indentation   +869 added lines, -869 removed lines patch added patch discarded remove patch
@@ -31,873 +31,873 @@
 block discarded – undo
31 31
  */
32 32
 class StaticMap {
33 33
 
34
-    // the final output
35
-    private $tileSize = 256;
36
-    private $tileInfo = array(
37
-        // OSM sources
38
-        'openstreetmap' => array(
39
-            'txt'  => '(c) OpenStreetMap data/ODbl',
40
-            'logo' => 'osm_logo.png',
41
-            'url'  => 'https://tile.openstreetmap.org/{Z}/{X}/{Y}.png'
42
-        ),
43
-        // OCM sources
44
-        'cycle'         => array(
45
-            'txt'  => '(c) Thunderforest maps',
46
-            'logo' => 'tf_logo.png',
47
-            'url'  => 'https://tile.thunderforest.com/cycle/{Z}/{X}/{Y}.png'
48
-        ),
49
-        'transport'     => array(
50
-            'txt'  => '(c) Thunderforest maps',
51
-            'logo' => 'tf_logo.png',
52
-            'url'  => 'https://tile.thunderforest.com/transport/{Z}/{X}/{Y}.png'
53
-        ),
54
-        'landscape'     => array(
55
-            'txt'  => '(c) Thunderforest maps',
56
-            'logo' => 'tf_logo.png',
57
-            'url'  => 'https://tile.thunderforest.com/landscape/{Z}/{X}/{Y}.png'
58
-        ),
59
-        'outdoors'      => array(
60
-            'txt'  => '(c) Thunderforest maps',
61
-            'logo' => 'tf_logo.png',
62
-            'url'  => 'https://tile.thunderforest.com/outdoors/{Z}/{X}/{Y}.png'
63
-        ),
64
-        'toner-lite'    => array(
65
-            'txt'  => 'Stamen tiles',
66
-            'logo' => 'stamen.png',
67
-            'url'  => 'https://stamen-tiles.a.ssl.fastly.net/toner/{Z}/{X}/{Y}.png'
68
-        ),
69
-        'terrain'       => array(
70
-            'txt'  => 'Stamen tiles',
71
-            'logo' => 'stamen.png',
72
-            'url'  => 'https://stamen-tiles.a.ssl.fastly.net/terrain/{Z}/{X}/{Y}.jpg'
73
-        )
74
-        //,
75
-        // 'piste'=>array(
76
-        // 'txt'=>'OpenPisteMap tiles',
77
-        // 'logo'=>'piste_logo.png',
78
-        // 'url'=>''),
79
-        // 'sea'=>array(
80
-        // 'txt'=>'OpenSeaMap tiles',
81
-        // 'logo'=>'sea_logo.png',
82
-        // 'url'=>''),
83
-        // H&B sources
84
-        //          'hikeandbike' => array (
85
-        //                  'txt' => 'Hike & Bike Map',
86
-        //                  'logo' => 'hnb_logo.png',
87
-        //                  //'url' => 'http://toolserver.org/tiles/hikebike/{Z}/{X}/{Y}.png'
88
-        //                  //moved to: https://www.toolserver.org/tiles/hikebike/12/2105/1388.png
89
-        //                  'url' => 'http://c.tiles.wmflabs.org/hikebike/{Z}/{X}/{Y}.png'
90
-        //          )
91
-    );
92
-    private $tileDefaultSrc = 'openstreetmap';
93
-
94
-    // set up markers
95
-    private $markerPrototypes = array(
96
-        // found at http://www.mapito.net/map-marker-icons.html
97
-        // these are 17x19 px with a pointer at the bottom left
98
-        'lightblue' => array(
99
-            'regex'        => '/^lightblue([0-9]+)$/',
100
-            'extension'    => '.png',
101
-            'shadow'       => false,
102
-            'offsetImage'  => '0,-19',
103
-            'offsetShadow' => false
104
-        ),
105
-        // openlayers std markers are 21x25px with shadow
106
-        'ol-marker' => array(
107
-            'regex'        => '/^marker(|-blue|-gold|-green|-red)+$/',
108
-            'extension'    => '.png',
109
-            'shadow'       => 'marker_shadow.png',
110
-            'offsetImage'  => '-10,-25',
111
-            'offsetShadow' => '-1,-13'
112
-        ),
113
-        // these are 16x16 px
114
-        'ww_icon'   => array(
115
-            'regex'        => '/ww_\S+$/',
116
-            'extension'    => '.png',
117
-            'shadow'       => false,
118
-            'offsetImage'  => '-8,-8',
119
-            'offsetShadow' => false
120
-        ),
121
-        // assume these are 16x16 px
122
-        'rest'      => array(
123
-            'regex'        => '/^(?!lightblue([0-9]+)$)(?!(ww_\S+$))(?!marker(|-blue|-gold|-green|-red)+$)(.*)/',
124
-            'extension'    => '.png',
125
-            'shadow'       => 'marker_shadow.png',
126
-            'offsetImage'  => '-8,-8',
127
-            'offsetShadow' => '-1,-1'
128
-        )
129
-    );
130
-    private $centerX;
131
-    private $centerY;
132
-    private $offsetX;
133
-    private $offsetY;
134
-    private $image;
135
-    private $zoom;
136
-    private $lat;
137
-    private $lon;
138
-    private $width;
139
-    private $height;
140
-    private $markers;
141
-    private $maptype;
142
-    private $kmlFileName;
143
-    private $gpxFileName;
144
-    private $geojsonFileName;
145
-    private $autoZoomExtent;
146
-    private $apikey;
147
-    private $tileCacheBaseDir;
148
-    private $mapCacheBaseDir;
149
-    private $mediaBaseDir;
150
-    private $useTileCache;
151
-    private $mapCacheID = '';
152
-    private $mapCacheFile = '';
153
-    private $mapCacheExtension = 'png';
154
-
155
-    /**
156
-     * Constructor.
157
-     *
158
-     * @param float  $lat
159
-     *            Latitude (x) of center of map
160
-     * @param float  $lon
161
-     *            Longitude (y) of center of map
162
-     * @param int    $zoom
163
-     *            Zoomlevel
164
-     * @param int    $width
165
-     *            Width in pixels
166
-     * @param int    $height
167
-     *            Height in pixels
168
-     * @param string $maptype
169
-     *            Name of the map
170
-     * @param array  $markers
171
-     *            array of markers
172
-     * @param string $gpx
173
-     *            GPX filename
174
-     * @param string $kml
175
-     *            KML filename
176
-     * @param string $geojson
177
-     * @param string $mediaDir
178
-     *            Directory to store/cache maps
179
-     * @param string $tileCacheBaseDir
180
-     *            Directory to cache map tiles
181
-     * @param bool   $autoZoomExtent
182
-     *            Wheter or not to override zoom/lat/lon and zoom to the extent of gpx/kml and markers
183
-     * @param string $apikey
184
-     */
185
-    public function __construct(
186
-        float $lat,
187
-        float $lon,
188
-        int $zoom,
189
-        int $width,
190
-        int $height,
191
-        string $maptype,
192
-        array $markers,
193
-        string $gpx,
194
-        string $kml,
195
-        string $geojson,
196
-        string $mediaDir,
197
-        string $tileCacheBaseDir,
198
-        bool $autoZoomExtent = true,
199
-        string $apikey = ''
200
-    ) {
201
-        $this->zoom   = $zoom;
202
-        $this->lat    = $lat;
203
-        $this->lon    = $lon;
204
-        $this->width  = $width;
205
-        $this->height = $height;
206
-        // validate + set maptype
207
-        $this->maptype = $this->tileDefaultSrc;
208
-        if(array_key_exists($maptype, $this->tileInfo)) {
209
-            $this->maptype = $maptype;
210
-        }
211
-        $this->markers          = $markers;
212
-        $this->kmlFileName      = $kml;
213
-        $this->gpxFileName      = $gpx;
214
-        $this->geojsonFileName  = $geojson;
215
-        $this->mediaBaseDir     = $mediaDir;
216
-        $this->tileCacheBaseDir = $tileCacheBaseDir . '/olmaptiles';
217
-        $this->useTileCache     = $this->tileCacheBaseDir !== '';
218
-        $this->mapCacheBaseDir  = $mediaDir . '/olmapmaps';
219
-        $this->autoZoomExtent   = $autoZoomExtent;
220
-        $this->apikey           = $apikey;
221
-    }
222
-
223
-    /**
224
-     * get the map, this may return a reference to a cached copy.
225
-     *
226
-     * @return string url relative to media dir
227
-     */
228
-    public function getMap(): string {
229
-        try {
230
-            if($this->autoZoomExtent) {
231
-                $this->autoZoom();
232
-            }
233
-        } catch(Exception $e) {
234
-            dbglog($e);
235
-        }
236
-
237
-        // use map cache, so check cache for map
238
-        if(!$this->checkMapCache()) {
239
-            // map is not in cache, needs to be build
240
-            $this->makeMap();
241
-            $this->mkdirRecursive(dirname($this->mapCacheIDToFilename()), 0777);
242
-            imagepng($this->image, $this->mapCacheIDToFilename(), 9);
243
-        }
244
-        $doc = $this->mapCacheIDToFilename();
245
-        // make url relative to media dir
246
-        return str_replace($this->mediaBaseDir, '', $doc);
247
-    }
248
-
249
-    /**
250
-     * Calculate the lat/lon/zoom values to make sure that all of the markers and gpx/kml are on the map.
251
-     * can throw an error like
252
-     * "Fatal error: Uncaught Exception: Cannot create a collection with non-geometries in
253
-     * D:\www\wild-water.nl\www\dokuwiki\lib\plugins\geophp\geoPHP\lib\geometry\Collection.class.php:29"
254
-     *
255
-     * @param float $paddingFactor
256
-     *            buffer constant to enlarge (>1.0) the zoom level
257
-     * @throws Exception
258
-     */
259
-    private function autoZoom(float $paddingFactor = 1.0): void {
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']);
265
-            }
266
-        }
267
-        if(file_exists($this->kmlFileName)) {
268
-            $g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
269
-            if($g !== false) {
270
-                $geoms [] = $g;
271
-            }
272
-        }
273
-        if(file_exists($this->gpxFileName)) {
274
-            $g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
275
-            if($g !== false) {
276
-                $geoms [] = $g;
277
-            }
278
-        }
279
-        if(file_exists($this->geojsonFileName)) {
280
-            $g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson');
281
-            if($g !== false) {
282
-                $geoms [] = $g;
283
-            }
284
-        }
285
-
286
-        if(count($geoms) <= 1) {
287
-            dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options");
288
-            return;
289
-        }
290
-
291
-        $geom     = new GeometryCollection ($geoms);
292
-        $centroid = $geom->centroid();
293
-        $bbox     = $geom->getBBox();
294
-
295
-        // determine vertical resolution, this depends on the distance from the equator
296
-        // $vy00 = log(tan(M_PI*(0.25 + $centroid->getY()/360)));
297
-        $vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360)));
298
-        $vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360)));
299
-        dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1");
300
-        if ($vy1 - $vy0 === 0.0){
301
-            $resolutionVertical = 0;
302
-            dbglog("StaticMap::autoZoom: using $resolutionVertical");
303
-        } else {
304
-            $zoomFactorPowered  = ($this->height / 2) / (40.7436654315252 * ($vy1 - $vy0));
305
-            $resolutionVertical = 360 / ($zoomFactorPowered * $this->tileSize);
306
-        }
307
-        // determine horizontal resolution
308
-        $resolutionHorizontal = ($bbox ['maxx'] - $bbox ['minx']) / $this->width;
309
-        dbglog("StaticMap::autoZoom: using $resolutionHorizontal");
310
-        $resolution           = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
311
-        $zoom                 = $this->zoom;
312
-        if ($resolution > 0){
313
-            $zoom             = log(360 / ($resolution * $this->tileSize), 2);
314
-        }
315
-
316
-        if(is_finite($zoom) && $zoom < 15 && $zoom > 2) {
317
-            $this->zoom = floor($zoom);
318
-        }
319
-        $this->lon = $centroid->getX();
320
-        $this->lat = $centroid->getY();
321
-        dbglog("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat");
322
-    }
323
-
324
-    public function checkMapCache(): bool {
325
-        // side effect: set the mapCacheID
326
-        $this->mapCacheID = md5($this->serializeParams());
327
-        $filename         = $this->mapCacheIDToFilename();
328
-        return file_exists($filename);
329
-    }
330
-
331
-    public function serializeParams(): string {
332
-        return implode(
333
-            "&", array(
334
-                   $this->zoom,
335
-                   $this->lat,
336
-                   $this->lon,
337
-                   $this->width,
338
-                   $this->height,
339
-                   serialize($this->markers),
340
-                   $this->maptype,
341
-                   $this->kmlFileName,
342
-                   $this->gpxFileName,
343
-                   $this->geojsonFileName
344
-               )
345
-        );
346
-    }
347
-
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);
353
-        }
354
-        return $this->mapCacheFile . "." . $this->mapCacheExtension;
355
-    }
356
-
357
-    /**
358
-     * make the map.
359
-     */
360
-    public function makeMap(): void {
361
-        $this->initCoords();
362
-        $this->createBaseMap();
363
-        if(!empty ($this->markers)) {
364
-            $this->placeMarkers();
365
-        }
366
-        if (file_exists($this->kmlFileName)) {
367
-            try {
368
-                $this->drawKML();
369
-            } catch (exception $e) {
370
-                dbglog('failed to load KML file', $e);
371
-            }
372
-        }
373
-        if (file_exists($this->gpxFileName)) {
374
-            try {
375
-                $this->drawGPX();
376
-            } catch (exception $e) {
377
-                dbglog('failed to load GPX file', $e);
378
-            }
379
-        }
380
-        if (file_exists($this->geojsonFileName)) {
381
-            try {
382
-                $this->drawGeojson();
383
-            } catch (exception $e) {
384
-                dbglog('failed to load GeoJSON file', $e);
385
-            }
386
-        }
387
-
388
-        $this->drawCopyright();
389
-    }
390
-
391
-    /**
392
-     */
393
-    public function initCoords(): void {
394
-        $this->centerX = $this->lonToTile($this->lon, $this->zoom);
395
-        $this->centerY = $this->latToTile($this->lat, $this->zoom);
396
-        $this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize);
397
-        $this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize);
398
-    }
399
-
400
-    /**
401
-     *
402
-     * @param float $long
403
-     * @param int   $zoom
404
-     * @return float|int
405
-     */
406
-    public function lonToTile(float $long, int $zoom) {
407
-        return (($long + 180) / 360) * pow(2, $zoom);
408
-    }
409
-
410
-    /**
411
-     *
412
-     * @param float $lat
413
-     * @param int   $zoom
414
-     * @return float|int
415
-     */
416
-    public function latToTile(float $lat, int $zoom) {
417
-        return (1 - log(tan($lat * pi() / 180) + 1 / cos($lat * M_PI / 180)) / M_PI) / 2 * pow(2, $zoom);
418
-    }
419
-
420
-    /**
421
-     * make basemap image.
422
-     */
423
-    public function createBaseMap(): void {
424
-        $this->image   = imagecreatetruecolor($this->width, $this->height);
425
-        $startX        = floor($this->centerX - ($this->width / $this->tileSize) / 2);
426
-        $startY        = floor($this->centerY - ($this->height / $this->tileSize) / 2);
427
-        $endX          = ceil($this->centerX + ($this->width / $this->tileSize) / 2);
428
-        $endY          = ceil($this->centerY + ($this->height / $this->tileSize) / 2);
429
-        $this->offsetX = -floor(($this->centerX - floor($this->centerX)) * $this->tileSize);
430
-        $this->offsetY = -floor(($this->centerY - floor($this->centerY)) * $this->tileSize);
431
-        $this->offsetX += floor($this->width / 2);
432
-        $this->offsetY += floor($this->height / 2);
433
-        $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize;
434
-        $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize;
435
-
436
-        for($x = $startX; $x <= $endX; $x++) {
437
-            for($y = $startY; $y <= $endY; $y++) {
438
-                $url = str_replace(
439
-                    array(
440
-                        '{Z}',
441
-                        '{X}',
442
-                        '{Y}'
443
-                    ), array(
444
-                        $this->zoom,
445
-                        $x,
446
-                        $y
447
-                    ), $this->tileInfo [$this->maptype] ['url']
448
-                );
449
-
450
-                $tileData = $this->fetchTile($url);
451
-                if($tileData) {
452
-                    $tileImage = imagecreatefromstring($tileData);
453
-                } else {
454
-                    $tileImage = imagecreate($this->tileSize, $this->tileSize);
455
-                    $color     = imagecolorallocate($tileImage, 255, 255, 255);
456
-                    @imagestring($tileImage, 1, 127, 127, 'err', $color);
457
-                }
458
-                $destX = ($x - $startX) * $this->tileSize + $this->offsetX;
459
-                $destY = ($y - $startY) * $this->tileSize + $this->offsetY;
460
-                dbglog($this->tileSize, "imagecopy tile into image: $destX, $destY");
461
-                imagecopy(
462
-                    $this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize,
463
-                    $this->tileSize
464
-                );
465
-            }
466
-        }
467
-    }
468
-
469
-    /**
470
-     * Fetch a tile and (if configured) store it in the cache.
471
-     * @param string $url
472
-     * @return bool|string
473
-     * @todo refactor this to use dokuwiki\HTTP\HTTPClient or dokuwiki\HTTP\DokuHTTPClient
474
-     *          for better proxy handling...
475
-     */
476
-    public function fetchTile(string $url) {
477
-        if($this->useTileCache && ($cached = $this->checkTileCache($url)))
478
-            return $cached;
479
-
480
-        $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')';
481
-        if(function_exists("curl_init")) {
482
-            // use cUrl
483
-            $ch = curl_init();
484
-            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
485
-            curl_setopt($ch, CURLOPT_USERAGENT, $_UA);
486
-            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
487
-            curl_setopt($ch, CURLOPT_URL, $url . $this->apikey);
488
-            dbglog("StaticMap::fetchTile: getting: $url using curl_exec");
489
-            $tile = curl_exec($ch);
490
-            curl_close($ch);
491
-        } else {
492
-            // use file_get_contents
493
-            global $conf;
494
-            $opts = array(
495
-                'http' => array(
496
-                    'method'          => "GET",
497
-                    'header'          => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n",
498
-                    'request_fulluri' => true
499
-                )
500
-            );
501
-            if(isset($conf['proxy']['host'], $conf['proxy']['port'])
502
-                && $conf['proxy']['host'] !== ''
503
-                && $conf['proxy']['port'] !== '') {
504
-                $opts['http'] += ['proxy' => "tcp://" . $conf['proxy']['host'] . ":" . $conf['proxy']['port']];
505
-            }
506
-
507
-            $context = stream_context_create($opts);
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);
510
-        }
511
-        if($tile && $this->useTileCache) {
512
-            $this->writeTileToCache($url, $tile);
513
-        }
514
-        return $tile;
515
-    }
516
-
517
-    /**
518
-     *
519
-     * @param string $url
520
-     * @return string|false
521
-     */
522
-    public function checkTileCache(string $url) {
523
-        $filename = $this->tileUrlToFilename($url);
524
-        if(file_exists($filename)) {
525
-            return file_get_contents($filename);
526
-        }
527
-        return false;
528
-    }
529
-
530
-    /**
531
-     *
532
-     * @param string $url
533
-     * @return string
534
-     */
535
-    public function tileUrlToFilename(string $url): string {
536
-        return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1);
537
-    }
538
-
539
-    /**
540
-     * Write a tile into the cache.
541
-     *
542
-     * @param string $url
543
-     * @param mixed  $data
544
-     */
545
-    public function writeTileToCache($url, $data): void {
546
-        $filename = $this->tileUrlToFilename($url);
547
-        $this->mkdirRecursive(dirname($filename), 0777);
548
-        file_put_contents($filename, $data);
549
-    }
550
-
551
-    /**
552
-     * Recursively create the directory.
553
-     *
554
-     * @param string $pathname
555
-     *            The directory path.
556
-     * @param int    $mode
557
-     *            File access mode. For more information on modes, read the details on the chmod manpage.
558
-     */
559
-    public function mkdirRecursive(string $pathname, int $mode): bool {
560
-        is_dir(dirname($pathname)) || $this->mkdirRecursive(dirname($pathname), $mode);
561
-        return is_dir($pathname) || mkdir($pathname, $mode) || is_dir($pathname);
562
-    }
563
-
564
-    /**
565
-     * Place markers on the map and number them in the same order as they are listed in the html.
566
-     */
567
-    public function placeMarkers(): void {
568
-        $count         = 0;
569
-        $color         = imagecolorallocate($this->image, 0, 0, 0);
570
-        $bgcolor       = imagecolorallocate($this->image, 200, 200, 200);
571
-        $markerBaseDir = __DIR__ . '/icons';
572
-        $markerImageOffsetX  = 0;
573
-        $markerImageOffsetY  = 0;
574
-        $markerShadowOffsetX = 0;
575
-        $markerShadowOffsetY = 0;
576
-        $markerShadowImg     = null;
577
-        // loop thru marker array
578
-        foreach($this->markers as $marker) {
579
-            // set some local variables
580
-            $markerLat  = $marker ['lat'];
581
-            $markerLon  = $marker ['lon'];
582
-            $markerType = $marker ['type'];
583
-            // clear variables from previous loops
584
-            $markerFilename = '';
585
-            $markerShadow   = '';
586
-            $matches        = false;
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']) {
593
-                            list ($markerImageOffsetX, $markerImageOffsetY) = explode(
594
-                                ",",
595
-                                $markerPrototype ['offsetImage']
596
-                            );
597
-                        }
598
-                        $markerShadow = $markerPrototype ['shadow'];
599
-                        if($markerShadow) {
600
-                            list ($markerShadowOffsetX, $markerShadowOffsetY) = explode(
601
-                                ",",
602
-                                $markerPrototype ['offsetShadow']
603
-                            );
604
-                        }
605
-                    }
606
-                }
607
-            }
608
-            // create img resource
609
-            if(file_exists($markerBaseDir . '/' . $markerFilename)) {
610
-                $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename);
611
-            } else {
612
-                $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png');
613
-            }
614
-            // check for shadow + create shadow recource
615
-            if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) {
616
-                $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow);
617
-            }
618
-            // calc position
619
-            $destX = floor(
620
-                ($this->width / 2) -
621
-                $this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom))
622
-            );
623
-            $destY = floor(
624
-                ($this->height / 2) -
625
-                $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))
626
-            );
627
-            // copy shadow on basemap
628
-            if($markerShadow && $markerShadowImg) {
629
-                imagecopy(
630
-                    $this->image,
631
-                    $markerShadowImg,
632
-                    $destX + (int) $markerShadowOffsetX,
633
-                    $destY + (int) $markerShadowOffsetY,
634
-                    0,
635
-                    0,
636
-                    imagesx($markerShadowImg),
637
-                    imagesy($markerShadowImg)
638
-                );
639
-            }
640
-            // copy marker on basemap above shadow
641
-            imagecopy(
642
-                $this->image,
643
-                $markerImg,
644
-                $destX + (int) $markerImageOffsetX,
645
-                $destY + (int) $markerImageOffsetY,
646
-                0,
647
-                0,
648
-                imagesx($markerImg),
649
-                imagesy($markerImg)
650
-            );
651
-            // add label
652
-            imagestring(
653
-                $this->image,
654
-                3,
655
-                $destX - imagesx($markerImg) + 1,
656
-                $destY + (int) $markerImageOffsetY + 1,
657
-                ++$count,
658
-                $bgcolor
659
-            );
660
-            imagestring(
661
-                $this->image,
662
-                3,
663
-                $destX - imagesx($markerImg),
664
-                $destY + (int) $markerImageOffsetY,
665
-                $count,
666
-                $color
667
-            );
668
-        }
669
-    }
670
-
671
-    /**
672
-     * Draw kml trace on the map.
673
-     * @throws exception when loading the KML fails
674
-     */
675
-    public function drawKML(): void {
676
-        // TODO get colour from kml node (not currently supported in geoPHP)
677
-        $col     = imagecolorallocatealpha($this->image, 255, 0, 0, .4 * 127);
678
-        $kmlgeom = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
679
-        $this->drawGeometry($kmlgeom, $col);
680
-    }
681
-
682
-    /**
683
-     * Draw geometry or geometry collection on the map.
684
-     *
685
-     * @param Geometry $geom
686
-     * @param int      $colour
687
-     *            drawing colour
688
-     */
689
-    private function drawGeometry(Geometry $geom, int $colour): void {
690
-        if(empty($geom)) {
691
-            return;
692
-        }
693
-
694
-        switch($geom->geometryType()) {
695
-            case 'GeometryCollection' :
696
-                // recursively draw part of the collection
697
-                for($i = 1; $i < $geom->numGeometries() + 1; $i++) {
698
-                    $_geom = $geom->geometryN($i);
699
-                    $this->drawGeometry($_geom, $colour);
700
-                }
701
-                break;
702
-            case 'MultiPolygon' :
703
-            case 'MultiLineString' :
704
-            case 'MultiPoint' :
705
-                // TODO implement / do nothing
706
-                break;
707
-            case 'Polygon' :
708
-                $this->drawPolygon($geom, $colour);
709
-                break;
710
-            case 'LineString' :
711
-                $this->drawLineString($geom, $colour);
712
-                break;
713
-            case 'Point' :
714
-                $this->drawPoint($geom, $colour);
715
-                break;
716
-            default :
717
-                // draw nothing
718
-                break;
719
-        }
720
-    }
721
-
722
-    /**
723
-     * Draw a polygon on the map.
724
-     *
725
-     * @param Polygon $polygon
726
-     * @param int     $colour
727
-     *            drawing colour
728
-     */
729
-    private function drawPolygon($polygon, int $colour) {
730
-        // TODO implementation of drawing holes,
731
-        // maybe draw the polygon to an in-memory image and use imagecopy, draw polygon in col., draw holes in bgcol?
732
-
733
-        // print_r('Polygon:<br />');
734
-        // print_r($polygon);
735
-        $extPoints = array();
736
-        // extring is a linestring actually..
737
-        $extRing = $polygon->exteriorRing();
738
-
739
-        for($i = 1; $i < $extRing->numGeometries(); $i++) {
740
-            $p1           = $extRing->geometryN($i);
741
-            $x            = floor(
742
-                ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
743
-            );
744
-            $y            = floor(
745
-                ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
746
-            );
747
-            $extPoints [] = $x;
748
-            $extPoints [] = $y;
749
-        }
750
-        // print_r('points:('.($i-1).')<br />');
751
-        // print_r($extPoints);
752
-        // imagepolygon ($this->image, $extPoints, $i-1, $colour );
753
-        imagefilledpolygon($this->image, $extPoints, $i - 1, $colour);
754
-    }
755
-
756
-    /**
757
-     * Draw a line on the map.
758
-     *
759
-     * @param LineString $line
760
-     * @param int        $colour
761
-     *            drawing colour
762
-     */
763
-    private function drawLineString($line, $colour) {
764
-        imagesetthickness($this->image, 2);
765
-        for($p = 1; $p < $line->numGeometries(); $p++) {
766
-            // get first pair of points
767
-            $p1 = $line->geometryN($p);
768
-            $p2 = $line->geometryN($p + 1);
769
-            // translate to paper space
770
-            $x1 = floor(
771
-                ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
772
-            );
773
-            $y1 = floor(
774
-                ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
775
-            );
776
-            $x2 = floor(
777
-                ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p2->x(), $this->zoom))
778
-            );
779
-            $y2 = floor(
780
-                ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p2->y(), $this->zoom))
781
-            );
782
-            // draw to image
783
-            imageline($this->image, $x1, $y1, $x2, $y2, $colour);
784
-        }
785
-        imagesetthickness($this->image, 1);
786
-    }
787
-
788
-    /**
789
-     * Draw a point on the map.
790
-     *
791
-     * @param Point $point
792
-     * @param int   $colour
793
-     *            drawing colour
794
-     */
795
-    private function drawPoint($point, $colour) {
796
-        imagesetthickness($this->image, 2);
797
-        // translate to paper space
798
-        $cx = floor(
799
-            ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($point->x(), $this->zoom))
800
-        );
801
-        $cy = floor(
802
-            ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($point->y(), $this->zoom))
803
-        );
804
-        $r  = 5;
805
-        // draw to image
806
-        // imageellipse($this->image, $cx, $cy,$r, $r, $colour);
807
-        imagefilledellipse($this->image, $cx, $cy, $r, $r, $colour);
808
-        // don't use imageellipse because the imagesetthickness function has
809
-        // no effect. So the better workaround is to use imagearc.
810
-        imagearc($this->image, $cx, $cy, $r, $r, 0, 359, $colour);
811
-        imagesetthickness($this->image, 1);
812
-    }
813
-
814
-    /**
815
-     * Draw gpx trace on the map.
816
-     * @throws exception when loading the GPX fails
817
-     */
818
-    public function drawGPX() {
819
-        $col     = imagecolorallocatealpha($this->image, 0, 0, 255, .4 * 127);
820
-        $gpxgeom = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
821
-        $this->drawGeometry($gpxgeom, $col);
822
-    }
823
-
824
-    /**
825
-     * Draw geojson on the map.
826
-     * @throws exception when loading the JSON fails
827
-     */
828
-    public function drawGeojson() {
829
-        $col     = imagecolorallocatealpha($this->image, 255, 0, 255, .4 * 127);
830
-        $gpxgeom = geoPHP::load(file_get_contents($this->geojsonFileName), 'json');
831
-        $this->drawGeometry($gpxgeom, $col);
832
-    }
833
-
834
-    /**
835
-     * add copyright and origin notice and icons to the map.
836
-     */
837
-    public function drawCopyright() {
838
-        $logoBaseDir = dirname(__FILE__) . '/' . 'logo/';
839
-        $logoImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']);
840
-        $textcolor   = imagecolorallocate($this->image, 0, 0, 0);
841
-        $bgcolor     = imagecolorallocate($this->image, 200, 200, 200);
842
-
843
-        imagecopy(
844
-            $this->image,
845
-            $logoImg,
846
-            0,
847
-            imagesy($this->image) - imagesy($logoImg),
848
-            0,
849
-            0,
850
-            imagesx($logoImg),
851
-            imagesy($logoImg)
852
-        );
853
-        imagestring(
854
-            $this->image,
855
-            1,
856
-            imagesx($logoImg) + 2,
857
-            imagesy($this->image) - imagesy($logoImg) + 1,
858
-            $this->tileInfo ['openstreetmap'] ['txt'],
859
-            $bgcolor
860
-        );
861
-        imagestring(
862
-            $this->image,
863
-            1,
864
-            imagesx($logoImg) + 1,
865
-            imagesy($this->image) - imagesy($logoImg),
866
-            $this->tileInfo ['openstreetmap'] ['txt'],
867
-            $textcolor
868
-        );
869
-
870
-        // additional tile source info, ie. who created/hosted the tiles
871
-        $xIconOffset = 0;
872
-        if($this->maptype === 'openstreetmap') {
873
-            $mapAuthor = "(c) OpenStreetMap maps/CC BY-SA";
874
-        } else {
875
-            $mapAuthor   = $this->tileInfo [$this->maptype] ['txt'];
876
-            $iconImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']);
877
-            $xIconOffset = imagesx($iconImg);
878
-            imagecopy(
879
-                $this->image,
880
-                $iconImg, imagesx($logoImg) + 1,
881
-                imagesy($this->image) - imagesy($iconImg),
882
-                0,
883
-                0,
884
-                imagesx($iconImg), imagesy($iconImg)
885
-            );
886
-        }
887
-        imagestring(
888
-            $this->image,
889
-            1, imagesx($logoImg) + $xIconOffset + 4,
890
-            imagesy($this->image) - ceil(imagesy($logoImg) / 2) + 1,
891
-            $mapAuthor,
892
-            $bgcolor
893
-        );
894
-        imagestring(
895
-            $this->image,
896
-            1, imagesx($logoImg) + $xIconOffset + 3,
897
-            imagesy($this->image) - ceil(imagesy($logoImg) / 2),
898
-            $mapAuthor,
899
-            $textcolor
900
-        );
901
-
902
-    }
34
+	// the final output
35
+	private $tileSize = 256;
36
+	private $tileInfo = array(
37
+		// OSM sources
38
+		'openstreetmap' => array(
39
+			'txt'  => '(c) OpenStreetMap data/ODbl',
40
+			'logo' => 'osm_logo.png',
41
+			'url'  => 'https://tile.openstreetmap.org/{Z}/{X}/{Y}.png'
42
+		),
43
+		// OCM sources
44
+		'cycle'         => array(
45
+			'txt'  => '(c) Thunderforest maps',
46
+			'logo' => 'tf_logo.png',
47
+			'url'  => 'https://tile.thunderforest.com/cycle/{Z}/{X}/{Y}.png'
48
+		),
49
+		'transport'     => array(
50
+			'txt'  => '(c) Thunderforest maps',
51
+			'logo' => 'tf_logo.png',
52
+			'url'  => 'https://tile.thunderforest.com/transport/{Z}/{X}/{Y}.png'
53
+		),
54
+		'landscape'     => array(
55
+			'txt'  => '(c) Thunderforest maps',
56
+			'logo' => 'tf_logo.png',
57
+			'url'  => 'https://tile.thunderforest.com/landscape/{Z}/{X}/{Y}.png'
58
+		),
59
+		'outdoors'      => array(
60
+			'txt'  => '(c) Thunderforest maps',
61
+			'logo' => 'tf_logo.png',
62
+			'url'  => 'https://tile.thunderforest.com/outdoors/{Z}/{X}/{Y}.png'
63
+		),
64
+		'toner-lite'    => array(
65
+			'txt'  => 'Stamen tiles',
66
+			'logo' => 'stamen.png',
67
+			'url'  => 'https://stamen-tiles.a.ssl.fastly.net/toner/{Z}/{X}/{Y}.png'
68
+		),
69
+		'terrain'       => array(
70
+			'txt'  => 'Stamen tiles',
71
+			'logo' => 'stamen.png',
72
+			'url'  => 'https://stamen-tiles.a.ssl.fastly.net/terrain/{Z}/{X}/{Y}.jpg'
73
+		)
74
+		//,
75
+		// 'piste'=>array(
76
+		// 'txt'=>'OpenPisteMap tiles',
77
+		// 'logo'=>'piste_logo.png',
78
+		// 'url'=>''),
79
+		// 'sea'=>array(
80
+		// 'txt'=>'OpenSeaMap tiles',
81
+		// 'logo'=>'sea_logo.png',
82
+		// 'url'=>''),
83
+		// H&B sources
84
+		//          'hikeandbike' => array (
85
+		//                  'txt' => 'Hike & Bike Map',
86
+		//                  'logo' => 'hnb_logo.png',
87
+		//                  //'url' => 'http://toolserver.org/tiles/hikebike/{Z}/{X}/{Y}.png'
88
+		//                  //moved to: https://www.toolserver.org/tiles/hikebike/12/2105/1388.png
89
+		//                  'url' => 'http://c.tiles.wmflabs.org/hikebike/{Z}/{X}/{Y}.png'
90
+		//          )
91
+	);
92
+	private $tileDefaultSrc = 'openstreetmap';
93
+
94
+	// set up markers
95
+	private $markerPrototypes = array(
96
+		// found at http://www.mapito.net/map-marker-icons.html
97
+		// these are 17x19 px with a pointer at the bottom left
98
+		'lightblue' => array(
99
+			'regex'        => '/^lightblue([0-9]+)$/',
100
+			'extension'    => '.png',
101
+			'shadow'       => false,
102
+			'offsetImage'  => '0,-19',
103
+			'offsetShadow' => false
104
+		),
105
+		// openlayers std markers are 21x25px with shadow
106
+		'ol-marker' => array(
107
+			'regex'        => '/^marker(|-blue|-gold|-green|-red)+$/',
108
+			'extension'    => '.png',
109
+			'shadow'       => 'marker_shadow.png',
110
+			'offsetImage'  => '-10,-25',
111
+			'offsetShadow' => '-1,-13'
112
+		),
113
+		// these are 16x16 px
114
+		'ww_icon'   => array(
115
+			'regex'        => '/ww_\S+$/',
116
+			'extension'    => '.png',
117
+			'shadow'       => false,
118
+			'offsetImage'  => '-8,-8',
119
+			'offsetShadow' => false
120
+		),
121
+		// assume these are 16x16 px
122
+		'rest'      => array(
123
+			'regex'        => '/^(?!lightblue([0-9]+)$)(?!(ww_\S+$))(?!marker(|-blue|-gold|-green|-red)+$)(.*)/',
124
+			'extension'    => '.png',
125
+			'shadow'       => 'marker_shadow.png',
126
+			'offsetImage'  => '-8,-8',
127
+			'offsetShadow' => '-1,-1'
128
+		)
129
+	);
130
+	private $centerX;
131
+	private $centerY;
132
+	private $offsetX;
133
+	private $offsetY;
134
+	private $image;
135
+	private $zoom;
136
+	private $lat;
137
+	private $lon;
138
+	private $width;
139
+	private $height;
140
+	private $markers;
141
+	private $maptype;
142
+	private $kmlFileName;
143
+	private $gpxFileName;
144
+	private $geojsonFileName;
145
+	private $autoZoomExtent;
146
+	private $apikey;
147
+	private $tileCacheBaseDir;
148
+	private $mapCacheBaseDir;
149
+	private $mediaBaseDir;
150
+	private $useTileCache;
151
+	private $mapCacheID = '';
152
+	private $mapCacheFile = '';
153
+	private $mapCacheExtension = 'png';
154
+
155
+	/**
156
+	 * Constructor.
157
+	 *
158
+	 * @param float  $lat
159
+	 *            Latitude (x) of center of map
160
+	 * @param float  $lon
161
+	 *            Longitude (y) of center of map
162
+	 * @param int    $zoom
163
+	 *            Zoomlevel
164
+	 * @param int    $width
165
+	 *            Width in pixels
166
+	 * @param int    $height
167
+	 *            Height in pixels
168
+	 * @param string $maptype
169
+	 *            Name of the map
170
+	 * @param array  $markers
171
+	 *            array of markers
172
+	 * @param string $gpx
173
+	 *            GPX filename
174
+	 * @param string $kml
175
+	 *            KML filename
176
+	 * @param string $geojson
177
+	 * @param string $mediaDir
178
+	 *            Directory to store/cache maps
179
+	 * @param string $tileCacheBaseDir
180
+	 *            Directory to cache map tiles
181
+	 * @param bool   $autoZoomExtent
182
+	 *            Wheter or not to override zoom/lat/lon and zoom to the extent of gpx/kml and markers
183
+	 * @param string $apikey
184
+	 */
185
+	public function __construct(
186
+		float $lat,
187
+		float $lon,
188
+		int $zoom,
189
+		int $width,
190
+		int $height,
191
+		string $maptype,
192
+		array $markers,
193
+		string $gpx,
194
+		string $kml,
195
+		string $geojson,
196
+		string $mediaDir,
197
+		string $tileCacheBaseDir,
198
+		bool $autoZoomExtent = true,
199
+		string $apikey = ''
200
+	) {
201
+		$this->zoom   = $zoom;
202
+		$this->lat    = $lat;
203
+		$this->lon    = $lon;
204
+		$this->width  = $width;
205
+		$this->height = $height;
206
+		// validate + set maptype
207
+		$this->maptype = $this->tileDefaultSrc;
208
+		if(array_key_exists($maptype, $this->tileInfo)) {
209
+			$this->maptype = $maptype;
210
+		}
211
+		$this->markers          = $markers;
212
+		$this->kmlFileName      = $kml;
213
+		$this->gpxFileName      = $gpx;
214
+		$this->geojsonFileName  = $geojson;
215
+		$this->mediaBaseDir     = $mediaDir;
216
+		$this->tileCacheBaseDir = $tileCacheBaseDir . '/olmaptiles';
217
+		$this->useTileCache     = $this->tileCacheBaseDir !== '';
218
+		$this->mapCacheBaseDir  = $mediaDir . '/olmapmaps';
219
+		$this->autoZoomExtent   = $autoZoomExtent;
220
+		$this->apikey           = $apikey;
221
+	}
222
+
223
+	/**
224
+	 * get the map, this may return a reference to a cached copy.
225
+	 *
226
+	 * @return string url relative to media dir
227
+	 */
228
+	public function getMap(): string {
229
+		try {
230
+			if($this->autoZoomExtent) {
231
+				$this->autoZoom();
232
+			}
233
+		} catch(Exception $e) {
234
+			dbglog($e);
235
+		}
236
+
237
+		// use map cache, so check cache for map
238
+		if(!$this->checkMapCache()) {
239
+			// map is not in cache, needs to be build
240
+			$this->makeMap();
241
+			$this->mkdirRecursive(dirname($this->mapCacheIDToFilename()), 0777);
242
+			imagepng($this->image, $this->mapCacheIDToFilename(), 9);
243
+		}
244
+		$doc = $this->mapCacheIDToFilename();
245
+		// make url relative to media dir
246
+		return str_replace($this->mediaBaseDir, '', $doc);
247
+	}
248
+
249
+	/**
250
+	 * Calculate the lat/lon/zoom values to make sure that all of the markers and gpx/kml are on the map.
251
+	 * can throw an error like
252
+	 * "Fatal error: Uncaught Exception: Cannot create a collection with non-geometries in
253
+	 * D:\www\wild-water.nl\www\dokuwiki\lib\plugins\geophp\geoPHP\lib\geometry\Collection.class.php:29"
254
+	 *
255
+	 * @param float $paddingFactor
256
+	 *            buffer constant to enlarge (>1.0) the zoom level
257
+	 * @throws Exception
258
+	 */
259
+	private function autoZoom(float $paddingFactor = 1.0): void {
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']);
265
+			}
266
+		}
267
+		if(file_exists($this->kmlFileName)) {
268
+			$g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
269
+			if($g !== false) {
270
+				$geoms [] = $g;
271
+			}
272
+		}
273
+		if(file_exists($this->gpxFileName)) {
274
+			$g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
275
+			if($g !== false) {
276
+				$geoms [] = $g;
277
+			}
278
+		}
279
+		if(file_exists($this->geojsonFileName)) {
280
+			$g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson');
281
+			if($g !== false) {
282
+				$geoms [] = $g;
283
+			}
284
+		}
285
+
286
+		if(count($geoms) <= 1) {
287
+			dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options");
288
+			return;
289
+		}
290
+
291
+		$geom     = new GeometryCollection ($geoms);
292
+		$centroid = $geom->centroid();
293
+		$bbox     = $geom->getBBox();
294
+
295
+		// determine vertical resolution, this depends on the distance from the equator
296
+		// $vy00 = log(tan(M_PI*(0.25 + $centroid->getY()/360)));
297
+		$vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360)));
298
+		$vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360)));
299
+		dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1");
300
+		if ($vy1 - $vy0 === 0.0){
301
+			$resolutionVertical = 0;
302
+			dbglog("StaticMap::autoZoom: using $resolutionVertical");
303
+		} else {
304
+			$zoomFactorPowered  = ($this->height / 2) / (40.7436654315252 * ($vy1 - $vy0));
305
+			$resolutionVertical = 360 / ($zoomFactorPowered * $this->tileSize);
306
+		}
307
+		// determine horizontal resolution
308
+		$resolutionHorizontal = ($bbox ['maxx'] - $bbox ['minx']) / $this->width;
309
+		dbglog("StaticMap::autoZoom: using $resolutionHorizontal");
310
+		$resolution           = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
311
+		$zoom                 = $this->zoom;
312
+		if ($resolution > 0){
313
+			$zoom             = log(360 / ($resolution * $this->tileSize), 2);
314
+		}
315
+
316
+		if(is_finite($zoom) && $zoom < 15 && $zoom > 2) {
317
+			$this->zoom = floor($zoom);
318
+		}
319
+		$this->lon = $centroid->getX();
320
+		$this->lat = $centroid->getY();
321
+		dbglog("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat");
322
+	}
323
+
324
+	public function checkMapCache(): bool {
325
+		// side effect: set the mapCacheID
326
+		$this->mapCacheID = md5($this->serializeParams());
327
+		$filename         = $this->mapCacheIDToFilename();
328
+		return file_exists($filename);
329
+	}
330
+
331
+	public function serializeParams(): string {
332
+		return implode(
333
+			"&", array(
334
+				   $this->zoom,
335
+				   $this->lat,
336
+				   $this->lon,
337
+				   $this->width,
338
+				   $this->height,
339
+				   serialize($this->markers),
340
+				   $this->maptype,
341
+				   $this->kmlFileName,
342
+				   $this->gpxFileName,
343
+				   $this->geojsonFileName
344
+			   )
345
+		);
346
+	}
347
+
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);
353
+		}
354
+		return $this->mapCacheFile . "." . $this->mapCacheExtension;
355
+	}
356
+
357
+	/**
358
+	 * make the map.
359
+	 */
360
+	public function makeMap(): void {
361
+		$this->initCoords();
362
+		$this->createBaseMap();
363
+		if(!empty ($this->markers)) {
364
+			$this->placeMarkers();
365
+		}
366
+		if (file_exists($this->kmlFileName)) {
367
+			try {
368
+				$this->drawKML();
369
+			} catch (exception $e) {
370
+				dbglog('failed to load KML file', $e);
371
+			}
372
+		}
373
+		if (file_exists($this->gpxFileName)) {
374
+			try {
375
+				$this->drawGPX();
376
+			} catch (exception $e) {
377
+				dbglog('failed to load GPX file', $e);
378
+			}
379
+		}
380
+		if (file_exists($this->geojsonFileName)) {
381
+			try {
382
+				$this->drawGeojson();
383
+			} catch (exception $e) {
384
+				dbglog('failed to load GeoJSON file', $e);
385
+			}
386
+		}
387
+
388
+		$this->drawCopyright();
389
+	}
390
+
391
+	/**
392
+	 */
393
+	public function initCoords(): void {
394
+		$this->centerX = $this->lonToTile($this->lon, $this->zoom);
395
+		$this->centerY = $this->latToTile($this->lat, $this->zoom);
396
+		$this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize);
397
+		$this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize);
398
+	}
399
+
400
+	/**
401
+	 *
402
+	 * @param float $long
403
+	 * @param int   $zoom
404
+	 * @return float|int
405
+	 */
406
+	public function lonToTile(float $long, int $zoom) {
407
+		return (($long + 180) / 360) * pow(2, $zoom);
408
+	}
409
+
410
+	/**
411
+	 *
412
+	 * @param float $lat
413
+	 * @param int   $zoom
414
+	 * @return float|int
415
+	 */
416
+	public function latToTile(float $lat, int $zoom) {
417
+		return (1 - log(tan($lat * pi() / 180) + 1 / cos($lat * M_PI / 180)) / M_PI) / 2 * pow(2, $zoom);
418
+	}
419
+
420
+	/**
421
+	 * make basemap image.
422
+	 */
423
+	public function createBaseMap(): void {
424
+		$this->image   = imagecreatetruecolor($this->width, $this->height);
425
+		$startX        = floor($this->centerX - ($this->width / $this->tileSize) / 2);
426
+		$startY        = floor($this->centerY - ($this->height / $this->tileSize) / 2);
427
+		$endX          = ceil($this->centerX + ($this->width / $this->tileSize) / 2);
428
+		$endY          = ceil($this->centerY + ($this->height / $this->tileSize) / 2);
429
+		$this->offsetX = -floor(($this->centerX - floor($this->centerX)) * $this->tileSize);
430
+		$this->offsetY = -floor(($this->centerY - floor($this->centerY)) * $this->tileSize);
431
+		$this->offsetX += floor($this->width / 2);
432
+		$this->offsetY += floor($this->height / 2);
433
+		$this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize;
434
+		$this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize;
435
+
436
+		for($x = $startX; $x <= $endX; $x++) {
437
+			for($y = $startY; $y <= $endY; $y++) {
438
+				$url = str_replace(
439
+					array(
440
+						'{Z}',
441
+						'{X}',
442
+						'{Y}'
443
+					), array(
444
+						$this->zoom,
445
+						$x,
446
+						$y
447
+					), $this->tileInfo [$this->maptype] ['url']
448
+				);
449
+
450
+				$tileData = $this->fetchTile($url);
451
+				if($tileData) {
452
+					$tileImage = imagecreatefromstring($tileData);
453
+				} else {
454
+					$tileImage = imagecreate($this->tileSize, $this->tileSize);
455
+					$color     = imagecolorallocate($tileImage, 255, 255, 255);
456
+					@imagestring($tileImage, 1, 127, 127, 'err', $color);
457
+				}
458
+				$destX = ($x - $startX) * $this->tileSize + $this->offsetX;
459
+				$destY = ($y - $startY) * $this->tileSize + $this->offsetY;
460
+				dbglog($this->tileSize, "imagecopy tile into image: $destX, $destY");
461
+				imagecopy(
462
+					$this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize,
463
+					$this->tileSize
464
+				);
465
+			}
466
+		}
467
+	}
468
+
469
+	/**
470
+	 * Fetch a tile and (if configured) store it in the cache.
471
+	 * @param string $url
472
+	 * @return bool|string
473
+	 * @todo refactor this to use dokuwiki\HTTP\HTTPClient or dokuwiki\HTTP\DokuHTTPClient
474
+	 *          for better proxy handling...
475
+	 */
476
+	public function fetchTile(string $url) {
477
+		if($this->useTileCache && ($cached = $this->checkTileCache($url)))
478
+			return $cached;
479
+
480
+		$_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')';
481
+		if(function_exists("curl_init")) {
482
+			// use cUrl
483
+			$ch = curl_init();
484
+			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
485
+			curl_setopt($ch, CURLOPT_USERAGENT, $_UA);
486
+			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
487
+			curl_setopt($ch, CURLOPT_URL, $url . $this->apikey);
488
+			dbglog("StaticMap::fetchTile: getting: $url using curl_exec");
489
+			$tile = curl_exec($ch);
490
+			curl_close($ch);
491
+		} else {
492
+			// use file_get_contents
493
+			global $conf;
494
+			$opts = array(
495
+				'http' => array(
496
+					'method'          => "GET",
497
+					'header'          => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n",
498
+					'request_fulluri' => true
499
+				)
500
+			);
501
+			if(isset($conf['proxy']['host'], $conf['proxy']['port'])
502
+				&& $conf['proxy']['host'] !== ''
503
+				&& $conf['proxy']['port'] !== '') {
504
+				$opts['http'] += ['proxy' => "tcp://" . $conf['proxy']['host'] . ":" . $conf['proxy']['port']];
505
+			}
506
+
507
+			$context = stream_context_create($opts);
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);
510
+		}
511
+		if($tile && $this->useTileCache) {
512
+			$this->writeTileToCache($url, $tile);
513
+		}
514
+		return $tile;
515
+	}
516
+
517
+	/**
518
+	 *
519
+	 * @param string $url
520
+	 * @return string|false
521
+	 */
522
+	public function checkTileCache(string $url) {
523
+		$filename = $this->tileUrlToFilename($url);
524
+		if(file_exists($filename)) {
525
+			return file_get_contents($filename);
526
+		}
527
+		return false;
528
+	}
529
+
530
+	/**
531
+	 *
532
+	 * @param string $url
533
+	 * @return string
534
+	 */
535
+	public function tileUrlToFilename(string $url): string {
536
+		return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1);
537
+	}
538
+
539
+	/**
540
+	 * Write a tile into the cache.
541
+	 *
542
+	 * @param string $url
543
+	 * @param mixed  $data
544
+	 */
545
+	public function writeTileToCache($url, $data): void {
546
+		$filename = $this->tileUrlToFilename($url);
547
+		$this->mkdirRecursive(dirname($filename), 0777);
548
+		file_put_contents($filename, $data);
549
+	}
550
+
551
+	/**
552
+	 * Recursively create the directory.
553
+	 *
554
+	 * @param string $pathname
555
+	 *            The directory path.
556
+	 * @param int    $mode
557
+	 *            File access mode. For more information on modes, read the details on the chmod manpage.
558
+	 */
559
+	public function mkdirRecursive(string $pathname, int $mode): bool {
560
+		is_dir(dirname($pathname)) || $this->mkdirRecursive(dirname($pathname), $mode);
561
+		return is_dir($pathname) || mkdir($pathname, $mode) || is_dir($pathname);
562
+	}
563
+
564
+	/**
565
+	 * Place markers on the map and number them in the same order as they are listed in the html.
566
+	 */
567
+	public function placeMarkers(): void {
568
+		$count         = 0;
569
+		$color         = imagecolorallocate($this->image, 0, 0, 0);
570
+		$bgcolor       = imagecolorallocate($this->image, 200, 200, 200);
571
+		$markerBaseDir = __DIR__ . '/icons';
572
+		$markerImageOffsetX  = 0;
573
+		$markerImageOffsetY  = 0;
574
+		$markerShadowOffsetX = 0;
575
+		$markerShadowOffsetY = 0;
576
+		$markerShadowImg     = null;
577
+		// loop thru marker array
578
+		foreach($this->markers as $marker) {
579
+			// set some local variables
580
+			$markerLat  = $marker ['lat'];
581
+			$markerLon  = $marker ['lon'];
582
+			$markerType = $marker ['type'];
583
+			// clear variables from previous loops
584
+			$markerFilename = '';
585
+			$markerShadow   = '';
586
+			$matches        = false;
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']) {
593
+							list ($markerImageOffsetX, $markerImageOffsetY) = explode(
594
+								",",
595
+								$markerPrototype ['offsetImage']
596
+							);
597
+						}
598
+						$markerShadow = $markerPrototype ['shadow'];
599
+						if($markerShadow) {
600
+							list ($markerShadowOffsetX, $markerShadowOffsetY) = explode(
601
+								",",
602
+								$markerPrototype ['offsetShadow']
603
+							);
604
+						}
605
+					}
606
+				}
607
+			}
608
+			// create img resource
609
+			if(file_exists($markerBaseDir . '/' . $markerFilename)) {
610
+				$markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename);
611
+			} else {
612
+				$markerImg = imagecreatefrompng($markerBaseDir . '/marker.png');
613
+			}
614
+			// check for shadow + create shadow recource
615
+			if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) {
616
+				$markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow);
617
+			}
618
+			// calc position
619
+			$destX = floor(
620
+				($this->width / 2) -
621
+				$this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom))
622
+			);
623
+			$destY = floor(
624
+				($this->height / 2) -
625
+				$this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))
626
+			);
627
+			// copy shadow on basemap
628
+			if($markerShadow && $markerShadowImg) {
629
+				imagecopy(
630
+					$this->image,
631
+					$markerShadowImg,
632
+					$destX + (int) $markerShadowOffsetX,
633
+					$destY + (int) $markerShadowOffsetY,
634
+					0,
635
+					0,
636
+					imagesx($markerShadowImg),
637
+					imagesy($markerShadowImg)
638
+				);
639
+			}
640
+			// copy marker on basemap above shadow
641
+			imagecopy(
642
+				$this->image,
643
+				$markerImg,
644
+				$destX + (int) $markerImageOffsetX,
645
+				$destY + (int) $markerImageOffsetY,
646
+				0,
647
+				0,
648
+				imagesx($markerImg),
649
+				imagesy($markerImg)
650
+			);
651
+			// add label
652
+			imagestring(
653
+				$this->image,
654
+				3,
655
+				$destX - imagesx($markerImg) + 1,
656
+				$destY + (int) $markerImageOffsetY + 1,
657
+				++$count,
658
+				$bgcolor
659
+			);
660
+			imagestring(
661
+				$this->image,
662
+				3,
663
+				$destX - imagesx($markerImg),
664
+				$destY + (int) $markerImageOffsetY,
665
+				$count,
666
+				$color
667
+			);
668
+		}
669
+	}
670
+
671
+	/**
672
+	 * Draw kml trace on the map.
673
+	 * @throws exception when loading the KML fails
674
+	 */
675
+	public function drawKML(): void {
676
+		// TODO get colour from kml node (not currently supported in geoPHP)
677
+		$col     = imagecolorallocatealpha($this->image, 255, 0, 0, .4 * 127);
678
+		$kmlgeom = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
679
+		$this->drawGeometry($kmlgeom, $col);
680
+	}
681
+
682
+	/**
683
+	 * Draw geometry or geometry collection on the map.
684
+	 *
685
+	 * @param Geometry $geom
686
+	 * @param int      $colour
687
+	 *            drawing colour
688
+	 */
689
+	private function drawGeometry(Geometry $geom, int $colour): void {
690
+		if(empty($geom)) {
691
+			return;
692
+		}
693
+
694
+		switch($geom->geometryType()) {
695
+			case 'GeometryCollection' :
696
+				// recursively draw part of the collection
697
+				for($i = 1; $i < $geom->numGeometries() + 1; $i++) {
698
+					$_geom = $geom->geometryN($i);
699
+					$this->drawGeometry($_geom, $colour);
700
+				}
701
+				break;
702
+			case 'MultiPolygon' :
703
+			case 'MultiLineString' :
704
+			case 'MultiPoint' :
705
+				// TODO implement / do nothing
706
+				break;
707
+			case 'Polygon' :
708
+				$this->drawPolygon($geom, $colour);
709
+				break;
710
+			case 'LineString' :
711
+				$this->drawLineString($geom, $colour);
712
+				break;
713
+			case 'Point' :
714
+				$this->drawPoint($geom, $colour);
715
+				break;
716
+			default :
717
+				// draw nothing
718
+				break;
719
+		}
720
+	}
721
+
722
+	/**
723
+	 * Draw a polygon on the map.
724
+	 *
725
+	 * @param Polygon $polygon
726
+	 * @param int     $colour
727
+	 *            drawing colour
728
+	 */
729
+	private function drawPolygon($polygon, int $colour) {
730
+		// TODO implementation of drawing holes,
731
+		// maybe draw the polygon to an in-memory image and use imagecopy, draw polygon in col., draw holes in bgcol?
732
+
733
+		// print_r('Polygon:<br />');
734
+		// print_r($polygon);
735
+		$extPoints = array();
736
+		// extring is a linestring actually..
737
+		$extRing = $polygon->exteriorRing();
738
+
739
+		for($i = 1; $i < $extRing->numGeometries(); $i++) {
740
+			$p1           = $extRing->geometryN($i);
741
+			$x            = floor(
742
+				($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
743
+			);
744
+			$y            = floor(
745
+				($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
746
+			);
747
+			$extPoints [] = $x;
748
+			$extPoints [] = $y;
749
+		}
750
+		// print_r('points:('.($i-1).')<br />');
751
+		// print_r($extPoints);
752
+		// imagepolygon ($this->image, $extPoints, $i-1, $colour );
753
+		imagefilledpolygon($this->image, $extPoints, $i - 1, $colour);
754
+	}
755
+
756
+	/**
757
+	 * Draw a line on the map.
758
+	 *
759
+	 * @param LineString $line
760
+	 * @param int        $colour
761
+	 *            drawing colour
762
+	 */
763
+	private function drawLineString($line, $colour) {
764
+		imagesetthickness($this->image, 2);
765
+		for($p = 1; $p < $line->numGeometries(); $p++) {
766
+			// get first pair of points
767
+			$p1 = $line->geometryN($p);
768
+			$p2 = $line->geometryN($p + 1);
769
+			// translate to paper space
770
+			$x1 = floor(
771
+				($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
772
+			);
773
+			$y1 = floor(
774
+				($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
775
+			);
776
+			$x2 = floor(
777
+				($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p2->x(), $this->zoom))
778
+			);
779
+			$y2 = floor(
780
+				($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p2->y(), $this->zoom))
781
+			);
782
+			// draw to image
783
+			imageline($this->image, $x1, $y1, $x2, $y2, $colour);
784
+		}
785
+		imagesetthickness($this->image, 1);
786
+	}
787
+
788
+	/**
789
+	 * Draw a point on the map.
790
+	 *
791
+	 * @param Point $point
792
+	 * @param int   $colour
793
+	 *            drawing colour
794
+	 */
795
+	private function drawPoint($point, $colour) {
796
+		imagesetthickness($this->image, 2);
797
+		// translate to paper space
798
+		$cx = floor(
799
+			($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($point->x(), $this->zoom))
800
+		);
801
+		$cy = floor(
802
+			($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($point->y(), $this->zoom))
803
+		);
804
+		$r  = 5;
805
+		// draw to image
806
+		// imageellipse($this->image, $cx, $cy,$r, $r, $colour);
807
+		imagefilledellipse($this->image, $cx, $cy, $r, $r, $colour);
808
+		// don't use imageellipse because the imagesetthickness function has
809
+		// no effect. So the better workaround is to use imagearc.
810
+		imagearc($this->image, $cx, $cy, $r, $r, 0, 359, $colour);
811
+		imagesetthickness($this->image, 1);
812
+	}
813
+
814
+	/**
815
+	 * Draw gpx trace on the map.
816
+	 * @throws exception when loading the GPX fails
817
+	 */
818
+	public function drawGPX() {
819
+		$col     = imagecolorallocatealpha($this->image, 0, 0, 255, .4 * 127);
820
+		$gpxgeom = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
821
+		$this->drawGeometry($gpxgeom, $col);
822
+	}
823
+
824
+	/**
825
+	 * Draw geojson on the map.
826
+	 * @throws exception when loading the JSON fails
827
+	 */
828
+	public function drawGeojson() {
829
+		$col     = imagecolorallocatealpha($this->image, 255, 0, 255, .4 * 127);
830
+		$gpxgeom = geoPHP::load(file_get_contents($this->geojsonFileName), 'json');
831
+		$this->drawGeometry($gpxgeom, $col);
832
+	}
833
+
834
+	/**
835
+	 * add copyright and origin notice and icons to the map.
836
+	 */
837
+	public function drawCopyright() {
838
+		$logoBaseDir = dirname(__FILE__) . '/' . 'logo/';
839
+		$logoImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']);
840
+		$textcolor   = imagecolorallocate($this->image, 0, 0, 0);
841
+		$bgcolor     = imagecolorallocate($this->image, 200, 200, 200);
842
+
843
+		imagecopy(
844
+			$this->image,
845
+			$logoImg,
846
+			0,
847
+			imagesy($this->image) - imagesy($logoImg),
848
+			0,
849
+			0,
850
+			imagesx($logoImg),
851
+			imagesy($logoImg)
852
+		);
853
+		imagestring(
854
+			$this->image,
855
+			1,
856
+			imagesx($logoImg) + 2,
857
+			imagesy($this->image) - imagesy($logoImg) + 1,
858
+			$this->tileInfo ['openstreetmap'] ['txt'],
859
+			$bgcolor
860
+		);
861
+		imagestring(
862
+			$this->image,
863
+			1,
864
+			imagesx($logoImg) + 1,
865
+			imagesy($this->image) - imagesy($logoImg),
866
+			$this->tileInfo ['openstreetmap'] ['txt'],
867
+			$textcolor
868
+		);
869
+
870
+		// additional tile source info, ie. who created/hosted the tiles
871
+		$xIconOffset = 0;
872
+		if($this->maptype === 'openstreetmap') {
873
+			$mapAuthor = "(c) OpenStreetMap maps/CC BY-SA";
874
+		} else {
875
+			$mapAuthor   = $this->tileInfo [$this->maptype] ['txt'];
876
+			$iconImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']);
877
+			$xIconOffset = imagesx($iconImg);
878
+			imagecopy(
879
+				$this->image,
880
+				$iconImg, imagesx($logoImg) + 1,
881
+				imagesy($this->image) - imagesy($iconImg),
882
+				0,
883
+				0,
884
+				imagesx($iconImg), imagesy($iconImg)
885
+			);
886
+		}
887
+		imagestring(
888
+			$this->image,
889
+			1, imagesx($logoImg) + $xIconOffset + 4,
890
+			imagesy($this->image) - ceil(imagesy($logoImg) / 2) + 1,
891
+			$mapAuthor,
892
+			$bgcolor
893
+		);
894
+		imagestring(
895
+			$this->image,
896
+			1, imagesx($logoImg) + $xIconOffset + 3,
897
+			imagesy($this->image) - ceil(imagesy($logoImg) / 2),
898
+			$mapAuthor,
899
+			$textcolor
900
+		);
901
+
902
+	}
903 903
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,
Please login to merge, or discard this patch.