1<?php 2/* 3 * Copyright (c) 2008-2014 Mark C. Prins <mprins@users.sf.net> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17if (! defined ( 'DOKU_INC' )) 18 define ( 'DOKU_INC', realpath ( dirname ( __FILE__ ) . '/../../' ) . '/' ); 19if (! defined ( 'DOKU_PLUGIN' )) 20 define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' ); 21require_once (DOKU_PLUGIN . 'syntax.php'); 22 23/** 24 * DokuWiki Plugin openlayersmap (Syntax Component). 25 * Provides for display of an OpenLayers based map in a wiki page. 26 * 27 * @author Mark Prins 28 */ 29class syntax_plugin_openlayersmap_olmap extends DokuWiki_Syntax_Plugin { 30 31 /** 32 * defaults of the known attributes of the olmap tag. 33 */ 34 private $dflt = array ( 35 'id' => 'olmap', 36 'width' => '550px', 37 'height' => '450px', 38 'lat' => 50.0, 39 'lon' => 5.1, 40 'zoom' => 12, 41 'statusbar' => true, 42 'controls' => true, 43 'poihoverstyle' => false, 44 'baselyr' => 'OpenStreetMap', 45 'gpxfile' => '', 46 'kmlfile' => '', 47 'geojsonfile' => '', 48 'summary' => '' 49 ); 50 51 /** 52 * 53 * @see DokuWiki_Syntax_Plugin::getType() 54 */ 55 function getType() { 56 return 'substition'; 57 } 58 59 /** 60 * 61 * @see DokuWiki_Syntax_Plugin::getPType() 62 */ 63 function getPType() { 64 return 'block'; 65 } 66 67 /** 68 * 69 * @see Doku_Parser_Mode::getSort() 70 */ 71 function getSort() { 72 return 901; 73 } 74 75 /** 76 * 77 * @see Doku_Parser_Mode::connectTo() 78 */ 79 function connectTo($mode) { 80 $this->Lexer->addSpecialPattern ( '<olmap ?[^>\n]*>.*?</olmap>', $mode, 'plugin_openlayersmap_olmap' ); 81 } 82 83 /** 84 * 85 * @see DokuWiki_Syntax_Plugin::handle() 86 */ 87 function handle($match, $state, $pos, &$handler) { 88 // break matched cdata into its components 89 list ( $str_params, $str_points ) = explode ( '>', substr ( $match, 7, - 9 ), 2 ); 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 96 $gmap = $this->_extract_params ( $str_params ); 97 $overlay = $this->_extract_points ( $str_points ); 98 $_firstimageID = ''; 99 100 // choose maptype based on the specified tag 101 $imgUrl = "{{"; 102 if (stripos ( $gmap ['baselyr'], 'google' ) !== false) { 103 $imgUrl .= $this->_getGoogle ( $gmap, $overlay ); 104 } elseif (stripos ( $gmap ['baselyr'], 'bing' ) !== false) { 105 if (! $this->getConf ( 'bingAPIKey' )) { 106 // in case there is no Bing api key we'll use OSM 107 $_firstimageID = $this->_getStaticOSM ( $gmap, $overlay ); 108 $imgUrl .= $_firstimageID; 109 if ($this->getConf ( 'optionStaticMapGenerator' ) == 'remote') { 110 $imgUrl .= "&.png"; 111 } 112 } else { 113 $imgUrl .= $this->_getBing ( $gmap, $overlay ); 114 } 115 } elseif (stripos ( $gmap ['baselyr'], 'mapquest' ) !== false) { 116 if (($this->getConf ( 'optionStaticMapGenerator' ) == 'remote') && (! $this->getConf ( 'mapquestAPIKey' ))){ 117 $imgUrl .= $this->_getMapQuest ( $gmap, $overlay ); 118 } else { 119 $_firstimageID = $this->_getStaticOSM ( $gmap, $overlay ); 120 $imgUrl .= $_firstimageID; 121 } 122 } else { 123 $_firstimageID = $this->_getStaticOSM ( $gmap, $overlay ); 124 $imgUrl .= $_firstimageID; 125 if ($this->getConf ( 'optionStaticMapGenerator' ) == 'remote') { 126 $imgUrl .= "&.png"; 127 } 128 } 129 130 // append dw p_render specific params and render 131 $imgUrl .= "?" . str_replace ( "px", "", $gmap ['width'] ) . "x" . str_replace ( "px", "", $gmap ['height'] ); 132 $imgUrl .= "&nolink"; 133 $imgUrl .= " |" . $gmap ['summary'] . " }}"; 134 135 $mapid = $gmap ['id']; 136 // create a javascript parameter string for the map 137 $param = ''; 138 foreach ( $gmap as $key => $val ) { 139 $param .= is_numeric ( $val ) ? "$key: $val, " : "$key: '" . hsc ( $val ) . "', "; 140 } 141 if (! empty ( $param )) { 142 $param = substr ( $param, 0, - 2 ); 143 } 144 unset ( $gmap ['id'] ); 145 146 // create a javascript serialisation of the point data 147 $poi = ''; 148 $poitable = ''; 149 $rowId = 0; 150 if (! empty ( $overlay )) { 151 foreach ( $overlay as $data ) { 152 list ( $lat, $lon, $text, $angle, $opacity, $img ) = $data; 153 $rowId ++; 154 $poi .= ", {lat: $lat, lon: $lon, txt: '$text', angle: $angle, opacity: $opacity, img: '$img', rowId: $rowId}"; 155 $poitable .= ' 156 <tr> 157 <td class="rowId">' . $rowId . '</td> 158 <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/icons/' . $img . '" alt="'. substr($img, 0, -4) . $this->getlang('alt_legend_poi').' " /></td> 159 <td class="lat" title="' . $this->getLang ( 'olmapPOIlatTitle' ) . '">' . $lat . '</td> 160 <td class="lon" title="' . $this->getLang ( 'olmapPOIlonTitle' ) . '">' . $lon . '</td> 161 <td class="txt">' . $text . '</td> 162 </tr>'; 163 } 164 $poi = substr ( $poi, 2 ); 165 } 166 if (! empty ( $gmap ['kmlfile'] )) { 167 $poitable .= ' 168 <tr> 169 <td class="rowId"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/kml_file.png" alt="KML file" /></td> 170 <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/kml_line.png" alt="' . $this->getlang('alt_legend_kml') .'" /></td> 171 <td class="txt" colspan="3">KML track: ' . $this->getFileName ( $gmap ['kmlfile'] ) . '</td> 172 </tr>'; 173 } 174 if (! empty ( $gmap ['gpxfile'] )) { 175 $poitable .= ' 176 <tr> 177 <td class="rowId"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/gpx_file.png" alt="GPX file" /></td> 178 <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/gpx_line.png" alt="' . $this->getlang('alt_legend_gpx') .'" /></td> 179 <td class="txt" colspan="3">GPX track: ' . $this->getFileName ( $gmap ['gpxfile'] ) . '</td> 180 </tr>'; 181 } 182 if (! empty ( $gmap ['geojsonfile'] )) { 183 $poitable .= ' 184 <tr> 185 <td class="rowId"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/geojson_file.png" alt="GeoJSON file" /></td> 186 <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/geojson_line.png" alt="' . $this->getlang('alt_legend_geojson') .'" /></td> 187 <td class="txt" colspan="3">GeoJSON track: ' . $this->getFileName ( $gmap ['geojsonfile'] ) . '</td> 188 </tr>'; 189 } 190 191 $js .= "{mapOpts:{" . $param . " },poi:[$poi]};"; 192 // unescape the json 193 $poitable = stripslashes ( $poitable ); 194 195 return array ( 196 $mapid, 197 $js, 198 $mainLat, 199 $mainLon, 200 $poitable, 201 $gmap ['summary'], 202 $imgUrl, 203 $_firstimageID 204 ); 205 } 206 207 /** 208 * 209 * @see DokuWiki_Syntax_Plugin::render() 210 */ 211 function render($mode, &$renderer, $data) { 212 // set to true after external scripts tags are written 213 static $initialised = false; 214 // incremented for each map tag in the page source so we can keep track of each map in this page 215 static $mapnumber = 0; 216 217 // dbglog($data, 'olmap::render() data.'); 218 list ( $mapid, $param, $mainLat, $mainLon, $poitable, $poitabledesc, $staticImgUrl, $_firstimage ) = $data; 219 220 if ($mode == 'xhtml') { 221 $olscript = ''; 222 $olEnable = false; 223 $gscript = ''; 224 $gEnable = $this->getConf ( 'enableGoogle' ); 225 $mqEnable = $this->getConf ( 'enableMapQuest' ); 226 $osmEnable = $this->getConf ( 'enableOSM' ); 227 $enableBing = $this->getConf ( 'enableBing' ); 228 229 $scriptEnable = ''; 230 if (! $initialised) { 231 $initialised = true; 232 // render necessary script tags 233 if ($gEnable) { 234 $gscript = '<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.14&sensor=false"></script>'; 235 } 236 $olscript = '<script type="text/javascript" src="' . DOKU_BASE . 'lib/plugins/openlayersmap/lib/OpenLayers.js"></script>'; 237 238 $scriptEnable = '<script type="text/javascript" charset="utf-8">/*<![CDATA[*/'; 239 $scriptEnable .= $olscript ? 'olEnable = true;' : 'olEnable = false;'; 240 $scriptEnable .= 'gEnable = ' . ($gEnable ? 'true' : 'false') . ';'; 241 $scriptEnable .= 'osmEnable = ' . ($osmEnable ? 'true' : 'false') . ';'; 242 $scriptEnable .= 'mqEnable = ' . ($mqEnable ? 'true' : 'false') . ';'; 243 $scriptEnable .= 'bEnable = ' . ($enableBing ? 'true' : 'false') . ';'; 244 $scriptEnable .= 'bApiKey="' . $this->getConf ( 'bingAPIKey' ) . '";'; 245 $scriptEnable .= '/*!]]>*/</script>'; 246 } 247 $renderer->doc .= "$gscript\n$olscript\n$scriptEnable"; 248 $renderer->doc .= '<div class="olMapHelp">' . $this->locale_xhtml ( "help" ) . '</div>'; 249 if ($this->getConf ( 'enableA11y' )) { 250 $renderer->doc .= '<div id="' . $mapid . '-static" class="olStaticMap">' . p_render ( $mode, p_get_instructions ( $staticImgUrl ), $info ) . '</div>'; 251 } 252 $renderer->doc .= '<div id="' . $mapid . '-clearer" class="clearer"><p> </p></div>'; 253 if ($this->getConf ( 'enableA11y' )) { 254 // render a table of the POI for the print and a11y presentation, it is hidden using javascript 255 $renderer->doc .= '<div class="olPOItableSpan" id="' . $mapid . '-table-span"> 256 <table class="olPOItable" id="' . $mapid . '-table"> 257 <caption class="olPOITblCaption">' . $this->getLang ( 'olmapPOItitle' ) . '</caption> 258 <thead class="olPOITblHeader"> 259 <tr> 260 <th class="rowId" scope="col">id</th> 261 <th class="icon" scope="col">' . $this->getLang ( 'olmapPOIicon' ) . '</th> 262 <th class="lat" scope="col" title="' . $this->getLang ( 'olmapPOIlatTitle' ) . '">' . $this->getLang ( 'olmapPOIlat' ) . '</th> 263 <th class="lon" scope="col" title="' . $this->getLang ( 'olmapPOIlonTitle' ) . '">' . $this->getLang ( 'olmapPOIlon' ) . '</th> 264 <th class="txt" scope="col">' . $this->getLang ( 'olmapPOItxt' ) . '</th> 265 </tr> 266 </thead>'; 267 if ($poitabledesc != '') { 268 $renderer->doc .= '<tfoot class="olPOITblFooter"><tr><td colspan="5">' . $poitabledesc . '</td></tr></tfoot>'; 269 } 270 $renderer->doc .= '<tbody class="olPOITblBody">' . $poitable . '</tbody> 271 </table></div>'; 272 } 273 // render inline mapscript parts 274 $renderer->doc .= '<script type="text/javascript" charset="utf-8">/*<![CDATA[*/'; 275 $renderer->doc .= " olMapData[$mapnumber] = $param /*!]]>*/</script>"; 276 $mapnumber ++; 277 return true; 278 } elseif ($mode == 'metadata') { 279 if (! (($this->dflt ['lat'] == $mainLat) && ($thisdflt ['lon'] == $mainLon))) { 280 // render geo metadata, unless they are the default 281 $renderer->meta ['geo'] ['lat'] = $mainLat; 282 $renderer->meta ['geo'] ['lon'] = $mainLon; 283 if ($geophp = &plugin_load ( 'helper', 'geophp' )) { 284 // if we have the geoPHP helper, add the geohash 285 // fails with older php versions.. $renderer->meta['geo']['geohash'] = (new Point($mainLon,$mainLat))->out('geohash'); 286 $p = new Point ( $mainLon, $mainLat ); 287 $renderer->meta ['geo'] ['geohash'] = $p->out ( 'geohash' ); 288 } 289 } 290 291 if (($this->getConf ( 'enableA11y' )) && (! empty ( $_firstimage ))) { 292 // add map local image into relation/firstimage if not already filled and when it is a local image 293 294 global $ID; 295 $rel = p_get_metadata ( $ID, 'relation', METADATA_RENDER_USING_CACHE ); 296 $img = $rel ['firstimage']; 297 if (empty ( $img ) /* || $img == $_firstimage*/){ 298 dbglog ( $_firstimage, 'olmap::render#rendering image relation metadata for _firstimage as $img was empty or the same.' ); 299 // This seems to never work; the firstimage entry in the .meta file is empty 300 // $renderer->meta['relation']['firstimage'] = $_firstimage; 301 302 // ... and neither does this; the firstimage entry in the .meta file is empty 303 // $relation = array('relation'=>array('firstimage'=>$_firstimage)); 304 // p_set_metadata($ID, $relation, false, false); 305 306 // ... this works 307 $renderer->internalmedia ( $_firstimage, $poitabledesc ); 308 } 309 } 310 return true; 311 } 312 return false; 313 } 314 315 /** 316 * extract parameters for the map from the parameter string 317 * 318 * @param string $str_params 319 * string of key="value" pairs 320 * @return array associative array of parameters key=>value 321 */ 322 private function _extract_params($str_params) { 323 $param = array (); 324 preg_match_all ( '/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER ); 325 // parse match for instructions, break into key value pairs 326 $gmap = $this->dflt; 327 foreach ( $param as $kvpair ) { 328 list ( $match, $key, $val ) = $kvpair; 329 $key = strtolower ( $key ); 330 if (isset ( $gmap [$key] )) { 331 if ($key == 'summary') { 332 // preserve case for summary field 333 $gmap [$key] = $val; 334 } elseif ($key == 'id') { 335 // preserve case for id field 336 $gmap [$key] = $val; 337 } else { 338 $gmap [$key] = strtolower ( $val ); 339 } 340 } 341 } 342 return $gmap; 343 } 344 345 /** 346 * extract overlay points for the map from the wiki syntax data 347 * 348 * @param string $str_points 349 * multi-line string of lat,lon,text triplets 350 * @return array multi-dimensional array of lat,lon,text triplets 351 */ 352 private function _extract_points($str_points) { 353 $point = array (); 354 // preg_match_all('/^([+-]?[0-9].*?),\s*([+-]?[0-9].*?),(.*?),(.*?),(.*?),(.*)$/um', $str_points, $point, PREG_SET_ORDER); 355 /* 356 * group 1: ([+-]?[0-9]+(?:\.[0-9]*)?) group 2: ([+-]?[0-9]+(?:\.[0-9]*)?) group 3: (.*?) group 4: (.*?) group 5: (.*?) group 6: (.*) 357 */ 358 preg_match_all ( '/^([+-]?[0-9]+(?:\.[0-9]*)?),\s*([+-]?[0-9]+(?:\.[0-9]*)?),(.*?),(.*?),(.*?),(.*)$/um', $str_points, $point, PREG_SET_ORDER ); 359 // create poi array 360 $overlay = array (); 361 foreach ( $point as $pt ) { 362 list ( $match, $lat, $lon, $angle, $opacity, $img, $text ) = $pt; 363 $lat = is_numeric ( $lat ) ? $lat : 0; 364 $lon = is_numeric ( $lon ) ? $lon : 0; 365 $angle = is_numeric ( $angle ) ? $angle : 0; 366 $opacity = is_numeric ( $opacity ) ? $opacity : 0.8; 367 // TODO validate using exist & set up default img? 368 $img = trim ( $img ); 369 $text = p_get_instructions ( $text ); 370 // dbg ( $text ); 371 $text = p_render ( "xhtml", $text, $info ); 372 // dbg ( $text ); 373 $text = addslashes ( str_replace ( "\n", "", $text ) ); 374 $overlay [] = array ( 375 $lat, 376 $lon, 377 $text, 378 $angle, 379 $opacity, 380 $img 381 ); 382 } 383 return $overlay; 384 } 385 386 /** 387 * Create a MapQuest static map API image url. 388 * 389 * @param array $gmap 390 * @param array $overlay 391 */ 392 private function _getMapQuest($gmap, $overlay) { 393 $sUrl = $this->getConf ( 'iconUrlOverload' ); 394 if (! $sUrl) { 395 $sUrl = DOKU_URL; 396 } 397 switch ($gmap ['baselyr']) { 398 case 'mapquest hybrid' : 399 $maptype = 'hyb'; 400 break; 401 case 'mapquest sat' : 402 // because sat coverage is very limited use 'hyb' instead of 'sat' so we don't get a blank map 403 $maptype = 'hyb'; 404 break; 405 case 'mapquest road' : 406 default : 407 $maptype = 'map'; 408 break; 409 } 410 $imgUrl = "http://open.mapquestapi.com/staticmap/v4/getmap?declutter=true&"; 411 if (count ( $overlay ) < 1) { 412 $imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon']; 413 // max level for mapquest is 16 414 if ($gmap ['zoom'] > 16) { 415 $imgUrl .= "&zoom=16"; 416 } else { 417 $imgUrl .= "&zoom=" . $gmap ['zoom']; 418 } 419 } 420 // use bestfit instead of center/zoom, needs upperleft/lowerright corners 421 // $bbox=$this->_calcBBOX($overlay, $gmap['lat'], $gmap['lon']); 422 // $imgUrl .= "bestfit=".$bbox['minlat'].",".$bbox['maxlon'].",".$bbox['maxlat'].",".$bbox['minlon']; 423 424 // TODO declutter option works well for square maps but not for rectangular, maybe compensate for that or compensate the mbr.. 425 $imgUrl .= "&size=" . str_replace ( "px", "", $gmap ['width'] ) . "," . str_replace ( "px", "", $gmap ['height'] ); 426 427 // TODO mapquest allows using one image url with a multiplier $NUMBER eg: 428 // $NUMBER = 2 429 // $imgUrl .= DOKU_URL."/".DOKU_PLUGIN."/".getPluginName()."/icons/".$img.",$NUMBER,C,".$lat1.",".$lon1.",0,0,0,0,C,".$lat2.",".$lon2.",0,0,0,0"; 430 if (! empty ( $overlay )) { 431 $imgUrl .= "&xis="; 432 foreach ( $overlay as $data ) { 433 list ( $lat, $lon, $text, $angle, $opacity, $img ) = $data; 434 // $imgUrl .= $sUrl."lib/plugins/openlayersmap/icons/".$img.",1,C,".$lat.",".$lon.",0,0,0,0,"; 435 $imgUrl .= $sUrl . "lib/plugins/openlayersmap/icons/" . $img . ",1,C," . $lat . "," . $lon . ","; 436 } 437 $imgUrl = substr ( $imgUrl, 0, - 1 ); 438 } 439 $imgUrl .= "&imageType=png&type=" . $maptype; 440 $imgUrl .= "&key=".$this->getConf ( 'mapquestAPIKey' ); 441 $imgUrl .= "&.png"; 442 dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getMapQuest: MapQuest image url is:'); 443 return $imgUrl; 444 } 445 446 /** 447 * Create a Google maps static image url w/ the poi. 448 * 449 * @param array $gmap 450 * @param array $overlay 451 */ 452 private function _getGoogle($gmap, $overlay) { 453 $sUrl = $this->getConf ( 'iconUrlOverload' ); 454 if (! $sUrl) { 455 $sUrl = DOKU_URL; 456 } 457 switch ($gmap ['baselyr']) { 458 case 'google hybrid' : 459 $maptype = 'hybrid'; 460 break; 461 case 'google sat' : 462 $maptype = 'satellite'; 463 break; 464 case 'google relief' : 465 $maptype = 'terrain'; 466 break; 467 case 'google road' : 468 default : 469 $maptype = 'roadmap'; 470 break; 471 } 472 // TODO maybe use viewport / visible instead of center/zoom, 473 // see: https://code.google.com/intl/nl/apis/maps/documentation/staticmaps/#ImplicitPositioning 474 // 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 475 $imgUrl = "http://maps.google.com/maps/api/staticmap?sensor=false"; 476 $imgUrl .= "&size=" . str_replace ( "px", "", $gmap ['width'] ) . "x" . str_replace ( "px", "", $gmap ['height'] ); 477 $imgUrl .= "¢er=" . $gmap ['lat'] . "," . $gmap ['lon']; 478 // max is 21 (== building scale), but that's overkill.. 479 if ($gmap ['zoom'] > 17) { 480 $imgUrl .= "&zoom=17"; 481 } else { 482 $imgUrl .= "&zoom=" . $gmap ['zoom']; 483 } 484 485 if (! empty ( $overlay )) { 486 $rowId = 0; 487 foreach ( $overlay as $data ) { 488 list ( $lat, $lon, $text, $angle, $opacity, $img ) = $data; 489 $imgUrl .= "&markers=icon%3a" . $sUrl . "lib/plugins/openlayersmap/icons/" . $img . "%7c" . $lat . "," . $lon . "%7clabel%3a" . ++ $rowId; 490 } 491 } 492 $imgUrl .= "&format=png&maptype=" . $maptype; 493 global $conf; 494 $imgUrl .= "&language=" . $conf ['lang']; 495 $imgUrl .= "&.png"; 496 dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getGoogle: Google image url is:'); 497 return $imgUrl; 498 } 499 500 /** 501 * Create a Bing maps static image url w/ the poi. 502 * 503 * @param array $gmap 504 * @param array $overlay 505 */ 506 private function _getBing($gmap, $overlay) { 507 switch ($gmap ['baselyr']) { 508 case 've hybrid' : 509 case 'bing hybrid' : 510 $maptype = 'AerialWithLabels'; 511 break; 512 case 've sat' : 513 case 'bing sat' : 514 $maptype = 'Aerial'; 515 break; 516 case 've normal' : 517 case 've road' : 518 case 've' : 519 case 'bing road' : 520 default : 521 $maptype = 'Road'; 522 break; 523 } 524 $imgUrl = "http://dev.virtualearth.net/REST/v1/Imagery/Map/" . $maptype . "/"; 525 if (! $this->getConf ( 'autoZoomMap' )) { 526 $bbox = $this->_calcBBOX ( $overlay, $gmap ['lat'], $gmap ['lon'] ); 527 $imgUrl .= "?mapArea=" . $bbox ['minlat'] . "," . $bbox ['minlon'] . "," . $bbox ['maxlat'] . "," . $bbox ['maxlon']; 528 $imgUrl .= "&declutter=1"; 529 // or 530 // $imgUrl .= $gmap['lat'].",".$gmap['lon']."/".$gmap['zoom']."?"; 531 } 532 if (strpos ( $imgUrl, "?" ) === false) 533 $imgUrl .= "?"; 534 535 $imgUrl .= "&ms=" . str_replace ( "px", "", $gmap ['width'] ) . "," . str_replace ( "px", "", $gmap ['height'] ); 536 $imgUrl .= "&key=" . $this->getConf ( 'bingAPIKey' ); 537 if (! empty ( $overlay )) { 538 $rowId = 0; 539 foreach ( $overlay as $data ) { 540 list ( $lat, $lon, $text, $angle, $opacity, $img ) = $data; 541 // TODO icon style lookup, see: http://msdn.microsoft.com/en-us/library/ff701719.aspx for iconStyle 542 $iconStyle = 32; 543 $rowId ++; 544 // NOTE: the max number of pushpins is 18! or we have to use POST (http://msdn.microsoft.com/en-us/library/ff701724.aspx) 545 if ($rowId == 18) { 546 break; 547 } 548 $imgUrl .= "&pp=$lat,$lon;$iconStyle;$rowId"; 549 } 550 } 551 $imgUrl .= "&.png"; 552 dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getBing: bing image url is:'); 553 return $imgUrl; 554 } 555 556 /** 557 * Create a static OSM map image url w/ the poi from http://staticmap.openstreetmap.de (staticMapLite) 558 * use http://staticmap.openstreetmap.de "staticMapLite" or a local version 559 * 560 * @param array $gmap 561 * @param array $overlay 562 * 563 * @todo implementation for http://ojw.dev.openstreetmap.org/StaticMapDev/ 564 */ 565 private function _getStaticOSM($gmap, $overlay) { 566 global $conf; 567 568 if ($this->getConf ( 'optionStaticMapGenerator' ) == 'local') { 569 // using local basemap composer 570 571 if (! $my = &plugin_load ( 'helper', 'openlayersmap_staticmap' )) { 572 dbglog ( $my, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: openlayersmap_staticmap plugin is not available.' ); 573 } 574 if (! $geophp = &plugin_load ( 'helper', 'geophp' )) { 575 dbglog ( $geophp, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: geophp plugin is not available.' ); 576 } 577 $size = str_replace ( "px", "", $gmap ['width'] ) . "x" . str_replace ( "px", "", $gmap ['height'] ); 578 579 $markers = ''; 580 if (! empty ( $overlay )) { 581 foreach ( $overlay as $data ) { 582 list ( $lat, $lon, $text, $angle, $opacity, $img ) = $data; 583 $iconStyle = substr ( $img, 0, strlen ( $img ) - 4 ); 584 $markers [] = array ( 585 'lat' => $lat, 586 'lon' => $lon, 587 'type' => $iconStyle 588 ); 589 } 590 } 591 592 switch ($gmap ['baselyr']) { 593 case 'mapnik' : 594 case 'openstreetmap' : 595 $maptype = 'openstreetmap'; 596 break; 597 case 'transport' : 598 $maptype = 'transport'; 599 break; 600 case 'landscape' : 601 $maptype = 'landscape'; 602 break; 603 case 'cycle map' : 604 $maptype = 'cycle'; 605 break; 606 case 'hike and bike map' : 607 $maptype = 'hikeandbike'; 608 break; 609 case 'mapquest hybrid' : 610 case 'mapquest road' : 611 case 'mapquest sat' : 612 $maptype = 'mapquest'; 613 break; 614 default : 615 $maptype = ''; 616 break; 617 } 618 619 $result = $my->getMap ( $gmap ['lat'], $gmap ['lon'], $gmap ['zoom'], $size, $maptype, $markers, $gmap ['gpxfile'], $gmap ['kmlfile'], $gmap ['geojsonfile'] ); 620 } else { 621 // using external basemap composer 622 623 // http://staticmap.openstreetmap.de/staticmap.php?center=47.000622235634,10.117187497601&zoom=5&size=500x350 624 // &markers=48.999812532766,8.3593749976708,lightblue1|43.154850037315,17.499999997306,lightblue1|49.487527053077,10.820312497573,ltblu-pushpin|47.951071133739,15.917968747369,ol-marker|47.921629720114,18.027343747285,ol-marker-gold|47.951071133739,19.257812497236,ol-marker-blue|47.180141361692,19.257812497236,ol-marker-green 625 $imgUrl = "http://staticmap.openstreetmap.de/staticmap.php"; 626 $imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon']; 627 $imgUrl .= "&size=" . str_replace ( "px", "", $gmap ['width'] ) . "x" . str_replace ( "px", "", $gmap ['height'] ); 628 629 if ($gmap ['zoom'] > 16) { 630 // actually this could even be 18, but that seems overkill 631 $imgUrl .= "&zoom=16"; 632 } else { 633 $imgUrl .= "&zoom=" . $gmap ['zoom']; 634 } 635 636 if (! empty ( $overlay )) { 637 $rowId = 0; 638 $imgUrl .= "&markers="; 639 foreach ( $overlay as $data ) { 640 list ( $lat, $lon, $text, $angle, $opacity, $img ) = $data; 641 $rowId ++; 642 $iconStyle = "lightblue$rowId"; 643 $imgUrl .= "$lat,$lon,$iconStyle%7c"; 644 } 645 $imgUrl = substr ( $imgUrl, 0, - 3 ); 646 } 647 648 $result = $imgUrl; 649 } 650 dbglog ( $result, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: osm image url is:' ); 651 return $result; 652 } 653 654 /** 655 * Calculate the minimum bbox for a start location + poi. 656 * 657 * @param array $overlay 658 * multi-dimensional array of array($lat, $lon, $text, $angle, $opacity, $img) 659 * @param float $lat 660 * latitude for map center 661 * @param float $lon 662 * longitude for map center 663 * @return multitype:float array describing the mbr and center point 664 */ 665 private function _calcBBOX($overlay, $lat, $lon) { 666 $lats [] = $lat; 667 $lons [] = $lon; 668 foreach ( $overlay as $data ) { 669 list ( $lat, $lon, $text, $angle, $opacity, $img ) = $data; 670 $lats [] = $lat; 671 $lons [] = $lon; 672 } 673 sort ( $lats ); 674 sort ( $lons ); 675 // TODO: make edge/wrap around cases work 676 $centerlat = $lats [0] + ($lats [count ( $lats ) - 1] - $lats [0]); 677 $centerlon = $lons [0] + ($lons [count ( $lats ) - 1] - $lons [0]); 678 return array ( 679 'minlat' => $lats [0], 680 'minlon' => $lons [0], 681 'maxlat' => $lats [count ( $lats ) - 1], 682 'maxlon' => $lons [count ( $lats ) - 1], 683 'centerlat' => $centerlat, 684 'centerlon' => $centerlon 685 ); 686 } 687 688 /** 689 * Figures out the base filename of a media path. 690 * 691 * @param String $mediaLink 692 */ 693 private function getFileName($mediaLink) { 694 $mediaLink = str_replace ( '[[', '', $mediaLink ); 695 $mediaLink = str_replace ( ']]', '', $mediaLink ); 696 $mediaLink = substr ( $mediaLink, 0, - 4 ); 697 $parts = explode ( ':', $mediaLink ); 698 $mediaLink = end ( $parts ); 699 return str_replace ( '_', ' ', $mediaLink ); 700 } 701}