1*628e43ccSMark Prins<?php 2*628e43ccSMark Prins/* 3*628e43ccSMark Prins * Copyright (c) 2008-2012 Mark C. Prins <mprins@users.sf.net> 4*628e43ccSMark Prins* 5*628e43ccSMark Prins* Permission to use, copy, modify, and distribute this software for any 6*628e43ccSMark Prins* purpose with or without fee is hereby granted, provided that the above 7*628e43ccSMark Prins* copyright notice and this permission notice appear in all copies. 8*628e43ccSMark Prins* 9*628e43ccSMark Prins* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10*628e43ccSMark Prins* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*628e43ccSMark Prins* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12*628e43ccSMark Prins* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*628e43ccSMark Prins* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*628e43ccSMark Prins* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15*628e43ccSMark Prins* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16*628e43ccSMark Prins*/ 17*628e43ccSMark Prins 18*628e43ccSMark Prinsif (!defined('DOKU_INC')) die(); 19*628e43ccSMark Prins 20*628e43ccSMark Prinsif (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 21*628e43ccSMark Prins 22*628e43ccSMark Prinsrequire_once DOKU_PLUGIN.'openlayersmap/StaticMap.php'; 23*628e43ccSMark Prins/** 24*628e43ccSMark Prins * DokuWiki Plugin openlayersmap (staticmap Helper Component) 25*628e43ccSMark Prins * 26*628e43ccSMark Prins * @author Mark Prins 27*628e43ccSMark Prins */ 28*628e43ccSMark Prinsclass helper_plugin_openlayersmap_staticmap extends DokuWiki_Plugin { 29*628e43ccSMark Prins private $maxWidth = 1024; 30*628e43ccSMark Prins private $maxHeight = 1024; 31*628e43ccSMark Prins /** 32*628e43ccSMark Prins * @override 33*628e43ccSMark Prins */ 34*628e43ccSMark Prins function getMethods(){ 35*628e43ccSMark Prins $result = array(); 36*628e43ccSMark Prins $result[] = array( 37*628e43ccSMark Prins 'name' => 'getMap', 38*628e43ccSMark Prins 'desc' => 'returns url to the image', 39*628e43ccSMark Prins 'params' => array( 40*628e43ccSMark Prins 'center' => 'string', 41*628e43ccSMark Prins 'zoom' => 'integer', 42*628e43ccSMark Prins 'size' => 'string', 43*628e43ccSMark Prins 'maptype' => 'string', 44*628e43ccSMark Prins 'markers' => 'string', 45*628e43ccSMark Prins 'gpx' => 'string', 46*628e43ccSMark Prins 'kml' => 'string'), 47*628e43ccSMark Prins 'return' => array('image' => 'string'), 48*628e43ccSMark Prins ); 49*628e43ccSMark Prins return $result; 50*628e43ccSMark Prins } 51*628e43ccSMark Prins 52*628e43ccSMark Prins /** 53*628e43ccSMark Prins * Create the map. 54*628e43ccSMark Prins * 55*628e43ccSMark Prins * @param number lat the latitude of the map's center, eg. 40.714728 56*628e43ccSMark Prins * @param number lon the longitude of the map's center, eg -73.998672 57*628e43ccSMark Prins * @param number zoom the zoom level in the tile cache, eg. 14 58*628e43ccSMark Prins * @param mixed size the size in WxH px, eg. 512x512 59*628e43ccSMark Prins * @param string maptype the maptype, eg. cycle 60*628e43ccSMark Prins * @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*628e43ccSMark Prins * @param string gpx media link 62*628e43ccSMark Prins * @param string kml media link 63*628e43ccSMark Prins * 64*628e43ccSMark Prins * @return the media id url 65*628e43ccSMark Prins */ 66*628e43ccSMark Prins public function getMap($lat, $lon, $zoom, $size, $maptype, $markers, $gpx, $kml){ 67*628e43ccSMark Prins global $conf; 68*628e43ccSMark Prins //dbglog($markers,'helper_plugin_openlayersmap_staticmap::getMap: markers :'); 69*628e43ccSMark Prins 70*628e43ccSMark Prins // normalize zoom 71*628e43ccSMark Prins $zoom = $zoom?intval($zoom):0; 72*628e43ccSMark Prins if($zoom > 18) $zoom = 18; 73*628e43ccSMark Prins // normalize WxH 74*628e43ccSMark Prins list($width, $height) = split('x',$size); 75*628e43ccSMark Prins $width = intval($width); 76*628e43ccSMark Prins if($width > $this->maxWidth) $width = $this->maxWidth; 77*628e43ccSMark Prins $height = intval($height); 78*628e43ccSMark Prins if($height > $this->maxHeight) $height = $this->maxHeight; 79*628e43ccSMark Prins // create map 80*628e43ccSMark Prins $map = new StaticMap($lat, $lon, $zoom, $width, $height, $maptype, $markers, $gpx, $kml, 81*628e43ccSMark Prins $conf['mediadir'], 82*628e43ccSMark Prins $conf['cachedir'] 83*628e43ccSMark Prins ); 84*628e43ccSMark Prins // return the media id url 85*628e43ccSMark Prins $mediaId = str_replace('/', ':', $map->getMap()); 86*628e43ccSMark Prins return $mediaId; 87*628e43ccSMark Prins } 88*628e43ccSMark Prins}