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