User:Mafs/GoogleMapExtension

From Meta, a Wikimedia project coordination wiki
 
A proposal to move this page to MediaWiki.org was rejected.
Google Map Extension


This extension integrates a google map into a wiki page. Optionally it displays geo tagged data of an xml/rss/gpx source. Further markers can be interactively added to a map.

Earthquakes

Using an external xml geo information file

<gmap> rss=http://earthquake.usgs.gov/recenteqsww/catalogs/eqs7day-M5.xml 
| width=600  | height=500 | zoom=15 | lat=39 | lon=28 </gmap>
File:Gmap2.png
Add a marker

Interactively creating/adding new markers

   <gmap> rss=GmapXML/ | width=600  | height=500 
| zoom=15 | lat=39 | lon=28 </gmap>

GPX-Geocaches in down under

<gmap>width=600|height=500|zoom=9|controls=no|type=hybrid|
rss=http://geocaching.com.au/caches/gca/au/wa.gpx|usecache=yes</gmap>

GPX-Yosemite Falls Trail

File:Gpx1.png
GPX
<gmap>width=600|height=500|zoom=4|controls=no|type=hybrid|
rss=http://www.gpxchange.com/gpxconvert/handler.asp?file=d%3A%5Cinetpub%5Cwwwroot%5CGPXchange%5CGPXconvert%5CGPX%5C100055%2Egpx&size=57509&name=100055%2Egpx|
usecache=yes</gmap>

Basis[edit]

This is an extended version of the Google map extension from User:IndyGreg, [1].

Changelog[edit]

  • This page and the code pages gmap.js and gmap.php have been updated on 2 August 2005 Mafs.
  • 3 August 2005 : in section MonoBook.php missing body tag added.
  • 30 August 2005: update to mediawiki version 1.5rc4
  • 7 September 2005 new version: markers can be interactively created/added. The scripts gmap.php and gmap.js contain many changes.
  • 8 September 2005 bugfix. An expression like rss=Test/Test/ between the gmap tags was not correctly handeled. The scripts gmap.php and gmap.js have been amended.
  • 21 September 2005: GPX support added. The files gmap.php, gmap.js and MonoBook.php have been updated.
  • 28 September 2005: Caching disabeled, it does not work correctly - gmap.php updated.
  • 16 October 2005: Pages which have interactively created may contain a redirect to an other wiki page - gmap.php updated.
  • 07.05.2008 changed function wfDisableCache (). Now compatible with MediaWiki 1.12 --Wikinaut 12:39, 7 May 2008 (UTC)

Installation[edit]

The extension has been tested with mediawiki version 1.5rc4, Firefox and Internet Explorer. There might still be bugs. Extension does not work properly on mediawiki version 1.4.7 (for further bugs, suggestions, etc. see User_talk:Mafs/GoogleMapExtension).

Get a key from Google[edit]

http://www.google.com/apis/maps/

LocalSettings.php[edit]

Add these lines to LocalSettings.php and fillin your key.

require_once('extensions/gmap.php');
$wgGmapKey = "Your_Google_Map_Key";
$wgGmapSource = "http://maps.google.com/maps?file=api&v=2&key=";

gmap.php[edit]

See this wiki page and download the code to subdirectory /extensions as gmap.php.

gmap.js[edit]

See this wiki page and download the code to subdirectory /skins/common as gmap.js.

MonoBook.php[edit]

The script /skins/MonoBook.php (MediaWiki 1.12.0) has to be modified by replacing the function function execute() with the code published on this wiki page.

Cache[edit]

The rss files are stored in a cache. Therefore, you must create a cache folder, eg. /your_wiki_folder/cache, which has to be writable by your web server. If you choose another name for your cache, you will have to adapt the name in gmap.php.

Usage[edit]

Use one section between <gmap>-tags for each map. The section may contain parameters separated by a pipe ("|"), just like links and templates. These parameters are supported:

  • rss=exp is optional and points to an external rss/xml/gpx resource file or wiki pages containing geo xml or gpx information data:
    1. If "exp" starts with "http://" (eg. http://earthquake.usgs.gov/recenteqsww/catalogs/eqs7day-M5.xml ) than the respective external resource file will be fetched and stored in a cache (see screenshot).
    2. If "exp" terminates with a slash-"/" (eg. rss=GmapXml/) than, after clicking on the map, a blue marker appears on the map and a link "Create" pointing to a wikipage is displayed below the map. Follow the link and write something on the page. Note that the page title contains the lat/long information of the marker. Go back to the map and refresh your browser. You should see the newly created marker. When clicking on the marker you see that at least part of the first line of the wiki page is rendered as link to the page. (If you write the tag "<disabledisplay/>" on the wiki page, no marker will be shown on the map for this particular page.)
    3. In all other cases "exp" is interpreted as a wiki page which has to contain valid xml or gpx geo information data (for an sml example see below).
    • Multiple xml geo information sources can be specified ( rss=source1 | rss=source2 ), their data is merged and rendered into one map.
    • GPX waypoints are displayed using a marker, for GPX tracks and routes a polyline is used. (All track and route segments are connected to a single line. A maximum of 500 track/route points are displayed.)
  • lat=x latitude
  • lon=y longitude
  • zoom=z zoom factor (1 represents detailed view)
  • width=a the width of the map in px
  • height=b the hight of the map in px
  • info=text displays the expression "text" in the centre of the map
  • maxrss=n the first n xml items are shown
  • controls=yes show some google controls
  • type=q q can be "satellite, "street" or "hybrid"


Example of xml rss geo xml information data[edit]

<?xml version = '1.0'?>
<rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Geomap Data</title>
    <link> </link>
    <pubDate>July 2005</pubDate>
    <item>
      <title>Freising</title>
      <description>Domberg</description>
      <link>http://www.freising.de</link>
      <geo:lat >48.4003</geo:lat>
      <geo:long >11.7455</geo:long>
    </item>
    <item>
      <title>Cuxhaven</title>
      <description>Elbmündung</description>
      <link>http://www.cuxhaven.de</link>
      <geo:lat >53.8721</geo:lat>
      <geo:long >8.7090</geo:long>
    </item>
    </channel>
</rss>