Completed
Push — master ( b22e29...3f2aa7 )
by Mark
14s queued 11s
created
helper/staticmap.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -24,125 +24,125 @@
 block discarded – undo
24 24
  * @author Mark Prins
25 25
  */
26 26
 class helper_plugin_openlayersmap_staticmap extends DokuWiki_Plugin {
27
-    /** maximum width of the resulting image. */
28
-    private $maxWidth = 1024;
29
-    /** maximum heigth of the resulting image. */
30
-    private $maxHeight = 1024;
27
+	/** maximum width of the resulting image. */
28
+	private $maxWidth = 1024;
29
+	/** maximum heigth of the resulting image. */
30
+	private $maxHeight = 1024;
31 31
 
32
-    /**
33
-     * Provide metadata of the public methods of this class.
34
-     *
35
-     * @return array Information to all provided methods.
36
-     */
37
-    public function getMethods(): array {
38
-        $result   = array();
39
-        $result[] = array(
40
-            'name'   => 'getMap',
41
-            'desc'   => 'returns url to the image',
42
-            'params' => array(
43
-                'lat'     => 'float',
44
-                'lon'     => 'float',
45
-                'zoom'    => 'integer',
46
-                'size'    => 'string',
47
-                'maptype' => 'string',
48
-                'markers' => 'string',
49
-                'gpx'     => 'string',
50
-                'kml'     => 'string',
51
-                'geojson' => 'string',
52
-                'apikey'  => 'string'
53
-            ),
54
-            'return' => array('image' => 'string'),
55
-        );
56
-        return $result;
57
-    }
32
+	/**
33
+	 * Provide metadata of the public methods of this class.
34
+	 *
35
+	 * @return array Information to all provided methods.
36
+	 */
37
+	public function getMethods(): array {
38
+		$result   = array();
39
+		$result[] = array(
40
+			'name'   => 'getMap',
41
+			'desc'   => 'returns url to the image',
42
+			'params' => array(
43
+				'lat'     => 'float',
44
+				'lon'     => 'float',
45
+				'zoom'    => 'integer',
46
+				'size'    => 'string',
47
+				'maptype' => 'string',
48
+				'markers' => 'string',
49
+				'gpx'     => 'string',
50
+				'kml'     => 'string',
51
+				'geojson' => 'string',
52
+				'apikey'  => 'string'
53
+			),
54
+			'return' => array('image' => 'string'),
55
+		);
56
+		return $result;
57
+	}
58 58
 
59
-    /**
60
-     * Create the map.
61
-     *
62
-     * @param float  $lat     the latitude of the map's center, eg. 40.714728
63
-     * @param float  $lon     the longitude of the map's center, eg -73.998672
64
-     * @param int    $zoom    the zoom level in the tile cache, eg. 14
65
-     * @param string $size    the size in WxH px, eg. 512x512
66
-     * @param string $maptype the maptype, eg. cycle
67
-     * @param array  $markers associative array of markers, array('lat'=>$lat,'lon'=>$lon,'type'=>$iconStyle),
68
-     *                        eg. array('lat'=>40.702147,'lon'=>-74.015794,'type'=>lightblue1);
69
-     * @param string $gpx     media link
70
-     * @param string $kml     media link
71
-     * @param string $geojson media link
72
-     * @param string $apikey  optional API key eg. for Thunderforest maps
73
-     *
74
-     * @return string
75
-     */
76
-    public function getMap(
77
-        float $lat,
78
-        float $lon,
79
-        int $zoom,
80
-        string $size,
81
-        string $maptype,
82
-        array $markers,
83
-        string $gpx,
84
-        string $kml,
85
-        string $geojson,
86
-        string $apikey = ''
87
-    ): string {
88
-        global $conf;
89
-        // dbglog($markers,'helper_plugin_openlayersmap_staticmap::getMap: markers :');
59
+	/**
60
+	 * Create the map.
61
+	 *
62
+	 * @param float  $lat     the latitude of the map's center, eg. 40.714728
63
+	 * @param float  $lon     the longitude of the map's center, eg -73.998672
64
+	 * @param int    $zoom    the zoom level in the tile cache, eg. 14
65
+	 * @param string $size    the size in WxH px, eg. 512x512
66
+	 * @param string $maptype the maptype, eg. cycle
67
+	 * @param array  $markers associative array of markers, array('lat'=>$lat,'lon'=>$lon,'type'=>$iconStyle),
68
+	 *                        eg. array('lat'=>40.702147,'lon'=>-74.015794,'type'=>lightblue1);
69
+	 * @param string $gpx     media link
70
+	 * @param string $kml     media link
71
+	 * @param string $geojson media link
72
+	 * @param string $apikey  optional API key eg. for Thunderforest maps
73
+	 *
74
+	 * @return string
75
+	 */
76
+	public function getMap(
77
+		float $lat,
78
+		float $lon,
79
+		int $zoom,
80
+		string $size,
81
+		string $maptype,
82
+		array $markers,
83
+		string $gpx,
84
+		string $kml,
85
+		string $geojson,
86
+		string $apikey = ''
87
+	): string {
88
+		global $conf;
89
+		// dbglog($markers,'helper_plugin_openlayersmap_staticmap::getMap: markers :');
90 90
 
91
-        // normalize zoom
92
-        $zoom = $zoom ?: 0;
93
-        if($zoom > 18) {
94
-            $zoom = 18;
95
-        }
96
-        // normalize WxH
97
-        list($width, $height) = explode('x', $size);
98
-        $width = (int) $width;
99
-        if($width > $this->maxWidth) {
100
-            $width = $this->maxWidth;
101
-        }
102
-        $height = (int) $height;
103
-        if($height > $this->maxHeight) {
104
-            $height = $this->maxHeight;
105
-        }
91
+		// normalize zoom
92
+		$zoom = $zoom ?: 0;
93
+		if($zoom > 18) {
94
+			$zoom = 18;
95
+		}
96
+		// normalize WxH
97
+		list($width, $height) = explode('x', $size);
98
+		$width = (int) $width;
99
+		if($width > $this->maxWidth) {
100
+			$width = $this->maxWidth;
101
+		}
102
+		$height = (int) $height;
103
+		if($height > $this->maxHeight) {
104
+			$height = $this->maxHeight;
105
+		}
106 106
 
107
-        // cleanup/validate gpx/kml
108
-        $kml = $this->mediaIdToPath($kml);
109
-        // dbglog($kml,'helper_plugin_openlayersmap_staticmap::getMap: kml file:');
110
-        $gpx = $this->mediaIdToPath($gpx);
111
-        // dbglog($gpx,'helper_plugin_openlayersmap_staticmap::getMap: gpx file:');
112
-        $geojson = $this->mediaIdToPath($geojson);
107
+		// cleanup/validate gpx/kml
108
+		$kml = $this->mediaIdToPath($kml);
109
+		// dbglog($kml,'helper_plugin_openlayersmap_staticmap::getMap: kml file:');
110
+		$gpx = $this->mediaIdToPath($gpx);
111
+		// dbglog($gpx,'helper_plugin_openlayersmap_staticmap::getMap: gpx file:');
112
+		$geojson = $this->mediaIdToPath($geojson);
113 113
 
114
-        // create map
115
-        require_once DOKU_PLUGIN . 'openlayersmap/StaticMap.php';
116
-        $map = new StaticMap(
117
-            $lat, $lon, $zoom, $width, $height, $maptype,
118
-            $markers, $gpx, $kml, $geojson, $conf['mediadir'], $conf['cachedir'],
119
-            $this->getConf('autoZoomMap'), $apikey
120
-        );
114
+		// create map
115
+		require_once DOKU_PLUGIN . 'openlayersmap/StaticMap.php';
116
+		$map = new StaticMap(
117
+			$lat, $lon, $zoom, $width, $height, $maptype,
118
+			$markers, $gpx, $kml, $geojson, $conf['mediadir'], $conf['cachedir'],
119
+			$this->getConf('autoZoomMap'), $apikey
120
+		);
121 121
 
122
-        // return the media id url
123
-        // $mediaId = str_replace('/', ':', $map->getMap());
124
-        // if($this->startsWith($mediaId,':')) {
125
-        //     $mediaId = substr($mediaId, 1);
126
-        // }
127
-        // return $mediaId;
128
-        return str_replace('/', ':', $map->getMap());
129
-    }
122
+		// return the media id url
123
+		// $mediaId = str_replace('/', ':', $map->getMap());
124
+		// if($this->startsWith($mediaId,':')) {
125
+		//     $mediaId = substr($mediaId, 1);
126
+		// }
127
+		// return $mediaId;
128
+		return str_replace('/', ':', $map->getMap());
129
+	}
130 130
 
131
-    /**
132
-     * Constructs the path to a file.
133
-     * @param string $id the DW media id
134
-     * @return string the path to the file
135
-     */
136
-    private function mediaIdToPath(string $id): string {
137
-        global $conf;
138
-        if(empty($id)) {
139
-            return "";
140
-        }
141
-        $id = str_replace(array("[[", "]]"), "", $id);
142
-        if((strpos($id, ':') === 0)) {
143
-            $id = substr($id, 1);
144
-        }
145
-        $id = str_replace(":", "/", $id);
146
-        return $conf['mediadir'] . '/' . $id;
147
-    }
131
+	/**
132
+	 * Constructs the path to a file.
133
+	 * @param string $id the DW media id
134
+	 * @return string the path to the file
135
+	 */
136
+	private function mediaIdToPath(string $id): string {
137
+		global $conf;
138
+		if(empty($id)) {
139
+			return "";
140
+		}
141
+		$id = str_replace(array("[[", "]]"), "", $id);
142
+		if((strpos($id, ':') === 0)) {
143
+			$id = substr($id, 1);
144
+		}
145
+		$id = str_replace(":", "/", $id);
146
+		return $conf['mediadir'] . '/' . $id;
147
+	}
148 148
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -90,17 +90,17 @@  discard block
 block discarded – undo
90 90
 
91 91
         // normalize zoom
92 92
         $zoom = $zoom ?: 0;
93
-        if($zoom > 18) {
93
+        if ($zoom > 18) {
94 94
             $zoom = 18;
95 95
         }
96 96
         // normalize WxH
97 97
         list($width, $height) = explode('x', $size);
98 98
         $width = (int) $width;
99
-        if($width > $this->maxWidth) {
99
+        if ($width > $this->maxWidth) {
100 100
             $width = $this->maxWidth;
101 101
         }
102 102
         $height = (int) $height;
103
-        if($height > $this->maxHeight) {
103
+        if ($height > $this->maxHeight) {
104 104
             $height = $this->maxHeight;
105 105
         }
106 106
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         $geojson = $this->mediaIdToPath($geojson);
113 113
 
114 114
         // create map
115
-        require_once DOKU_PLUGIN . 'openlayersmap/StaticMap.php';
115
+        require_once DOKU_PLUGIN.'openlayersmap/StaticMap.php';
116 116
         $map = new StaticMap(
117 117
             $lat, $lon, $zoom, $width, $height, $maptype,
118 118
             $markers, $gpx, $kml, $geojson, $conf['mediadir'], $conf['cachedir'],
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
      */
136 136
     private function mediaIdToPath(string $id): string {
137 137
         global $conf;
138
-        if(empty($id)) {
138
+        if (empty($id)) {
139 139
             return "";
140 140
         }
141 141
         $id = str_replace(array("[[", "]]"), "", $id);
142
-        if((strpos($id, ':') === 0)) {
142
+        if ((strpos($id, ':') === 0)) {
143 143
             $id = substr($id, 1);
144 144
         }
145 145
         $id = str_replace(":", "/", $id);
146
-        return $conf['mediadir'] . '/' . $id;
146
+        return $conf['mediadir'].'/'.$id;
147 147
     }
148 148
 }
Please login to merge, or discard this patch.
syntax/olmap.php 2 patches
Indentation   +732 added lines, -732 removed lines patch added patch discarded remove patch
@@ -25,108 +25,108 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class syntax_plugin_openlayersmap_olmap extends DokuWiki_Syntax_Plugin {
27 27
 
28
-    /**
29
-     * defaults of the known attributes of the olmap tag.
30
-     */
31
-    private $dflt = array(
32
-        'id'            => 'olmap',
33
-        'width'         => '550px',
34
-        'height'        => '450px',
35
-        'lat'           => 50.0,
36
-        'lon'           => 5.1,
37
-        'zoom'          => 12,
38
-        'autozoom'      => 1,
39
-        'statusbar'     => true,
40
-        'toolbar'       => true,
41
-        'controls'      => true,
42
-        'poihoverstyle' => false,
43
-        'baselyr'       => 'OpenStreetMap',
44
-        'gpxfile'       => '',
45
-        'kmlfile'       => '',
46
-        'geojsonfile'   => '',
47
-        'summary'       => ''
48
-    );
49
-
50
-    /**
51
-     *
52
-     * @see DokuWiki_Syntax_Plugin::getType()
53
-     */
54
-    public function getType(): string {
55
-        return 'substition';
56
-    }
57
-
58
-    /**
59
-     *
60
-     * @see DokuWiki_Syntax_Plugin::getPType()
61
-     */
62
-    public function getPType(): string {
63
-        return 'block';
64
-    }
65
-
66
-    /**
67
-     *
68
-     * @see Doku_Parser_Mode::getSort()
69
-     */
70
-    public function getSort(): int {
71
-        return 901;
72
-    }
73
-
74
-    /**
75
-     *
76
-     * @see Doku_Parser_Mode::connectTo()
77
-     */
78
-    public function connectTo($mode) {
79
-        $this->Lexer->addSpecialPattern(
80
-            '<olmap ?[^>\n]*>.*?</olmap>', $mode,
81
-            'plugin_openlayersmap_olmap'
82
-        );
83
-    }
84
-
85
-    /**
86
-     *
87
-     * @see DokuWiki_Syntax_Plugin::handle()
88
-     */
89
-    public function handle($match, $state, $pos, Doku_Handler $handler): array {
90
-        // break matched cdata into its components
91
-        list ($str_params, $str_points) = explode('>', substr($match, 7, -9), 2);
92
-        // get the lat/lon for adding them to the metadata (used by geotag)
93
-        preg_match('(lat[:|=]\"-?\d*\.?\d*\")', $match, $mainLat);
94
-        preg_match('(lon[:|=]\"-?\d*\.?\d*\")', $match, $mainLon);
95
-        $mainLat = substr($mainLat [0], 5, -1);
96
-        $mainLon = substr($mainLon [0], 5, -1);
97
-        if(!is_numeric($mainLat)) {
98
-            $mainLat = $this->dflt ['lat'];
99
-        }
100
-        if(!is_numeric($mainLon)) {
101
-            $mainLon = $this->dflt ['lon'];
102
-        }
103
-
104
-        $gmap          = $this->extractParams($str_params);
105
-        $overlay       = $this->extractPoints($str_points);
106
-        $_firstimageID = '';
107
-
108
-        $_nocache = false;
109
-        // choose maptype based on the specified tag
110
-        $imgUrl = "{{";
111
-        if(stripos($gmap ['baselyr'], 'google') !== false) {
112
-            // Google
113
-            $imgUrl .= $this->getGoogle($gmap, $overlay);
114
-            $imgUrl .= "&.png";
115
-        } elseif(stripos($gmap ['baselyr'], 'bing') !== false) {
116
-            // Bing
117
-            if(!$this->getConf('bingAPIKey')) {
118
-                // in case there is no Bing api key we'll use OSM
119
-                $_firstimageID = $this->getStaticOSM($gmap, $overlay);
120
-                $imgUrl        .= $_firstimageID;
121
-                if($this->getConf('optionStaticMapGenerator') == 'remote') {
122
-                    $imgUrl .= "&.png";
123
-                }
124
-            } else {
125
-                // seems that Bing doesn't like the DW client, turn off caching
126
-                $_nocache = true;
127
-                $imgUrl   .= $this->getBing($gmap, $overlay) . "&.png";
128
-            }
129
-        } /* elseif (stripos ( $gmap ['baselyr'], 'mapquest' ) !== false) {
28
+	/**
29
+	 * defaults of the known attributes of the olmap tag.
30
+	 */
31
+	private $dflt = array(
32
+		'id'            => 'olmap',
33
+		'width'         => '550px',
34
+		'height'        => '450px',
35
+		'lat'           => 50.0,
36
+		'lon'           => 5.1,
37
+		'zoom'          => 12,
38
+		'autozoom'      => 1,
39
+		'statusbar'     => true,
40
+		'toolbar'       => true,
41
+		'controls'      => true,
42
+		'poihoverstyle' => false,
43
+		'baselyr'       => 'OpenStreetMap',
44
+		'gpxfile'       => '',
45
+		'kmlfile'       => '',
46
+		'geojsonfile'   => '',
47
+		'summary'       => ''
48
+	);
49
+
50
+	/**
51
+	 *
52
+	 * @see DokuWiki_Syntax_Plugin::getType()
53
+	 */
54
+	public function getType(): string {
55
+		return 'substition';
56
+	}
57
+
58
+	/**
59
+	 *
60
+	 * @see DokuWiki_Syntax_Plugin::getPType()
61
+	 */
62
+	public function getPType(): string {
63
+		return 'block';
64
+	}
65
+
66
+	/**
67
+	 *
68
+	 * @see Doku_Parser_Mode::getSort()
69
+	 */
70
+	public function getSort(): int {
71
+		return 901;
72
+	}
73
+
74
+	/**
75
+	 *
76
+	 * @see Doku_Parser_Mode::connectTo()
77
+	 */
78
+	public function connectTo($mode) {
79
+		$this->Lexer->addSpecialPattern(
80
+			'<olmap ?[^>\n]*>.*?</olmap>', $mode,
81
+			'plugin_openlayersmap_olmap'
82
+		);
83
+	}
84
+
85
+	/**
86
+	 *
87
+	 * @see DokuWiki_Syntax_Plugin::handle()
88
+	 */
89
+	public function handle($match, $state, $pos, Doku_Handler $handler): array {
90
+		// break matched cdata into its components
91
+		list ($str_params, $str_points) = explode('>', substr($match, 7, -9), 2);
92
+		// get the lat/lon for adding them to the metadata (used by geotag)
93
+		preg_match('(lat[:|=]\"-?\d*\.?\d*\")', $match, $mainLat);
94
+		preg_match('(lon[:|=]\"-?\d*\.?\d*\")', $match, $mainLon);
95
+		$mainLat = substr($mainLat [0], 5, -1);
96
+		$mainLon = substr($mainLon [0], 5, -1);
97
+		if(!is_numeric($mainLat)) {
98
+			$mainLat = $this->dflt ['lat'];
99
+		}
100
+		if(!is_numeric($mainLon)) {
101
+			$mainLon = $this->dflt ['lon'];
102
+		}
103
+
104
+		$gmap          = $this->extractParams($str_params);
105
+		$overlay       = $this->extractPoints($str_points);
106
+		$_firstimageID = '';
107
+
108
+		$_nocache = false;
109
+		// choose maptype based on the specified tag
110
+		$imgUrl = "{{";
111
+		if(stripos($gmap ['baselyr'], 'google') !== false) {
112
+			// Google
113
+			$imgUrl .= $this->getGoogle($gmap, $overlay);
114
+			$imgUrl .= "&.png";
115
+		} elseif(stripos($gmap ['baselyr'], 'bing') !== false) {
116
+			// Bing
117
+			if(!$this->getConf('bingAPIKey')) {
118
+				// in case there is no Bing api key we'll use OSM
119
+				$_firstimageID = $this->getStaticOSM($gmap, $overlay);
120
+				$imgUrl        .= $_firstimageID;
121
+				if($this->getConf('optionStaticMapGenerator') == 'remote') {
122
+					$imgUrl .= "&.png";
123
+				}
124
+			} else {
125
+				// seems that Bing doesn't like the DW client, turn off caching
126
+				$_nocache = true;
127
+				$imgUrl   .= $this->getBing($gmap, $overlay) . "&.png";
128
+			}
129
+		} /* elseif (stripos ( $gmap ['baselyr'], 'mapquest' ) !== false) {
130 130
             // MapQuest
131 131
             if (! $this->getConf ( 'mapquestAPIKey' )) {
132 132
                 // no API key for MapQuest, use OSM
@@ -140,169 +140,169 @@  discard block
 block discarded – undo
140 140
                 $imgUrl .= "&.png";
141 141
             }
142 142
         } */ else {
143
-            // default OSM
144
-            $_firstimageID = $this->getStaticOSM($gmap, $overlay);
145
-            $imgUrl        .= $_firstimageID;
146
-            if($this->getConf('optionStaticMapGenerator') == 'remote') {
147
-                $imgUrl .= "&.png";
148
-            }
149
-        }
150
-
151
-        // append dw p_render specific params and render
152
-        $imgUrl .= "?" . str_replace("px", "", $gmap ['width']) . "x"
153
-            . str_replace("px", "", $gmap ['height']);
154
-        $imgUrl .= "&nolink";
155
-
156
-        // add nocache option for selected services
157
-        if($_nocache) {
158
-            $imgUrl .= "&nocache";
159
-        }
160
-
161
-        $imgUrl .= " |" . $gmap ['summary'] . " }}";
162
-
163
-        // dbglog($imgUrl,"complete image tags is:");
164
-
165
-        $mapid = $gmap ['id'];
166
-        // create a javascript parameter string for the map
167
-        $param = '';
168
-        foreach($gmap as $key => $val) {
169
-            $param .= is_numeric($val) ? "$key: $val, " : "$key: '" . hsc($val) . "', ";
170
-        }
171
-        if(!empty ($param)) {
172
-            $param = substr($param, 0, -2);
173
-        }
174
-        unset ($gmap ['id']);
175
-
176
-        // create a javascript serialisation of the point data
177
-        $poi      = '';
178
-        $poitable = '';
179
-        $rowId    = 0;
180
-        if(!empty ($overlay)) {
181
-            foreach($overlay as $data) {
182
-                list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
183
-                $rowId++;
184
-                $poi .= ", {lat:$lat,lon:$lon,txt:'$text',angle:$angle,opacity:$opacity,img:'$img',rowId: $rowId}";
185
-
186
-                if($this->getConf('displayformat') === 'DMS') {
187
-                    $lat = $this->convertLat($lat);
188
-                    $lon = $this->convertLon($lon);
189
-                } else {
190
-                    $lat .= 'º';
191
-                    $lon .= 'º';
192
-                }
193
-
194
-                $poitable .= '
143
+			// default OSM
144
+			$_firstimageID = $this->getStaticOSM($gmap, $overlay);
145
+			$imgUrl        .= $_firstimageID;
146
+			if($this->getConf('optionStaticMapGenerator') == 'remote') {
147
+				$imgUrl .= "&.png";
148
+			}
149
+		}
150
+
151
+		// append dw p_render specific params and render
152
+		$imgUrl .= "?" . str_replace("px", "", $gmap ['width']) . "x"
153
+			. str_replace("px", "", $gmap ['height']);
154
+		$imgUrl .= "&nolink";
155
+
156
+		// add nocache option for selected services
157
+		if($_nocache) {
158
+			$imgUrl .= "&nocache";
159
+		}
160
+
161
+		$imgUrl .= " |" . $gmap ['summary'] . " }}";
162
+
163
+		// dbglog($imgUrl,"complete image tags is:");
164
+
165
+		$mapid = $gmap ['id'];
166
+		// create a javascript parameter string for the map
167
+		$param = '';
168
+		foreach($gmap as $key => $val) {
169
+			$param .= is_numeric($val) ? "$key: $val, " : "$key: '" . hsc($val) . "', ";
170
+		}
171
+		if(!empty ($param)) {
172
+			$param = substr($param, 0, -2);
173
+		}
174
+		unset ($gmap ['id']);
175
+
176
+		// create a javascript serialisation of the point data
177
+		$poi      = '';
178
+		$poitable = '';
179
+		$rowId    = 0;
180
+		if(!empty ($overlay)) {
181
+			foreach($overlay as $data) {
182
+				list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
183
+				$rowId++;
184
+				$poi .= ", {lat:$lat,lon:$lon,txt:'$text',angle:$angle,opacity:$opacity,img:'$img',rowId: $rowId}";
185
+
186
+				if($this->getConf('displayformat') === 'DMS') {
187
+					$lat = $this->convertLat($lat);
188
+					$lon = $this->convertLon($lon);
189
+				} else {
190
+					$lat .= 'º';
191
+					$lon .= 'º';
192
+				}
193
+
194
+				$poitable .= '
195 195
                     <tr>
196 196
                     <td class="rowId">' . $rowId . '</td>
197 197
                     <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/icons/' . $img . '" alt="'
198
-                    . substr($img, 0, -4) . $this->getlang('alt_legend_poi') . '" /></td>
198
+					. substr($img, 0, -4) . $this->getlang('alt_legend_poi') . '" /></td>
199 199
                     <td class="lat" title="' . $this->getLang('olmapPOIlatTitle') . '">' . $lat . '</td>
200 200
                     <td class="lon" title="' . $this->getLang('olmapPOIlonTitle') . '">' . $lon . '</td>
201 201
                     <td class="txt">' . $text . '</td>
202 202
                     </tr>';
203
-            }
204
-            $poi = substr($poi, 2);
205
-        }
206
-        if(!empty ($gmap ['kmlfile'])) {
207
-            $poitable .= '
203
+			}
204
+			$poi = substr($poi, 2);
205
+		}
206
+		if(!empty ($gmap ['kmlfile'])) {
207
+			$poitable .= '
208 208
                     <tr>
209 209
                     <td class="rowId"><img src="' . DOKU_BASE
210
-                . 'lib/plugins/openlayersmap/toolbar/kml_file.png" alt="KML file" /></td>
210
+				. 'lib/plugins/openlayersmap/toolbar/kml_file.png" alt="KML file" /></td>
211 211
                     <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/kml_line.png" alt="'
212
-                . $this->getlang('alt_legend_kml') . '" /></td>
212
+				. $this->getlang('alt_legend_kml') . '" /></td>
213 213
                     <td class="txt" colspan="3">KML track: ' . $this->getFileName($gmap ['kmlfile']) . '</td>
214 214
                     </tr>';
215
-        }
216
-        if(!empty ($gmap ['gpxfile'])) {
217
-            $poitable .= '
215
+		}
216
+		if(!empty ($gmap ['gpxfile'])) {
217
+			$poitable .= '
218 218
                     <tr>
219 219
                     <td class="rowId"><img src="' . DOKU_BASE
220
-                . 'lib/plugins/openlayersmap/toolbar/gpx_file.png" alt="GPX file" /></td>
220
+				. 'lib/plugins/openlayersmap/toolbar/gpx_file.png" alt="GPX file" /></td>
221 221
                     <td class="icon"><img src="' . DOKU_BASE
222
-                . 'lib/plugins/openlayersmap/toolbar/gpx_line.png" alt="'
223
-                . $this->getlang('alt_legend_gpx') . '" /></td>
222
+				. 'lib/plugins/openlayersmap/toolbar/gpx_line.png" alt="'
223
+				. $this->getlang('alt_legend_gpx') . '" /></td>
224 224
                     <td class="txt" colspan="3">GPX track: ' . $this->getFileName($gmap ['gpxfile']) . '</td>
225 225
                     </tr>';
226
-        }
227
-        if(!empty ($gmap ['geojsonfile'])) {
228
-            $poitable .= '
226
+		}
227
+		if(!empty ($gmap ['geojsonfile'])) {
228
+			$poitable .= '
229 229
                     <tr>
230 230
                     <td class="rowId"><img src="' . DOKU_BASE
231
-                . 'lib/plugins/openlayersmap/toolbar/geojson_file.png" alt="GeoJSON file" /></td>
231
+				. 'lib/plugins/openlayersmap/toolbar/geojson_file.png" alt="GeoJSON file" /></td>
232 232
                     <td class="icon"><img src="' . DOKU_BASE
233
-                . 'lib/plugins/openlayersmap/toolbar/geojson_line.png" alt="'
234
-                . $this->getlang('alt_legend_geojson') . '" /></td>
233
+				. 'lib/plugins/openlayersmap/toolbar/geojson_line.png" alt="'
234
+				. $this->getlang('alt_legend_geojson') . '" /></td>
235 235
                     <td class="txt" colspan="3">GeoJSON track: ' . $this->getFileName($gmap ['geojsonfile']) . '</td>
236 236
                     </tr>';
237
-        }
238
-
239
-        $autozoom = empty ($gmap ['autozoom']) ? $this->getConf('autoZoomMap') : $gmap ['autozoom'];
240
-        $js       = "{mapOpts: {" . $param . ", displayformat: '" . $this->getConf('displayformat')
241
-            . "', autozoom: " . $autozoom . "}, poi: [$poi]};";
242
-        // unescape the json
243
-        $poitable = stripslashes($poitable);
244
-
245
-        return array(
246
-            $mapid,
247
-            $js,
248
-            $mainLat,
249
-            $mainLon,
250
-            $poitable,
251
-            $gmap ['summary'],
252
-            $imgUrl,
253
-            $_firstimageID
254
-        );
255
-    }
256
-
257
-    /**
258
-     * extract parameters for the map from the parameter string
259
-     *
260
-     * @param string $str_params
261
-     *            string of key="value" pairs
262
-     * @return array associative array of parameters key=>value
263
-     */
264
-    private function extractParams(string $str_params): array {
265
-        $param = array();
266
-        preg_match_all('/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER);
267
-        // parse match for instructions, break into key value pairs
268
-        $gmap = $this->dflt;
269
-        foreach($gmap as $key => &$value) {
270
-            $defval = $this->getConf('default_' . $key);
271
-            if($defval !== '') {
272
-                $value = $defval;
273
-            }
274
-        }
275
-        unset ($value);
276
-        foreach($param as $kvpair) {
277
-            list ($match, $key, $val) = $kvpair;
278
-            $key = strtolower($key);
279
-            if(isset ($gmap [$key])) {
280
-                if($key == 'summary') {
281
-                    // preserve case for summary field
282
-                    $gmap [$key] = $val;
283
-                } elseif($key == 'id') {
284
-                    // preserve case for id field
285
-                    $gmap [$key] = $val;
286
-                } else {
287
-                    $gmap [$key] = strtolower($val);
288
-                }
289
-            }
290
-        }
291
-        return $gmap;
292
-    }
293
-
294
-    /**
295
-     * extract overlay points for the map from the wiki syntax data
296
-     *
297
-     * @param string $str_points
298
-     *            multi-line string of lat,lon,text triplets
299
-     * @return array multi-dimensional array of lat,lon,text triplets
300
-     */
301
-    private function extractPoints(string $str_points): array {
302
-        $point = array();
303
-        // preg_match_all('/^([+-]?[0-9].*?),\s*([+-]?[0-9].*?),(.*?),(.*?),(.*?),(.*)$/um',
304
-        //      $str_points, $point, PREG_SET_ORDER);
305
-        /*
237
+		}
238
+
239
+		$autozoom = empty ($gmap ['autozoom']) ? $this->getConf('autoZoomMap') : $gmap ['autozoom'];
240
+		$js       = "{mapOpts: {" . $param . ", displayformat: '" . $this->getConf('displayformat')
241
+			. "', autozoom: " . $autozoom . "}, poi: [$poi]};";
242
+		// unescape the json
243
+		$poitable = stripslashes($poitable);
244
+
245
+		return array(
246
+			$mapid,
247
+			$js,
248
+			$mainLat,
249
+			$mainLon,
250
+			$poitable,
251
+			$gmap ['summary'],
252
+			$imgUrl,
253
+			$_firstimageID
254
+		);
255
+	}
256
+
257
+	/**
258
+	 * extract parameters for the map from the parameter string
259
+	 *
260
+	 * @param string $str_params
261
+	 *            string of key="value" pairs
262
+	 * @return array associative array of parameters key=>value
263
+	 */
264
+	private function extractParams(string $str_params): array {
265
+		$param = array();
266
+		preg_match_all('/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER);
267
+		// parse match for instructions, break into key value pairs
268
+		$gmap = $this->dflt;
269
+		foreach($gmap as $key => &$value) {
270
+			$defval = $this->getConf('default_' . $key);
271
+			if($defval !== '') {
272
+				$value = $defval;
273
+			}
274
+		}
275
+		unset ($value);
276
+		foreach($param as $kvpair) {
277
+			list ($match, $key, $val) = $kvpair;
278
+			$key = strtolower($key);
279
+			if(isset ($gmap [$key])) {
280
+				if($key == 'summary') {
281
+					// preserve case for summary field
282
+					$gmap [$key] = $val;
283
+				} elseif($key == 'id') {
284
+					// preserve case for id field
285
+					$gmap [$key] = $val;
286
+				} else {
287
+					$gmap [$key] = strtolower($val);
288
+				}
289
+			}
290
+		}
291
+		return $gmap;
292
+	}
293
+
294
+	/**
295
+	 * extract overlay points for the map from the wiki syntax data
296
+	 *
297
+	 * @param string $str_points
298
+	 *            multi-line string of lat,lon,text triplets
299
+	 * @return array multi-dimensional array of lat,lon,text triplets
300
+	 */
301
+	private function extractPoints(string $str_points): array {
302
+		$point = array();
303
+		// preg_match_all('/^([+-]?[0-9].*?),\s*([+-]?[0-9].*?),(.*?),(.*?),(.*?),(.*)$/um',
304
+		//      $str_points, $point, PREG_SET_ORDER);
305
+		/*
306 306
          * group 1: ([+-]?[0-9]+(?:\.[0-9]*)?)
307 307
          * group 2: ([+-]?[0-9]+(?:\.[0-9]*)?)
308 308
          * group 3: (.*?)
@@ -310,104 +310,104 @@  discard block
 block discarded – undo
310 310
          * group 5: (.*?)
311 311
          * group 6: (.*)
312 312
          */
313
-        preg_match_all(
314
-            '/^([+-]?[0-9]+(?:\.[0-9]*)?),\s*([+-]?[0-9]+(?:\.[0-9]*)?),(.*?),(.*?),(.*?),(.*)$/um',
315
-            $str_points, $point, PREG_SET_ORDER
316
-        );
317
-        // create poi array
318
-        $overlay = array();
319
-        foreach($point as $pt) {
320
-            list ($match, $lat, $lon, $angle, $opacity, $img, $text) = $pt;
321
-            $lat     = is_numeric($lat) ? $lat : 0;
322
-            $lon     = is_numeric($lon) ? $lon : 0;
323
-            $angle   = is_numeric($angle) ? $angle : 0;
324
-            $opacity = is_numeric($opacity) ? $opacity : 0.8;
325
-            // TODO validate using exist & set up default img?
326
-            $img  = trim($img);
327
-            $text = p_get_instructions($text);
328
-            // dbg ( $text );
329
-            $text = p_render("xhtml", $text, $info);
330
-            // dbg ( $text );
331
-            $text       = addslashes(str_replace("\n", "", $text));
332
-            $overlay [] = array(
333
-                $lat,
334
-                $lon,
335
-                $text,
336
-                $angle,
337
-                $opacity,
338
-                $img
339
-            );
340
-        }
341
-        return $overlay;
342
-    }
343
-
344
-    /**
345
-     * Create a Google maps static image url w/ the poi.
346
-     *
347
-     * @param array $gmap
348
-     * @param array $overlay
349
-     * @return string
350
-     */
351
-    private function getGoogle(array $gmap, array $overlay): string {
352
-        $sUrl = $this->getConf('iconUrlOverload');
353
-        if(!$sUrl) {
354
-            $sUrl = DOKU_URL;
355
-        }
356
-        switch($gmap ['baselyr']) {
357
-            case 'google hybrid' :
358
-                $maptype = 'hybrid';
359
-                break;
360
-            case 'google sat' :
361
-                $maptype = 'satellite';
362
-                break;
363
-            case 'terrain' :
364
-            case 'google relief' :
365
-                $maptype = 'terrain';
366
-                break;
367
-            case 'google road' :
368
-            default :
369
-                $maptype = 'roadmap';
370
-                break;
371
-        }
372
-        // TODO maybe use viewport / visible instead of center/zoom,
373
-        // see: https://developers.google.com/maps/documentation/staticmaps/index#Viewports
374
-        // http://maps.google.com/maps/api/staticmap?center=51.565690,5.456756&zoom=16&size=600x400&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker.png|label:1|51.565690,5.456756&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker-blue.png|51.566197,5.458966|label:2&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.567177,5.457909|label:3&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.566283,5.457330|label:4&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.565630,5.457695|label:5&sensor=false&format=png&maptype=roadmap
375
-        $imgUrl = "https://maps.googleapis.com/maps/api/staticmap?";
376
-        $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x"
377
-            . str_replace("px", "", $gmap ['height']);
378
-        //if (!$this->getConf( 'autoZoomMap')) { // no need for center & zoom params }
379
-        $imgUrl .= "&center=" . $gmap ['lat'] . "," . $gmap ['lon'];
380
-        // max is 21 (== building scale), but that's overkill..
381
-        if($gmap ['zoom'] > 17) {
382
-            $imgUrl .= "&zoom=17";
383
-        } else {
384
-            $imgUrl .= "&zoom=" . $gmap ['zoom'];
385
-        }
386
-        if(!empty ($overlay)) {
387
-            $rowId = 0;
388
-            foreach($overlay as $data) {
389
-                list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
390
-                $imgUrl .= "&markers=icon%3a" . $sUrl . "lib/plugins/openlayersmap/icons/" . $img . "%7c"
391
-                    . $lat . "," . $lon . "%7clabel%3a" . ++$rowId;
392
-            }
393
-        }
394
-        $imgUrl .= "&format=png&maptype=" . $maptype;
395
-        global $conf;
396
-        $imgUrl .= "&language=" . $conf ['lang'];
397
-        if($this->getConf('googleAPIkey')) {
398
-            $imgUrl .= "&key=" . $this->getConf('googleAPIkey');
399
-        }
400
-        // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::getGoogle: Google image url is:');
401
-        return $imgUrl;
402
-    }
403
-
404
-    /**
405
-     * Create a MapQuest static map API image url.
406
-     *
407
-     * @param array $gmap
408
-     * @param array $overlay
409
-     */
410
-    /*
313
+		preg_match_all(
314
+			'/^([+-]?[0-9]+(?:\.[0-9]*)?),\s*([+-]?[0-9]+(?:\.[0-9]*)?),(.*?),(.*?),(.*?),(.*)$/um',
315
+			$str_points, $point, PREG_SET_ORDER
316
+		);
317
+		// create poi array
318
+		$overlay = array();
319
+		foreach($point as $pt) {
320
+			list ($match, $lat, $lon, $angle, $opacity, $img, $text) = $pt;
321
+			$lat     = is_numeric($lat) ? $lat : 0;
322
+			$lon     = is_numeric($lon) ? $lon : 0;
323
+			$angle   = is_numeric($angle) ? $angle : 0;
324
+			$opacity = is_numeric($opacity) ? $opacity : 0.8;
325
+			// TODO validate using exist & set up default img?
326
+			$img  = trim($img);
327
+			$text = p_get_instructions($text);
328
+			// dbg ( $text );
329
+			$text = p_render("xhtml", $text, $info);
330
+			// dbg ( $text );
331
+			$text       = addslashes(str_replace("\n", "", $text));
332
+			$overlay [] = array(
333
+				$lat,
334
+				$lon,
335
+				$text,
336
+				$angle,
337
+				$opacity,
338
+				$img
339
+			);
340
+		}
341
+		return $overlay;
342
+	}
343
+
344
+	/**
345
+	 * Create a Google maps static image url w/ the poi.
346
+	 *
347
+	 * @param array $gmap
348
+	 * @param array $overlay
349
+	 * @return string
350
+	 */
351
+	private function getGoogle(array $gmap, array $overlay): string {
352
+		$sUrl = $this->getConf('iconUrlOverload');
353
+		if(!$sUrl) {
354
+			$sUrl = DOKU_URL;
355
+		}
356
+		switch($gmap ['baselyr']) {
357
+			case 'google hybrid' :
358
+				$maptype = 'hybrid';
359
+				break;
360
+			case 'google sat' :
361
+				$maptype = 'satellite';
362
+				break;
363
+			case 'terrain' :
364
+			case 'google relief' :
365
+				$maptype = 'terrain';
366
+				break;
367
+			case 'google road' :
368
+			default :
369
+				$maptype = 'roadmap';
370
+				break;
371
+		}
372
+		// TODO maybe use viewport / visible instead of center/zoom,
373
+		// see: https://developers.google.com/maps/documentation/staticmaps/index#Viewports
374
+		// http://maps.google.com/maps/api/staticmap?center=51.565690,5.456756&zoom=16&size=600x400&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker.png|label:1|51.565690,5.456756&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker-blue.png|51.566197,5.458966|label:2&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.567177,5.457909|label:3&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.566283,5.457330|label:4&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.565630,5.457695|label:5&sensor=false&format=png&maptype=roadmap
375
+		$imgUrl = "https://maps.googleapis.com/maps/api/staticmap?";
376
+		$imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x"
377
+			. str_replace("px", "", $gmap ['height']);
378
+		//if (!$this->getConf( 'autoZoomMap')) { // no need for center & zoom params }
379
+		$imgUrl .= "&center=" . $gmap ['lat'] . "," . $gmap ['lon'];
380
+		// max is 21 (== building scale), but that's overkill..
381
+		if($gmap ['zoom'] > 17) {
382
+			$imgUrl .= "&zoom=17";
383
+		} else {
384
+			$imgUrl .= "&zoom=" . $gmap ['zoom'];
385
+		}
386
+		if(!empty ($overlay)) {
387
+			$rowId = 0;
388
+			foreach($overlay as $data) {
389
+				list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
390
+				$imgUrl .= "&markers=icon%3a" . $sUrl . "lib/plugins/openlayersmap/icons/" . $img . "%7c"
391
+					. $lat . "," . $lon . "%7clabel%3a" . ++$rowId;
392
+			}
393
+		}
394
+		$imgUrl .= "&format=png&maptype=" . $maptype;
395
+		global $conf;
396
+		$imgUrl .= "&language=" . $conf ['lang'];
397
+		if($this->getConf('googleAPIkey')) {
398
+			$imgUrl .= "&key=" . $this->getConf('googleAPIkey');
399
+		}
400
+		// dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::getGoogle: Google image url is:');
401
+		return $imgUrl;
402
+	}
403
+
404
+	/**
405
+	 * Create a MapQuest static map API image url.
406
+	 *
407
+	 * @param array $gmap
408
+	 * @param array $overlay
409
+	 */
410
+	/*
411 411
    private function _getMapQuest($gmap, $overlay) {
412 412
        $sUrl = $this->getConf ( 'iconUrlOverload' );
413 413
        if (! $sUrl) {
@@ -465,344 +465,344 @@  discard block
 block discarded – undo
465 465
    }
466 466
    */
467 467
 
468
-    /**
469
-     * Create a static OSM map image url w/ the poi from http://staticmap.openstreetmap.de (staticMapLite)
470
-     * use http://staticmap.openstreetmap.de "staticMapLite" or a local version
471
-     *
472
-     * @param array $gmap
473
-     * @param array $overlay
474
-     *
475
-     * @return false|string
476
-     * @todo implementation for http://ojw.dev.openstreetmap.org/StaticMapDev/
477
-     */
478
-    private function getStaticOSM(array $gmap, array $overlay) {
479
-        global $conf;
480
-
481
-        if($this->getConf('optionStaticMapGenerator') == 'local') {
482
-            // using local basemap composer
483
-            if(!$myMap = plugin_load('helper', 'openlayersmap_staticmap')) {
484
-                dbglog(
485
-                    $myMap,
486
-                    'openlayersmap_staticmap plugin is not available for use.'
487
-                );
488
-            }
489
-            if(!$geophp = plugin_load('helper', 'geophp')) {
490
-                dbglog($geophp, 'geophp plugin is not available for use.');
491
-            }
492
-            $size = str_replace("px", "", $gmap ['width']) . "x"
493
-                . str_replace("px", "", $gmap ['height']);
494
-
495
-            $markers = array();
496
-            if(!empty ($overlay)) {
497
-                foreach($overlay as $data) {
498
-                    list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
499
-                    $iconStyle  = substr($img, 0, strlen($img) - 4);
500
-                    $markers [] = array(
501
-                        'lat'  => $lat,
502
-                        'lon'  => $lon,
503
-                        'type' => $iconStyle
504
-                    );
505
-                }
506
-            }
507
-
508
-            $apikey = '';
509
-            switch($gmap ['baselyr']) {
510
-                case 'mapnik' :
511
-                case 'openstreetmap' :
512
-                    $maptype = 'openstreetmap';
513
-                    break;
514
-                case 'transport' :
515
-                    $maptype = 'transport';
516
-                    $apikey  = '?apikey=' . $this->getConf('tfApiKey');
517
-                    break;
518
-                case 'landscape' :
519
-                    $maptype = 'landscape';
520
-                    $apikey  = '?apikey=' . $this->getConf('tfApiKey');
521
-                    break;
522
-                case 'outdoors' :
523
-                    $maptype = 'outdoors';
524
-                    $apikey  = '?apikey=' . $this->getConf('tfApiKey');
525
-                    break;
526
-                case 'cycle map' :
527
-                    $maptype = 'cycle';
528
-                    $apikey  = '?apikey=' . $this->getConf('tfApiKey');
529
-                    break;
530
-                case 'hike and bike map' :
531
-                    $maptype = 'hikeandbike';
532
-                    break;
533
-                case 'mapquest hybrid' :
534
-                case 'mapquest road' :
535
-                case 'mapquest sat' :
536
-                    $maptype = 'mapquest';
537
-                    break;
538
-                default :
539
-                    $maptype = '';
540
-                    break;
541
-            }
542
-
543
-            $result = $myMap->getMap(
544
-                $gmap ['lat'], $gmap ['lon'], $gmap ['zoom'], $size, $maptype, $markers,
545
-                $gmap ['gpxfile'], $gmap ['kmlfile'], $gmap ['geojsonfile'], $apikey
546
-            );
547
-        } else {
548
-            // using external basemap composer
549
-
550
-            // https://staticmap.openstreetmap.de/staticmap.php?center=47.000622235634,10
551
-            //.117187497601&zoom=5&size=500x350
552
-            // &markers=48.999812532766,8.3593749976708,lightblue1|43.154850037315,17.499999997306,
553
-            //  lightblue1|49.487527053077,10.820312497573,ltblu-pushpin|47.951071133739,15.917968747369,
554
-            //  ol-marker|47.921629720114,18.027343747285,ol-marker-gold|47.951071133739,19.257812497236,
555
-            //  ol-marker-blue|47.180141361692,19.257812497236,ol-marker-green
556
-            $imgUrl = "https://staticmap.openstreetmap.de/staticmap.php";
557
-            $imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon'];
558
-            $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x"
559
-                . str_replace("px", "", $gmap ['height']);
560
-
561
-            if($gmap ['zoom'] > 16) {
562
-                // actually this could even be 18, but that seems overkill
563
-                $imgUrl .= "&zoom=16";
564
-            } else {
565
-                $imgUrl .= "&zoom=" . $gmap ['zoom'];
566
-            }
567
-
568
-            if(!empty ($overlay)) {
569
-                $rowId  = 0;
570
-                $imgUrl .= "&markers=";
571
-                foreach($overlay as $data) {
572
-                    list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
573
-                    $rowId++;
574
-                    $iconStyle = "lightblue$rowId";
575
-                    $imgUrl    .= "$lat,$lon,$iconStyle%7c";
576
-                }
577
-                $imgUrl = substr($imgUrl, 0, -3);
578
-            }
579
-
580
-            $result = $imgUrl;
581
-        }
582
-        // dbglog ( $result, 'syntax_plugin_openlayersmap_olmap::getStaticOSM: osm image url is:' );
583
-        return $result;
584
-    }
585
-
586
-    /**
587
-     * Create a Bing maps static image url w/ the poi.
588
-     *
589
-     * @param array $gmap
590
-     * @param array $overlay
591
-     * @return string
592
-     */
593
-    private function getBing(array $gmap, array $overlay): string {
594
-        switch($gmap ['baselyr']) {
595
-            case 've hybrid' :
596
-            case 'bing hybrid' :
597
-                $maptype = 'AerialWithLabels';
598
-                break;
599
-            case 've sat' :
600
-            case 'bing sat' :
601
-                $maptype = 'Aerial';
602
-                break;
603
-            case 've normal' :
604
-            case 've road' :
605
-            case 've' :
606
-            case 'bing road' :
607
-            default :
608
-                $maptype = 'Road';
609
-                break;
610
-        }
611
-        $imgUrl = "https://dev.virtualearth.net/REST/v1/Imagery/Map/" . $maptype;// . "/";
612
-        if($this->getConf('autoZoomMap')) {
613
-            $bbox = $this->calcBBOX($overlay, $gmap ['lat'], $gmap ['lon']);
614
-            //$imgUrl .= "?ma=" . $bbox ['minlat'] . "," . $bbox ['minlon'] . ","
615
-            //          . $bbox ['maxlat'] . "," . $bbox ['maxlon'];
616
-            $imgUrl .= "?ma=" . $bbox ['minlat'] . "%2C" . $bbox ['minlon'] . "%2C" . $bbox ['maxlat']
617
-                . "%2C" . $bbox ['maxlon'];
618
-            $imgUrl .= "&dcl=1";
619
-        }
620
-        if(strpos($imgUrl, "?") === false)
621
-            $imgUrl .= "?";
622
-
623
-        //$imgUrl .= "&ms=" . str_replace ( "px", "", $gmap ['width'] ) . ","
624
-        //          . str_replace ( "px", "", $gmap ['height'] );
625
-        $imgUrl .= "&ms=" . str_replace("px", "", $gmap ['width']) . "%2C"
626
-            . str_replace("px", "", $gmap ['height']);
627
-        $imgUrl .= "&key=" . $this->getConf('bingAPIKey');
628
-        if(!empty ($overlay)) {
629
-            $rowId = 0;
630
-            foreach($overlay as $data) {
631
-                list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
632
-                // TODO icon style lookup, see: http://msdn.microsoft.com/en-us/library/ff701719.aspx for iconStyle
633
-                $iconStyle = 32;
634
-                $rowId++;
635
-                // NOTE: the max number of pushpins is 18! or we have to use POST
636
-                //  (http://msdn.microsoft.com/en-us/library/ff701724.aspx)
637
-                if($rowId == 18) {
638
-                    break;
639
-                }
640
-                //$imgUrl .= "&pp=$lat,$lon;$iconStyle;$rowId";
641
-                $imgUrl .= "&pp=$lat%2C$lon%3B$iconStyle%3B$rowId";
642
-
643
-            }
644
-        }
645
-        global $conf;
646
-        $imgUrl .= "&fmt=png";
647
-        $imgUrl .= "&c=" . $conf ['lang'];
648
-        // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::getBing: bing image url is:');
649
-        return $imgUrl;
650
-    }
651
-
652
-    /**
653
-     * Calculate the minimum bbox for a start location + poi.
654
-     *
655
-     * @param array $overlay
656
-     *            multi-dimensional array of array($lat, $lon, $text, $angle, $opacity, $img)
657
-     * @param float $lat
658
-     *            latitude for map center
659
-     * @param float $lon
660
-     *            longitude for map center
661
-     * @return array :float array describing the mbr and center point
662
-     */
663
-    private function calcBBOX(array $overlay, float $lat, float $lon): array {
664
-        $lats = array($lat);
665
-        $lons = array($lon);
666
-        foreach($overlay as $data) {
667
-            list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
668
-            $lats [] = $lat;
669
-            $lons [] = $lon;
670
-        }
671
-        sort($lats);
672
-        sort($lons);
673
-        // TODO: make edge/wrap around cases work
674
-        $centerlat = $lats [0] + ($lats [count($lats) - 1] - $lats [0]);
675
-        $centerlon = $lons [0] + ($lons [count($lats) - 1] - $lons [0]);
676
-        return array(
677
-            'minlat'    => $lats [0],
678
-            'minlon'    => $lons [0],
679
-            'maxlat'    => $lats [count($lats) - 1],
680
-            'maxlon'    => $lons [count($lats) - 1],
681
-            'centerlat' => $centerlat,
682
-            'centerlon' => $centerlon
683
-        );
684
-    }
685
-
686
-    /**
687
-     * convert latitude in decimal degrees to DMS+hemisphere.
688
-     *
689
-     * @param float $decimaldegrees
690
-     * @return string
691
-     * @todo move this into a shared library
692
-     */
693
-    private function convertLat(float $decimaldegrees): string {
694
-        if(strpos($decimaldegrees, '-') !== false) {
695
-            $latPos = "S";
696
-        } else {
697
-            $latPos = "N";
698
-        }
699
-        $dms = $this->convertDDtoDMS(abs($decimaldegrees));
700
-        return hsc($dms . $latPos);
701
-    }
702
-
703
-    /**
704
-     * Convert decimal degrees to degrees, minutes, seconds format
705
-     *
706
-     * @param float $decimaldegrees
707
-     * @return string dms
708
-     * @todo move this into a shared library
709
-     */
710
-    private function convertDDtoDMS(float $decimaldegrees): string {
711
-        $dms  = floor($decimaldegrees);
712
-        $secs = ($decimaldegrees - $dms) * 3600;
713
-        $min  = floor($secs / 60);
714
-        $sec  = round($secs - ($min * 60), 3);
715
-        $dms  .= 'º' . $min . '\'' . $sec . '"';
716
-        return $dms;
717
-    }
718
-
719
-    /**
720
-     * convert longitude in decimal degrees to DMS+hemisphere.
721
-     *
722
-     * @param float $decimaldegrees
723
-     * @return string
724
-     * @todo move this into a shared library
725
-     */
726
-    private function convertLon(float $decimaldegrees): string {
727
-        if(strpos($decimaldegrees, '-') !== false) {
728
-            $lonPos = "W";
729
-        } else {
730
-            $lonPos = "E";
731
-        }
732
-        $dms = $this->convertDDtoDMS(abs($decimaldegrees));
733
-        return hsc($dms . $lonPos);
734
-    }
735
-
736
-    /**
737
-     * Figures out the base filename of a media path.
738
-     *
739
-     * @param string $mediaLink
740
-     * @return string
741
-     */
742
-    private function getFileName(string $mediaLink): string {
743
-        $mediaLink = str_replace('[[', '', $mediaLink);
744
-        $mediaLink = str_replace(']]', '', $mediaLink);
745
-        $mediaLink = substr($mediaLink, 0, -4);
746
-        $parts     = explode(':', $mediaLink);
747
-        $mediaLink = end($parts);
748
-        return str_replace('_', ' ', $mediaLink);
749
-    }
750
-
751
-    /**
752
-     *
753
-     * @see DokuWiki_Syntax_Plugin::render()
754
-     */
755
-    public function render($format, Doku_Renderer $renderer, $data): bool {
756
-        // set to true after external scripts tags are written
757
-        static $initialised = false;
758
-        // incremented for each map tag in the page source so we can keep track of each map in this page
759
-        static $mapnumber = 0;
760
-
761
-        // dbglog($data, 'olmap::render() data.');
762
-        list ($mapid, $param, $mainLat, $mainLon, $poitable, $poitabledesc, $staticImgUrl, $_firstimage) = $data;
763
-
764
-        if($format == 'xhtml') {
765
-            $olscript     = '';
766
-            $olEnable     = false;
767
-            $gscript      = '';
768
-            $gEnable      = $this->getConf('enableGoogle');
769
-            $stamenEnable = $this->getConf('enableStamen');
770
-            $osmEnable    = $this->getConf('enableOSM');
771
-            $enableBing   = $this->getConf('enableBing');
772
-
773
-            $scriptEnable = '';
774
-            if(!$initialised) {
775
-                $initialised = true;
776
-                // render necessary script tags
777
-                if($gEnable) {
778
-                    $gscript = '<script defer="defer" src="//maps.google.com/maps/api/js?v=3.29&amp;key='
779
-                        . $this->getConf('googleAPIkey') . '"></script>';
780
-                }
781
-                $olscript = '<script defer="defer" src="' . DOKU_BASE
782
-                    . 'lib/plugins/openlayersmap/lib/OpenLayers.js"></script>';
783
-
784
-                $scriptEnable = '<script defer="defer" src="data:text/javascript;base64,';
785
-                $scriptSrc    = $olscript ? 'olEnable = true;' : 'olEnable = false;';
786
-                $scriptSrc    .= 'gEnable = ' . ($gEnable ? 'true' : 'false') . ';';
787
-                $scriptSrc    .= 'osmEnable = ' . ($osmEnable ? 'true' : 'false') . ';';
788
-                $scriptSrc    .= 'stamenEnable = ' . ($stamenEnable ? 'true' : 'false') . ';';
789
-                $scriptSrc    .= 'bEnable = ' . ($enableBing ? 'true' : 'false') . ';';
790
-                $scriptSrc    .= 'bApiKey="' . $this->getConf('bingAPIKey') . '";';
791
-                $scriptSrc    .= 'tfApiKey="' . $this->getConf('tfApiKey') . '";';
792
-                $scriptSrc    .= 'gApiKey="' . $this->getConf('googleAPIkey') . '";';
793
-                $scriptEnable .= base64_encode($scriptSrc);
794
-                $scriptEnable .= '"></script>';
795
-            }
796
-            $renderer->doc .= "$gscript\n$olscript\n$scriptEnable";
797
-            $renderer->doc .= '<div class="olMapHelp">' . $this->locale_xhtml("help") . '</div>';
798
-            if($this->getConf('enableA11y')) {
799
-                $renderer->doc .= '<div id="' . $mapid . '-static" class="olStaticMap">'
800
-                    . p_render($format, p_get_instructions($staticImgUrl), $info) . '</div>';
801
-            }
802
-            $renderer->doc .= '<div id="' . $mapid . '-clearer" class="clearer"><p>&nbsp;</p></div>';
803
-            if($this->getConf('enableA11y')) {
804
-                // render a table of the POI for the print and a11y presentation, it is hidden using javascript
805
-                $renderer->doc .= '<div class="olPOItableSpan" id="' . $mapid . '-table-span">
468
+	/**
469
+	 * Create a static OSM map image url w/ the poi from http://staticmap.openstreetmap.de (staticMapLite)
470
+	 * use http://staticmap.openstreetmap.de "staticMapLite" or a local version
471
+	 *
472
+	 * @param array $gmap
473
+	 * @param array $overlay
474
+	 *
475
+	 * @return false|string
476
+	 * @todo implementation for http://ojw.dev.openstreetmap.org/StaticMapDev/
477
+	 */
478
+	private function getStaticOSM(array $gmap, array $overlay) {
479
+		global $conf;
480
+
481
+		if($this->getConf('optionStaticMapGenerator') == 'local') {
482
+			// using local basemap composer
483
+			if(!$myMap = plugin_load('helper', 'openlayersmap_staticmap')) {
484
+				dbglog(
485
+					$myMap,
486
+					'openlayersmap_staticmap plugin is not available for use.'
487
+				);
488
+			}
489
+			if(!$geophp = plugin_load('helper', 'geophp')) {
490
+				dbglog($geophp, 'geophp plugin is not available for use.');
491
+			}
492
+			$size = str_replace("px", "", $gmap ['width']) . "x"
493
+				. str_replace("px", "", $gmap ['height']);
494
+
495
+			$markers = array();
496
+			if(!empty ($overlay)) {
497
+				foreach($overlay as $data) {
498
+					list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
499
+					$iconStyle  = substr($img, 0, strlen($img) - 4);
500
+					$markers [] = array(
501
+						'lat'  => $lat,
502
+						'lon'  => $lon,
503
+						'type' => $iconStyle
504
+					);
505
+				}
506
+			}
507
+
508
+			$apikey = '';
509
+			switch($gmap ['baselyr']) {
510
+				case 'mapnik' :
511
+				case 'openstreetmap' :
512
+					$maptype = 'openstreetmap';
513
+					break;
514
+				case 'transport' :
515
+					$maptype = 'transport';
516
+					$apikey  = '?apikey=' . $this->getConf('tfApiKey');
517
+					break;
518
+				case 'landscape' :
519
+					$maptype = 'landscape';
520
+					$apikey  = '?apikey=' . $this->getConf('tfApiKey');
521
+					break;
522
+				case 'outdoors' :
523
+					$maptype = 'outdoors';
524
+					$apikey  = '?apikey=' . $this->getConf('tfApiKey');
525
+					break;
526
+				case 'cycle map' :
527
+					$maptype = 'cycle';
528
+					$apikey  = '?apikey=' . $this->getConf('tfApiKey');
529
+					break;
530
+				case 'hike and bike map' :
531
+					$maptype = 'hikeandbike';
532
+					break;
533
+				case 'mapquest hybrid' :
534
+				case 'mapquest road' :
535
+				case 'mapquest sat' :
536
+					$maptype = 'mapquest';
537
+					break;
538
+				default :
539
+					$maptype = '';
540
+					break;
541
+			}
542
+
543
+			$result = $myMap->getMap(
544
+				$gmap ['lat'], $gmap ['lon'], $gmap ['zoom'], $size, $maptype, $markers,
545
+				$gmap ['gpxfile'], $gmap ['kmlfile'], $gmap ['geojsonfile'], $apikey
546
+			);
547
+		} else {
548
+			// using external basemap composer
549
+
550
+			// https://staticmap.openstreetmap.de/staticmap.php?center=47.000622235634,10
551
+			//.117187497601&zoom=5&size=500x350
552
+			// &markers=48.999812532766,8.3593749976708,lightblue1|43.154850037315,17.499999997306,
553
+			//  lightblue1|49.487527053077,10.820312497573,ltblu-pushpin|47.951071133739,15.917968747369,
554
+			//  ol-marker|47.921629720114,18.027343747285,ol-marker-gold|47.951071133739,19.257812497236,
555
+			//  ol-marker-blue|47.180141361692,19.257812497236,ol-marker-green
556
+			$imgUrl = "https://staticmap.openstreetmap.de/staticmap.php";
557
+			$imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon'];
558
+			$imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x"
559
+				. str_replace("px", "", $gmap ['height']);
560
+
561
+			if($gmap ['zoom'] > 16) {
562
+				// actually this could even be 18, but that seems overkill
563
+				$imgUrl .= "&zoom=16";
564
+			} else {
565
+				$imgUrl .= "&zoom=" . $gmap ['zoom'];
566
+			}
567
+
568
+			if(!empty ($overlay)) {
569
+				$rowId  = 0;
570
+				$imgUrl .= "&markers=";
571
+				foreach($overlay as $data) {
572
+					list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
573
+					$rowId++;
574
+					$iconStyle = "lightblue$rowId";
575
+					$imgUrl    .= "$lat,$lon,$iconStyle%7c";
576
+				}
577
+				$imgUrl = substr($imgUrl, 0, -3);
578
+			}
579
+
580
+			$result = $imgUrl;
581
+		}
582
+		// dbglog ( $result, 'syntax_plugin_openlayersmap_olmap::getStaticOSM: osm image url is:' );
583
+		return $result;
584
+	}
585
+
586
+	/**
587
+	 * Create a Bing maps static image url w/ the poi.
588
+	 *
589
+	 * @param array $gmap
590
+	 * @param array $overlay
591
+	 * @return string
592
+	 */
593
+	private function getBing(array $gmap, array $overlay): string {
594
+		switch($gmap ['baselyr']) {
595
+			case 've hybrid' :
596
+			case 'bing hybrid' :
597
+				$maptype = 'AerialWithLabels';
598
+				break;
599
+			case 've sat' :
600
+			case 'bing sat' :
601
+				$maptype = 'Aerial';
602
+				break;
603
+			case 've normal' :
604
+			case 've road' :
605
+			case 've' :
606
+			case 'bing road' :
607
+			default :
608
+				$maptype = 'Road';
609
+				break;
610
+		}
611
+		$imgUrl = "https://dev.virtualearth.net/REST/v1/Imagery/Map/" . $maptype;// . "/";
612
+		if($this->getConf('autoZoomMap')) {
613
+			$bbox = $this->calcBBOX($overlay, $gmap ['lat'], $gmap ['lon']);
614
+			//$imgUrl .= "?ma=" . $bbox ['minlat'] . "," . $bbox ['minlon'] . ","
615
+			//          . $bbox ['maxlat'] . "," . $bbox ['maxlon'];
616
+			$imgUrl .= "?ma=" . $bbox ['minlat'] . "%2C" . $bbox ['minlon'] . "%2C" . $bbox ['maxlat']
617
+				. "%2C" . $bbox ['maxlon'];
618
+			$imgUrl .= "&dcl=1";
619
+		}
620
+		if(strpos($imgUrl, "?") === false)
621
+			$imgUrl .= "?";
622
+
623
+		//$imgUrl .= "&ms=" . str_replace ( "px", "", $gmap ['width'] ) . ","
624
+		//          . str_replace ( "px", "", $gmap ['height'] );
625
+		$imgUrl .= "&ms=" . str_replace("px", "", $gmap ['width']) . "%2C"
626
+			. str_replace("px", "", $gmap ['height']);
627
+		$imgUrl .= "&key=" . $this->getConf('bingAPIKey');
628
+		if(!empty ($overlay)) {
629
+			$rowId = 0;
630
+			foreach($overlay as $data) {
631
+				list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
632
+				// TODO icon style lookup, see: http://msdn.microsoft.com/en-us/library/ff701719.aspx for iconStyle
633
+				$iconStyle = 32;
634
+				$rowId++;
635
+				// NOTE: the max number of pushpins is 18! or we have to use POST
636
+				//  (http://msdn.microsoft.com/en-us/library/ff701724.aspx)
637
+				if($rowId == 18) {
638
+					break;
639
+				}
640
+				//$imgUrl .= "&pp=$lat,$lon;$iconStyle;$rowId";
641
+				$imgUrl .= "&pp=$lat%2C$lon%3B$iconStyle%3B$rowId";
642
+
643
+			}
644
+		}
645
+		global $conf;
646
+		$imgUrl .= "&fmt=png";
647
+		$imgUrl .= "&c=" . $conf ['lang'];
648
+		// dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::getBing: bing image url is:');
649
+		return $imgUrl;
650
+	}
651
+
652
+	/**
653
+	 * Calculate the minimum bbox for a start location + poi.
654
+	 *
655
+	 * @param array $overlay
656
+	 *            multi-dimensional array of array($lat, $lon, $text, $angle, $opacity, $img)
657
+	 * @param float $lat
658
+	 *            latitude for map center
659
+	 * @param float $lon
660
+	 *            longitude for map center
661
+	 * @return array :float array describing the mbr and center point
662
+	 */
663
+	private function calcBBOX(array $overlay, float $lat, float $lon): array {
664
+		$lats = array($lat);
665
+		$lons = array($lon);
666
+		foreach($overlay as $data) {
667
+			list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
668
+			$lats [] = $lat;
669
+			$lons [] = $lon;
670
+		}
671
+		sort($lats);
672
+		sort($lons);
673
+		// TODO: make edge/wrap around cases work
674
+		$centerlat = $lats [0] + ($lats [count($lats) - 1] - $lats [0]);
675
+		$centerlon = $lons [0] + ($lons [count($lats) - 1] - $lons [0]);
676
+		return array(
677
+			'minlat'    => $lats [0],
678
+			'minlon'    => $lons [0],
679
+			'maxlat'    => $lats [count($lats) - 1],
680
+			'maxlon'    => $lons [count($lats) - 1],
681
+			'centerlat' => $centerlat,
682
+			'centerlon' => $centerlon
683
+		);
684
+	}
685
+
686
+	/**
687
+	 * convert latitude in decimal degrees to DMS+hemisphere.
688
+	 *
689
+	 * @param float $decimaldegrees
690
+	 * @return string
691
+	 * @todo move this into a shared library
692
+	 */
693
+	private function convertLat(float $decimaldegrees): string {
694
+		if(strpos($decimaldegrees, '-') !== false) {
695
+			$latPos = "S";
696
+		} else {
697
+			$latPos = "N";
698
+		}
699
+		$dms = $this->convertDDtoDMS(abs($decimaldegrees));
700
+		return hsc($dms . $latPos);
701
+	}
702
+
703
+	/**
704
+	 * Convert decimal degrees to degrees, minutes, seconds format
705
+	 *
706
+	 * @param float $decimaldegrees
707
+	 * @return string dms
708
+	 * @todo move this into a shared library
709
+	 */
710
+	private function convertDDtoDMS(float $decimaldegrees): string {
711
+		$dms  = floor($decimaldegrees);
712
+		$secs = ($decimaldegrees - $dms) * 3600;
713
+		$min  = floor($secs / 60);
714
+		$sec  = round($secs - ($min * 60), 3);
715
+		$dms  .= 'º' . $min . '\'' . $sec . '"';
716
+		return $dms;
717
+	}
718
+
719
+	/**
720
+	 * convert longitude in decimal degrees to DMS+hemisphere.
721
+	 *
722
+	 * @param float $decimaldegrees
723
+	 * @return string
724
+	 * @todo move this into a shared library
725
+	 */
726
+	private function convertLon(float $decimaldegrees): string {
727
+		if(strpos($decimaldegrees, '-') !== false) {
728
+			$lonPos = "W";
729
+		} else {
730
+			$lonPos = "E";
731
+		}
732
+		$dms = $this->convertDDtoDMS(abs($decimaldegrees));
733
+		return hsc($dms . $lonPos);
734
+	}
735
+
736
+	/**
737
+	 * Figures out the base filename of a media path.
738
+	 *
739
+	 * @param string $mediaLink
740
+	 * @return string
741
+	 */
742
+	private function getFileName(string $mediaLink): string {
743
+		$mediaLink = str_replace('[[', '', $mediaLink);
744
+		$mediaLink = str_replace(']]', '', $mediaLink);
745
+		$mediaLink = substr($mediaLink, 0, -4);
746
+		$parts     = explode(':', $mediaLink);
747
+		$mediaLink = end($parts);
748
+		return str_replace('_', ' ', $mediaLink);
749
+	}
750
+
751
+	/**
752
+	 *
753
+	 * @see DokuWiki_Syntax_Plugin::render()
754
+	 */
755
+	public function render($format, Doku_Renderer $renderer, $data): bool {
756
+		// set to true after external scripts tags are written
757
+		static $initialised = false;
758
+		// incremented for each map tag in the page source so we can keep track of each map in this page
759
+		static $mapnumber = 0;
760
+
761
+		// dbglog($data, 'olmap::render() data.');
762
+		list ($mapid, $param, $mainLat, $mainLon, $poitable, $poitabledesc, $staticImgUrl, $_firstimage) = $data;
763
+
764
+		if($format == 'xhtml') {
765
+			$olscript     = '';
766
+			$olEnable     = false;
767
+			$gscript      = '';
768
+			$gEnable      = $this->getConf('enableGoogle');
769
+			$stamenEnable = $this->getConf('enableStamen');
770
+			$osmEnable    = $this->getConf('enableOSM');
771
+			$enableBing   = $this->getConf('enableBing');
772
+
773
+			$scriptEnable = '';
774
+			if(!$initialised) {
775
+				$initialised = true;
776
+				// render necessary script tags
777
+				if($gEnable) {
778
+					$gscript = '<script defer="defer" src="//maps.google.com/maps/api/js?v=3.29&amp;key='
779
+						. $this->getConf('googleAPIkey') . '"></script>';
780
+				}
781
+				$olscript = '<script defer="defer" src="' . DOKU_BASE
782
+					. 'lib/plugins/openlayersmap/lib/OpenLayers.js"></script>';
783
+
784
+				$scriptEnable = '<script defer="defer" src="data:text/javascript;base64,';
785
+				$scriptSrc    = $olscript ? 'olEnable = true;' : 'olEnable = false;';
786
+				$scriptSrc    .= 'gEnable = ' . ($gEnable ? 'true' : 'false') . ';';
787
+				$scriptSrc    .= 'osmEnable = ' . ($osmEnable ? 'true' : 'false') . ';';
788
+				$scriptSrc    .= 'stamenEnable = ' . ($stamenEnable ? 'true' : 'false') . ';';
789
+				$scriptSrc    .= 'bEnable = ' . ($enableBing ? 'true' : 'false') . ';';
790
+				$scriptSrc    .= 'bApiKey="' . $this->getConf('bingAPIKey') . '";';
791
+				$scriptSrc    .= 'tfApiKey="' . $this->getConf('tfApiKey') . '";';
792
+				$scriptSrc    .= 'gApiKey="' . $this->getConf('googleAPIkey') . '";';
793
+				$scriptEnable .= base64_encode($scriptSrc);
794
+				$scriptEnable .= '"></script>';
795
+			}
796
+			$renderer->doc .= "$gscript\n$olscript\n$scriptEnable";
797
+			$renderer->doc .= '<div class="olMapHelp">' . $this->locale_xhtml("help") . '</div>';
798
+			if($this->getConf('enableA11y')) {
799
+				$renderer->doc .= '<div id="' . $mapid . '-static" class="olStaticMap">'
800
+					. p_render($format, p_get_instructions($staticImgUrl), $info) . '</div>';
801
+			}
802
+			$renderer->doc .= '<div id="' . $mapid . '-clearer" class="clearer"><p>&nbsp;</p></div>';
803
+			if($this->getConf('enableA11y')) {
804
+				// render a table of the POI for the print and a11y presentation, it is hidden using javascript
805
+				$renderer->doc .= '<div class="olPOItableSpan" id="' . $mapid . '-table-span">
806 806
                     <table class="olPOItable" id="' . $mapid . '-table">
807 807
                     <caption class="olPOITblCaption">' . $this->getLang('olmapPOItitle') . '</caption>
808 808
                     <thead class="olPOITblHeader">
@@ -810,62 +810,62 @@  discard block
 block discarded – undo
810 810
                     <th class="rowId" scope="col">id</th>
811 811
                     <th class="icon" scope="col">' . $this->getLang('olmapPOIicon') . '</th>
812 812
                     <th class="lat" scope="col" title="' . $this->getLang('olmapPOIlatTitle') . '">'
813
-                    . $this->getLang('olmapPOIlat') . '</th>
813
+					. $this->getLang('olmapPOIlat') . '</th>
814 814
                     <th class="lon" scope="col" title="' . $this->getLang('olmapPOIlonTitle') . '">'
815
-                    . $this->getLang('olmapPOIlon') . '</th>
815
+					. $this->getLang('olmapPOIlon') . '</th>
816 816
                     <th class="txt" scope="col">' . $this->getLang('olmapPOItxt') . '</th>
817 817
                     </tr>
818 818
                     </thead>';
819
-                if($poitabledesc != '') {
820
-                    $renderer->doc .= '<tfoot class="olPOITblFooter"><tr><td colspan="5">' . $poitabledesc
821
-                        . '</td></tr></tfoot>';
822
-                }
823
-                $renderer->doc .= '<tbody class="olPOITblBody">' . $poitable . '</tbody>
819
+				if($poitabledesc != '') {
820
+					$renderer->doc .= '<tfoot class="olPOITblFooter"><tr><td colspan="5">' . $poitabledesc
821
+						. '</td></tr></tfoot>';
822
+				}
823
+				$renderer->doc .= '<tbody class="olPOITblBody">' . $poitable . '</tbody>
824 824
                     </table></div>';
825
-            }
826
-            // render inline mapscript parts
827
-            $renderer->doc .= '<script defer="defer" src="data:text/javascript;base64,';
828
-            $renderer->doc .= base64_encode("olMapData[$mapnumber] = $param");
829
-            $renderer->doc .= '"></script>';
830
-            $mapnumber++;
831
-            return true;
832
-        } elseif($format == 'metadata') {
833
-            if(!(($this->dflt ['lat'] == $mainLat) && ($this->dflt ['lon'] == $mainLon))) {
834
-                // render geo metadata, unless they are the default
835
-                $renderer->meta ['geo'] ['lat'] = $mainLat;
836
-                $renderer->meta ['geo'] ['lon'] = $mainLon;
837
-                if($geophp = plugin_load('helper', 'geophp')) {
838
-                    // if we have the geoPHP helper, add the geohash
839
-
840
-                    // fails with older php versions..
841
-                    // $renderer->meta['geo']['geohash'] = (new Point($mainLon,$mainLat))->out('geohash');
842
-                    $p                                  = new Point ($mainLon, $mainLat);
843
-                    $renderer->meta ['geo'] ['geohash'] = $p->out('geohash');
844
-                }
845
-            }
846
-
847
-            if(($this->getConf('enableA11y')) && (!empty ($_firstimage))) {
848
-                // add map local image into relation/firstimage if not already filled and when it is a local image
849
-
850
-                global $ID;
851
-                $rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE);
852
-                $img = $rel ['firstimage'];
853
-                if(empty ($img) /* || $img == $_firstimage*/) {
854
-                    //dbglog ( $_firstimage,
855
-                    // 'olmap::render#rendering image relation metadata for _firstimage as $img was empty or same.' );
856
-                    // This seems to never work; the firstimage entry in the .meta file is empty
857
-                    // $renderer->meta['relation']['firstimage'] = $_firstimage;
858
-
859
-                    // ... and neither does this; the firstimage entry in the .meta file is empty
860
-                    // $relation = array('relation'=>array('firstimage'=>$_firstimage));
861
-                    // p_set_metadata($ID, $relation, false, false);
862
-
863
-                    // ... this works
864
-                    $renderer->internalmedia($_firstimage, $poitabledesc);
865
-                }
866
-            }
867
-            return true;
868
-        }
869
-        return false;
870
-    }
825
+			}
826
+			// render inline mapscript parts
827
+			$renderer->doc .= '<script defer="defer" src="data:text/javascript;base64,';
828
+			$renderer->doc .= base64_encode("olMapData[$mapnumber] = $param");
829
+			$renderer->doc .= '"></script>';
830
+			$mapnumber++;
831
+			return true;
832
+		} elseif($format == 'metadata') {
833
+			if(!(($this->dflt ['lat'] == $mainLat) && ($this->dflt ['lon'] == $mainLon))) {
834
+				// render geo metadata, unless they are the default
835
+				$renderer->meta ['geo'] ['lat'] = $mainLat;
836
+				$renderer->meta ['geo'] ['lon'] = $mainLon;
837
+				if($geophp = plugin_load('helper', 'geophp')) {
838
+					// if we have the geoPHP helper, add the geohash
839
+
840
+					// fails with older php versions..
841
+					// $renderer->meta['geo']['geohash'] = (new Point($mainLon,$mainLat))->out('geohash');
842
+					$p                                  = new Point ($mainLon, $mainLat);
843
+					$renderer->meta ['geo'] ['geohash'] = $p->out('geohash');
844
+				}
845
+			}
846
+
847
+			if(($this->getConf('enableA11y')) && (!empty ($_firstimage))) {
848
+				// add map local image into relation/firstimage if not already filled and when it is a local image
849
+
850
+				global $ID;
851
+				$rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE);
852
+				$img = $rel ['firstimage'];
853
+				if(empty ($img) /* || $img == $_firstimage*/) {
854
+					//dbglog ( $_firstimage,
855
+					// 'olmap::render#rendering image relation metadata for _firstimage as $img was empty or same.' );
856
+					// This seems to never work; the firstimage entry in the .meta file is empty
857
+					// $renderer->meta['relation']['firstimage'] = $_firstimage;
858
+
859
+					// ... and neither does this; the firstimage entry in the .meta file is empty
860
+					// $relation = array('relation'=>array('firstimage'=>$_firstimage));
861
+					// p_set_metadata($ID, $relation, false, false);
862
+
863
+					// ... this works
864
+					$renderer->internalmedia($_firstimage, $poitabledesc);
865
+				}
866
+			}
867
+			return true;
868
+		}
869
+		return false;
870
+	}
871 871
 }
Please login to merge, or discard this patch.
Spacing   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
         preg_match('(lon[:|=]\"-?\d*\.?\d*\")', $match, $mainLon);
95 95
         $mainLat = substr($mainLat [0], 5, -1);
96 96
         $mainLon = substr($mainLon [0], 5, -1);
97
-        if(!is_numeric($mainLat)) {
97
+        if (!is_numeric($mainLat)) {
98 98
             $mainLat = $this->dflt ['lat'];
99 99
         }
100
-        if(!is_numeric($mainLon)) {
100
+        if (!is_numeric($mainLon)) {
101 101
             $mainLon = $this->dflt ['lon'];
102 102
         }
103 103
 
@@ -108,23 +108,23 @@  discard block
 block discarded – undo
108 108
         $_nocache = false;
109 109
         // choose maptype based on the specified tag
110 110
         $imgUrl = "{{";
111
-        if(stripos($gmap ['baselyr'], 'google') !== false) {
111
+        if (stripos($gmap ['baselyr'], 'google') !== false) {
112 112
             // Google
113 113
             $imgUrl .= $this->getGoogle($gmap, $overlay);
114 114
             $imgUrl .= "&.png";
115
-        } elseif(stripos($gmap ['baselyr'], 'bing') !== false) {
115
+        } elseif (stripos($gmap ['baselyr'], 'bing') !== false) {
116 116
             // Bing
117
-            if(!$this->getConf('bingAPIKey')) {
117
+            if (!$this->getConf('bingAPIKey')) {
118 118
                 // in case there is no Bing api key we'll use OSM
119 119
                 $_firstimageID = $this->getStaticOSM($gmap, $overlay);
120
-                $imgUrl        .= $_firstimageID;
121
-                if($this->getConf('optionStaticMapGenerator') == 'remote') {
120
+                $imgUrl .= $_firstimageID;
121
+                if ($this->getConf('optionStaticMapGenerator') == 'remote') {
122 122
                     $imgUrl .= "&.png";
123 123
                 }
124 124
             } else {
125 125
                 // seems that Bing doesn't like the DW client, turn off caching
126 126
                 $_nocache = true;
127
-                $imgUrl   .= $this->getBing($gmap, $overlay) . "&.png";
127
+                $imgUrl .= $this->getBing($gmap, $overlay)."&.png";
128 128
             }
129 129
         } /* elseif (stripos ( $gmap ['baselyr'], 'mapquest' ) !== false) {
130 130
             // MapQuest
@@ -142,33 +142,33 @@  discard block
 block discarded – undo
142 142
         } */ else {
143 143
             // default OSM
144 144
             $_firstimageID = $this->getStaticOSM($gmap, $overlay);
145
-            $imgUrl        .= $_firstimageID;
146
-            if($this->getConf('optionStaticMapGenerator') == 'remote') {
145
+            $imgUrl .= $_firstimageID;
146
+            if ($this->getConf('optionStaticMapGenerator') == 'remote') {
147 147
                 $imgUrl .= "&.png";
148 148
             }
149 149
         }
150 150
 
151 151
         // append dw p_render specific params and render
152
-        $imgUrl .= "?" . str_replace("px", "", $gmap ['width']) . "x"
152
+        $imgUrl .= "?".str_replace("px", "", $gmap ['width'])."x"
153 153
             . str_replace("px", "", $gmap ['height']);
154 154
         $imgUrl .= "&nolink";
155 155
 
156 156
         // add nocache option for selected services
157
-        if($_nocache) {
157
+        if ($_nocache) {
158 158
             $imgUrl .= "&nocache";
159 159
         }
160 160
 
161
-        $imgUrl .= " |" . $gmap ['summary'] . " }}";
161
+        $imgUrl .= " |".$gmap ['summary']." }}";
162 162
 
163 163
         // dbglog($imgUrl,"complete image tags is:");
164 164
 
165 165
         $mapid = $gmap ['id'];
166 166
         // create a javascript parameter string for the map
167 167
         $param = '';
168
-        foreach($gmap as $key => $val) {
169
-            $param .= is_numeric($val) ? "$key: $val, " : "$key: '" . hsc($val) . "', ";
168
+        foreach ($gmap as $key => $val) {
169
+            $param .= is_numeric($val) ? "$key: $val, " : "$key: '".hsc($val)."', ";
170 170
         }
171
-        if(!empty ($param)) {
171
+        if (!empty ($param)) {
172 172
             $param = substr($param, 0, -2);
173 173
         }
174 174
         unset ($gmap ['id']);
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
         $poi      = '';
178 178
         $poitable = '';
179 179
         $rowId    = 0;
180
-        if(!empty ($overlay)) {
181
-            foreach($overlay as $data) {
180
+        if (!empty ($overlay)) {
181
+            foreach ($overlay as $data) {
182 182
                 list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
183 183
                 $rowId++;
184 184
                 $poi .= ", {lat:$lat,lon:$lon,txt:'$text',angle:$angle,opacity:$opacity,img:'$img',rowId: $rowId}";
185 185
 
186
-                if($this->getConf('displayformat') === 'DMS') {
186
+                if ($this->getConf('displayformat') === 'DMS') {
187 187
                     $lat = $this->convertLat($lat);
188 188
                     $lon = $this->convertLon($lon);
189 189
                 } else {
@@ -193,52 +193,52 @@  discard block
 block discarded – undo
193 193
 
194 194
                 $poitable .= '
195 195
                     <tr>
196
-                    <td class="rowId">' . $rowId . '</td>
197
-                    <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/icons/' . $img . '" alt="'
198
-                    . substr($img, 0, -4) . $this->getlang('alt_legend_poi') . '" /></td>
199
-                    <td class="lat" title="' . $this->getLang('olmapPOIlatTitle') . '">' . $lat . '</td>
200
-                    <td class="lon" title="' . $this->getLang('olmapPOIlonTitle') . '">' . $lon . '</td>
201
-                    <td class="txt">' . $text . '</td>
196
+                    <td class="rowId">' . $rowId.'</td>
197
+                    <td class="icon"><img src="' . DOKU_BASE.'lib/plugins/openlayersmap/icons/'.$img.'" alt="'
198
+                    . substr($img, 0, -4).$this->getlang('alt_legend_poi').'" /></td>
199
+                    <td class="lat" title="' . $this->getLang('olmapPOIlatTitle').'">'.$lat.'</td>
200
+                    <td class="lon" title="' . $this->getLang('olmapPOIlonTitle').'">'.$lon.'</td>
201
+                    <td class="txt">' . $text.'</td>
202 202
                     </tr>';
203 203
             }
204 204
             $poi = substr($poi, 2);
205 205
         }
206
-        if(!empty ($gmap ['kmlfile'])) {
206
+        if (!empty ($gmap ['kmlfile'])) {
207 207
             $poitable .= '
208 208
                     <tr>
209 209
                     <td class="rowId"><img src="' . DOKU_BASE
210 210
                 . 'lib/plugins/openlayersmap/toolbar/kml_file.png" alt="KML file" /></td>
211
-                    <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/kml_line.png" alt="'
212
-                . $this->getlang('alt_legend_kml') . '" /></td>
213
-                    <td class="txt" colspan="3">KML track: ' . $this->getFileName($gmap ['kmlfile']) . '</td>
211
+                    <td class="icon"><img src="' . DOKU_BASE.'lib/plugins/openlayersmap/toolbar/kml_line.png" alt="'
212
+                . $this->getlang('alt_legend_kml').'" /></td>
213
+                    <td class="txt" colspan="3">KML track: ' . $this->getFileName($gmap ['kmlfile']).'</td>
214 214
                     </tr>';
215 215
         }
216
-        if(!empty ($gmap ['gpxfile'])) {
216
+        if (!empty ($gmap ['gpxfile'])) {
217 217
             $poitable .= '
218 218
                     <tr>
219 219
                     <td class="rowId"><img src="' . DOKU_BASE
220 220
                 . 'lib/plugins/openlayersmap/toolbar/gpx_file.png" alt="GPX file" /></td>
221 221
                     <td class="icon"><img src="' . DOKU_BASE
222 222
                 . 'lib/plugins/openlayersmap/toolbar/gpx_line.png" alt="'
223
-                . $this->getlang('alt_legend_gpx') . '" /></td>
224
-                    <td class="txt" colspan="3">GPX track: ' . $this->getFileName($gmap ['gpxfile']) . '</td>
223
+                . $this->getlang('alt_legend_gpx').'" /></td>
224
+                    <td class="txt" colspan="3">GPX track: ' . $this->getFileName($gmap ['gpxfile']).'</td>
225 225
                     </tr>';
226 226
         }
227
-        if(!empty ($gmap ['geojsonfile'])) {
227
+        if (!empty ($gmap ['geojsonfile'])) {
228 228
             $poitable .= '
229 229
                     <tr>
230 230
                     <td class="rowId"><img src="' . DOKU_BASE
231 231
                 . 'lib/plugins/openlayersmap/toolbar/geojson_file.png" alt="GeoJSON file" /></td>
232 232
                     <td class="icon"><img src="' . DOKU_BASE
233 233
                 . 'lib/plugins/openlayersmap/toolbar/geojson_line.png" alt="'
234
-                . $this->getlang('alt_legend_geojson') . '" /></td>
235
-                    <td class="txt" colspan="3">GeoJSON track: ' . $this->getFileName($gmap ['geojsonfile']) . '</td>
234
+                . $this->getlang('alt_legend_geojson').'" /></td>
235
+                    <td class="txt" colspan="3">GeoJSON track: ' . $this->getFileName($gmap ['geojsonfile']).'</td>
236 236
                     </tr>';
237 237
         }
238 238
 
239 239
         $autozoom = empty ($gmap ['autozoom']) ? $this->getConf('autoZoomMap') : $gmap ['autozoom'];
240
-        $js       = "{mapOpts: {" . $param . ", displayformat: '" . $this->getConf('displayformat')
241
-            . "', autozoom: " . $autozoom . "}, poi: [$poi]};";
240
+        $js       = "{mapOpts: {".$param.", displayformat: '".$this->getConf('displayformat')
241
+            . "', autozoom: ".$autozoom."}, poi: [$poi]};";
242 242
         // unescape the json
243 243
         $poitable = stripslashes($poitable);
244 244
 
@@ -266,21 +266,21 @@  discard block
 block discarded – undo
266 266
         preg_match_all('/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER);
267 267
         // parse match for instructions, break into key value pairs
268 268
         $gmap = $this->dflt;
269
-        foreach($gmap as $key => &$value) {
270
-            $defval = $this->getConf('default_' . $key);
271
-            if($defval !== '') {
269
+        foreach ($gmap as $key => &$value) {
270
+            $defval = $this->getConf('default_'.$key);
271
+            if ($defval !== '') {
272 272
                 $value = $defval;
273 273
             }
274 274
         }
275 275
         unset ($value);
276
-        foreach($param as $kvpair) {
276
+        foreach ($param as $kvpair) {
277 277
             list ($match, $key, $val) = $kvpair;
278 278
             $key = strtolower($key);
279
-            if(isset ($gmap [$key])) {
280
-                if($key == 'summary') {
279
+            if (isset ($gmap [$key])) {
280
+                if ($key == 'summary') {
281 281
                     // preserve case for summary field
282 282
                     $gmap [$key] = $val;
283
-                } elseif($key == 'id') {
283
+                } elseif ($key == 'id') {
284 284
                     // preserve case for id field
285 285
                     $gmap [$key] = $val;
286 286
                 } else {
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
         );
317 317
         // create poi array
318 318
         $overlay = array();
319
-        foreach($point as $pt) {
319
+        foreach ($point as $pt) {
320 320
             list ($match, $lat, $lon, $angle, $opacity, $img, $text) = $pt;
321 321
             $lat     = is_numeric($lat) ? $lat : 0;
322 322
             $lon     = is_numeric($lon) ? $lon : 0;
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
      */
351 351
     private function getGoogle(array $gmap, array $overlay): string {
352 352
         $sUrl = $this->getConf('iconUrlOverload');
353
-        if(!$sUrl) {
353
+        if (!$sUrl) {
354 354
             $sUrl = DOKU_URL;
355 355
         }
356
-        switch($gmap ['baselyr']) {
356
+        switch ($gmap ['baselyr']) {
357 357
             case 'google hybrid' :
358 358
                 $maptype = 'hybrid';
359 359
                 break;
@@ -373,29 +373,29 @@  discard block
 block discarded – undo
373 373
         // see: https://developers.google.com/maps/documentation/staticmaps/index#Viewports
374 374
         // http://maps.google.com/maps/api/staticmap?center=51.565690,5.456756&zoom=16&size=600x400&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker.png|label:1|51.565690,5.456756&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker-blue.png|51.566197,5.458966|label:2&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.567177,5.457909|label:3&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.566283,5.457330|label:4&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.565630,5.457695|label:5&sensor=false&format=png&maptype=roadmap
375 375
         $imgUrl = "https://maps.googleapis.com/maps/api/staticmap?";
376
-        $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x"
376
+        $imgUrl .= "&size=".str_replace("px", "", $gmap ['width'])."x"
377 377
             . str_replace("px", "", $gmap ['height']);
378 378
         //if (!$this->getConf( 'autoZoomMap')) { // no need for center & zoom params }
379
-        $imgUrl .= "&center=" . $gmap ['lat'] . "," . $gmap ['lon'];
379
+        $imgUrl .= "&center=".$gmap ['lat'].",".$gmap ['lon'];
380 380
         // max is 21 (== building scale), but that's overkill..
381
-        if($gmap ['zoom'] > 17) {
381
+        if ($gmap ['zoom'] > 17) {
382 382
             $imgUrl .= "&zoom=17";
383 383
         } else {
384
-            $imgUrl .= "&zoom=" . $gmap ['zoom'];
384
+            $imgUrl .= "&zoom=".$gmap ['zoom'];
385 385
         }
386
-        if(!empty ($overlay)) {
386
+        if (!empty ($overlay)) {
387 387
             $rowId = 0;
388
-            foreach($overlay as $data) {
388
+            foreach ($overlay as $data) {
389 389
                 list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
390
-                $imgUrl .= "&markers=icon%3a" . $sUrl . "lib/plugins/openlayersmap/icons/" . $img . "%7c"
391
-                    . $lat . "," . $lon . "%7clabel%3a" . ++$rowId;
390
+                $imgUrl .= "&markers=icon%3a".$sUrl."lib/plugins/openlayersmap/icons/".$img."%7c"
391
+                    . $lat.",".$lon."%7clabel%3a".++$rowId;
392 392
             }
393 393
         }
394
-        $imgUrl .= "&format=png&maptype=" . $maptype;
394
+        $imgUrl .= "&format=png&maptype=".$maptype;
395 395
         global $conf;
396
-        $imgUrl .= "&language=" . $conf ['lang'];
397
-        if($this->getConf('googleAPIkey')) {
398
-            $imgUrl .= "&key=" . $this->getConf('googleAPIkey');
396
+        $imgUrl .= "&language=".$conf ['lang'];
397
+        if ($this->getConf('googleAPIkey')) {
398
+            $imgUrl .= "&key=".$this->getConf('googleAPIkey');
399 399
         }
400 400
         // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::getGoogle: Google image url is:');
401 401
         return $imgUrl;
@@ -478,23 +478,23 @@  discard block
 block discarded – undo
478 478
     private function getStaticOSM(array $gmap, array $overlay) {
479 479
         global $conf;
480 480
 
481
-        if($this->getConf('optionStaticMapGenerator') == 'local') {
481
+        if ($this->getConf('optionStaticMapGenerator') == 'local') {
482 482
             // using local basemap composer
483
-            if(!$myMap = plugin_load('helper', 'openlayersmap_staticmap')) {
483
+            if (!$myMap = plugin_load('helper', 'openlayersmap_staticmap')) {
484 484
                 dbglog(
485 485
                     $myMap,
486 486
                     'openlayersmap_staticmap plugin is not available for use.'
487 487
                 );
488 488
             }
489
-            if(!$geophp = plugin_load('helper', 'geophp')) {
489
+            if (!$geophp = plugin_load('helper', 'geophp')) {
490 490
                 dbglog($geophp, 'geophp plugin is not available for use.');
491 491
             }
492
-            $size = str_replace("px", "", $gmap ['width']) . "x"
492
+            $size = str_replace("px", "", $gmap ['width'])."x"
493 493
                 . str_replace("px", "", $gmap ['height']);
494 494
 
495 495
             $markers = array();
496
-            if(!empty ($overlay)) {
497
-                foreach($overlay as $data) {
496
+            if (!empty ($overlay)) {
497
+                foreach ($overlay as $data) {
498 498
                     list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
499 499
                     $iconStyle  = substr($img, 0, strlen($img) - 4);
500 500
                     $markers [] = array(
@@ -506,26 +506,26 @@  discard block
 block discarded – undo
506 506
             }
507 507
 
508 508
             $apikey = '';
509
-            switch($gmap ['baselyr']) {
509
+            switch ($gmap ['baselyr']) {
510 510
                 case 'mapnik' :
511 511
                 case 'openstreetmap' :
512 512
                     $maptype = 'openstreetmap';
513 513
                     break;
514 514
                 case 'transport' :
515 515
                     $maptype = 'transport';
516
-                    $apikey  = '?apikey=' . $this->getConf('tfApiKey');
516
+                    $apikey  = '?apikey='.$this->getConf('tfApiKey');
517 517
                     break;
518 518
                 case 'landscape' :
519 519
                     $maptype = 'landscape';
520
-                    $apikey  = '?apikey=' . $this->getConf('tfApiKey');
520
+                    $apikey  = '?apikey='.$this->getConf('tfApiKey');
521 521
                     break;
522 522
                 case 'outdoors' :
523 523
                     $maptype = 'outdoors';
524
-                    $apikey  = '?apikey=' . $this->getConf('tfApiKey');
524
+                    $apikey  = '?apikey='.$this->getConf('tfApiKey');
525 525
                     break;
526 526
                 case 'cycle map' :
527 527
                     $maptype = 'cycle';
528
-                    $apikey  = '?apikey=' . $this->getConf('tfApiKey');
528
+                    $apikey  = '?apikey='.$this->getConf('tfApiKey');
529 529
                     break;
530 530
                 case 'hike and bike map' :
531 531
                     $maptype = 'hikeandbike';
@@ -554,25 +554,25 @@  discard block
 block discarded – undo
554 554
             //  ol-marker|47.921629720114,18.027343747285,ol-marker-gold|47.951071133739,19.257812497236,
555 555
             //  ol-marker-blue|47.180141361692,19.257812497236,ol-marker-green
556 556
             $imgUrl = "https://staticmap.openstreetmap.de/staticmap.php";
557
-            $imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon'];
558
-            $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x"
557
+            $imgUrl .= "?center=".$gmap ['lat'].",".$gmap ['lon'];
558
+            $imgUrl .= "&size=".str_replace("px", "", $gmap ['width'])."x"
559 559
                 . str_replace("px", "", $gmap ['height']);
560 560
 
561
-            if($gmap ['zoom'] > 16) {
561
+            if ($gmap ['zoom'] > 16) {
562 562
                 // actually this could even be 18, but that seems overkill
563 563
                 $imgUrl .= "&zoom=16";
564 564
             } else {
565
-                $imgUrl .= "&zoom=" . $gmap ['zoom'];
565
+                $imgUrl .= "&zoom=".$gmap ['zoom'];
566 566
             }
567 567
 
568
-            if(!empty ($overlay)) {
569
-                $rowId  = 0;
568
+            if (!empty ($overlay)) {
569
+                $rowId = 0;
570 570
                 $imgUrl .= "&markers=";
571
-                foreach($overlay as $data) {
571
+                foreach ($overlay as $data) {
572 572
                     list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
573 573
                     $rowId++;
574 574
                     $iconStyle = "lightblue$rowId";
575
-                    $imgUrl    .= "$lat,$lon,$iconStyle%7c";
575
+                    $imgUrl .= "$lat,$lon,$iconStyle%7c";
576 576
                 }
577 577
                 $imgUrl = substr($imgUrl, 0, -3);
578 578
             }
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
      * @return string
592 592
      */
593 593
     private function getBing(array $gmap, array $overlay): string {
594
-        switch($gmap ['baselyr']) {
594
+        switch ($gmap ['baselyr']) {
595 595
             case 've hybrid' :
596 596
             case 'bing hybrid' :
597 597
                 $maptype = 'AerialWithLabels';
@@ -608,33 +608,33 @@  discard block
 block discarded – undo
608 608
                 $maptype = 'Road';
609 609
                 break;
610 610
         }
611
-        $imgUrl = "https://dev.virtualearth.net/REST/v1/Imagery/Map/" . $maptype;// . "/";
612
-        if($this->getConf('autoZoomMap')) {
611
+        $imgUrl = "https://dev.virtualearth.net/REST/v1/Imagery/Map/".$maptype; // . "/";
612
+        if ($this->getConf('autoZoomMap')) {
613 613
             $bbox = $this->calcBBOX($overlay, $gmap ['lat'], $gmap ['lon']);
614 614
             //$imgUrl .= "?ma=" . $bbox ['minlat'] . "," . $bbox ['minlon'] . ","
615 615
             //          . $bbox ['maxlat'] . "," . $bbox ['maxlon'];
616
-            $imgUrl .= "?ma=" . $bbox ['minlat'] . "%2C" . $bbox ['minlon'] . "%2C" . $bbox ['maxlat']
617
-                . "%2C" . $bbox ['maxlon'];
616
+            $imgUrl .= "?ma=".$bbox ['minlat']."%2C".$bbox ['minlon']."%2C".$bbox ['maxlat']
617
+                . "%2C".$bbox ['maxlon'];
618 618
             $imgUrl .= "&dcl=1";
619 619
         }
620
-        if(strpos($imgUrl, "?") === false)
620
+        if (strpos($imgUrl, "?") === false)
621 621
             $imgUrl .= "?";
622 622
 
623 623
         //$imgUrl .= "&ms=" . str_replace ( "px", "", $gmap ['width'] ) . ","
624 624
         //          . str_replace ( "px", "", $gmap ['height'] );
625
-        $imgUrl .= "&ms=" . str_replace("px", "", $gmap ['width']) . "%2C"
625
+        $imgUrl .= "&ms=".str_replace("px", "", $gmap ['width'])."%2C"
626 626
             . str_replace("px", "", $gmap ['height']);
627
-        $imgUrl .= "&key=" . $this->getConf('bingAPIKey');
628
-        if(!empty ($overlay)) {
627
+        $imgUrl .= "&key=".$this->getConf('bingAPIKey');
628
+        if (!empty ($overlay)) {
629 629
             $rowId = 0;
630
-            foreach($overlay as $data) {
630
+            foreach ($overlay as $data) {
631 631
                 list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
632 632
                 // TODO icon style lookup, see: http://msdn.microsoft.com/en-us/library/ff701719.aspx for iconStyle
633 633
                 $iconStyle = 32;
634 634
                 $rowId++;
635 635
                 // NOTE: the max number of pushpins is 18! or we have to use POST
636 636
                 //  (http://msdn.microsoft.com/en-us/library/ff701724.aspx)
637
-                if($rowId == 18) {
637
+                if ($rowId == 18) {
638 638
                     break;
639 639
                 }
640 640
                 //$imgUrl .= "&pp=$lat,$lon;$iconStyle;$rowId";
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
         }
645 645
         global $conf;
646 646
         $imgUrl .= "&fmt=png";
647
-        $imgUrl .= "&c=" . $conf ['lang'];
647
+        $imgUrl .= "&c=".$conf ['lang'];
648 648
         // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::getBing: bing image url is:');
649 649
         return $imgUrl;
650 650
     }
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
     private function calcBBOX(array $overlay, float $lat, float $lon): array {
664 664
         $lats = array($lat);
665 665
         $lons = array($lon);
666
-        foreach($overlay as $data) {
666
+        foreach ($overlay as $data) {
667 667
             list ($lat, $lon, $text, $angle, $opacity, $img) = $data;
668 668
             $lats [] = $lat;
669 669
             $lons [] = $lon;
@@ -691,13 +691,13 @@  discard block
 block discarded – undo
691 691
      * @todo move this into a shared library
692 692
      */
693 693
     private function convertLat(float $decimaldegrees): string {
694
-        if(strpos($decimaldegrees, '-') !== false) {
694
+        if (strpos($decimaldegrees, '-') !== false) {
695 695
             $latPos = "S";
696 696
         } else {
697 697
             $latPos = "N";
698 698
         }
699 699
         $dms = $this->convertDDtoDMS(abs($decimaldegrees));
700
-        return hsc($dms . $latPos);
700
+        return hsc($dms.$latPos);
701 701
     }
702 702
 
703 703
     /**
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
         $secs = ($decimaldegrees - $dms) * 3600;
713 713
         $min  = floor($secs / 60);
714 714
         $sec  = round($secs - ($min * 60), 3);
715
-        $dms  .= 'º' . $min . '\'' . $sec . '"';
715
+        $dms .= 'º'.$min.'\''.$sec.'"';
716 716
         return $dms;
717 717
     }
718 718
 
@@ -724,13 +724,13 @@  discard block
 block discarded – undo
724 724
      * @todo move this into a shared library
725 725
      */
726 726
     private function convertLon(float $decimaldegrees): string {
727
-        if(strpos($decimaldegrees, '-') !== false) {
727
+        if (strpos($decimaldegrees, '-') !== false) {
728 728
             $lonPos = "W";
729 729
         } else {
730 730
             $lonPos = "E";
731 731
         }
732 732
         $dms = $this->convertDDtoDMS(abs($decimaldegrees));
733
-        return hsc($dms . $lonPos);
733
+        return hsc($dms.$lonPos);
734 734
     }
735 735
 
736 736
     /**
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
         // dbglog($data, 'olmap::render() data.');
762 762
         list ($mapid, $param, $mainLat, $mainLon, $poitable, $poitabledesc, $staticImgUrl, $_firstimage) = $data;
763 763
 
764
-        if($format == 'xhtml') {
764
+        if ($format == 'xhtml') {
765 765
             $olscript     = '';
766 766
             $olEnable     = false;
767 767
             $gscript      = '';
@@ -771,56 +771,56 @@  discard block
 block discarded – undo
771 771
             $enableBing   = $this->getConf('enableBing');
772 772
 
773 773
             $scriptEnable = '';
774
-            if(!$initialised) {
774
+            if (!$initialised) {
775 775
                 $initialised = true;
776 776
                 // render necessary script tags
777
-                if($gEnable) {
777
+                if ($gEnable) {
778 778
                     $gscript = '<script defer="defer" src="//maps.google.com/maps/api/js?v=3.29&amp;key='
779
-                        . $this->getConf('googleAPIkey') . '"></script>';
779
+                        . $this->getConf('googleAPIkey').'"></script>';
780 780
                 }
781
-                $olscript = '<script defer="defer" src="' . DOKU_BASE
781
+                $olscript = '<script defer="defer" src="'.DOKU_BASE
782 782
                     . 'lib/plugins/openlayersmap/lib/OpenLayers.js"></script>';
783 783
 
784 784
                 $scriptEnable = '<script defer="defer" src="data:text/javascript;base64,';
785 785
                 $scriptSrc    = $olscript ? 'olEnable = true;' : 'olEnable = false;';
786
-                $scriptSrc    .= 'gEnable = ' . ($gEnable ? 'true' : 'false') . ';';
787
-                $scriptSrc    .= 'osmEnable = ' . ($osmEnable ? 'true' : 'false') . ';';
788
-                $scriptSrc    .= 'stamenEnable = ' . ($stamenEnable ? 'true' : 'false') . ';';
789
-                $scriptSrc    .= 'bEnable = ' . ($enableBing ? 'true' : 'false') . ';';
790
-                $scriptSrc    .= 'bApiKey="' . $this->getConf('bingAPIKey') . '";';
791
-                $scriptSrc    .= 'tfApiKey="' . $this->getConf('tfApiKey') . '";';
792
-                $scriptSrc    .= 'gApiKey="' . $this->getConf('googleAPIkey') . '";';
786
+                $scriptSrc    .= 'gEnable = '.($gEnable ? 'true' : 'false').';';
787
+                $scriptSrc    .= 'osmEnable = '.($osmEnable ? 'true' : 'false').';';
788
+                $scriptSrc    .= 'stamenEnable = '.($stamenEnable ? 'true' : 'false').';';
789
+                $scriptSrc    .= 'bEnable = '.($enableBing ? 'true' : 'false').';';
790
+                $scriptSrc    .= 'bApiKey="'.$this->getConf('bingAPIKey').'";';
791
+                $scriptSrc    .= 'tfApiKey="'.$this->getConf('tfApiKey').'";';
792
+                $scriptSrc    .= 'gApiKey="'.$this->getConf('googleAPIkey').'";';
793 793
                 $scriptEnable .= base64_encode($scriptSrc);
794 794
                 $scriptEnable .= '"></script>';
795 795
             }
796 796
             $renderer->doc .= "$gscript\n$olscript\n$scriptEnable";
797
-            $renderer->doc .= '<div class="olMapHelp">' . $this->locale_xhtml("help") . '</div>';
798
-            if($this->getConf('enableA11y')) {
799
-                $renderer->doc .= '<div id="' . $mapid . '-static" class="olStaticMap">'
800
-                    . p_render($format, p_get_instructions($staticImgUrl), $info) . '</div>';
797
+            $renderer->doc .= '<div class="olMapHelp">'.$this->locale_xhtml("help").'</div>';
798
+            if ($this->getConf('enableA11y')) {
799
+                $renderer->doc .= '<div id="'.$mapid.'-static" class="olStaticMap">'
800
+                    . p_render($format, p_get_instructions($staticImgUrl), $info).'</div>';
801 801
             }
802
-            $renderer->doc .= '<div id="' . $mapid . '-clearer" class="clearer"><p>&nbsp;</p></div>';
803
-            if($this->getConf('enableA11y')) {
802
+            $renderer->doc .= '<div id="'.$mapid.'-clearer" class="clearer"><p>&nbsp;</p></div>';
803
+            if ($this->getConf('enableA11y')) {
804 804
                 // render a table of the POI for the print and a11y presentation, it is hidden using javascript
805
-                $renderer->doc .= '<div class="olPOItableSpan" id="' . $mapid . '-table-span">
806
-                    <table class="olPOItable" id="' . $mapid . '-table">
807
-                    <caption class="olPOITblCaption">' . $this->getLang('olmapPOItitle') . '</caption>
805
+                $renderer->doc .= '<div class="olPOItableSpan" id="'.$mapid.'-table-span">
806
+                    <table class="olPOItable" id="' . $mapid.'-table">
807
+                    <caption class="olPOITblCaption">' . $this->getLang('olmapPOItitle').'</caption>
808 808
                     <thead class="olPOITblHeader">
809 809
                     <tr>
810 810
                     <th class="rowId" scope="col">id</th>
811
-                    <th class="icon" scope="col">' . $this->getLang('olmapPOIicon') . '</th>
812
-                    <th class="lat" scope="col" title="' . $this->getLang('olmapPOIlatTitle') . '">'
813
-                    . $this->getLang('olmapPOIlat') . '</th>
814
-                    <th class="lon" scope="col" title="' . $this->getLang('olmapPOIlonTitle') . '">'
815
-                    . $this->getLang('olmapPOIlon') . '</th>
816
-                    <th class="txt" scope="col">' . $this->getLang('olmapPOItxt') . '</th>
811
+                    <th class="icon" scope="col">' . $this->getLang('olmapPOIicon').'</th>
812
+                    <th class="lat" scope="col" title="' . $this->getLang('olmapPOIlatTitle').'">'
813
+                    . $this->getLang('olmapPOIlat').'</th>
814
+                    <th class="lon" scope="col" title="' . $this->getLang('olmapPOIlonTitle').'">'
815
+                    . $this->getLang('olmapPOIlon').'</th>
816
+                    <th class="txt" scope="col">' . $this->getLang('olmapPOItxt').'</th>
817 817
                     </tr>
818 818
                     </thead>';
819
-                if($poitabledesc != '') {
820
-                    $renderer->doc .= '<tfoot class="olPOITblFooter"><tr><td colspan="5">' . $poitabledesc
819
+                if ($poitabledesc != '') {
820
+                    $renderer->doc .= '<tfoot class="olPOITblFooter"><tr><td colspan="5">'.$poitabledesc
821 821
                         . '</td></tr></tfoot>';
822 822
                 }
823
-                $renderer->doc .= '<tbody class="olPOITblBody">' . $poitable . '</tbody>
823
+                $renderer->doc .= '<tbody class="olPOITblBody">'.$poitable.'</tbody>
824 824
                     </table></div>';
825 825
             }
826 826
             // render inline mapscript parts
@@ -829,28 +829,28 @@  discard block
 block discarded – undo
829 829
             $renderer->doc .= '"></script>';
830 830
             $mapnumber++;
831 831
             return true;
832
-        } elseif($format == 'metadata') {
833
-            if(!(($this->dflt ['lat'] == $mainLat) && ($this->dflt ['lon'] == $mainLon))) {
832
+        } elseif ($format == 'metadata') {
833
+            if (!(($this->dflt ['lat'] == $mainLat) && ($this->dflt ['lon'] == $mainLon))) {
834 834
                 // render geo metadata, unless they are the default
835 835
                 $renderer->meta ['geo'] ['lat'] = $mainLat;
836 836
                 $renderer->meta ['geo'] ['lon'] = $mainLon;
837
-                if($geophp = plugin_load('helper', 'geophp')) {
837
+                if ($geophp = plugin_load('helper', 'geophp')) {
838 838
                     // if we have the geoPHP helper, add the geohash
839 839
 
840 840
                     // fails with older php versions..
841 841
                     // $renderer->meta['geo']['geohash'] = (new Point($mainLon,$mainLat))->out('geohash');
842
-                    $p                                  = new Point ($mainLon, $mainLat);
842
+                    $p                                  = new Point($mainLon, $mainLat);
843 843
                     $renderer->meta ['geo'] ['geohash'] = $p->out('geohash');
844 844
                 }
845 845
             }
846 846
 
847
-            if(($this->getConf('enableA11y')) && (!empty ($_firstimage))) {
847
+            if (($this->getConf('enableA11y')) && (!empty ($_firstimage))) {
848 848
                 // add map local image into relation/firstimage if not already filled and when it is a local image
849 849
 
850 850
                 global $ID;
851 851
                 $rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE);
852 852
                 $img = $rel ['firstimage'];
853
-                if(empty ($img) /* || $img == $_firstimage*/) {
853
+                if (empty ($img) /* || $img == $_firstimage*/) {
854 854
                     //dbglog ( $_firstimage,
855 855
                     // 'olmap::render#rendering image relation metadata for _firstimage as $img was empty or same.' );
856 856
                     // This seems to never work; the firstimage entry in the .meta file is empty
Please login to merge, or discard this patch.
StaticMap.php 3 patches
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -351,14 +351,18 @@  discard block
 block discarded – undo
351 351
     public function makeMap(): void {
352 352
         $this->initCoords();
353 353
         $this->createBaseMap();
354
-        if(!empty ($this->markers))
355
-            $this->placeMarkers();
356
-        if(file_exists($this->kmlFileName))
357
-            $this->drawKML();
358
-        if(file_exists($this->gpxFileName))
359
-            $this->drawGPX();
360
-        if(file_exists($this->geojsonFileName))
361
-            $this->drawGeojson();
354
+        if(!empty ($this->markers)) {
355
+                    $this->placeMarkers();
356
+        }
357
+        if(file_exists($this->kmlFileName)) {
358
+                    $this->drawKML();
359
+        }
360
+        if(file_exists($this->gpxFileName)) {
361
+                    $this->drawGPX();
362
+        }
363
+        if(file_exists($this->geojsonFileName)) {
364
+                    $this->drawGeojson();
365
+        }
362 366
 
363 367
         $this->drawCopyright();
364 368
     }
@@ -448,8 +452,9 @@  discard block
 block discarded – undo
448 452
      * @return bool|string
449 453
      */
450 454
     public function fetchTile(string $url) {
451
-        if($this->useTileCache && ($cached = $this->checkTileCache($url)))
452
-            return $cached;
455
+        if($this->useTileCache && ($cached = $this->checkTileCache($url))) {
456
+                    return $cached;
457
+        }
453 458
 
454 459
         $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')';
455 460
         if(function_exists("curl_init")) {
Please login to merge, or discard this patch.
Indentation   +828 added lines, -828 removed lines patch added patch discarded remove patch
@@ -31,832 +31,832 @@
 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'  => 'http://tile.stamen.com/toner-lite/{Z}/{X}/{Y}.png'
68
-        ),
69
-        'terrain'       => array(
70
-            'txt'  => 'Stamen tiles',
71
-            'logo' => 'stamen.png',
72
-            'url'  => 'http://tile.stamen.com/terrain/{Z}/{X}/{Y}.png'
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
-        $zoomFactorPowered  = ($this->height / 2) / (40.7436654315252 * ($vy1 - $vy0));
301
-        $resolutionVertical = 360 / ($zoomFactorPowered * $this->tileSize);
302
-        // determine horizontal resolution
303
-        $resolutionHorizontal = ($bbox ['maxx'] - $bbox ['minx']) / $this->width;
304
-        $resolution           = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
305
-        $zoom                 = log(360 / ($resolution * $this->tileSize), 2);
306
-
307
-        if(is_finite($zoom) && $zoom < 15 && $zoom > 2) {
308
-            $this->zoom = floor($zoom);
309
-        }
310
-        $this->lon = $centroid->getX();
311
-        $this->lat = $centroid->getY();
312
-        dbglog("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat");
313
-    }
314
-
315
-    public function checkMapCache(): bool {
316
-        // side effect: set the mapCacheID
317
-        $this->mapCacheID = md5($this->serializeParams());
318
-        $filename         = $this->mapCacheIDToFilename();
319
-        return file_exists($filename);
320
-    }
321
-
322
-    public function serializeParams(): string {
323
-        return join(
324
-            "&", array(
325
-                   $this->zoom,
326
-                   $this->lat,
327
-                   $this->lon,
328
-                   $this->width,
329
-                   $this->height,
330
-                   serialize($this->markers),
331
-                   $this->maptype,
332
-                   $this->kmlFileName,
333
-                   $this->gpxFileName,
334
-                   $this->geojsonFileName
335
-               )
336
-        );
337
-    }
338
-
339
-    public function mapCacheIDToFilename(): string {
340
-        if(!$this->mapCacheFile) {
341
-            $this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_"
342
-                . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2)
343
-                . "/" . substr($this->mapCacheID, 4);
344
-        }
345
-        return $this->mapCacheFile . "." . $this->mapCacheExtension;
346
-    }
347
-
348
-    /**
349
-     * make the map.
350
-     */
351
-    public function makeMap(): void {
352
-        $this->initCoords();
353
-        $this->createBaseMap();
354
-        if(!empty ($this->markers))
355
-            $this->placeMarkers();
356
-        if(file_exists($this->kmlFileName))
357
-            $this->drawKML();
358
-        if(file_exists($this->gpxFileName))
359
-            $this->drawGPX();
360
-        if(file_exists($this->geojsonFileName))
361
-            $this->drawGeojson();
362
-
363
-        $this->drawCopyright();
364
-    }
365
-
366
-    /**
367
-     */
368
-    public function initCoords(): void {
369
-        $this->centerX = $this->lonToTile($this->lon, $this->zoom);
370
-        $this->centerY = $this->latToTile($this->lat, $this->zoom);
371
-        $this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize);
372
-        $this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize);
373
-    }
374
-
375
-    /**
376
-     *
377
-     * @param float $long
378
-     * @param int   $zoom
379
-     * @return float|int
380
-     */
381
-    public function lonToTile(float $long, int $zoom) {
382
-        return (($long + 180) / 360) * pow(2, $zoom);
383
-    }
384
-
385
-    /**
386
-     *
387
-     * @param float $lat
388
-     * @param int   $zoom
389
-     * @return float|int
390
-     */
391
-    public function latToTile(float $lat, int $zoom) {
392
-        return (1 - log(tan($lat * pi() / 180) + 1 / cos($lat * M_PI / 180)) / M_PI) / 2 * pow(2, $zoom);
393
-    }
394
-
395
-    /**
396
-     * make basemap image.
397
-     */
398
-    public function createBaseMap(): void {
399
-        $this->image   = imagecreatetruecolor($this->width, $this->height);
400
-        $startX        = floor($this->centerX - ($this->width / $this->tileSize) / 2);
401
-        $startY        = floor($this->centerY - ($this->height / $this->tileSize) / 2);
402
-        $endX          = ceil($this->centerX + ($this->width / $this->tileSize) / 2);
403
-        $endY          = ceil($this->centerY + ($this->height / $this->tileSize) / 2);
404
-        $this->offsetX = -floor(($this->centerX - floor($this->centerX)) * $this->tileSize);
405
-        $this->offsetY = -floor(($this->centerY - floor($this->centerY)) * $this->tileSize);
406
-        $this->offsetX += floor($this->width / 2);
407
-        $this->offsetY += floor($this->height / 2);
408
-        $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize;
409
-        $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize;
410
-
411
-        for($x = $startX; $x <= $endX; $x++) {
412
-            for($y = $startY; $y <= $endY; $y++) {
413
-                $url = str_replace(
414
-                    array(
415
-                        '{Z}',
416
-                        '{X}',
417
-                        '{Y}'
418
-                    ), array(
419
-                        $this->zoom,
420
-                        $x,
421
-                        $y
422
-                    ), $this->tileInfo [$this->maptype] ['url']
423
-                );
424
-
425
-                $tileData = $this->fetchTile($url);
426
-                if($tileData) {
427
-                    $tileImage = imagecreatefromstring($tileData);
428
-                } else {
429
-                    $tileImage = imagecreate($this->tileSize, $this->tileSize);
430
-                    $color     = imagecolorallocate($tileImage, 255, 255, 255);
431
-                    @imagestring($tileImage, 1, 127, 127, 'err', $color);
432
-                }
433
-                $destX = ($x - $startX) * $this->tileSize + $this->offsetX;
434
-                $destY = ($y - $startY) * $this->tileSize + $this->offsetY;
435
-                dbglog($this->tileSize, "imagecopy tile into image: $destX, $destY");
436
-                imagecopy(
437
-                    $this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize,
438
-                    $this->tileSize
439
-                );
440
-            }
441
-        }
442
-    }
443
-
444
-    /**
445
-     * Fetch a tile and (if configured) store it in the cache.
446
-     *
447
-     * @param string $url
448
-     * @return bool|string
449
-     */
450
-    public function fetchTile(string $url) {
451
-        if($this->useTileCache && ($cached = $this->checkTileCache($url)))
452
-            return $cached;
453
-
454
-        $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')';
455
-        if(function_exists("curl_init")) {
456
-            // use cUrl
457
-            $ch = curl_init();
458
-            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
459
-            curl_setopt($ch, CURLOPT_USERAGENT, $_UA);
460
-            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
461
-            curl_setopt($ch, CURLOPT_URL, $url . $this->apikey);
462
-            $tile = curl_exec($ch);
463
-            curl_close($ch);
464
-        } else {
465
-            // use file_get_contents
466
-            global $conf;
467
-            $opts    = array(
468
-                'http' => array(
469
-                    'method'          => "GET",
470
-                    'header'          => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n",
471
-                    'proxy'           => "tcp://" . $conf ['proxy'] ['host'] . ":" . $conf ['proxy'] ['port'],
472
-                    'request_fulluri' => true
473
-                )
474
-            );
475
-            $context = stream_context_create($opts);
476
-            $tile    = file_get_contents($url . $this->apikey, false, $context);
477
-        }
478
-        if($tile && $this->useTileCache) {
479
-            $this->writeTileToCache($url, $tile);
480
-        }
481
-        return $tile;
482
-    }
483
-
484
-    /**
485
-     *
486
-     * @param string $url
487
-     * @return string|false
488
-     */
489
-    public function checkTileCache(string $url) {
490
-        $filename = $this->tileUrlToFilename($url);
491
-        if(file_exists($filename)) {
492
-            return file_get_contents($filename);
493
-        }
494
-        return false;
495
-    }
496
-
497
-    /**
498
-     *
499
-     * @param string $url
500
-     * @return string
501
-     */
502
-    public function tileUrlToFilename(string $url): string {
503
-        return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1);
504
-    }
505
-
506
-    /**
507
-     * Write a tile into the cache.
508
-     *
509
-     * @param string $url
510
-     * @param mixed  $data
511
-     */
512
-    public function writeTileToCache($url, $data): void {
513
-        $filename = $this->tileUrlToFilename($url);
514
-        $this->mkdirRecursive(dirname($filename), 0777);
515
-        file_put_contents($filename, $data);
516
-    }
517
-
518
-    /**
519
-     * Recursively create the directory.
520
-     *
521
-     * @param string $pathname
522
-     *            The directory path.
523
-     * @param int    $mode
524
-     *            File access mode. For more information on modes, read the details on the chmod manpage.
525
-     */
526
-    public function mkdirRecursive(string $pathname, int $mode): bool {
527
-        is_dir(dirname($pathname)) || $this->mkdirRecursive(dirname($pathname), $mode);
528
-        return is_dir($pathname) || mkdir($pathname, $mode) || is_dir($pathname);
529
-    }
530
-
531
-    /**
532
-     * Place markers on the map and number them in the same order as they are listed in the html.
533
-     */
534
-    public function placeMarkers(): void {
535
-        $count         = 0;
536
-        $color         = imagecolorallocate($this->image, 0, 0, 0);
537
-        $bgcolor       = imagecolorallocate($this->image, 200, 200, 200);
538
-        $markerBaseDir = __DIR__ . '/icons';
539
-        // loop thru marker array
540
-        foreach($this->markers as $marker) {
541
-            // set some local variables
542
-            $markerLat  = $marker ['lat'];
543
-            $markerLon  = $marker ['lon'];
544
-            $markerType = $marker ['type'];
545
-            // clear variables from previous loops
546
-            $markerFilename = '';
547
-            $markerShadow   = '';
548
-            $matches        = false;
549
-            // check for marker type, get settings from markerPrototypes
550
-            if($markerType) {
551
-                foreach($this->markerPrototypes as $markerPrototype) {
552
-                    if(preg_match($markerPrototype ['regex'], $markerType, $matches)) {
553
-                        $markerFilename = $matches [0] . $markerPrototype ['extension'];
554
-                        if($markerPrototype ['offsetImage']) {
555
-                            list ($markerImageOffsetX, $markerImageOffsetY) = explode(
556
-                                ",",
557
-                                $markerPrototype ['offsetImage']
558
-                            );
559
-                        }
560
-                        $markerShadow = $markerPrototype ['shadow'];
561
-                        if($markerShadow) {
562
-                            list ($markerShadowOffsetX, $markerShadowOffsetY) = explode(
563
-                                ",",
564
-                                $markerPrototype ['offsetShadow']
565
-                            );
566
-                        }
567
-                    }
568
-                }
569
-            }
570
-            // create img resource
571
-            if(file_exists($markerBaseDir . '/' . $markerFilename)) {
572
-                $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename);
573
-            } else {
574
-                $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png');
575
-            }
576
-            // check for shadow + create shadow recource
577
-            if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) {
578
-                $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow);
579
-            }
580
-            // calc position
581
-            $destX = floor(
582
-                ($this->width / 2) -
583
-                $this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom))
584
-            );
585
-            $destY = floor(
586
-                ($this->height / 2) -
587
-                $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))
588
-            );
589
-            // copy shadow on basemap
590
-            if($markerShadow && $markerShadowImg) {
591
-                imagecopy(
592
-                    $this->image,
593
-                    $markerShadowImg,
594
-                    $destX + (int) $markerShadowOffsetX,
595
-                    $destY + (int) $markerShadowOffsetY,
596
-                    0,
597
-                    0,
598
-                    imagesx($markerShadowImg),
599
-                    imagesy($markerShadowImg)
600
-                );
601
-            }
602
-            // copy marker on basemap above shadow
603
-            imagecopy(
604
-                $this->image,
605
-                $markerImg,
606
-                $destX + (int) $markerImageOffsetX,
607
-                $destY + (int) $markerImageOffsetY,
608
-                0,
609
-                0,
610
-                imagesx($markerImg),
611
-                imagesy($markerImg)
612
-            );
613
-            // add label
614
-            imagestring(
615
-                $this->image,
616
-                3,
617
-                $destX - imagesx($markerImg) + 1,
618
-                $destY + (int) $markerImageOffsetY + 1,
619
-                ++$count,
620
-                $bgcolor
621
-            );
622
-            imagestring(
623
-                $this->image,
624
-                3,
625
-                $destX - imagesx($markerImg),
626
-                $destY + (int) $markerImageOffsetY,
627
-                $count,
628
-                $color
629
-            );
630
-        }
631
-    }
632
-
633
-    /**
634
-     * Draw kml trace on the map.
635
-     */
636
-    public function drawKML(): void {
637
-        // TODO get colour from kml node (not currently supported in geoPHP)
638
-        $col     = imagecolorallocatealpha($this->image, 255, 0, 0, .4 * 127);
639
-        $kmlgeom = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
640
-        $this->drawGeometry($kmlgeom, $col);
641
-    }
642
-
643
-    /**
644
-     * Draw geometry or geometry collection on the map.
645
-     *
646
-     * @param Geometry $geom
647
-     * @param int      $colour
648
-     *            drawing colour
649
-     */
650
-    private function drawGeometry(Geometry $geom, int $colour): void {
651
-        if(empty($geom)) {
652
-            return;
653
-        }
654
-
655
-        switch($geom->geometryType()) {
656
-            case 'GeometryCollection' :
657
-                // recursively draw part of the collection
658
-                for($i = 1; $i < $geom->numGeometries() + 1; $i++) {
659
-                    $_geom = $geom->geometryN($i);
660
-                    $this->drawGeometry($_geom, $colour);
661
-                }
662
-                break;
663
-            case 'MultiPolygon' :
664
-            case 'MultiLineString' :
665
-            case 'MultiPoint' :
666
-                // TODO implement / do nothing
667
-                break;
668
-            case 'Polygon' :
669
-                $this->drawPolygon($geom, $colour);
670
-                break;
671
-            case 'LineString' :
672
-                $this->drawLineString($geom, $colour);
673
-                break;
674
-            case 'Point' :
675
-                $this->drawPoint($geom, $colour);
676
-                break;
677
-            default :
678
-                // draw nothing
679
-                break;
680
-        }
681
-    }
682
-
683
-    /**
684
-     * Draw a polygon on the map.
685
-     *
686
-     * @param Polygon $polygon
687
-     * @param int     $colour
688
-     *            drawing colour
689
-     */
690
-    private function drawPolygon($polygon, int $colour) {
691
-        // TODO implementation of drawing holes,
692
-        // maybe draw the polygon to an in-memory image and use imagecopy, draw polygon in col., draw holes in bgcol?
693
-
694
-        // print_r('Polygon:<br />');
695
-        // print_r($polygon);
696
-        $extPoints = array();
697
-        // extring is a linestring actually..
698
-        $extRing = $polygon->exteriorRing();
699
-
700
-        for($i = 1; $i < $extRing->numGeometries(); $i++) {
701
-            $p1           = $extRing->geometryN($i);
702
-            $x            = floor(
703
-                ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
704
-            );
705
-            $y            = floor(
706
-                ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
707
-            );
708
-            $extPoints [] = $x;
709
-            $extPoints [] = $y;
710
-        }
711
-        // print_r('points:('.($i-1).')<br />');
712
-        // print_r($extPoints);
713
-        // imagepolygon ($this->image, $extPoints, $i-1, $colour );
714
-        imagefilledpolygon($this->image, $extPoints, $i - 1, $colour);
715
-    }
716
-
717
-    /**
718
-     * Draw a line on the map.
719
-     *
720
-     * @param LineString $line
721
-     * @param int        $colour
722
-     *            drawing colour
723
-     */
724
-    private function drawLineString($line, $colour) {
725
-        imagesetthickness($this->image, 2);
726
-        for($p = 1; $p < $line->numGeometries(); $p++) {
727
-            // get first pair of points
728
-            $p1 = $line->geometryN($p);
729
-            $p2 = $line->geometryN($p + 1);
730
-            // translate to paper space
731
-            $x1 = floor(
732
-                ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
733
-            );
734
-            $y1 = floor(
735
-                ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
736
-            );
737
-            $x2 = floor(
738
-                ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p2->x(), $this->zoom))
739
-            );
740
-            $y2 = floor(
741
-                ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p2->y(), $this->zoom))
742
-            );
743
-            // draw to image
744
-            imageline($this->image, $x1, $y1, $x2, $y2, $colour);
745
-        }
746
-        imagesetthickness($this->image, 1);
747
-    }
748
-
749
-    /**
750
-     * Draw a point on the map.
751
-     *
752
-     * @param Point $point
753
-     * @param int   $colour
754
-     *            drawing colour
755
-     */
756
-    private function drawPoint($point, $colour) {
757
-        imagesetthickness($this->image, 2);
758
-        // translate to paper space
759
-        $cx = floor(
760
-            ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($point->x(), $this->zoom))
761
-        );
762
-        $cy = floor(
763
-            ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($point->y(), $this->zoom))
764
-        );
765
-        $r  = 5;
766
-        // draw to image
767
-        // imageellipse($this->image, $cx, $cy,$r, $r, $colour);
768
-        imagefilledellipse($this->image, $cx, $cy, $r, $r, $colour);
769
-        // don't use imageellipse because the imagesetthickness function has
770
-        // no effect. So the better workaround is to use imagearc.
771
-        imagearc($this->image, $cx, $cy, $r, $r, 0, 359, $colour);
772
-        imagesetthickness($this->image, 1);
773
-    }
774
-
775
-    /**
776
-     * Draw gpx trace on the map.
777
-     */
778
-    public function drawGPX() {
779
-        $col     = imagecolorallocatealpha($this->image, 0, 0, 255, .4 * 127);
780
-        $gpxgeom = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
781
-        $this->drawGeometry($gpxgeom, $col);
782
-    }
783
-
784
-    /**
785
-     * Draw geojson on the map.
786
-     */
787
-    public function drawGeojson() {
788
-        $col     = imagecolorallocatealpha($this->image, 255, 0, 255, .4 * 127);
789
-        $gpxgeom = geoPHP::load(file_get_contents($this->geojsonFileName), 'json');
790
-        $this->drawGeometry($gpxgeom, $col);
791
-    }
792
-
793
-    /**
794
-     * add copyright and origin notice and icons to the map.
795
-     */
796
-    public function drawCopyright() {
797
-        $logoBaseDir = dirname(__FILE__) . '/' . 'logo/';
798
-        $logoImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']);
799
-        $textcolor   = imagecolorallocate($this->image, 0, 0, 0);
800
-        $bgcolor     = imagecolorallocate($this->image, 200, 200, 200);
801
-
802
-        imagecopy(
803
-            $this->image,
804
-            $logoImg,
805
-            0,
806
-            imagesy($this->image) - imagesy($logoImg),
807
-            0,
808
-            0,
809
-            imagesx($logoImg),
810
-            imagesy($logoImg)
811
-        );
812
-        imagestring(
813
-            $this->image,
814
-            1,
815
-            imagesx($logoImg) + 2,
816
-            imagesy($this->image) - imagesy($logoImg) + 1,
817
-            $this->tileInfo ['openstreetmap'] ['txt'],
818
-            $bgcolor
819
-        );
820
-        imagestring(
821
-            $this->image,
822
-            1,
823
-            imagesx($logoImg) + 1,
824
-            imagesy($this->image) - imagesy($logoImg),
825
-            $this->tileInfo ['openstreetmap'] ['txt'],
826
-            $textcolor
827
-        );
828
-
829
-        // additional tile source info, ie. who created/hosted the tiles
830
-        $xIconOffset = 0;
831
-        if($this->maptype === 'openstreetmap') {
832
-            $mapAuthor = "(c) OpenStreetMap maps/CC BY-SA";
833
-        } else {
834
-            $mapAuthor   = $this->tileInfo [$this->maptype] ['txt'];
835
-            $iconImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']);
836
-            $xIconOffset = imagesx($iconImg);
837
-            imagecopy(
838
-                $this->image,
839
-                $iconImg, imagesx($logoImg) + 1,
840
-                imagesy($this->image) - imagesy($iconImg),
841
-                0,
842
-                0,
843
-                imagesx($iconImg), imagesy($iconImg)
844
-            );
845
-        }
846
-        imagestring(
847
-            $this->image,
848
-            1, imagesx($logoImg) + $xIconOffset + 4,
849
-            imagesy($this->image) - ceil(imagesy($logoImg) / 2) + 1,
850
-            $mapAuthor,
851
-            $bgcolor
852
-        );
853
-        imagestring(
854
-            $this->image,
855
-            1, imagesx($logoImg) + $xIconOffset + 3,
856
-            imagesy($this->image) - ceil(imagesy($logoImg) / 2),
857
-            $mapAuthor,
858
-            $textcolor
859
-        );
860
-
861
-    }
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'  => 'http://tile.stamen.com/toner-lite/{Z}/{X}/{Y}.png'
68
+		),
69
+		'terrain'       => array(
70
+			'txt'  => 'Stamen tiles',
71
+			'logo' => 'stamen.png',
72
+			'url'  => 'http://tile.stamen.com/terrain/{Z}/{X}/{Y}.png'
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
+		$zoomFactorPowered  = ($this->height / 2) / (40.7436654315252 * ($vy1 - $vy0));
301
+		$resolutionVertical = 360 / ($zoomFactorPowered * $this->tileSize);
302
+		// determine horizontal resolution
303
+		$resolutionHorizontal = ($bbox ['maxx'] - $bbox ['minx']) / $this->width;
304
+		$resolution           = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
305
+		$zoom                 = log(360 / ($resolution * $this->tileSize), 2);
306
+
307
+		if(is_finite($zoom) && $zoom < 15 && $zoom > 2) {
308
+			$this->zoom = floor($zoom);
309
+		}
310
+		$this->lon = $centroid->getX();
311
+		$this->lat = $centroid->getY();
312
+		dbglog("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat");
313
+	}
314
+
315
+	public function checkMapCache(): bool {
316
+		// side effect: set the mapCacheID
317
+		$this->mapCacheID = md5($this->serializeParams());
318
+		$filename         = $this->mapCacheIDToFilename();
319
+		return file_exists($filename);
320
+	}
321
+
322
+	public function serializeParams(): string {
323
+		return join(
324
+			"&", array(
325
+				   $this->zoom,
326
+				   $this->lat,
327
+				   $this->lon,
328
+				   $this->width,
329
+				   $this->height,
330
+				   serialize($this->markers),
331
+				   $this->maptype,
332
+				   $this->kmlFileName,
333
+				   $this->gpxFileName,
334
+				   $this->geojsonFileName
335
+			   )
336
+		);
337
+	}
338
+
339
+	public function mapCacheIDToFilename(): string {
340
+		if(!$this->mapCacheFile) {
341
+			$this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_"
342
+				. substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2)
343
+				. "/" . substr($this->mapCacheID, 4);
344
+		}
345
+		return $this->mapCacheFile . "." . $this->mapCacheExtension;
346
+	}
347
+
348
+	/**
349
+	 * make the map.
350
+	 */
351
+	public function makeMap(): void {
352
+		$this->initCoords();
353
+		$this->createBaseMap();
354
+		if(!empty ($this->markers))
355
+			$this->placeMarkers();
356
+		if(file_exists($this->kmlFileName))
357
+			$this->drawKML();
358
+		if(file_exists($this->gpxFileName))
359
+			$this->drawGPX();
360
+		if(file_exists($this->geojsonFileName))
361
+			$this->drawGeojson();
362
+
363
+		$this->drawCopyright();
364
+	}
365
+
366
+	/**
367
+	 */
368
+	public function initCoords(): void {
369
+		$this->centerX = $this->lonToTile($this->lon, $this->zoom);
370
+		$this->centerY = $this->latToTile($this->lat, $this->zoom);
371
+		$this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize);
372
+		$this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize);
373
+	}
374
+
375
+	/**
376
+	 *
377
+	 * @param float $long
378
+	 * @param int   $zoom
379
+	 * @return float|int
380
+	 */
381
+	public function lonToTile(float $long, int $zoom) {
382
+		return (($long + 180) / 360) * pow(2, $zoom);
383
+	}
384
+
385
+	/**
386
+	 *
387
+	 * @param float $lat
388
+	 * @param int   $zoom
389
+	 * @return float|int
390
+	 */
391
+	public function latToTile(float $lat, int $zoom) {
392
+		return (1 - log(tan($lat * pi() / 180) + 1 / cos($lat * M_PI / 180)) / M_PI) / 2 * pow(2, $zoom);
393
+	}
394
+
395
+	/**
396
+	 * make basemap image.
397
+	 */
398
+	public function createBaseMap(): void {
399
+		$this->image   = imagecreatetruecolor($this->width, $this->height);
400
+		$startX        = floor($this->centerX - ($this->width / $this->tileSize) / 2);
401
+		$startY        = floor($this->centerY - ($this->height / $this->tileSize) / 2);
402
+		$endX          = ceil($this->centerX + ($this->width / $this->tileSize) / 2);
403
+		$endY          = ceil($this->centerY + ($this->height / $this->tileSize) / 2);
404
+		$this->offsetX = -floor(($this->centerX - floor($this->centerX)) * $this->tileSize);
405
+		$this->offsetY = -floor(($this->centerY - floor($this->centerY)) * $this->tileSize);
406
+		$this->offsetX += floor($this->width / 2);
407
+		$this->offsetY += floor($this->height / 2);
408
+		$this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize;
409
+		$this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize;
410
+
411
+		for($x = $startX; $x <= $endX; $x++) {
412
+			for($y = $startY; $y <= $endY; $y++) {
413
+				$url = str_replace(
414
+					array(
415
+						'{Z}',
416
+						'{X}',
417
+						'{Y}'
418
+					), array(
419
+						$this->zoom,
420
+						$x,
421
+						$y
422
+					), $this->tileInfo [$this->maptype] ['url']
423
+				);
424
+
425
+				$tileData = $this->fetchTile($url);
426
+				if($tileData) {
427
+					$tileImage = imagecreatefromstring($tileData);
428
+				} else {
429
+					$tileImage = imagecreate($this->tileSize, $this->tileSize);
430
+					$color     = imagecolorallocate($tileImage, 255, 255, 255);
431
+					@imagestring($tileImage, 1, 127, 127, 'err', $color);
432
+				}
433
+				$destX = ($x - $startX) * $this->tileSize + $this->offsetX;
434
+				$destY = ($y - $startY) * $this->tileSize + $this->offsetY;
435
+				dbglog($this->tileSize, "imagecopy tile into image: $destX, $destY");
436
+				imagecopy(
437
+					$this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize,
438
+					$this->tileSize
439
+				);
440
+			}
441
+		}
442
+	}
443
+
444
+	/**
445
+	 * Fetch a tile and (if configured) store it in the cache.
446
+	 *
447
+	 * @param string $url
448
+	 * @return bool|string
449
+	 */
450
+	public function fetchTile(string $url) {
451
+		if($this->useTileCache && ($cached = $this->checkTileCache($url)))
452
+			return $cached;
453
+
454
+		$_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')';
455
+		if(function_exists("curl_init")) {
456
+			// use cUrl
457
+			$ch = curl_init();
458
+			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
459
+			curl_setopt($ch, CURLOPT_USERAGENT, $_UA);
460
+			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
461
+			curl_setopt($ch, CURLOPT_URL, $url . $this->apikey);
462
+			$tile = curl_exec($ch);
463
+			curl_close($ch);
464
+		} else {
465
+			// use file_get_contents
466
+			global $conf;
467
+			$opts    = array(
468
+				'http' => array(
469
+					'method'          => "GET",
470
+					'header'          => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n",
471
+					'proxy'           => "tcp://" . $conf ['proxy'] ['host'] . ":" . $conf ['proxy'] ['port'],
472
+					'request_fulluri' => true
473
+				)
474
+			);
475
+			$context = stream_context_create($opts);
476
+			$tile    = file_get_contents($url . $this->apikey, false, $context);
477
+		}
478
+		if($tile && $this->useTileCache) {
479
+			$this->writeTileToCache($url, $tile);
480
+		}
481
+		return $tile;
482
+	}
483
+
484
+	/**
485
+	 *
486
+	 * @param string $url
487
+	 * @return string|false
488
+	 */
489
+	public function checkTileCache(string $url) {
490
+		$filename = $this->tileUrlToFilename($url);
491
+		if(file_exists($filename)) {
492
+			return file_get_contents($filename);
493
+		}
494
+		return false;
495
+	}
496
+
497
+	/**
498
+	 *
499
+	 * @param string $url
500
+	 * @return string
501
+	 */
502
+	public function tileUrlToFilename(string $url): string {
503
+		return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1);
504
+	}
505
+
506
+	/**
507
+	 * Write a tile into the cache.
508
+	 *
509
+	 * @param string $url
510
+	 * @param mixed  $data
511
+	 */
512
+	public function writeTileToCache($url, $data): void {
513
+		$filename = $this->tileUrlToFilename($url);
514
+		$this->mkdirRecursive(dirname($filename), 0777);
515
+		file_put_contents($filename, $data);
516
+	}
517
+
518
+	/**
519
+	 * Recursively create the directory.
520
+	 *
521
+	 * @param string $pathname
522
+	 *            The directory path.
523
+	 * @param int    $mode
524
+	 *            File access mode. For more information on modes, read the details on the chmod manpage.
525
+	 */
526
+	public function mkdirRecursive(string $pathname, int $mode): bool {
527
+		is_dir(dirname($pathname)) || $this->mkdirRecursive(dirname($pathname), $mode);
528
+		return is_dir($pathname) || mkdir($pathname, $mode) || is_dir($pathname);
529
+	}
530
+
531
+	/**
532
+	 * Place markers on the map and number them in the same order as they are listed in the html.
533
+	 */
534
+	public function placeMarkers(): void {
535
+		$count         = 0;
536
+		$color         = imagecolorallocate($this->image, 0, 0, 0);
537
+		$bgcolor       = imagecolorallocate($this->image, 200, 200, 200);
538
+		$markerBaseDir = __DIR__ . '/icons';
539
+		// loop thru marker array
540
+		foreach($this->markers as $marker) {
541
+			// set some local variables
542
+			$markerLat  = $marker ['lat'];
543
+			$markerLon  = $marker ['lon'];
544
+			$markerType = $marker ['type'];
545
+			// clear variables from previous loops
546
+			$markerFilename = '';
547
+			$markerShadow   = '';
548
+			$matches        = false;
549
+			// check for marker type, get settings from markerPrototypes
550
+			if($markerType) {
551
+				foreach($this->markerPrototypes as $markerPrototype) {
552
+					if(preg_match($markerPrototype ['regex'], $markerType, $matches)) {
553
+						$markerFilename = $matches [0] . $markerPrototype ['extension'];
554
+						if($markerPrototype ['offsetImage']) {
555
+							list ($markerImageOffsetX, $markerImageOffsetY) = explode(
556
+								",",
557
+								$markerPrototype ['offsetImage']
558
+							);
559
+						}
560
+						$markerShadow = $markerPrototype ['shadow'];
561
+						if($markerShadow) {
562
+							list ($markerShadowOffsetX, $markerShadowOffsetY) = explode(
563
+								",",
564
+								$markerPrototype ['offsetShadow']
565
+							);
566
+						}
567
+					}
568
+				}
569
+			}
570
+			// create img resource
571
+			if(file_exists($markerBaseDir . '/' . $markerFilename)) {
572
+				$markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename);
573
+			} else {
574
+				$markerImg = imagecreatefrompng($markerBaseDir . '/marker.png');
575
+			}
576
+			// check for shadow + create shadow recource
577
+			if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) {
578
+				$markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow);
579
+			}
580
+			// calc position
581
+			$destX = floor(
582
+				($this->width / 2) -
583
+				$this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom))
584
+			);
585
+			$destY = floor(
586
+				($this->height / 2) -
587
+				$this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))
588
+			);
589
+			// copy shadow on basemap
590
+			if($markerShadow && $markerShadowImg) {
591
+				imagecopy(
592
+					$this->image,
593
+					$markerShadowImg,
594
+					$destX + (int) $markerShadowOffsetX,
595
+					$destY + (int) $markerShadowOffsetY,
596
+					0,
597
+					0,
598
+					imagesx($markerShadowImg),
599
+					imagesy($markerShadowImg)
600
+				);
601
+			}
602
+			// copy marker on basemap above shadow
603
+			imagecopy(
604
+				$this->image,
605
+				$markerImg,
606
+				$destX + (int) $markerImageOffsetX,
607
+				$destY + (int) $markerImageOffsetY,
608
+				0,
609
+				0,
610
+				imagesx($markerImg),
611
+				imagesy($markerImg)
612
+			);
613
+			// add label
614
+			imagestring(
615
+				$this->image,
616
+				3,
617
+				$destX - imagesx($markerImg) + 1,
618
+				$destY + (int) $markerImageOffsetY + 1,
619
+				++$count,
620
+				$bgcolor
621
+			);
622
+			imagestring(
623
+				$this->image,
624
+				3,
625
+				$destX - imagesx($markerImg),
626
+				$destY + (int) $markerImageOffsetY,
627
+				$count,
628
+				$color
629
+			);
630
+		}
631
+	}
632
+
633
+	/**
634
+	 * Draw kml trace on the map.
635
+	 */
636
+	public function drawKML(): void {
637
+		// TODO get colour from kml node (not currently supported in geoPHP)
638
+		$col     = imagecolorallocatealpha($this->image, 255, 0, 0, .4 * 127);
639
+		$kmlgeom = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
640
+		$this->drawGeometry($kmlgeom, $col);
641
+	}
642
+
643
+	/**
644
+	 * Draw geometry or geometry collection on the map.
645
+	 *
646
+	 * @param Geometry $geom
647
+	 * @param int      $colour
648
+	 *            drawing colour
649
+	 */
650
+	private function drawGeometry(Geometry $geom, int $colour): void {
651
+		if(empty($geom)) {
652
+			return;
653
+		}
654
+
655
+		switch($geom->geometryType()) {
656
+			case 'GeometryCollection' :
657
+				// recursively draw part of the collection
658
+				for($i = 1; $i < $geom->numGeometries() + 1; $i++) {
659
+					$_geom = $geom->geometryN($i);
660
+					$this->drawGeometry($_geom, $colour);
661
+				}
662
+				break;
663
+			case 'MultiPolygon' :
664
+			case 'MultiLineString' :
665
+			case 'MultiPoint' :
666
+				// TODO implement / do nothing
667
+				break;
668
+			case 'Polygon' :
669
+				$this->drawPolygon($geom, $colour);
670
+				break;
671
+			case 'LineString' :
672
+				$this->drawLineString($geom, $colour);
673
+				break;
674
+			case 'Point' :
675
+				$this->drawPoint($geom, $colour);
676
+				break;
677
+			default :
678
+				// draw nothing
679
+				break;
680
+		}
681
+	}
682
+
683
+	/**
684
+	 * Draw a polygon on the map.
685
+	 *
686
+	 * @param Polygon $polygon
687
+	 * @param int     $colour
688
+	 *            drawing colour
689
+	 */
690
+	private function drawPolygon($polygon, int $colour) {
691
+		// TODO implementation of drawing holes,
692
+		// maybe draw the polygon to an in-memory image and use imagecopy, draw polygon in col., draw holes in bgcol?
693
+
694
+		// print_r('Polygon:<br />');
695
+		// print_r($polygon);
696
+		$extPoints = array();
697
+		// extring is a linestring actually..
698
+		$extRing = $polygon->exteriorRing();
699
+
700
+		for($i = 1; $i < $extRing->numGeometries(); $i++) {
701
+			$p1           = $extRing->geometryN($i);
702
+			$x            = floor(
703
+				($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
704
+			);
705
+			$y            = floor(
706
+				($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
707
+			);
708
+			$extPoints [] = $x;
709
+			$extPoints [] = $y;
710
+		}
711
+		// print_r('points:('.($i-1).')<br />');
712
+		// print_r($extPoints);
713
+		// imagepolygon ($this->image, $extPoints, $i-1, $colour );
714
+		imagefilledpolygon($this->image, $extPoints, $i - 1, $colour);
715
+	}
716
+
717
+	/**
718
+	 * Draw a line on the map.
719
+	 *
720
+	 * @param LineString $line
721
+	 * @param int        $colour
722
+	 *            drawing colour
723
+	 */
724
+	private function drawLineString($line, $colour) {
725
+		imagesetthickness($this->image, 2);
726
+		for($p = 1; $p < $line->numGeometries(); $p++) {
727
+			// get first pair of points
728
+			$p1 = $line->geometryN($p);
729
+			$p2 = $line->geometryN($p + 1);
730
+			// translate to paper space
731
+			$x1 = floor(
732
+				($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
733
+			);
734
+			$y1 = floor(
735
+				($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
736
+			);
737
+			$x2 = floor(
738
+				($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p2->x(), $this->zoom))
739
+			);
740
+			$y2 = floor(
741
+				($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p2->y(), $this->zoom))
742
+			);
743
+			// draw to image
744
+			imageline($this->image, $x1, $y1, $x2, $y2, $colour);
745
+		}
746
+		imagesetthickness($this->image, 1);
747
+	}
748
+
749
+	/**
750
+	 * Draw a point on the map.
751
+	 *
752
+	 * @param Point $point
753
+	 * @param int   $colour
754
+	 *            drawing colour
755
+	 */
756
+	private function drawPoint($point, $colour) {
757
+		imagesetthickness($this->image, 2);
758
+		// translate to paper space
759
+		$cx = floor(
760
+			($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($point->x(), $this->zoom))
761
+		);
762
+		$cy = floor(
763
+			($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($point->y(), $this->zoom))
764
+		);
765
+		$r  = 5;
766
+		// draw to image
767
+		// imageellipse($this->image, $cx, $cy,$r, $r, $colour);
768
+		imagefilledellipse($this->image, $cx, $cy, $r, $r, $colour);
769
+		// don't use imageellipse because the imagesetthickness function has
770
+		// no effect. So the better workaround is to use imagearc.
771
+		imagearc($this->image, $cx, $cy, $r, $r, 0, 359, $colour);
772
+		imagesetthickness($this->image, 1);
773
+	}
774
+
775
+	/**
776
+	 * Draw gpx trace on the map.
777
+	 */
778
+	public function drawGPX() {
779
+		$col     = imagecolorallocatealpha($this->image, 0, 0, 255, .4 * 127);
780
+		$gpxgeom = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
781
+		$this->drawGeometry($gpxgeom, $col);
782
+	}
783
+
784
+	/**
785
+	 * Draw geojson on the map.
786
+	 */
787
+	public function drawGeojson() {
788
+		$col     = imagecolorallocatealpha($this->image, 255, 0, 255, .4 * 127);
789
+		$gpxgeom = geoPHP::load(file_get_contents($this->geojsonFileName), 'json');
790
+		$this->drawGeometry($gpxgeom, $col);
791
+	}
792
+
793
+	/**
794
+	 * add copyright and origin notice and icons to the map.
795
+	 */
796
+	public function drawCopyright() {
797
+		$logoBaseDir = dirname(__FILE__) . '/' . 'logo/';
798
+		$logoImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']);
799
+		$textcolor   = imagecolorallocate($this->image, 0, 0, 0);
800
+		$bgcolor     = imagecolorallocate($this->image, 200, 200, 200);
801
+
802
+		imagecopy(
803
+			$this->image,
804
+			$logoImg,
805
+			0,
806
+			imagesy($this->image) - imagesy($logoImg),
807
+			0,
808
+			0,
809
+			imagesx($logoImg),
810
+			imagesy($logoImg)
811
+		);
812
+		imagestring(
813
+			$this->image,
814
+			1,
815
+			imagesx($logoImg) + 2,
816
+			imagesy($this->image) - imagesy($logoImg) + 1,
817
+			$this->tileInfo ['openstreetmap'] ['txt'],
818
+			$bgcolor
819
+		);
820
+		imagestring(
821
+			$this->image,
822
+			1,
823
+			imagesx($logoImg) + 1,
824
+			imagesy($this->image) - imagesy($logoImg),
825
+			$this->tileInfo ['openstreetmap'] ['txt'],
826
+			$textcolor
827
+		);
828
+
829
+		// additional tile source info, ie. who created/hosted the tiles
830
+		$xIconOffset = 0;
831
+		if($this->maptype === 'openstreetmap') {
832
+			$mapAuthor = "(c) OpenStreetMap maps/CC BY-SA";
833
+		} else {
834
+			$mapAuthor   = $this->tileInfo [$this->maptype] ['txt'];
835
+			$iconImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']);
836
+			$xIconOffset = imagesx($iconImg);
837
+			imagecopy(
838
+				$this->image,
839
+				$iconImg, imagesx($logoImg) + 1,
840
+				imagesy($this->image) - imagesy($iconImg),
841
+				0,
842
+				0,
843
+				imagesx($iconImg), imagesy($iconImg)
844
+			);
845
+		}
846
+		imagestring(
847
+			$this->image,
848
+			1, imagesx($logoImg) + $xIconOffset + 4,
849
+			imagesy($this->image) - ceil(imagesy($logoImg) / 2) + 1,
850
+			$mapAuthor,
851
+			$bgcolor
852
+		);
853
+		imagestring(
854
+			$this->image,
855
+			1, imagesx($logoImg) + $xIconOffset + 3,
856
+			imagesy($this->image) - ceil(imagesy($logoImg) / 2),
857
+			$mapAuthor,
858
+			$textcolor
859
+		);
860
+
861
+	}
862 862
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 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
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         $resolution           = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
305 305
         $zoom                 = log(360 / ($resolution * $this->tileSize), 2);
306 306
 
307
-        if(is_finite($zoom) && $zoom < 15 && $zoom > 2) {
307
+        if (is_finite($zoom) && $zoom < 15 && $zoom > 2) {
308 308
             $this->zoom = floor($zoom);
309 309
         }
310 310
         $this->lon = $centroid->getX();
@@ -337,12 +337,12 @@  discard block
 block discarded – undo
337 337
     }
338 338
 
339 339
     public function mapCacheIDToFilename(): string {
340
-        if(!$this->mapCacheFile) {
341
-            $this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_"
342
-                . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2)
343
-                . "/" . substr($this->mapCacheID, 4);
340
+        if (!$this->mapCacheFile) {
341
+            $this->mapCacheFile = $this->mapCacheBaseDir."/".$this->maptype."/".$this->zoom."/cache_"
342
+                . substr($this->mapCacheID, 0, 2)."/".substr($this->mapCacheID, 2, 2)
343
+                . "/".substr($this->mapCacheID, 4);
344 344
         }
345
-        return $this->mapCacheFile . "." . $this->mapCacheExtension;
345
+        return $this->mapCacheFile.".".$this->mapCacheExtension;
346 346
     }
347 347
 
348 348
     /**
@@ -351,13 +351,13 @@  discard block
 block discarded – undo
351 351
     public function makeMap(): void {
352 352
         $this->initCoords();
353 353
         $this->createBaseMap();
354
-        if(!empty ($this->markers))
354
+        if (!empty ($this->markers))
355 355
             $this->placeMarkers();
356
-        if(file_exists($this->kmlFileName))
356
+        if (file_exists($this->kmlFileName))
357 357
             $this->drawKML();
358
-        if(file_exists($this->gpxFileName))
358
+        if (file_exists($this->gpxFileName))
359 359
             $this->drawGPX();
360
-        if(file_exists($this->geojsonFileName))
360
+        if (file_exists($this->geojsonFileName))
361 361
             $this->drawGeojson();
362 362
 
363 363
         $this->drawCopyright();
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
         $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize;
409 409
         $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize;
410 410
 
411
-        for($x = $startX; $x <= $endX; $x++) {
412
-            for($y = $startY; $y <= $endY; $y++) {
411
+        for ($x = $startX; $x <= $endX; $x++) {
412
+            for ($y = $startY; $y <= $endY; $y++) {
413 413
                 $url = str_replace(
414 414
                     array(
415 415
                         '{Z}',
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
                 );
424 424
 
425 425
                 $tileData = $this->fetchTile($url);
426
-                if($tileData) {
426
+                if ($tileData) {
427 427
                     $tileImage = imagecreatefromstring($tileData);
428 428
                 } else {
429 429
                     $tileImage = imagecreate($this->tileSize, $this->tileSize);
@@ -448,34 +448,34 @@  discard block
 block discarded – undo
448 448
      * @return bool|string
449 449
      */
450 450
     public function fetchTile(string $url) {
451
-        if($this->useTileCache && ($cached = $this->checkTileCache($url)))
451
+        if ($this->useTileCache && ($cached = $this->checkTileCache($url)))
452 452
             return $cached;
453 453
 
454
-        $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')';
455
-        if(function_exists("curl_init")) {
454
+        $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; '.PHP_OS.')';
455
+        if (function_exists("curl_init")) {
456 456
             // use cUrl
457 457
             $ch = curl_init();
458 458
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
459 459
             curl_setopt($ch, CURLOPT_USERAGENT, $_UA);
460 460
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
461
-            curl_setopt($ch, CURLOPT_URL, $url . $this->apikey);
461
+            curl_setopt($ch, CURLOPT_URL, $url.$this->apikey);
462 462
             $tile = curl_exec($ch);
463 463
             curl_close($ch);
464 464
         } else {
465 465
             // use file_get_contents
466 466
             global $conf;
467
-            $opts    = array(
467
+            $opts = array(
468 468
                 'http' => array(
469 469
                     'method'          => "GET",
470
-                    'header'          => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n",
471
-                    'proxy'           => "tcp://" . $conf ['proxy'] ['host'] . ":" . $conf ['proxy'] ['port'],
470
+                    'header'          => "Accept-language: en\r\n"."User-Agent: $_UA\r\n"."accept: image/png\r\n",
471
+                    'proxy'           => "tcp://".$conf ['proxy'] ['host'].":".$conf ['proxy'] ['port'],
472 472
                     'request_fulluri' => true
473 473
                 )
474 474
             );
475 475
             $context = stream_context_create($opts);
476
-            $tile    = file_get_contents($url . $this->apikey, false, $context);
476
+            $tile    = file_get_contents($url.$this->apikey, false, $context);
477 477
         }
478
-        if($tile && $this->useTileCache) {
478
+        if ($tile && $this->useTileCache) {
479 479
             $this->writeTileToCache($url, $tile);
480 480
         }
481 481
         return $tile;
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
      */
489 489
     public function checkTileCache(string $url) {
490 490
         $filename = $this->tileUrlToFilename($url);
491
-        if(file_exists($filename)) {
491
+        if (file_exists($filename)) {
492 492
             return file_get_contents($filename);
493 493
         }
494 494
         return false;
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
      * @return string
501 501
      */
502 502
     public function tileUrlToFilename(string $url): string {
503
-        return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1);
503
+        return $this->tileCacheBaseDir."/".substr($url, strpos($url, '/') + 1);
504 504
     }
505 505
 
506 506
     /**
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
         $count         = 0;
536 536
         $color         = imagecolorallocate($this->image, 0, 0, 0);
537 537
         $bgcolor       = imagecolorallocate($this->image, 200, 200, 200);
538
-        $markerBaseDir = __DIR__ . '/icons';
538
+        $markerBaseDir = __DIR__.'/icons';
539 539
         // loop thru marker array
540
-        foreach($this->markers as $marker) {
540
+        foreach ($this->markers as $marker) {
541 541
             // set some local variables
542 542
             $markerLat  = $marker ['lat'];
543 543
             $markerLon  = $marker ['lon'];
@@ -547,18 +547,18 @@  discard block
 block discarded – undo
547 547
             $markerShadow   = '';
548 548
             $matches        = false;
549 549
             // check for marker type, get settings from markerPrototypes
550
-            if($markerType) {
551
-                foreach($this->markerPrototypes as $markerPrototype) {
552
-                    if(preg_match($markerPrototype ['regex'], $markerType, $matches)) {
553
-                        $markerFilename = $matches [0] . $markerPrototype ['extension'];
554
-                        if($markerPrototype ['offsetImage']) {
550
+            if ($markerType) {
551
+                foreach ($this->markerPrototypes as $markerPrototype) {
552
+                    if (preg_match($markerPrototype ['regex'], $markerType, $matches)) {
553
+                        $markerFilename = $matches [0].$markerPrototype ['extension'];
554
+                        if ($markerPrototype ['offsetImage']) {
555 555
                             list ($markerImageOffsetX, $markerImageOffsetY) = explode(
556 556
                                 ",",
557 557
                                 $markerPrototype ['offsetImage']
558 558
                             );
559 559
                         }
560 560
                         $markerShadow = $markerPrototype ['shadow'];
561
-                        if($markerShadow) {
561
+                        if ($markerShadow) {
562 562
                             list ($markerShadowOffsetX, $markerShadowOffsetY) = explode(
563 563
                                 ",",
564 564
                                 $markerPrototype ['offsetShadow']
@@ -568,14 +568,14 @@  discard block
 block discarded – undo
568 568
                 }
569 569
             }
570 570
             // create img resource
571
-            if(file_exists($markerBaseDir . '/' . $markerFilename)) {
572
-                $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename);
571
+            if (file_exists($markerBaseDir.'/'.$markerFilename)) {
572
+                $markerImg = imagecreatefrompng($markerBaseDir.'/'.$markerFilename);
573 573
             } else {
574
-                $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png');
574
+                $markerImg = imagecreatefrompng($markerBaseDir.'/marker.png');
575 575
             }
576 576
             // check for shadow + create shadow recource
577
-            if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) {
578
-                $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow);
577
+            if ($markerShadow && file_exists($markerBaseDir.'/'.$markerShadow)) {
578
+                $markerShadowImg = imagecreatefrompng($markerBaseDir.'/'.$markerShadow);
579 579
             }
580 580
             // calc position
581 581
             $destX = floor(
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
                 $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))
588 588
             );
589 589
             // copy shadow on basemap
590
-            if($markerShadow && $markerShadowImg) {
590
+            if ($markerShadow && $markerShadowImg) {
591 591
                 imagecopy(
592 592
                     $this->image,
593 593
                     $markerShadowImg,
@@ -648,14 +648,14 @@  discard block
 block discarded – undo
648 648
      *            drawing colour
649 649
      */
650 650
     private function drawGeometry(Geometry $geom, int $colour): void {
651
-        if(empty($geom)) {
651
+        if (empty($geom)) {
652 652
             return;
653 653
         }
654 654
 
655
-        switch($geom->geometryType()) {
655
+        switch ($geom->geometryType()) {
656 656
             case 'GeometryCollection' :
657 657
                 // recursively draw part of the collection
658
-                for($i = 1; $i < $geom->numGeometries() + 1; $i++) {
658
+                for ($i = 1; $i < $geom->numGeometries() + 1; $i++) {
659 659
                     $_geom = $geom->geometryN($i);
660 660
                     $this->drawGeometry($_geom, $colour);
661 661
                 }
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
         // extring is a linestring actually..
698 698
         $extRing = $polygon->exteriorRing();
699 699
 
700
-        for($i = 1; $i < $extRing->numGeometries(); $i++) {
700
+        for ($i = 1; $i < $extRing->numGeometries(); $i++) {
701 701
             $p1           = $extRing->geometryN($i);
702 702
             $x            = floor(
703 703
                 ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
      */
724 724
     private function drawLineString($line, $colour) {
725 725
         imagesetthickness($this->image, 2);
726
-        for($p = 1; $p < $line->numGeometries(); $p++) {
726
+        for ($p = 1; $p < $line->numGeometries(); $p++) {
727 727
             // get first pair of points
728 728
             $p1 = $line->geometryN($p);
729 729
             $p2 = $line->geometryN($p + 1);
@@ -794,8 +794,8 @@  discard block
 block discarded – undo
794 794
      * add copyright and origin notice and icons to the map.
795 795
      */
796 796
     public function drawCopyright() {
797
-        $logoBaseDir = dirname(__FILE__) . '/' . 'logo/';
798
-        $logoImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']);
797
+        $logoBaseDir = dirname(__FILE__).'/'.'logo/';
798
+        $logoImg     = imagecreatefrompng($logoBaseDir.$this->tileInfo ['openstreetmap'] ['logo']);
799 799
         $textcolor   = imagecolorallocate($this->image, 0, 0, 0);
800 800
         $bgcolor     = imagecolorallocate($this->image, 200, 200, 200);
801 801
 
@@ -828,11 +828,11 @@  discard block
 block discarded – undo
828 828
 
829 829
         // additional tile source info, ie. who created/hosted the tiles
830 830
         $xIconOffset = 0;
831
-        if($this->maptype === 'openstreetmap') {
831
+        if ($this->maptype === 'openstreetmap') {
832 832
             $mapAuthor = "(c) OpenStreetMap maps/CC BY-SA";
833 833
         } else {
834 834
             $mapAuthor   = $this->tileInfo [$this->maptype] ['txt'];
835
-            $iconImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']);
835
+            $iconImg     = imagecreatefrompng($logoBaseDir.$this->tileInfo [$this->maptype] ['logo']);
836 836
             $xIconOffset = imagesx($iconImg);
837 837
             imagecopy(
838 838
                 $this->image,
Please login to merge, or discard this patch.