xref: /plugin/openlayersmap/helper/staticmap.php (revision da6f229f6a0134a382d8502bff367a6523d94bc4)
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*/
17
18if (!defined('DOKU_INC')) die();
19
20if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
21
22require_once DOKU_PLUGIN.'openlayersmap/StaticMap.php';
23/**
24 * DokuWiki Plugin openlayersmap (staticmap Helper Component)
25 *
26 * @author Mark Prins
27 */
28class helper_plugin_openlayersmap_staticmap extends DokuWiki_Plugin {
29	private $maxWidth = 1024;
30	private $maxHeight = 1024;
31	/**
32	 * @override
33	 */
34	function getMethods(){
35		$result = array();
36		$result[] = array(
37				'name'   => 'getMap',
38				'desc'   => 'returns url to the image',
39				'params' => array(
40						'center' => 'string',
41						'zoom' => 'integer',
42						'size' => 'string',
43						'maptype' => 'string',
44						'markers' => 'string',
45						'gpx' => 'string',
46						'kml' => 'string'),
47				'return' => array('image' => 'string'),
48		);
49		return $result;
50	}
51
52	/**
53	 * Create the map.
54	 *
55	 * @param number lat the latitude of the map's center, eg. 40.714728
56	 * @param number lon the longitude of the map's center, eg -73.998672
57	 * @param number zoom the zoom level in the tile cache, eg. 14
58	 * @param mixed size the size in WxH px, eg. 512x512
59	 * @param string maptype the maptype, eg. cycle
60	 * @param mixed markers associative array of markers, array('lat'=>$lat,'lon'=>$lon,'type'=>$iconStyle), eg. array(	'lat'=>40.702147,	'lon'=>-74.015794,	'type'=>lightblue1);
61	 * @param string gpx media link
62	 * @param string kml media link
63	 *
64	 * @return the media id url
65	 */
66	public function getMap($lat, $lon, $zoom, $size, $maptype, $markers, $gpx, $kml){
67		global $conf;
68		//dbglog($markers,'helper_plugin_openlayersmap_staticmap::getMap: markers :');
69
70		// normalize zoom
71		$zoom = $zoom?intval($zoom):0;
72		if($zoom > 18) $zoom = 18;
73		// normalize WxH
74		list($width, $height) = split('x',$size);
75		$width = intval($width);
76		if($width > $this->maxWidth) $width = $this->maxWidth;
77		$height = intval($height);
78		if($height > $this->maxHeight) $height = $this->maxHeight;
79		// validate gpx/kml
80		$kml=str_replace(":","/",$kml);
81		$kml=str_replace("[","/",$kml);
82		$kml=str_replace("]","/",$kml);
83		$gpx=str_replace(":","/",$gpx);
84		$gpx=str_replace("[","/",$gpx);
85		$gpx=str_replace("]","/",$gpx);
86		//TODO make sure we don't end up with a double file sep. char here
87		$gpx = $conf['mediadir'].'/'.$gpx;
88		$kml = $conf['mediadir'].'/'.$kml;
89
90		// create map
91		$map = new StaticMap($lat, $lon, $zoom, $width, $height, $maptype, $markers, $gpx, $kml,
92				$conf['mediadir'],
93				$conf['cachedir']
94		);
95		// return the media id url
96		$mediaId = str_replace('/', ':',  $map->getMap());
97		return $mediaId;
98	}
99}