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" charset="utf-8">/*<![CDATA[*/'; 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 .= '/*!]]>*/</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 .='<script type="text/javascript" charset="utf-8">/*<![CDATA[*/'; 252 $renderer->doc .=" olMapData[$mapnumber] = $param /*!]]>*/</script>"; 253 $mapnumber++; 254 return true; 255 } elseif ($mode == 'metadata') { 256 if (!(($this->dflt['lat']==$mainLat) && ($thisdflt['lon']==$mainLon))){ 257 // render geo metadata, unless they are the default 258 $renderer->meta['geo']['lat'] = $mainLat; 259 $renderer->meta['geo']['lon'] = $mainLon; 260 if ($geophp = &plugin_load('helper', 'geophp')){ 261 // if we have the geoPHP helper, add the geohash 262 $renderer->meta['geo']['geohash'] = (new Point($mainLon,$mainLat))->out('geohash'); 263 } 264 } 265 266 if(($this->getConf('enableA11y')) && (!empty($_firstimage))){ 267 // add map local image into relation/firstimage if not already filled and when it is a local image 268 269 global $ID; 270 $rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE); 271 $img = $rel['firstimage']; 272 if(empty($img) /* || $img == $_firstimage*/){ 273 dbglog($_firstimage,'olmap::render#rendering image relation metadata for _firstimage as $img was empty or the same.'); 274 // This seems to never work; the firstimage entry in the .meta file is empty 275 // $renderer->meta['relation']['firstimage'] = $_firstimage; 276 277 // ... and neither does this; the firstimage entry in the .meta file is empty 278 // $relation = array('relation'=>array('firstimage'=>$_firstimage)); 279 // p_set_metadata($ID, $relation, false, false); 280 281 // ... this works 282 $renderer->internalmedia($_firstimage, $poitabledesc); 283 } 284 } 285 return true; 286 } 287 return false; 288 } 289 290 /** 291 * extract parameters for the map from the parameter string 292 * 293 * @param string $str_params string of key="value" pairs 294 * @return array associative array of parameters key=>value 295 */ 296 private function _extract_params($str_params) { 297 $param = array (); 298 preg_match_all('/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER); 299 // parse match for instructions, break into key value pairs 300 $gmap = $this->dflt; 301 foreach ($param as $kvpair) { 302 list ($match, $key, $val) = $kvpair; 303 $key = strtolower($key); 304 if (isset ($gmap[$key])){ 305 if ($key == 'summary'){ 306 // preserve case for summary field 307 $gmap[$key] = $val; 308 }else { 309 $gmap[$key] = strtolower($val); 310 } 311 } 312 } 313 return $gmap; 314 } 315 316 /** 317 * extract overlay points for the map from the wiki syntax data 318 * 319 * @param string $str_points multi-line string of lat,lon,text triplets 320 * @return array multi-dimensional array of lat,lon,text triplets 321 */ 322 private function _extract_points($str_points) { 323 $point = array (); 324 //preg_match_all('/^([+-]?[0-9].*?),\s*([+-]?[0-9].*?),(.*?),(.*?),(.*?),(.*)$/um', $str_points, $point, PREG_SET_ORDER); 325 /* 326 group 1: ([+-]?[0-9]+(?:\.[0-9]*)?) 327 group 2: ([+-]?[0-9]+(?:\.[0-9]*)?) 328 group 3: (.*?) 329 group 4: (.*?) 330 group 5: (.*?) 331 group 6: (.*) 332 */ 333 preg_match_all('/^([+-]?[0-9]+(?:\.[0-9]*)?),\s*([+-]?[0-9]+(?:\.[0-9]*)?),(.*?),(.*?),(.*?),(.*)$/um', $str_points, $point, PREG_SET_ORDER); 334 // create poi array 335 $overlay = array (); 336 foreach ($point as $pt) { 337 list ($match, $lat, $lon, $angle, $opacity, $img, $text) = $pt; 338 $lat = is_numeric($lat) ? $lat : 0; 339 $lon = is_numeric($lon) ? $lon : 0; 340 $angle = is_numeric($angle) ? $angle : 0; 341 $opacity = is_numeric($opacity) ? $opacity : 0.8; 342 $img = trim($img); 343 // TODO validate using exist & set up default img? 344 $text = addslashes(str_replace("\n", "", p_render("xhtml", p_get_instructions($text), $info))); 345 $overlay[] = array($lat, $lon, $text, $angle, $opacity, $img); 346 } 347 return $overlay; 348 } 349 350 /** 351 * Create a MapQuest static map API image url. 352 * @param array $gmap 353 * @param array $overlay 354 */ 355 private function _getMapQuest($gmap,$overlay) { 356 $sUrl=$this->getConf('iconUrlOverload'); 357 if (!$sUrl){ 358 $sUrl=DOKU_URL; 359 } 360 switch ($gmap['baselyr']){ 361 case 'mapquest hybrid': 362 $maptype='hyb'; 363 break; 364 case 'mapquest sat': 365 // because sat coverage is very limited use 'hyb' instead of 'sat' so we don't get a blank map 366 $maptype='hyb'; 367 break; 368 case 'mapquest road': 369 default: 370 $maptype='map'; 371 break; 372 } 373 $imgUrl = "http://open.mapquestapi.com/staticmap/v4/getmap?declutter=true&"; 374 if (count($overlay)< 1){ 375 $imgUrl .= "?center=".$gmap['lat'].",".$gmap['lon']; 376 //max level for mapquest is 16 377 if ($gmap['zoom']>16) { 378 $imgUrl .= "&zoom=16"; 379 } else { 380 $imgUrl .= "&zoom=".$gmap['zoom']; 381 } 382 } 383 // use bestfit instead of center/zoom, needs upperleft/lowerright corners 384 //$bbox=$this->_calcBBOX($overlay, $gmap['lat'], $gmap['lon']); 385 //$imgUrl .= "bestfit=".$bbox['minlat'].",".$bbox['maxlon'].",".$bbox['maxlat'].",".$bbox['minlon']; 386 387 // TODO declutter option works well for square maps but not for rectangular, maybe compensate for that or compensate the mbr.. 388 $imgUrl .= "&size=".str_replace("px", "",$gmap['width']).",".str_replace("px", "",$gmap['height']); 389 390 // TODO mapquest allows using one image url with a multiplier $NUMBER eg: 391 // $NUMBER = 2 392 // $imgUrl .= DOKU_URL."/".DOKU_PLUGIN."/".getPluginName()."/icons/".$img.",$NUMBER,C,".$lat1.",".$lon1.",0,0,0,0,C,".$lat2.",".$lon2.",0,0,0,0"; 393 if (!empty ($overlay)) { 394 $imgUrl .= "&xis="; 395 foreach ($overlay as $data) { 396 list ($lat, $lon, $text, $angle, $opacity, $img) = $data; 397 //$imgUrl .= $sUrl."lib/plugins/openlayersmap/icons/".$img.",1,C,".$lat.",".$lon.",0,0,0,0,"; 398 $imgUrl .= $sUrl."lib/plugins/openlayersmap/icons/".$img.",1,C,".$lat.",".$lon.","; 399 } 400 $imgUrl = substr($imgUrl,0,-1); 401 } 402 $imgUrl .= "&imageType=png&type=".$maptype; 403 //dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getMapQuest: MapQuest image url is:'); 404 return $imgUrl; 405 } 406 407 /** 408 * Create a Google maps static image url w/ the poi. 409 * @param array $gmap 410 * @param array $overlay 411 */ 412 private function _getGoogle($gmap, $overlay){ 413 $sUrl=$this->getConf('iconUrlOverload'); 414 if (!$sUrl){ 415 $sUrl=DOKU_URL; 416 } 417 switch ($gmap['baselyr']){ 418 case 'google hybrid': 419 $maptype='hybrid'; 420 break; 421 case 'google sat': 422 $maptype='satellite'; 423 break; 424 case 'google relief': 425 $maptype='terrain'; 426 break; 427 case 'google road': 428 default: 429 $maptype='roadmap'; 430 break; 431 } 432 // TODO maybe use viewport / visible instead of center/zoom, 433 // see: https://code.google.com/intl/nl/apis/maps/documentation/staticmaps/#ImplicitPositioning 434 //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 435 $imgUrl = "http://maps.google.com/maps/api/staticmap?sensor=false"; 436 $imgUrl .= "&size=".str_replace("px", "",$gmap['width'])."x".str_replace("px", "",$gmap['height']); 437 $imgUrl .= "¢er=".$gmap['lat'].",".$gmap['lon']; 438 // max is 21 (== building scale), but that's overkill.. 439 if ($gmap['zoom']>17) { 440 $imgUrl .= "&zoom=17"; 441 } else { 442 $imgUrl .= "&zoom=".$gmap['zoom']; 443 } 444 445 if (!empty ($overlay)) { 446 $rowId=0; 447 foreach ($overlay as $data) { 448 list ($lat, $lon, $text, $angle, $opacity, $img) = $data; 449 $imgUrl .= "&markers=icon%3a".$sUrl."lib/plugins/openlayersmap/icons/".$img."%7c".$lat.",".$lon."%7clabel%3a".++$rowId; 450 } 451 } 452 $imgUrl .= "&format=png&maptype=".$maptype; 453 global $conf; 454 $imgUrl .= "&language=".$conf['lang']; 455 //dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getGoogle: Google image url is:'); 456 return $imgUrl; 457 } 458 459 /** 460 * Create a Bing maps static image url w/ the poi. 461 * @param array $gmap 462 * @param array $overlay 463 */ 464 private function _getBing($gmap, $overlay){ 465 if(!$this->getConf('bingAPIKey')){ 466 // in case there is no Bing api key we'll use OSM 467 $this->_getStaticOSM($gmap, $overlay); 468 } 469 switch ($gmap['baselyr']){ 470 case 've hybrid': 471 case 'bing hybrid': 472 $maptype='AerialWithLabels'; 473 break; 474 case 've sat': 475 case 'bing sat': 476 $maptype='Aerial'; 477 break; 478 case 've normal': 479 case 've road': 480 case 've': 481 case 'bing road': 482 default: 483 $maptype='Road'; 484 break; 485 } 486 $imgUrl = "http://dev.virtualearth.net/REST/v1/Imagery/Map/".$maptype."/"; 487 if (!$this->getConf('autoZoomMap')){ 488 $bbox=$this->_calcBBOX($overlay, $gmap['lat'], $gmap['lon']); 489 $imgUrl .= "?mapArea=".$bbox['minlat'].",".$bbox['minlon'].",".$bbox['maxlat'].",".$bbox['maxlon']; 490 $imgUrl .= "&declutter=1"; 491 // or 492 //$imgUrl .= $gmap['lat'].",".$gmap['lon']."/".$gmap['zoom']."?"; 493 } 494 if (strpos($imgUrl, "?") === false) $imgUrl .= "?"; 495 496 $imgUrl .= "&ms=".str_replace("px", "",$gmap['width']).",".str_replace("px", "",$gmap['height']); 497 $imgUrl .= "&key=".$this->getConf('bingAPIKey'); 498 if (!empty ($overlay)) { 499 $rowId=0; 500 foreach ($overlay as $data) { 501 list ($lat, $lon, $text, $angle, $opacity, $img) = $data; 502 // TODO icon style lookup, see: http://msdn.microsoft.com/en-us/library/ff701719.aspx for iconStyle 503 $iconStyle=32; 504 $rowId++; 505 // NOTE: the max number of pushpins is 18! or we have tuo use POST (http://msdn.microsoft.com/en-us/library/ff701724.aspx) 506 if ($rowId==18) { 507 break; 508 } 509 $imgUrl .= "&pp=$lat,$lon;$iconStyle;$rowId"; 510 } 511 } 512 //dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getBing: bing image url is:'); 513 return $imgUrl; 514 } 515 516 /** 517 * Create a static OSM map image url w/ the poi from http://staticmap.openstreetmap.de (staticMapLite) 518 * use http://staticmap.openstreetmap.de "staticMapLite" or a local version 519 * @param array $gmap 520 * @param array $overlay 521 * 522 * @todo implementation for http://ojw.dev.openstreetmap.org/StaticMapDev/ 523 */ 524 private function _getStaticOSM($gmap, $overlay){ 525 //http://staticmap.openstreetmap.de/staticmap.php?center=47.000622235634,10.117187497601&zoom=5&size=500x350 526 // &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 527 global $conf; 528 529 switch ($this->getConf('optionStaticMapGenerator')){ 530 case 'local': 531 // TODO this is not ever used see below.. 532 $imgUrl =$conf['baseurl']."/lib/plugins/openlayersmap/StaticMap.php"; 533 $imgUrl .= '?kml='.$gmap['kmlfile']; 534 $imgUrl .= '&gpx='.$gmap['gpxfile']; 535 break; 536 case 'remote': 537 // fall through to default 538 default: 539 $imgUrl = "http://staticmap.openstreetmap.de/staticmap.php"; 540 break; 541 } 542 543 $imgUrl .= "¢er=".$gmap['lat'].",".$gmap['lon']; 544 $imgUrl .= "&size=".str_replace("px", "",$gmap['width'])."x".str_replace("px", "",$gmap['height']); 545 $size =str_replace("px", "",$gmap['width'])."x".str_replace("px", "",$gmap['height']); 546 547 if ($gmap['zoom']>16) { 548 // actually this could even be 18, but that seems overkill 549 $imgUrl .= "&zoom=16"; 550 } else { 551 $imgUrl .= "&zoom=".$gmap['zoom']; 552 } 553 554 switch ($gmap['baselyr']){ 555 case 'mapnik': 556 case 'openstreetmap': 557 $maptype='openstreetmap'; 558 break; 559 case 'transport': 560 $maptype='transport'; 561 break; 562 case 'landscape': 563 $maptype='landscape'; 564 break; 565 case 'cycle map': 566 $maptype='cycle'; 567 break; 568 case 'cloudmade': 569 $maptype='cloudmade'; 570 break; 571 case 'cloudmade fresh': 572 $maptype='fresh'; 573 break; 574 case 'hike and bike map': 575 $maptype='hikeandbike'; 576 break; 577 case 'mapquest hybrid': 578 case 'mapquest road': 579 case 'mapquest sat': 580 $maptype='mapquest'; 581 break; 582 default: 583 $maptype=''; 584 break; 585 } 586 $imgUrl .= "&maptype=".$maptype; 587 588 $markers=''; 589 if (!empty ($overlay)) { 590 $rowId=0; 591 $imgUrl .= "&markers="; 592 foreach ($overlay as $data) { 593 list ($lat, $lon, $text, $angle, $opacity, $img) = $data; 594 $rowId++; 595 if ($this->getConf('optionStaticMapGenerator')=='remote') $iconStyle = "lightblue$rowId"; 596 if ($this->getConf('optionStaticMapGenerator')=='local') $iconStyle = substr($img, 0,strlen($img)-4); 597 $imgUrl .= "$lat,$lon,$iconStyle%7c"; 598 $markers[] = array( 599 'lat'=>$lat, 600 'lon'=>$lon, 601 'type'=>$iconStyle); 602 } 603 $imgUrl = substr($imgUrl,0,-3); 604 } 605 606 if (!$my = &plugin_load('helper', 'openlayersmap_staticmap')){ 607 dbglog($my,'syntax_plugin_openlayersmap_olmap::_getStaticOSM: openlayersmap_staticmap plugin is not available.'); 608 } 609 if (!$geophp = &plugin_load('helper', 'geophp')){ 610 dbglog($geophp,'syntax_plugin_openlayersmap_olmap::_getStaticOSM: geophp plugin is not available.'); 611 } 612 613 // default to external provider 614 $result= $imgUrl; 615 if ($this->getConf('optionStaticMapGenerator')=='local') { 616 $result = $my->getMap($gmap['lat'],$gmap['lon'],$gmap['zoom'],$size,$maptype,$markers,$gmap['gpxfile'],$gmap['kmlfile']); 617 } 618 619 //dbglog($result,'syntax_plugin_openlayersmap_olmap::_getStaticOSM: osm image url is:'); 620 return $result; 621 } 622 623 /** 624 * Calculate the minimum bbox for a start location + poi. 625 * 626 * @param array $overlay multi-dimensional array of array($lat, $lon, $text, $angle, $opacity, $img) 627 * @param float $lat latitude for map center 628 * @param float $lon longitude for map center 629 * @return multitype:float array describing the mbr and center point 630 */ 631 private function _calcBBOX($overlay, $lat, $lon){ 632 $lats[] = $lat; 633 $lons[] = $lon; 634 foreach ($overlay as $data) { 635 list ($lat, $lon, $text, $angle, $opacity, $img) = $data; 636 $lats[] = $lat; 637 $lons[] = $lon; 638 } 639 sort($lats); 640 sort($lons); 641 // TODO: make edge/wrap around cases work 642 $centerlat = $lats[0]+($lats[count($lats)-1]-$lats[0]); 643 $centerlon = $lons[0]+($lons[count($lats)-1]-$lons[0]); 644 return array('minlat'=>$lats[0], 'minlon'=>$lons[0], 645 'maxlat'=>$lats[count($lats)-1], 'maxlon'=>$lons[count($lats)-1], 646 'centerlat'=>$centerlat,'centerlon'=>$centerlon); 647 } 648 649 /** 650 * Figures out the base filename of a media path. 651 * @param String $mediaLink 652 */ 653 private function getFileName($mediaLink){ 654 $mediaLink=str_replace('[[','',$mediaLink); 655 $mediaLink=str_replace(']]','',$mediaLink); 656 $mediaLink = substr($mediaLink, 0, -4); 657 $parts=explode(':',$mediaLink); 658 $mediaLink = end($parts); 659 return str_replace('_',' ',$mediaLink); 660 } 661}