MediaWiki GIS Extensions
Inhaltsverzeichnis
Google Maps Extensions
Google Maps ist der Karten- und Routing-Service von Google.
Infofenster-Extension
Code
<?php # Google Map WikiMedia extension # Copy this text into a file called "hjlGoogleMap.php" # To activate the extension, include it from your LocalSettings.php # with: include("extensions/hjlGoogleMap.php"); # # Use the tags <GoogleMap>Latitude|Longitude|ZoomFactor|InfoText<GoogleMap> to display this map. # # Sample: "<GoogleMap>53.053|7.803|10|GISWiki got a GoogleMap</GoogleMap>" # # Missing: error-handling, .... function wfGoogleMapExtension() { global $wgParser; $wgParser->setHook( "GoogleMap", "renderGoogleMap" ); } # The callback function for converting the input text to HTML output function renderGoogleMap( $input ) { $varAr = explode("|", $input); $varLat = $varAr[0]; $varLon = $varAr[1]; $varZoom= $varAr[2]; $varInfo = $varAr[3]; # Hint: you need to sign up for a Google Maps API key!! # http://www.google.com/apis/maps/signup.html # Then replace the key below. $aMap = " <script src='http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAtThFd25f3RSm_Uyo-qMHZhSEt_GnVgvWmIxz4pFM1BN9jZGypxTTPP-dRrFjQMULBxRQCp9iRU2O2w' type='text/javascript'></script> <div id='map' style='width: 500px; height: 400px'></div> <script type='text/javascript'> //<![CDATA[ var map = new GMap(document.getElementById('map')); //map.addControl(new GSmallMapControl()); //map.addControl(new GMapTypeControl()); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.centerAndZoom(new GPoint(".$varLat.", ".$varLon."), ".$varZoom."); map.setMapType(_SATELLITE_TYPE); map.openInfoWindow(map.getCenterLatLng(), document.createTextNode('".$varInfo."')); </script> "; return $aMap; } ?>
Beispiel
Eingabe
<GoogleMap>53.0419921875|8.85000228881836|10|GISWiki got a GoogleMap</GoogleMap>
Ergebnis
<GoogleMap>53.0419921875|8.85000228881836|10|GISWiki got a GoogleMap</GoogleMap>
Marker Extension
Code
<?php # Google Map WikiMedia extension # # Copy this text into a file called "hjlGoogleMapMarker.php" # To activate the extension, include it from your LocalSettings.php # with: include("extensions/hjlGoogleMap.php"); # # Use the tags <GoogleMapM>Latitude|Longitude|ZoomFactor|URL|URL-Text|URL-Image|Image-Height<GoogleMapM> to display this map. # # Sample: "<GoogleMapM>53.053|7.803|10|http://www.giswiki.org/|GISWiki|http://www.giswiki.org/skins/common/images/wiki.png\|30</GoogleMapM>" # # Missing: error-handling, .... $wgExtensionFunctions[] = "wfGoogleMapMarkerExtension"; function wfGoogleMapMarkerExtension() { global $wgParser; $wgParser->setHook( "GoogleMapM", "renderGoogleMapMarker" ); } # The callback function for converting the input text to HTML output function renderGoogleMapMarker( $input ) { $varAr = explode("|", $input); $varLat = $varAr[0]; $varLon = $varAr[1]; $varZoom = $varAr[2]; $varURL = $varAr[3]; $varText = $varAr[4]; $varImg = $varAr[5]; $varImgH = $varAr[6]; # Hint: you need to sign up for a Google Maps API key!! # http://www.google.com/apis/maps/signup.html # Then replace the key below. $varInfo = "<img src=\"".$varImg."\" height=\"".$varImgH."\" width=\"".$varImgW."\"><br><a href=\"".$varURL."\" target=\"_blank\">".$varText."</a>"; $aMap = " <script> // Creates a marker whose info window displays the given number function createMarker(point, text) { var marker = new GMarker(point); var html = text + \"<br><br><font size='-1'>(öffnet in neuem Fenster)</font>\"; GEvent.addListener(marker, \"click\", function() {marker.openInfoWindowHtml(html);}); return marker; } </script> <script src='http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAtThFd25f3RSm_Uyo-qMHZhSEt_GnVgvWmIxz4pFM1BN9jZGypxTTPP-dRrFjQMULBxRQCp9iRU2O2w' type='text/javascript'></script> <div id='map' style='width: 500px; height: 400px'></div> <script type='text/javascript'> //<![CDATA[ var map = new GMap(document.getElementById('map')); //map.addControl(new GSmallMapControl()); //map.addControl(new GMapTypeControl()); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.centerAndZoom(new GPoint(".$varLat.", ".$varLon."), ".$varZoom."); map.setMapType(_SATELLITE_TYPE); var point = new GPoint(".$varLat.",".$varLon."); var marker = createMarker(point, '".$varInfo."'); map.addOverlay(marker); </script> "; return $aMap; } ?>
Beispiel
Eingabe
<GoogleMapM>53.0419921875|8.85000228881836|10|http://www.giswiki.org/|GISWiki|http://www.giswiki.org/skins/common/images/wiki.png\|30</GoogleMapM>
Ergebnis
<GoogleMapM>53.0419921875|8.85000228881836|10|http://www.giswiki.org/%7CGISWiki%7Chttp://www.giswiki.org/skins/common/images/wiki.png\%7C30</GoogleMapM>
Weblinks
Siehe auch
- Google Maps Hacking and Bookmarklets
which contains several steps on how you can customize and add information to Google Maps.
- There's also a pointer to http://mygmaps.com , which allows you to display custom data files with Google Maps. (The site is alphaish, so things may break.)
GIS-Extension
Die GIS-Erweiterung auf der MediaWiki-Seite wurde erweitert.
Die Tabelle GIS wurde um zwei Felder erweitert. In folgender SQL-Anweisung sind die Änderungen fett hervorgehoben. Hinzu kam ein Feld gis_title für die Aufnahme alternativer/zusätzlicher Texte sowie das Feld gis_url um auf weitere Weblinks verweisen zu können als nur die aktuell verwendete Artikelseite.
Tabelle
CREATE TABLE /*$wgDBprefix*/gis ( gis_page int(8) unsigned NOT NULL, gis_title varchar(255) binary default NULL, gis_url varchar(255) binary default NULL, gis_latitude_min real NOT NULL, gis_latitude_max real NOT NULL, gis_longitude_min real NOT NULL, gis_longitude_max real NOT NULL, gis_globe char(8) binary NOT NULL default , gis_type char(12) binary, gis_type_arg real NOT NULL default 0, KEY gis_page (gis_page), INDEX gis_globe (gis_globe), INDEX gis_type (gis_type), INDEX gis_type_arg (gis_type_arg) );
Dateien/Funktionen
Folgende Dateien/Funktionen der GIS-Erweiterung wurden diesbezüglich angepasst.
- database.php
- geo.php
Hier die Änderungen in den Funktionen. Änderungen sind fett gekennzeichnet.
database.php - function article_save_geo
function article_save_geo ( $article, $user, $text ) { $id = $article->getID(); $g = new gis_database(); $g->delete_position( $id ); $tag = 'geo'; $gis_content = array(); $text = Parser::extractTags( $tag, $text, $gis_content ); foreach( $gis_content as $marker => $content ) { $p = new geo_param( $content ); $attr = $p->get_attr(); //Begin Changes // //Added code for support of field "gis_title" and "gis_url" //see also "database.php" //Heinz-Josef Lücking - 7.7.2005 // $g->add_position( $id, $p->latdeg_min, $p->londeg_min, $p->latdeg_max, $p->londeg_max, $attr['globe'], $attr['type'], $attr['arg:type'], $attr['title'], $attr['url'] ); //End Changes } return true; }
database.php - function add_position
function add_position( $id, $latmin, $lonmin, $latmax, $lonmax, $globe, $type, $type_arg, $title, $url) { $fname = 'gis_database::add_position'; //Begin Changes // //Added code for support of field "gis_title" and "gis_url" //see also "database.php" //Heinz-Josef Lücking - 7.7.2005 // //If no title is set, the pagename is used. if ($title == "") { $aTitle = gis_database::get_title( $id ); } else { $aTitle = $title; };
if (!$globe) $globe = ""; $type_arg = str_replace( ',', , $type_arg); /* ignore commas */ $this->db->insert( 'gis', array( 'gis_page' => $id, 'gis_title' => $aTitle, 'gis_url' => $url, 'gis_latitude_min' => $latmin, 'gis_longitude_min' => $lonmin, 'gis_latitude_max' => $latmax, 'gis_longitude_max' => $lonmax, 'gis_globe' => $globe, 'gis_type' => $type, 'gis_type_arg' => $type_arg), $fname ); //End Changes }
geo.php - function geo_param
function geo_param( $param ) { //Begin Changes // //Added code for support of field "gis_title" and "gis_url" //see also "database.php" //Heinz-Josef Lücking - 7.7.2005 // $sparam = str_replace( ' title:', '#|title:', $param); $sparam = str_replace( ' url:', '#|url:', $sparam); $arparam = explode("#", $sparam ); for ($i=0; $i<count($arparam); $i++) { $var = stristr($arparam[$i],'|'); if ($var === false) { $var = str_replace( '_', ' ', $arparam[$i] ); $var = str_replace( ' ', '|', $var ); $arparam[$i] = $var; } } $sparam =implode("",$arparam); $this->pieces = explode("|", str_replace( '_', ' ', $sparam )); //End Changes $this->get_coor( ); $this->latdeg_min = $this->latdeg_max = $this->latdeg; $this->londeg_min = $this->londeg_max = $this->londeg; if ($this->pieces[0] == "to") { array_shift($this->pieces); $this->get_coor(); if ($this->latdeg < $this->latdeg_max) { $this->latdeg_min = $this->latdeg; } else { $this->latdeg_max = $this->latdeg; } if ($this->londeg < $this->londeg_max) { $this->londeg_min = $this->londeg; } else { $this->londeg_max = $this->londeg; } $this->latdeg = ($this->latdeg_max+$this->latdeg_min) / 2; $this->londeg = ($this->londeg_max+$this->londeg_min) / 2; $this->coor = array(); } }
Koordinatentool "hjl_get_Coor"
Unter Zurhilfenahme der Google Maps wurde ein Tool für das GISWiki und MediaWiki entwickelt, das die Erstellung von Koordinatenbezügen erleichtert. Die Geokoordinaten werden den Google Maps entnommen. Eingabe- und Auswahlfelder bieten die Möglichkeit weitere Informationen hinzuzufügen.
Näheres siehe hjl_get_Coor.