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