plugin:googlemaps
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:googlemaps [2013-02-14 23:39] – 66.158.184.28 | plugin:googlemaps [2023-10-30 23:18] (current) – Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Google Maps plugin | + | ====== Google Maps Plugin |
---- plugin ---- | ---- plugin ---- | ||
Line 7: | Line 7: | ||
type : syntax | type : syntax | ||
lastupdate : 2008-11-11 | lastupdate : 2008-11-11 | ||
- | compatible : 2008-05-05 | + | compatible : 2008-05-05, !Hogfather, |
depends | depends | ||
conflicts | conflicts | ||
Line 25: | Line 25: | ||
- | = | + | ===== Syntax ===== |
+ | |||
+ | < | ||
+ | lat, | ||
+ | lat, | ||
+ | </ | ||
+ | |||
+ | The lines of " | ||
+ | |||
+ | |||
+ | ==== Parameters ==== | ||
+ | |||
+ | * width --- //999[css length unit*]// (e.g. 500px, 50%) width of the Google map, default is " | ||
+ | * height --- //999[css length unit*]// (e.g. 500px, 30em) height of the Google map, default is " | ||
+ | * type --- values: map | satellite | hybrid. default map. | ||
+ | * lat --- values: -90.0 - 90.0; latitude of map centre, negative values are south. | ||
+ | * lon --- values: -180.0 - 180.0; longitude of map centre, negative values are west. | ||
+ | * zoom --- integer, zoom level, default value 8. Valid values depend on the map and location. | ||
+ | * controls --- values on | off. default on. Whether or not to show controls for zooming and panning on the map. | ||
+ | * kml --- values: off | [URL of kml file]. | ||
+ | |||
+ | The parameters can be in any order. | ||
+ | |||
+ | (*) For width and height any valid CSS length unit can be used. The common ones are **px** and **em**, plus **%** for widths. | ||
+ | |||
+ | |||
+ | ===== Demonstration ===== | ||
+ | |||
+ | See the page in action [[http:// | ||
+ | |||
+ | |||
+ | ===== Installation ===== | ||
+ | |||
+ | Search and install the plugin using the [[plugin: | ||
+ | |||
+ | |||
+ | **Plugin sources: | ||
+ | * All DokuWiki versions after 2006-11-06, including 2008-05-05 (current): --- [[http:// | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Configuration ===== | ||
+ | |||
+ | The plugin has two configuration constants: | ||
+ | |||
+ | * GMAP_KEY --- Your Google Maps API Key. To access Google Maps data you need a key. That key is unique to the URL (domain + path/ | ||
+ | * GMAP_SCRIPT --- The location of the Google maps JavaScript. | ||
+ | |||
+ | These two constants can be modified via the [[plugin: | ||
+ | |||
+ | ===== Details ===== | ||
+ | |||
+ | The plugin consists of seven files, the plugin php scripts [[# | ||
+ | |||
+ | ==== syntax/ | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | /** | ||
+ | * Plugin Google Maps: Allow Display of a Google Map in a wiki page. | ||
+ | * | ||
+ | * @license | ||
+ | * @author | ||
+ | */ | ||
+ | |||
+ | if(!defined(' | ||
+ | if(!defined(' | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | // ---------- [ Settings ] ----------------------------------------- | ||
+ | |||
+ | /** | ||
+ | * All DokuWiki plugins to extend the parser/ | ||
+ | * need to inherit from this class | ||
+ | */ | ||
+ | class syntax_plugin_googlemaps_googlemap extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | var $dflt = array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | |||
+ | function getInfo(){ | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | function getType() { return ' | ||
+ | function getPType() { return ' | ||
+ | function getSort() { return 900; } | ||
+ | |||
+ | function connectTo($mode) { | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | function handle($match, | ||
+ | |||
+ | // break matched cdata into its components | ||
+ | list($str_params, | ||
+ | |||
+ | $gmap = $this-> | ||
+ | $overlay = $this-> | ||
+ | |||
+ | // determine width and height (inline styles) for the map image | ||
+ | if ($gmap[' | ||
+ | $style = $gmap[' | ||
+ | $style .= $gmap[' | ||
+ | $style = " | ||
+ | } else { | ||
+ | $style = ''; | ||
+ | } | ||
+ | |||
+ | // unset gmap values for width and height - they don't go into javascript | ||
+ | unset($gmap[' | ||
+ | |||
+ | // create a javascript parameter string for the map | ||
+ | $param = ''; | ||
+ | foreach ($gmap as $key => $val) { | ||
+ | $param .= is_numeric($val) ? " $key : $val," : "$key : '" | ||
+ | } | ||
+ | |||
+ | if (!empty($param)) $param = substr($param, | ||
+ | |||
+ | // create a javascript serialisation of the point data | ||
+ | $points = ''; | ||
+ | if (!empty($overlay)) { | ||
+ | foreach ($overlay as $data) { | ||
+ | list($lat, | ||
+ | $points .= ", | ||
+ | } | ||
+ | $points = ", overlay : [ " | ||
+ | } | ||
+ | |||
+ | $js = " | ||
+ | |||
+ | return array($style, | ||
+ | } | ||
+ | |||
+ | function render($mode, | ||
+ | |||
+ | static $initialised = false; | ||
+ | |||
+ | if ($mode == ' | ||
+ | list($style, | ||
+ | |||
+ | $script = ''; | ||
+ | |||
+ | if (!$initialised) { | ||
+ | $initialised = true; | ||
+ | $script = $this-> | ||
+ | $script = '< | ||
+ | } | ||
+ | |||
+ | $renderer-> | ||
+ | <div class=' | ||
+ | $script | ||
+ | <script type=' | ||
+ | $param | ||
+ | </ | ||
+ | </ | ||
+ | } | ||
+ | |||
+ | return false; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * extract parameters for the googlemap from the parameter string | ||
+ | * | ||
+ | * @param | ||
+ | * @return | ||
+ | */ | ||
+ | function _extract_params($str_params) { | ||
+ | |||
+ | $param = array(); | ||
+ | preg_match_all('/ | ||
+ | |||
+ | // parse match for instructions, | ||
+ | $gmap = $this-> | ||
+ | foreach($param as $kvpair) { | ||
+ | list($match, | ||
+ | $key = strtolower($key); | ||
+ | if (isset($gmap[$key])) $gmap[$key] = strtolower($val); | ||
+ | } | ||
+ | |||
+ | return $gmap; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * extract overlay points for the googlemap from the wiki syntax data | ||
+ | * | ||
+ | * @param | ||
+ | * @return | ||
+ | */ | ||
+ | function _extract_points($str_points) { | ||
+ | |||
+ | $point = array(); | ||
+ | preg_match_all('/ | ||
+ | |||
+ | $overlay = array(); | ||
+ | foreach ($point as $pt) { | ||
+ | list($match, | ||
+ | |||
+ | $lat = is_numeric($lat) ? $lat : 0; | ||
+ | $lon = is_numeric($lon) ? $lon : 0; | ||
+ | $text = addslashes(str_replace(" | ||
+ | |||
+ | $overlay[] = array($lat, | ||
+ | } | ||
+ | |||
+ | return $overlay; | ||
+ | } | ||
+ | |||
+ | }</ | ||
+ | |||
+ | ==== script.js ==== | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | /* | ||
+ | | ||
+ | */ | ||
+ | |||
+ | |||
+ | function in_array(needle, | ||
+ | for (var i=0; i< | ||
+ | if (haystack[i] == needle) return true; | ||
+ | |||
+ | return false; | ||
+ | } | ||
+ | |||
+ | // Creates a marker at the given point with the given number label | ||
+ | // from http:// | ||
+ | // with minor modifications | ||
+ | function create_marker(point, | ||
+ | var marker = new GMarker(point); | ||
+ | GEvent.addListener(marker, | ||
+ | marker.openInfoWindowHtml(text); | ||
+ | }); | ||
+ | return marker; | ||
+ | } | ||
+ | |||
+ | function init_googlemaps() { | ||
+ | |||
+ | // nothing to do? | ||
+ | if (googlemap.length == 0) return; | ||
+ | |||
+ | var maptypes = { map : G_NORMAL_MAP, | ||
+ | | ||
+ | | ||
+ | | ||
+ | }; | ||
+ | |||
+ | // retrieve all google map containers | ||
+ | var nodes = document.body.getElementsByTagName(' | ||
+ | |||
+ | var i=0; | ||
+ | for (var j=0; j< | ||
+ | if (nodes[j].className.match(/ | ||
+ | googlemap[i++].node = nodes[j]; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // iterate through all the map containers and set up each map | ||
+ | for (i=0; i< | ||
+ | googlemap[i].map = new GMap2(googlemap[i].node); | ||
+ | |||
+ | with (googlemap[i]) { | ||
+ | if (controls == ' | ||
+ | map.addControl(new GSmallMapControl()); | ||
+ | map.addControl(new GMapTypeControl()); | ||
+ | } | ||
+ | map.setCenter(new GLatLng(lat, | ||
+ | |||
+ | var supported = map.getMapTypes(); | ||
+ | var requested = maptypes[type]; | ||
+ | |||
+ | map.setMapType(in_array(requested, | ||
+ | |||
+ | if (googlemap[i].overlay && overlay.length > 0) { | ||
+ | for (j=0; j< | ||
+ | map.addOverlay(create_marker(new GLatLng(overlay[j].lat, | ||
+ | } | ||
+ | } | ||
+ | if (kml != ' | ||
+ | var geoXml = new GGeoXml(kml); | ||
+ | map.addOverlay(geoXml); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | addEvent(document.body, | ||
+ | } | ||
+ | |||
+ | |||
+ | var googlemap = new Array(); | ||
+ | addInitEvent(init_googlemaps); | ||
+ | </ | ||
+ | |||
+ | ==== style.css ==== | ||
+ | |||
+ | These may be modified to suit your own requirements. | ||
+ | |||
+ | <code css> | ||
+ | /* plugin: googlemaps */ | ||
+ | .googlemap { | ||
+ | width: 400px; | ||
+ | height: 300px; | ||
+ | border: 1px solid #333; | ||
+ | } | ||
+ | /* end plugin: googlemaps */ | ||
+ | </ | ||
+ | |||
+ | ===== Revision History ===== | ||
+ | |||
+ | * 2008-11-11 | ||
+ | * Remove obsolete code for V1 of Googlemaps and DokuWiki 2006-03-09 | ||
+ | * Add support for KML (thanks to Martin at meggle-freund.de) | ||
+ | * 2006-10-15 --- Fix bug that prevented the plugin working with DokuWiki rc20060928 | ||
+ | * made Googlemaps V2 version of the plugin compatible with DokuWiki 2006-03xx versions | ||
+ | * 2006-07-24 --- Major revision | ||
+ | * added support for overlays with markers | ||
+ | * changes to syntax to handle overlays | ||
+ | * fix bug which prevented correct interpretation of map type | ||
+ | * 2006-05-22 --- Updated to Google Maps API version 2. | ||
+ | * 2006-05-01 --- (darcs only, other versions to follow) Settings altered to use [[devel: | ||
+ | * 2006-02-18 --- Initial release | ||
+ | |||
+ | |||
+ | ===== To Do ===== | ||
+ | |||
+ | * --- add directions support ([[http:// | ||
+ | * allow user to switch between built-in controls e.g. GLargeMapControl via Gui | ||
+ | |||
+ | |||
+ | ===== Bugs ===== | ||
+ | in this code, there is no px unit. so if you have trouble with width and height, fix the syntax.php like this | ||
+ | <code php> | ||
+ | $style = $gmap[' | ||
+ | $style .= $gmap[' | ||
+ | </ | ||
+ | |||
+ | > This isn't a bug, you need to supply the unit with the width/ | ||
+ | >> I was so confused.Thanx. you made it clearly. At result, it is different of image wiki syntax. ppl must write css unit with this plugin. --- // | ||
+ | |||
+ | ==== Invalid XHTML ==== | ||
+ | |||
+ | lib/ | ||
+ | < | ||
+ | $renderer-> | ||
+ | <div class=' | ||
+ | $script | ||
+ | <script type=' | ||
+ | //< | ||
+ | $param | ||
+ | // | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== KML (Overlay) Support ===== | ||
+ | |||
+ | KML file support is now included in the plugin. | ||
+ | |||
+ | [original note from author of KML modifications] | ||
+ | |||
+ | This works in general, but there remains a slight problem: Direct links to Google-Maps like [[http:// | ||
+ | |||
+ | You can see the extended plugin in action [[http:// | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | ===== Discussion ===== | ||
+ | |||
+ | How about loggin user IPs and then generating the map based on them. Like here: [[http:// | ||
+ | |||
+ | Thank you for you effort, but google_maps won't work in my [[http:// | ||
+ | [[http:// | ||
+ | |||
+ | Installed dev today (aug 2nd), had the empty frame issue. '' | ||
+ | |||
+ | |||
+ | \\ | ||
+ | I still have the empty frame issue. I guess the cache is not at fault, since the maps are correctly displayed in preview mode. But as soon as I save the page and display it, the frame come just blank. Any idea? | ||
+ | -- //kilian 2006-10-13 15:57// | ||
+ | |||
+ | > There was a bug causing the recent empty frame problems. | ||
+ | |||
+ | >> Indeed, an update resolved the issue. Thanks a lot! -- //kilian 2006-10-15 13:17// | ||
+ | |||
+ | Do you plan any support for Geocoding? i.e. entering an address instead of lat/lon. That would be a great addition! //ben 2006-12-30 0:56// | ||
+ | |||
+ | you have a typo in the URL encoded into the plugin: it leads people to [[plugin: | ||
+ | > seems not really possible, but maybe at least something like [[http:// | ||
+ | |||
+ | Why can't we use addresses ? Inserting geocodes is way too complicated ! The plugin should use the geocoder API ! Is it difficult ? | ||
+ | \\ | ||
+ | --- | ||
+ | \\ | ||
+ | Hi, my name is Bernhard. Great plugin! I use it with the new DokuWiki Release 2007-06-26. Works fine! (Have a look at http:// | ||
+ | BTW: Google is asking to cache the geocoded addresses, so it should not be generated each time, somebody is opening you page wit the googlemap. If you have a lot of points (addresses) to geocode, it could happen, that Google is blocking your account for 24 hours! (Further Info: [[http:// | ||
+ | \\ | ||
+ | \\ | ||
+ | I made a simple modification in the JavaScript script.js, to choose the small map controls or the large map controls by the additional values " | ||
+ | |||
+ | // iterate through all the map containers and set up each map | ||
+ | for (i=0; i< | ||
+ | googlemap[i].map = new GMap2(googlemap[i].node); | ||
+ | |||
+ | with (googlemap[i]) { | ||
+ | /* this part of the code is substituted with the switch | ||
+ | if (controls == ' | ||
+ | map.addControl(new GSmallMapControl()); | ||
+ | map.addControl(new GMapTypeControl()); | ||
+ | } | ||
+ | */ | ||
+ | |||
+ | /* start to choose small or large MapControl */ | ||
+ | switch (controls){ | ||
+ | case " | ||
+ | map.addControl(new GSmallMapControl()); | ||
+ | map.addControl(new GMapTypeControl()); | ||
+ | break; | ||
+ | case " | ||
+ | map.addControl(new GSmallMapControl()); | ||
+ | map.addControl(new GMapTypeControl()); | ||
+ | break; | ||
+ | case " | ||
+ | map.addControl(new GLargeMapControl()); | ||
+ | map.addControl(new GMapTypeControl()); | ||
+ | break; | ||
+ | } | ||
+ | /* end to choose small or large MapControl */ | ||
+ | |||
+ | | ||
+ | |||
+ | |||
+ | If controls=" | ||
+ | \\--- Bernhard 2007-07-04 9:43 | ||
+ | |||
+ | |||
+ | |||
+ | ==== Geocoder for Google Map DokuWiki ==== | ||
+ | |||
+ | I work on a " | ||
+ | |||
+ | You can hack the page as you want, just see the source (not really fun actually; | ||
+ | |||
+ | Just take an address, click on the marker, move the marker, etc... | ||
+ | |||
+ | the page : | ||
+ | http:// | ||
+ | |||
+ | More information soon... in french but look down and you have the wiki googlemap syntax.... | ||
+ | |||
+ | ==== Caching ==== | ||
+ | |||
+ | Is it possible to cache the Maps? We have a page in our Wiki using quite a few Maps ( http:// | ||
+ | |||
+ | |||
+ | ==== Own & User- interactive map ==== | ||
+ | |||
+ | The possibility to create own maps – not a world map but a map coming from RPGs – would be very welcome.\\ | ||
+ | (For me this possibility is the reason why I decide to learn how a wiki works) | ||
+ | |||
+ | The best explanation of what I would like to see in DokuWiki can be found here:\\ | ||
+ | http:// | ||
+ | |||
+ | If this feature is possible without the Google code, it would be even more welcome. | ||
+ | Maybe some useful things can be found here:\\ | ||
+ | http:// | ||
+ | &\\ | ||
+ | http:// | ||
+ | |||
+ | There is an alternative based upon OpenLayers: [[plugin: | ||
+ | |||
+ | |||
+ | ---- | ||
+ | Hi. Has anyone tried making this work in conjunction with the [[plugin: | ||
+ | |||
+ | ==== direction support ==== | ||
+ | If the direction support is not added, a link to google map could be a good idea. When you click on the " | ||
+ | |||
+ | It could be a nice idea to display that kind of link, so people could use the direction option (super useful since google map offer direction for the subway/bus in many cities). | ||
+ | |||
+ | --// [[http:// | ||
+ | |||
+ | |||
+ | ==== KML file url problem (info AT netlamps DOT org) ==== | ||
+ | |||
+ | Have a look at: http:// | ||
+ | |||
+ | It seems that using a " | ||
+ | |||
+ | Both urls are valid, if you follow them with the browser you get the same file. | ||
+ | |||
+ | Any idea? | ||
+ | |||
+ | Thank you | ||
+ | |||
+ | ==== Caching problem? (info AT netlamps DOT org) ==== | ||
+ | |||
+ | |||
+ | [[http:// | ||
+ | |||
+ | Any idea? | ||
+ | |||
+ | Thank you | ||
+ | |||
+ | ==== Overview ==== | ||
+ | |||
+ | is it possible to get an overview-amp? | ||
+ | ==== GoogleMap API key problem ==== | ||
+ | |||
+ | I keep getting error messages about the key | ||
+ | "this web site needs a different google maps API key" | ||
+ | |||
+ | default.php file keeps beeing empty although I did save configuration in dokuwiki conf settings | ||
+ | $ tail -2 default.php | ||
+ | $conf[' | ||
+ | $conf[' | ||
+ | |||
+ | is this normal ? | ||
+ | |||
+ | I must admit that my DNS conf is not simple, www.reve.fr has 157.159.11.54 ip address, but the hostname that serves www.reve.fr is wheberges.it-sudparis.eu which also has 157.159.11.54, | ||
+ | Thanks . | ||
+ | |||
+ | > Google has more info about this: http:// | ||
+ | > You should register your key for every different (base)url of your site. Check the examples on the faq. | ||
+ | > - Klap-in |
plugin/googlemaps.1360881548.txt.gz · Last modified: 2013-02-14 23:39 by 66.158.184.28