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