| Total Complexity | 106 |
| Total Lines | 821 |
| Duplicated Lines | 0 % |
| Changes | 70 | ||
| Bugs | 13 | Features | 9 |
Complex classes like syntax_plugin_openlayersmap_olmap often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use syntax_plugin_openlayersmap_olmap, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class syntax_plugin_openlayersmap_olmap extends SyntaxPlugin |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * defaults of the known attributes of the olmap tag. |
||
| 33 | */ |
||
| 34 | private $dflt = ['id' => 'olmap', 'width' => '550px', 'height' => '450px', 'lat' => 50.0, 'lon' => 5.1, 'zoom' => 12, 'autozoom' => 1, 'controls' => true, 'baselyr' => 'OpenStreetMap', 'gpxfile' => '', 'kmlfile' => '', 'geojsonfile' => '', 'summary' => '']; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * |
||
| 38 | * @see DokuWiki_Syntax_Plugin::getType() |
||
| 39 | */ |
||
| 40 | public function getType(): string |
||
| 41 | { |
||
| 42 | return 'substition'; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * |
||
| 47 | * @see DokuWiki_Syntax_Plugin::getPType() |
||
| 48 | */ |
||
| 49 | public function getPType(): string |
||
| 50 | { |
||
| 51 | return 'block'; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * |
||
| 56 | * @see Doku_Parser_Mode::getSort() |
||
| 57 | */ |
||
| 58 | public function getSort(): int |
||
| 59 | { |
||
| 60 | return 901; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * |
||
| 65 | * @see Doku_Parser_Mode::connectTo() |
||
| 66 | */ |
||
| 67 | public function connectTo($mode) |
||
| 68 | { |
||
| 69 | $this->Lexer->addSpecialPattern( |
||
| 70 | '<olmap ?[^>\n]*>.*?</olmap>', |
||
| 71 | $mode, |
||
| 72 | 'plugin_openlayersmap_olmap' |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * |
||
| 78 | * @see DokuWiki_Syntax_Plugin::handle() |
||
| 79 | */ |
||
| 80 | public function handle($match, $state, $pos, Doku_Handler $handler): array |
||
| 81 | { |
||
| 82 | // break matched data into its components |
||
| 83 | $_tag = explode('>', substr($match, 7, -9), 2); |
||
| 84 | $str_params = $_tag[0]; |
||
| 85 | if (array_key_exists(1, $_tag)) { |
||
| 86 | $str_points = $_tag[1]; |
||
| 87 | } else { |
||
| 88 | $str_points = ''; |
||
| 89 | } |
||
| 90 | // get the lat/lon for adding them to the metadata (used by geotag) |
||
| 91 | preg_match('(lat[:|=]\"-?\d*\.?\d*\")', $match, $mainLat); |
||
| 92 | preg_match('(lon[:|=]\"-?\d*\.?\d*\")', $match, $mainLon); |
||
| 93 | $mainLat = substr($mainLat [0], 5, -1); |
||
| 94 | $mainLon = substr($mainLon [0], 5, -1); |
||
| 95 | if (!is_numeric($mainLat)) { |
||
| 96 | $mainLat = $this->dflt ['lat']; |
||
| 97 | } |
||
| 98 | if (!is_numeric($mainLon)) { |
||
| 99 | $mainLon = $this->dflt ['lon']; |
||
| 100 | } |
||
| 101 | |||
| 102 | $gmap = $this->extractParams($str_params); |
||
| 103 | $overlay = $this->extractPoints($str_points); |
||
| 104 | $_firstimageID = ''; |
||
| 105 | |||
| 106 | $_nocache = false; |
||
| 107 | // choose maptype based on the specified tag |
||
| 108 | $imgUrl = "{{"; |
||
| 109 | if (stripos($gmap ['baselyr'], 'google') !== false) { |
||
| 110 | |||
| 111 | $imgUrl .= $this->getGoogle($gmap, $overlay); |
||
| 112 | $imgUrl .= "&.png"; |
||
| 113 | } elseif (stripos($gmap ['baselyr'], 'bing') !== false) { |
||
| 114 | // Bing |
||
| 115 | if (!$this->getConf('bingAPIKey')) { |
||
| 116 | // in case there is no Bing api key we'll use OSM |
||
| 117 | $_firstimageID = $this->getStaticOSM($gmap, $overlay); |
||
| 118 | $imgUrl .= $_firstimageID; |
||
| 119 | if ($this->getConf('optionStaticMapGenerator') == 'remote') { |
||
| 120 | $imgUrl .= "&.png"; |
||
| 121 | } |
||
| 122 | } else { |
||
| 123 | // seems that Bing doesn't like the DW client, turn off caching |
||
| 124 | $_nocache = true; |
||
| 125 | $imgUrl .= $this->getBing($gmap, $overlay) . "&.png"; |
||
| 126 | } |
||
| 127 | } /* elseif (stripos ( $gmap ['baselyr'], 'mapquest' ) !== false) { |
||
| 128 | // MapQuest |
||
| 129 | if (! $this->getConf ( 'mapquestAPIKey' )) { |
||
| 130 | // no API key for MapQuest, use OSM |
||
| 131 | $_firstimageID = $this->getStaticOSM ( $gmap, $overlay ); |
||
| 132 | $imgUrl .= $_firstimageID; |
||
| 133 | if ($this->getConf ( 'optionStaticMapGenerator' ) == 'remote') { |
||
| 134 | $imgUrl .= "&.png"; |
||
| 135 | } |
||
| 136 | } else { |
||
| 137 | $imgUrl .= $this->_getMapQuest ( $gmap, $overlay ); |
||
| 138 | $imgUrl .= "&.png"; |
||
| 139 | } |
||
| 140 | } */ else { |
||
| 141 | // default OSM |
||
| 142 | $_firstimageID = $this->getStaticOSM($gmap, $overlay); |
||
| 143 | $imgUrl .= $_firstimageID; |
||
| 144 | if ($this->getConf('optionStaticMapGenerator') == 'remote') { |
||
| 145 | $imgUrl .= "&.png"; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | // append dw p_render specific params and render |
||
| 150 | $imgUrl .= "?" . str_replace("px", "", $gmap ['width']) . "x" |
||
| 151 | . str_replace("px", "", $gmap ['height']); |
||
| 152 | $imgUrl .= "&nolink"; |
||
| 153 | |||
| 154 | // add nocache option for selected services |
||
| 155 | if ($_nocache) { |
||
| 156 | $imgUrl .= "&nocache"; |
||
| 157 | } |
||
| 158 | |||
| 159 | $imgUrl .= " |" . $gmap ['summary'] . " }}"; |
||
| 160 | |||
| 161 | // dbglog($imgUrl,"complete image tags is:"); |
||
| 162 | |||
| 163 | $mapid = $gmap ['id']; |
||
| 164 | // create a javascript parameter string for the map |
||
| 165 | $param = ''; |
||
| 166 | foreach ($gmap as $key => $val) { |
||
| 167 | $param .= is_numeric($val) ? "$key: $val, " : "$key: '" . hsc($val) . "', "; |
||
| 168 | } |
||
| 169 | if (!empty($param)) { |
||
| 170 | $param = substr($param, 0, -2); |
||
| 171 | } |
||
| 172 | unset($gmap ['id']); |
||
| 173 | |||
| 174 | // create a javascript serialisation of the point data |
||
| 175 | $poi = ''; |
||
| 176 | $poitable = ''; |
||
| 177 | $rowId = 0; |
||
| 178 | if ($overlay !== []) { |
||
| 179 | foreach ($overlay as $data) { |
||
| 180 | [$lat, $lon, $text, $angle, $opacity, $img] = $data; |
||
| 181 | $rowId++; |
||
| 182 | $poi .= ", {lat:$lat,lon:$lon,txt:'$text',angle:$angle,opacity:$opacity,img:'$img',rowId: $rowId}"; |
||
| 183 | |||
| 184 | if ($this->getConf('displayformat') === 'DMS') { |
||
| 185 | $lat = $this->convertLat($lat); |
||
| 186 | $lon = $this->convertLon($lon); |
||
| 187 | } else { |
||
| 188 | $lat .= 'º'; |
||
| 189 | $lon .= 'º'; |
||
| 190 | } |
||
| 191 | |||
| 192 | $poitable .= ' |
||
| 193 | <tr> |
||
| 194 | <td class="rowId">' . $rowId . '</td> |
||
| 195 | <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/icons/' . $img . '" alt="' |
||
| 196 | . substr($img, 0, -4) . $this->getlang('alt_legend_poi') . '" /></td> |
||
| 197 | <td class="lat" title="' . $this->getLang('olmapPOIlatTitle') . '">' . $lat . '</td> |
||
| 198 | <td class="lon" title="' . $this->getLang('olmapPOIlonTitle') . '">' . $lon . '</td> |
||
| 199 | <td class="txt">' . $text . '</td> |
||
| 200 | </tr>'; |
||
| 201 | } |
||
| 202 | $poi = substr($poi, 2); |
||
| 203 | } |
||
| 204 | if (!empty($gmap ['kmlfile'])) { |
||
| 205 | $poitable .= ' |
||
| 206 | <tr> |
||
| 207 | <td class="rowId"><img src="' . DOKU_BASE |
||
| 208 | . 'lib/plugins/openlayersmap/toolbar/kml_file.png" alt="KML file" /></td> |
||
| 209 | <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/kml_line.png" alt="' |
||
| 210 | . $this->getlang('alt_legend_kml') . '" /></td> |
||
| 211 | <td class="txt" colspan="3">KML track: ' . $this->getFileName($gmap ['kmlfile']) . '</td> |
||
| 212 | </tr>'; |
||
| 213 | } |
||
| 214 | if (!empty($gmap ['gpxfile'])) { |
||
| 215 | $poitable .= ' |
||
| 216 | <tr> |
||
| 217 | <td class="rowId"><img src="' . DOKU_BASE |
||
| 218 | . 'lib/plugins/openlayersmap/toolbar/gpx_file.png" alt="GPX file" /></td> |
||
| 219 | <td class="icon"><img src="' . DOKU_BASE |
||
| 220 | . 'lib/plugins/openlayersmap/toolbar/gpx_line.png" alt="' |
||
| 221 | . $this->getlang('alt_legend_gpx') . '" /></td> |
||
| 222 | <td class="txt" colspan="3">GPX track: ' . $this->getFileName($gmap ['gpxfile']) . '</td> |
||
| 223 | </tr>'; |
||
| 224 | } |
||
| 225 | if (!empty($gmap ['geojsonfile'])) { |
||
| 226 | $poitable .= ' |
||
| 227 | <tr> |
||
| 228 | <td class="rowId"><img src="' . DOKU_BASE |
||
| 229 | . 'lib/plugins/openlayersmap/toolbar/geojson_file.png" alt="GeoJSON file" /></td> |
||
| 230 | <td class="icon"><img src="' . DOKU_BASE |
||
| 231 | . 'lib/plugins/openlayersmap/toolbar/geojson_line.png" alt="' |
||
| 232 | . $this->getlang('alt_legend_geojson') . '" /></td> |
||
| 233 | <td class="txt" colspan="3">GeoJSON track: ' . $this->getFileName($gmap ['geojsonfile']) . '</td> |
||
| 234 | </tr>'; |
||
| 235 | } |
||
| 236 | |||
| 237 | $autozoom = empty($gmap ['autozoom']) ? $this->getConf('autoZoomMap') : $gmap ['autozoom']; |
||
| 238 | $js = "{mapOpts: {" . $param . ", displayformat: '" . $this->getConf('displayformat') |
||
| 239 | . "', autozoom: " . $autozoom . "}, poi: [$poi]};"; |
||
| 240 | // unescape the json |
||
| 241 | $poitable = stripslashes($poitable); |
||
| 242 | |||
| 243 | return [$mapid, $js, $mainLat, $mainLon, $poitable, $gmap ['summary'], $imgUrl, $_firstimageID]; |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * extract parameters for the map from the parameter string |
||
| 248 | * |
||
| 249 | * @param string $str_params |
||
| 250 | * string of key="value" pairs |
||
| 251 | * @return array associative array of parameters key=>value |
||
| 252 | */ |
||
| 253 | private function extractParams(string $str_params): array |
||
| 254 | { |
||
| 255 | $param = []; |
||
| 256 | preg_match_all('/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER); |
||
| 257 | // parse match for instructions, break into key value pairs |
||
| 258 | $gmap = $this->dflt; |
||
| 259 | foreach ($gmap as $key => &$value) { |
||
| 260 | $defval = $this->getConf('default_' . $key); |
||
| 261 | if ($defval !== '') { |
||
| 262 | $value = $defval; |
||
| 263 | } |
||
| 264 | } |
||
| 265 | unset($value); |
||
| 266 | foreach ($param as $kvpair) { |
||
| 267 | [$match, $key, $val] = $kvpair; |
||
| 268 | $key = strtolower($key); |
||
| 269 | if (isset($gmap [$key])) { |
||
| 270 | if ($key == 'summary') { |
||
| 271 | // preserve case for summary field |
||
| 272 | $gmap [$key] = $val; |
||
| 273 | } elseif ($key == 'id') { |
||
| 274 | // preserve case for id field |
||
| 275 | $gmap [$key] = $val; |
||
| 276 | } else { |
||
| 277 | $gmap [$key] = strtolower($val); |
||
| 278 | } |
||
| 279 | } |
||
| 280 | } |
||
| 281 | return $gmap; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * extract overlay points for the map from the wiki syntax data |
||
| 286 | * |
||
| 287 | * @param string $str_points |
||
| 288 | * multi-line string of lat,lon,text triplets |
||
| 289 | * @return array multi-dimensional array of lat,lon,text triplets |
||
| 290 | */ |
||
| 291 | private function extractPoints(string $str_points): array |
||
| 292 | { |
||
| 293 | $point = []; |
||
| 294 | // preg_match_all('/^([+-]?[0-9].*?),\s*([+-]?[0-9].*?),(.*?),(.*?),(.*?),(.*)$/um', |
||
| 295 | // $str_points, $point, PREG_SET_ORDER); |
||
| 296 | /* |
||
| 297 | * group 1: ([+-]?[0-9]+(?:\.[0-9]*)?) |
||
| 298 | * group 2: ([+-]?[0-9]+(?:\.[0-9]*)?) |
||
| 299 | * group 3: (.*?) |
||
| 300 | * group 4: (.*?) |
||
| 301 | * group 5: (.*?) |
||
| 302 | * group 6: (.*) |
||
| 303 | */ |
||
| 304 | preg_match_all( |
||
| 305 | '/^([+-]?[0-9]+(?:\.[0-9]*)?),\s*([+-]?[0-9]+(?:\.[0-9]*)?),(.*?),(.*?),(.*?),(.*)$/um', |
||
| 306 | $str_points, |
||
| 307 | $point, |
||
| 308 | PREG_SET_ORDER |
||
| 309 | ); |
||
| 310 | // create poi array |
||
| 311 | $overlay = []; |
||
| 312 | foreach ($point as $pt) { |
||
| 313 | [$match, $lat, $lon, $angle, $opacity, $img, $text] = $pt; |
||
| 314 | $lat = is_numeric($lat) ? $lat : 0; |
||
| 315 | $lon = is_numeric($lon) ? $lon : 0; |
||
| 316 | $angle = is_numeric($angle) ? $angle : 0; |
||
| 317 | $opacity = is_numeric($opacity) ? $opacity : 0.8; |
||
| 318 | // TODO validate using exist & set up default img? |
||
| 319 | $img = trim($img); |
||
| 320 | $text = p_get_instructions($text); |
||
| 321 | // dbg ( $text ); |
||
| 322 | $text = p_render("xhtml", $text, $info); |
||
| 323 | // dbg ( $text ); |
||
| 324 | $text = addslashes(str_replace("\n", "", $text)); |
||
| 325 | $overlay [] = [$lat, $lon, $text, $angle, $opacity, $img]; |
||
| 326 | } |
||
| 327 | return $overlay; |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Create a Google maps static image url w/ the poi. |
||
| 332 | * |
||
| 333 | * @param array $gmap |
||
| 334 | * @param array $overlay |
||
| 335 | */ |
||
| 336 | private function getGoogle(array $gmap, array $overlay): string |
||
| 337 | { |
||
| 338 | $sUrl = $this->getConf('iconUrlOverload'); |
||
| 339 | if (!$sUrl) { |
||
| 340 | $sUrl = DOKU_URL; |
||
| 341 | } |
||
| 342 | switch ($gmap ['baselyr']) { |
||
| 343 | case 'google hybrid': |
||
| 344 | $maptype = 'hybrid'; |
||
| 345 | break; |
||
| 346 | case 'google sat': |
||
| 347 | $maptype = 'satellite'; |
||
| 348 | break; |
||
| 349 | case 'terrain': |
||
| 350 | case 'google relief': |
||
| 351 | $maptype = 'terrain'; |
||
| 352 | break; |
||
| 353 | case 'google road': |
||
| 354 | default: |
||
| 355 | $maptype = 'roadmap'; |
||
| 356 | break; |
||
| 357 | } |
||
| 358 | // TODO maybe use viewport / visible instead of center/zoom, |
||
| 359 | // see: https://developers.google.com/maps/documentation/staticmaps/index#Viewports |
||
| 360 | // 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 |
||
| 361 | $imgUrl = "https://maps.googleapis.com/maps/api/staticmap?"; |
||
| 362 | $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x" |
||
| 363 | . str_replace("px", "", $gmap ['height']); |
||
| 364 | //if (!$this->getConf( 'autoZoomMap')) { // no need for center & zoom params } |
||
| 365 | $imgUrl .= "¢er=" . $gmap ['lat'] . "," . $gmap ['lon']; |
||
| 366 | // max is 21 (== building scale), but that's overkill.. |
||
| 367 | if ($gmap ['zoom'] > 17) { |
||
| 368 | $imgUrl .= "&zoom=17"; |
||
| 369 | } else { |
||
| 370 | $imgUrl .= "&zoom=" . $gmap ['zoom']; |
||
| 371 | } |
||
| 372 | if ($overlay !== []) { |
||
| 373 | $rowId = 0; |
||
| 374 | foreach ($overlay as $data) { |
||
| 375 | [$lat, $lon, $text, $angle, $opacity, $img] = $data; |
||
| 376 | $imgUrl .= "&markers=icon%3a" . $sUrl . "lib/plugins/openlayersmap/icons/" . $img . "%7c" |
||
| 377 | . $lat . "," . $lon . "%7clabel%3a" . ++$rowId; |
||
| 378 | } |
||
| 379 | } |
||
| 380 | $imgUrl .= "&format=png&maptype=" . $maptype; |
||
| 381 | global $conf; |
||
| 382 | $imgUrl .= "&language=" . $conf ['lang']; |
||
| 383 | if ($this->getConf('googleAPIkey')) { |
||
| 384 | $imgUrl .= "&key=" . $this->getConf('googleAPIkey'); |
||
| 385 | } |
||
| 386 | // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::getGoogle: Google image url is:'); |
||
| 387 | return $imgUrl; |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Create a MapQuest static map API image url. |
||
| 392 | * |
||
| 393 | * @param array $gmap |
||
| 394 | * @param array $overlay |
||
| 395 | */ |
||
| 396 | /* |
||
| 397 | private function _getMapQuest($gmap, $overlay) { |
||
| 398 | $sUrl = $this->getConf ( 'iconUrlOverload' ); |
||
| 399 | if (! $sUrl) { |
||
| 400 | $sUrl = DOKU_URL; |
||
| 401 | } |
||
| 402 | switch ($gmap ['baselyr']) { |
||
| 403 | case 'mapquest hybrid' : |
||
| 404 | $maptype = 'hyb'; |
||
| 405 | break; |
||
| 406 | case 'mapquest sat' : |
||
| 407 | // because sat coverage is very limited use 'hyb' instead of 'sat' so we don't get a blank map |
||
| 408 | $maptype = 'hyb'; |
||
| 409 | break; |
||
| 410 | case 'mapquest road' : |
||
| 411 | default : |
||
| 412 | $maptype = 'map'; |
||
| 413 | break; |
||
| 414 | } |
||
| 415 | $imgUrl = "http://open.mapquestapi.com/staticmap/v4/getmap?declutter=true&"; |
||
| 416 | if (count ( $overlay ) < 1) { |
||
| 417 | $imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon']; |
||
| 418 | // max level for mapquest is 16 |
||
| 419 | if ($gmap ['zoom'] > 16) { |
||
| 420 | $imgUrl .= "&zoom=16"; |
||
| 421 | } else { |
||
| 422 | $imgUrl .= "&zoom=" . $gmap ['zoom']; |
||
| 423 | } |
||
| 424 | } |
||
| 425 | // use bestfit instead of center/zoom, needs upperleft/lowerright corners |
||
| 426 | // $bbox=$this->calcBBOX($overlay, $gmap['lat'], $gmap['lon']); |
||
| 427 | // $imgUrl .= "bestfit=".$bbox['minlat'].",".$bbox['maxlon'].",".$bbox['maxlat'].",".$bbox['minlon']; |
||
| 428 | |||
| 429 | // TODO declutter option works well for square maps but not for rectangular, maybe compensate for that |
||
| 430 | // or compensate the mbr.. |
||
| 431 | |||
| 432 | $imgUrl .= "&size=" . str_replace ( "px", "", $gmap ['width'] ) . "," . str_replace ("px","",$gmap['height']); |
||
| 433 | |||
| 434 | // TODO mapquest allows using one image url with a multiplier $NUMBER eg: |
||
| 435 | // $NUMBER = 2 |
||
| 436 | // $imgUrl .= DOKU_URL."/".DOKU_PLUGIN."/".getPluginName()."/icons/".$img.",$NUMBER,C," |
||
| 437 | // .$lat1.",".$lon1.",0,0,0,0,C,".$lat2.",".$lon2.",0,0,0,0"; |
||
| 438 | if (! empty ( $overlay )) { |
||
| 439 | $imgUrl .= "&xis="; |
||
| 440 | foreach ( $overlay as $data ) { |
||
| 441 | list ( $lat, $lon, $text, $angle, $opacity, $img ) = $data; |
||
| 442 | // $imgUrl .= $sUrl."lib/plugins/openlayersmap/icons/".$img.",1,C,".$lat.",".$lon.",0,0,0,0,"; |
||
| 443 | $imgUrl .= $sUrl . "lib/plugins/openlayersmap/icons/" . $img . ",1,C," . $lat . "," . $lon . ","; |
||
| 444 | } |
||
| 445 | $imgUrl = substr ( $imgUrl, 0, - 1 ); |
||
| 446 | } |
||
| 447 | $imgUrl .= "&imageType=png&type=" . $maptype; |
||
| 448 | $imgUrl .= "&key=".$this->getConf ( 'mapquestAPIKey' ); |
||
| 449 | // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getMapQuest: MapQuest image url is:'); |
||
| 450 | return $imgUrl; |
||
| 451 | } |
||
| 452 | */ |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Create a static OSM map image url w/ the poi from http://staticmap.openstreetmap.de (staticMapLite) |
||
| 456 | * use http://staticmap.openstreetmap.de "staticMapLite" or a local version |
||
| 457 | * |
||
| 458 | * @param array $gmap |
||
| 459 | * @param array $overlay |
||
| 460 | * |
||
| 461 | * @return false|string |
||
| 462 | * @todo implementation for http://ojw.dev.openstreetmap.org/StaticMapDev/ |
||
| 463 | */ |
||
| 464 | private function getStaticOSM(array $gmap, array $overlay) |
||
| 465 | { |
||
| 466 | global $conf; |
||
| 467 | |||
| 468 | if ($this->getConf('optionStaticMapGenerator') === 'local') { |
||
| 469 | // using local basemap composer |
||
| 470 | if (($myMap = plugin_load('helper', 'openlayersmap_staticmap')) === null) { |
||
| 471 | dbglog( |
||
| 472 | $myMap, |
||
| 473 | 'openlayersmap_staticmap plugin is not available for use.' |
||
| 474 | ); |
||
| 475 | } |
||
| 476 | if (($geophp = plugin_load('helper', 'geophp')) === null) { |
||
| 477 | dbglog($geophp, 'geophp plugin is not available for use.'); |
||
| 478 | } |
||
| 479 | $size = str_replace("px", "", $gmap ['width']) . "x" |
||
| 480 | . str_replace("px", "", $gmap ['height']); |
||
| 481 | |||
| 482 | $markers = []; |
||
| 483 | if ($overlay !== []) { |
||
| 484 | foreach ($overlay as $data) { |
||
| 485 | [$lat, $lon, $text, $angle, $opacity, $img] = $data; |
||
| 486 | $iconStyle = substr($img, 0, -4); |
||
| 487 | $markers [] = ['lat' => $lat, 'lon' => $lon, 'type' => $iconStyle]; |
||
| 488 | } |
||
| 489 | } |
||
| 490 | |||
| 491 | $apikey = ''; |
||
| 492 | switch ($gmap ['baselyr']) { |
||
| 493 | case 'mapnik': |
||
| 494 | case 'openstreetmap': |
||
| 495 | $maptype = 'openstreetmap'; |
||
| 496 | break; |
||
| 497 | case 'transport': |
||
| 498 | $maptype = 'transport'; |
||
| 499 | $apikey = '?apikey=' . $this->getConf('tfApiKey'); |
||
| 500 | break; |
||
| 501 | case 'landscape': |
||
| 502 | $maptype = 'landscape'; |
||
| 503 | $apikey = '?apikey=' . $this->getConf('tfApiKey'); |
||
| 504 | break; |
||
| 505 | case 'outdoors': |
||
| 506 | $maptype = 'outdoors'; |
||
| 507 | $apikey = '?apikey=' . $this->getConf('tfApiKey'); |
||
| 508 | break; |
||
| 509 | case 'cycle map': |
||
| 510 | $maptype = 'cycle'; |
||
| 511 | $apikey = '?apikey=' . $this->getConf('tfApiKey'); |
||
| 512 | break; |
||
| 513 | case 'hike and bike map': |
||
| 514 | $maptype = 'hikeandbike'; |
||
| 515 | break; |
||
| 516 | case 'mapquest hybrid': |
||
| 517 | case 'mapquest road': |
||
| 518 | case 'mapquest sat': |
||
| 519 | $maptype = 'mapquest'; |
||
| 520 | break; |
||
| 521 | default: |
||
| 522 | $maptype = ''; |
||
| 523 | break; |
||
| 524 | } |
||
| 525 | |||
| 526 | $result = $myMap->getMap( |
||
| 527 | $gmap ['lat'], |
||
| 528 | $gmap ['lon'], |
||
| 529 | $gmap ['zoom'], |
||
| 530 | $size, |
||
| 531 | $maptype, |
||
| 532 | $markers, |
||
| 533 | $gmap ['gpxfile'], |
||
| 534 | $gmap ['kmlfile'], |
||
| 535 | $gmap ['geojsonfile'], |
||
| 536 | $apikey |
||
| 537 | ); |
||
| 538 | } else { |
||
| 539 | // using external basemap composer |
||
| 540 | |||
| 541 | // https://staticmap.openstreetmap.de/staticmap.php?center=47.000622235634,10 |
||
| 542 | //.117187497601&zoom=5&size=500x350 |
||
| 543 | // &markers=48.999812532766,8.3593749976708,lightblue1|43.154850037315,17.499999997306, |
||
| 544 | // lightblue1|49.487527053077,10.820312497573,ltblu-pushpin|47.951071133739,15.917968747369, |
||
| 545 | // ol-marker|47.921629720114,18.027343747285,ol-marker-gold|47.951071133739,19.257812497236, |
||
| 546 | // ol-marker-blue|47.180141361692,19.257812497236,ol-marker-green |
||
| 547 | $imgUrl = "https://staticmap.openstreetmap.de/staticmap.php"; |
||
| 548 | $imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon']; |
||
| 549 | $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x" |
||
| 550 | . str_replace("px", "", $gmap ['height']); |
||
| 551 | |||
| 552 | if ($gmap ['zoom'] > 16) { |
||
| 553 | // actually this could even be 18, but that seems overkill |
||
| 554 | $imgUrl .= "&zoom=16"; |
||
| 555 | } else { |
||
| 556 | $imgUrl .= "&zoom=" . $gmap ['zoom']; |
||
| 557 | } |
||
| 558 | |||
| 559 | if ($overlay !== []) { |
||
| 560 | $rowId = 0; |
||
| 561 | $imgUrl .= "&markers="; |
||
| 562 | foreach ($overlay as $data) { |
||
| 563 | [$lat, $lon, $text, $angle, $opacity, $img] = $data; |
||
| 564 | $rowId++; |
||
| 565 | $iconStyle = "lightblue$rowId"; |
||
| 566 | $imgUrl .= "$lat,$lon,$iconStyle%7c"; |
||
| 567 | } |
||
| 568 | $imgUrl = substr($imgUrl, 0, -3); |
||
| 569 | } |
||
| 570 | |||
| 571 | $result = $imgUrl; |
||
| 572 | } |
||
| 573 | return $result; |
||
| 574 | } |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Create a Bing maps static image url w/ the poi. |
||
| 578 | * |
||
| 579 | * @param array $gmap |
||
| 580 | * @param array $overlay |
||
| 581 | */ |
||
| 582 | private function getBing(array $gmap, array $overlay): string |
||
| 583 | { |
||
| 584 | switch ($gmap ['baselyr']) { |
||
| 585 | case 've hybrid': |
||
| 586 | case 'bing hybrid': |
||
| 587 | $maptype = 'AerialWithLabels'; |
||
| 588 | break; |
||
| 589 | case 've sat': |
||
| 590 | case 'bing sat': |
||
| 591 | $maptype = 'Aerial'; |
||
| 592 | break; |
||
| 593 | case 've normal': |
||
| 594 | case 've road': |
||
| 595 | case 've': |
||
| 596 | case 'bing road': |
||
| 597 | default: |
||
| 598 | $maptype = 'Road'; |
||
| 599 | break; |
||
| 600 | } |
||
| 601 | $imgUrl = "https://dev.virtualearth.net/REST/v1/Imagery/Map/" . $maptype;// . "/"; |
||
| 602 | if ($this->getConf('autoZoomMap')) { |
||
| 603 | $bbox = $this->calcBBOX($overlay, $gmap ['lat'], $gmap ['lon']); |
||
| 604 | //$imgUrl .= "?ma=" . $bbox ['minlat'] . "," . $bbox ['minlon'] . "," |
||
| 605 | // . $bbox ['maxlat'] . "," . $bbox ['maxlon']; |
||
| 606 | $imgUrl .= "?ma=" . $bbox ['minlat'] . "%2C" . $bbox ['minlon'] . "%2C" . $bbox ['maxlat'] |
||
| 607 | . "%2C" . $bbox ['maxlon']; |
||
| 608 | $imgUrl .= "&dcl=1"; |
||
| 609 | } |
||
| 610 | if (strpos($imgUrl, "?") === false) |
||
| 611 | $imgUrl .= "?"; |
||
| 612 | |||
| 613 | //$imgUrl .= "&ms=" . str_replace ( "px", "", $gmap ['width'] ) . "," |
||
| 614 | // . str_replace ( "px", "", $gmap ['height'] ); |
||
| 615 | $imgUrl .= "&ms=" . str_replace("px", "", $gmap ['width']) . "%2C" |
||
| 616 | . str_replace("px", "", $gmap ['height']); |
||
| 617 | $imgUrl .= "&key=" . $this->getConf('bingAPIKey'); |
||
| 618 | if ($overlay !== []) { |
||
| 619 | $rowId = 0; |
||
| 620 | foreach ($overlay as $data) { |
||
| 621 | [$lat, $lon, $text, $angle, $opacity, $img] = $data; |
||
| 622 | // TODO icon style lookup, see: http://msdn.microsoft.com/en-us/library/ff701719.aspx for iconStyle |
||
| 623 | $iconStyle = 32; |
||
| 624 | $rowId++; |
||
| 625 | // NOTE: the max number of pushpins is 18! or we have to use POST |
||
| 626 | // (http://msdn.microsoft.com/en-us/library/ff701724.aspx) |
||
| 627 | if ($rowId == 18) { |
||
| 628 | break; |
||
| 629 | } |
||
| 630 | //$imgUrl .= "&pp=$lat,$lon;$iconStyle;$rowId"; |
||
| 631 | $imgUrl .= "&pp=$lat%2C$lon%3B$iconStyle%3B$rowId"; |
||
| 632 | } |
||
| 633 | } |
||
| 634 | global $conf; |
||
| 635 | $imgUrl .= "&fmt=png"; |
||
| 636 | $imgUrl .= "&c=" . $conf ['lang']; |
||
| 637 | return $imgUrl; |
||
| 638 | } |
||
| 639 | |||
| 640 | /** |
||
| 641 | * Calculate the minimum bbox for a start location + poi. |
||
| 642 | * |
||
| 643 | * @param array $overlay |
||
| 644 | * multi-dimensional array of array($lat, $lon, $text, $angle, $opacity, $img) |
||
| 645 | * @param float $lat |
||
| 646 | * latitude for map center |
||
| 647 | * @param float $lon |
||
| 648 | * longitude for map center |
||
| 649 | * @return array :float array describing the mbr and center point |
||
| 650 | */ |
||
| 651 | private function calcBBOX(array $overlay, float $lat, float $lon): array |
||
| 652 | { |
||
| 653 | $lats = [$lat]; |
||
| 654 | $lons = [$lon]; |
||
| 655 | foreach ($overlay as $data) { |
||
| 656 | [$lat, $lon, $text, $angle, $opacity, $img] = $data; |
||
| 657 | $lats [] = $lat; |
||
| 658 | $lons [] = $lon; |
||
| 659 | } |
||
| 660 | sort($lats); |
||
| 661 | sort($lons); |
||
| 662 | // TODO: make edge/wrap around cases work |
||
| 663 | $centerlat = $lats [0] + ($lats [count($lats) - 1] - $lats [0]); |
||
| 664 | $centerlon = $lons [0] + ($lons [count($lats) - 1] - $lons [0]); |
||
| 665 | return ['minlat' => $lats [0], 'minlon' => $lons [0], 'maxlat' => $lats [count($lats) - 1], 'maxlon' => $lons [count($lats) - 1], 'centerlat' => $centerlat, 'centerlon' => $centerlon]; |
||
| 666 | } |
||
| 667 | |||
| 668 | /** |
||
| 669 | * convert latitude in decimal degrees to DMS+hemisphere. |
||
| 670 | * |
||
| 671 | * @param float $decimaldegrees |
||
| 672 | * @todo move this into a shared library |
||
| 673 | */ |
||
| 674 | private function convertLat(float $decimaldegrees): string |
||
| 675 | { |
||
| 676 | if (strpos($decimaldegrees, '-') !== false) { |
||
| 677 | $latPos = "S"; |
||
| 678 | } else { |
||
| 679 | $latPos = "N"; |
||
| 680 | } |
||
| 681 | $dms = $this->convertDDtoDMS(abs($decimaldegrees)); |
||
| 682 | return hsc($dms . $latPos); |
||
| 683 | } |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Convert decimal degrees to degrees, minutes, seconds format |
||
| 687 | * |
||
| 688 | * @param float $decimaldegrees |
||
| 689 | * @return string dms |
||
| 690 | * @todo move this into a shared library |
||
| 691 | */ |
||
| 692 | private function convertDDtoDMS(float $decimaldegrees): string |
||
| 700 | } |
||
| 701 | |||
| 702 | /** |
||
| 703 | * convert longitude in decimal degrees to DMS+hemisphere. |
||
| 704 | * |
||
| 705 | * @param float $decimaldegrees |
||
| 706 | * @todo move this into a shared library |
||
| 707 | */ |
||
| 708 | private function convertLon(float $decimaldegrees): string |
||
| 717 | } |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Figures out the base filename of a media path. |
||
| 721 | * |
||
| 722 | * @param string $mediaLink |
||
| 723 | */ |
||
| 724 | private function getFileName(string $mediaLink): string |
||
| 733 | } |
||
| 734 | |||
| 735 | /** |
||
| 736 | * |
||
| 737 | * @see DokuWiki_Syntax_Plugin::render() |
||
| 738 | */ |
||
| 739 | public function render($format, Doku_Renderer $renderer, $data): bool |
||
| 850 | } |
||
| 851 | } |
||
| 852 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths