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