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 } 118 119 // append dw p_render specific params and render 120 $imgUrl .="?".str_replace("px", "",$gmap['width'])."x".str_replace("px", "",$gmap['height']); 121 $imgUrl .= "&nolink"; 122 $imgUrl .= " |".$gmap['summary']." }}"; 123 124 $mapid = $gmap['id']; 125 // create a javascript parameter string for the map 126 $param = ''; 127 foreach ($gmap as $key => $val) { 128 $param .= is_numeric($val) ? "$key: $val, " : "$key: '" . hsc($val) . "', "; 129 } 130 if (!empty ($param)) { 131 $param = substr($param, 0, -2); 132 } 133 unset ($gmap['id']); 134 135 // create a javascript serialisation of the point data 136 $poi = ''; 137 $poitable=''; 138 $rowId=0; 139 if (!empty ($overlay)) { 140 foreach ($overlay as $data) { 141 list ($lat, $lon, $text, $angle, $opacity, $img) = $data; 142 $rowId++; 143 $poi .= ", {lat: $lat, lon: $lon, txt: '$text', angle: $angle, opacity: $opacity, img: '$img', rowId: $rowId}"; 144 $poitable .=' 145 <tr> 146 <td class="rowId">'.$rowId.'</td> 147 <td class="icon"><img src="'.DOKU_BASE.'lib/plugins/openlayersmap/icons/'.$img.'" alt="icon" /></td> 148 <td class="lat" title="'.$this->getLang('olmapPOIlatTitle').'">'.$lat.'</td> 149 <td class="lon" title="'.$this->getLang('olmapPOIlonTitle').'">'.$lon.'</td> 150 <td class="txt">'.$text.'</td> 151 </tr>'; 152 } 153 $poi = substr($poi, 2); 154 } 155 if (!empty ($gmap['kmlfile'])) { 156 $poitable .=' 157 <tr> 158 <td class="rowId"><img src="'.DOKU_BASE.'lib/plugins/openlayersmap/toolbar/kml_file.png" alt="KML icon" /></td> 159 <td class="icon"><img src="'.DOKU_BASE.'lib/plugins/openlayersmap/toolbar/kml_line.png" alt="icon" /></td> 160 <td class="txt" colspan="3">KML track: '.$this->getFileName($gmap['kmlfile']).'</td> 161 </tr>'; 162 } 163 if (!empty ($gmap['gpxfile'])) { 164 $poitable .=' 165 <tr> 166 <td class="rowId"><img src="'.DOKU_BASE.'lib/plugins/openlayersmap/toolbar/gpx_file.png" alt="GPX icon" /></td> 167 <td class="icon"><img src="'.DOKU_BASE.'lib/plugins/openlayersmap/toolbar/gpx_line.png" alt="icon" /></td> 168 <td class="txt" colspan="3">GPX track: '.$this->getFileName($gmap['gpxfile']).'</td> 169 </tr>'; 170 } 171 172 $js .= "{mapOpts:{" . $param . " },poi:[$poi]};"; 173 // unescape the json 174 $poitable = stripslashes($poitable); 175 176 return array($mapid,$js,$mainLat,$mainLon,$poitable,$gmap['summary'],$imgUrl,$_firstimageID); 177 } 178 179 /** 180 * @see DokuWiki_Syntax_Plugin::render() 181 */ 182 function render($mode, &$renderer, $data) { 183 // set to true after external scripts tags are written 184 static $initialised = false; 185 // incremented for each map tag in the page source so we can keep track of each map in a page 186 static $mapnumber = 0; 187 188 // dbglog($data, 'olmap::render() data.'); 189 list ($mapid, $param, $mainLat, $mainLon, $poitable, $poitabledesc, $staticImgUrl, $_firstimage) = $data; 190 191 if ($mode == 'xhtml') { 192 $olscript = ''; 193 $olEnable = false; 194 $gscript = ''; 195 $gEnable = $this->getConf('enableGoogle'); 196 $mqEnable = $this->getConf('enableMapQuest'); 197 $osmEnable = $this->getConf('enableOSM'); 198 $enableBing = $this->getConf('enableBing'); 199 200 $scriptEnable = ''; 201 202 if (!$initialised) { 203 $initialised = true; 204 // render necessary script tags 205 if($gEnable){ 206 $gscript ='<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.11&sensor=false"></script>'; 207 } 208 $olscript = $this->getConf('olScriptUrl'); 209 $olscript = $olscript ? '<script type="text/javascript" src="' . $olscript . '"></script>' : ""; 210 $olscript = str_replace('DOKU_BASE/', DOKU_BASE, $olscript); 211 212 $scriptEnable = '<script type="text/javascript"><!--//--><![CDATA[//><!--' . "\n"; 213 $scriptEnable .= $olscript ? 'olEnable = true;' : 'olEnable = false;'; 214 $scriptEnable .= 'gEnable = '.($gEnable ? 'true' : 'false').';'; 215 $scriptEnable .= 'osmEnable = '.($osmEnable ? 'true' : 'false').';'; 216 $scriptEnable .= 'mqEnable = '.($mqEnable ? 'true' : 'false').';'; 217 $scriptEnable .= 'bEnable = '.($enableBing ? 'true' : 'false').';'; 218 $scriptEnable .= 'bApiKey="'.$this->getConf('bingAPIKey').'";'; 219 $scriptEnable .= 'OpenLayers.ImgPath = "'.DOKU_BASE.'lib/plugins/openlayersmap/lib/'.$this->getConf('olMapStyle').'/";'; 220 $scriptEnable .= "\n" . '//--><!]]></script>'; 221 } 222 $renderer->doc .= " 223 $gscript 224 $olscript 225 $scriptEnable"; 226 227 if ($this->getConf('enableA11y')){ 228 $renderer->doc .= '<div id="'.$mapid.'-static" class="olStaticMap">'.p_render($mode, p_get_instructions($staticImgUrl), $info).'</div>'; 229 } 230 $renderer->doc .= '<div id="'.$mapid.'-clearer" class="clearer"><p> </p></div>'; 231 if ($this->getConf('enableA11y')){ 232 // render a (initially hidden) table of the POI for the print and a11y presentation 233 $renderer->doc .= '<div class="olPOItableSpan" id="'.$mapid.'-table-span"><table class="olPOItable" id="'.$mapid.'-table" summary="'.$poitabledesc.'" title="'.$this->getLang('olmapPOItitle').'"> 234 <caption class="olPOITblCaption">'.$this->getLang('olmapPOItitle').'</caption> 235 <thead class="olPOITblHeader"> 236 <tr> 237 <th class="rowId" scope="col">id</th> 238 <th class="icon" scope="col">'.$this->getLang('olmapPOIicon').'</th> 239 <th class="lat" scope="col" title="'.$this->getLang('olmapPOIlatTitle').'">'.$this->getLang('olmapPOIlat').'</th> 240 <th class="lon" scope="col" title="'.$this->getLang('olmapPOIlonTitle').'">'.$this->getLang('olmapPOIlon').'</th> 241 <th class="txt" scope="col">'.$this->getLang('olmapPOItxt').'</th> 242 </tr> 243 </thead>'; 244 if ($poitabledesc !=''){ 245 $renderer->doc .='<tfoot class="olPOITblFooter"><tr><td colspan="5">'.$poitabledesc.'</td></tr></tfoot>'; 246 } 247 $renderer->doc .='<tbody class="olPOITblBody">'.$poitable.'</tbody> 248 </table></div>'; 249 } 250 // render inline mapscript parts 251 $renderer->doc .="\n <script type='text/javascript'><!--//--><![CDATA[//><!--\n"; 252 $renderer->doc .=" olMapData[$mapnumber] = $param 253 //--><!]]></script>"; 254 $mapnumber++; 255 return true; 256 } elseif ($mode == 'metadata') { 257 if (!(($this->dflt['lat']==$mainLat) && ($thisdflt['lon']==$mainLon))){ 258 // render geo metadata, unless they are the default 259 $renderer->meta['geo']['lat'] = $mainLat; 260 $renderer->meta['geo']['lon'] = $mainLon; 261 if ($geophp = &plugin_load('helper', 'geophp')){ 262 // if we have the geoPHP helper, add the geohash 263 $renderer->meta['geo']['geohash'] = (new Point($mainLon,$mainLat))->out('geohash'); 264 } 265 } 266 267 if(($this->getConf('enableA11y')) && (!empty($_firstimage))){ 268 // add map local image into relation/firstimage if not already filled and when it is a local image 269 270 //$metaresult = p_render($mode, p_get_instructions($staticImgUrl), $info); 271 //dbglog($metaresult,'olmap::render#rendering image relation metadata for metaresult'); 272 //dbglog($info,'olmap::render#rendering info'); 273 274 global $ID; 275 $rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE); 276 $img = $rel['firstimage']; 277 if(empty($img)){ 278 dbglog($_firstimage,'olmap::render#rendering image relation metadata for _firstimage'); 279 // TODO this seems to never work; the firstimage entry in the .meta file is empty 280 $renderer->meta['relation']['firstimage'] = $_firstimage; 281 // but this works fine 282 // $renderer->meta['relation']['test_firstimage'] = $_firstimage; 283 284 // TODO and neither does this; the firstimage entry in the .meta file is empty 285 // $relation = array('relation'=>array('firstimage'=>$_firstimage)); 286 // dbglog($relation,'olmap::render#rendering image relation metadata for relation'); 287 // p_set_metadata($ID, $relation, false, false); 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 switch ($this->getConf('optionStaticMapGenerator')){ 535 case 'local': 536 // TODO this is not ever used see below.. 537 $imgUrl =$conf['baseurl']."/lib/plugins/openlayersmap/StaticMap.php"; 538 $imgUrl .= '?kml='.$gmap['kmlfile']; 539 $imgUrl .= '&gpx='.$gmap['gpxfile']; 540 break; 541 case 'remote': 542 // fall through to default 543 default: 544 $imgUrl = "http://staticmap.openstreetmap.de/staticmap.php"; 545 break; 546 } 547 548 $imgUrl .= "¢er=".$gmap['lat'].",".$gmap['lon']; 549 $imgUrl .= "&size=".str_replace("px", "",$gmap['width'])."x".str_replace("px", "",$gmap['height']); 550 $size =str_replace("px", "",$gmap['width'])."x".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 switch ($gmap['baselyr']){ 560 case 'mapnik': 561 case 'openstreetmap': 562 $maptype='openstreetmap'; 563 break; 564 case 'transport': 565 $maptype='transport'; 566 break; 567 case 'landscape': 568 $maptype='landscape'; 569 break; 570 case 'cycle map': 571 $maptype='cycle'; 572 break; 573 case 'cloudmade': 574 $maptype='cloudmade'; 575 break; 576 case 'cloudmade fresh': 577 $maptype='fresh'; 578 break; 579 case 'hike and bike map': 580 $maptype='hikeandbike'; 581 break; 582 case 'mapquest hybrid': 583 case 'mapquest road': 584 case 'mapquest sat': 585 $maptype='mapquest'; 586 break; 587 default: 588 $maptype=''; 589 break; 590 } 591 $imgUrl .= "&maptype=".$maptype; 592 593 $markers=''; 594 if (!empty ($overlay)) { 595 $rowId=0; 596 $imgUrl .= "&markers="; 597 foreach ($overlay as $data) { 598 list ($lat, $lon, $text, $angle, $opacity, $img) = $data; 599 $rowId++; 600 if ($this->getConf('optionStaticMapGenerator')=='remote') $iconStyle = "lightblue$rowId"; 601 if ($this->getConf('optionStaticMapGenerator')=='local') $iconStyle = substr($img, 0,strlen($img)-4); 602 $imgUrl .= "$lat,$lon,$iconStyle%7c"; 603 $markers[] = array( 604 'lat'=>$lat, 605 'lon'=>$lon, 606 'type'=>$iconStyle); 607 } 608 $imgUrl = substr($imgUrl,0,-3); 609 } 610 611 if (!$my = &plugin_load('helper', 'openlayersmap_staticmap')){ 612 dbglog($my,'syntax_plugin_openlayersmap_olmap::_getStaticOSM: openlayersmap_staticmap plugin is not available.'); 613 } 614 if (!$geophp = &plugin_load('helper', 'geophp')){ 615 dbglog($geophp,'syntax_plugin_openlayersmap_olmap::_getStaticOSM: geophp plugin is not available.'); 616 } 617 618 // default to external provider 619 $result= $imgUrl; 620 if ($this->getConf('optionStaticMapGenerator')=='local') { 621 $result = $my->getMap($gmap['lat'],$gmap['lon'],$gmap['zoom'],$size,$maptype,$markers,$gmap['gpxfile'],$gmap['kmlfile']); 622 } 623 624 //dbglog($result,'syntax_plugin_openlayersmap_olmap::_getStaticOSM: osm image url is:'); 625 return $result; 626 } 627 628 /** 629 * Calculate the minimum bbox for a start location + poi. 630 * 631 * @param array $overlay multi-dimensional array of array($lat, $lon, $text, $angle, $opacity, $img) 632 * @param float $lat latitude for map center 633 * @param float $lon longitude for map center 634 * @return multitype:float array describing the mbr and center point 635 */ 636 private function _calcBBOX($overlay, $lat, $lon){ 637 $lats[] = $lat; 638 $lons[] = $lon; 639 foreach ($overlay as $data) { 640 list ($lat, $lon, $text, $angle, $opacity, $img) = $data; 641 $lats[] = $lat; 642 $lons[] = $lon; 643 } 644 sort($lats); 645 sort($lons); 646 // TODO: make edge/wrap around cases work 647 $centerlat = $lats[0]+($lats[count($lats)-1]-$lats[0]); 648 $centerlon = $lons[0]+($lons[count($lats)-1]-$lons[0]); 649 return array('minlat'=>$lats[0], 'minlon'=>$lons[0], 650 'maxlat'=>$lats[count($lats)-1], 'maxlon'=>$lons[count($lats)-1], 651 'centerlat'=>$centerlat,'centerlon'=>$centerlon); 652 } 653 654 /** 655 * Figures out the base filename of a media path. 656 * @param String $mediaLink 657 */ 658 private function getFileName($mediaLink){ 659 $mediaLink=str_replace('[[','',$mediaLink); 660 $mediaLink=str_replace(']]','',$mediaLink); 661 $mediaLink = substr($mediaLink, 0, -4); 662 $parts=explode(':',$mediaLink); 663 $mediaLink = end($parts); 664 return str_replace('_',' ',$mediaLink); 665 } 666}