MediaWiki GIS Extensions: Unterschied zwischen den Versionen

GISWiki - Das freie Portal für Geoinformatik (GIS)
Wechseln zu: Navigation, Suche
(Installation der GoogleMap-Extension)
(GIS-Extension)
Zeile 233: Zeile 233:
 
* [http://www.golem.de/0503/37128.html Google: Ortsbezogene Suche kommt nach Deutschland]
 
* [http://www.golem.de/0503/37128.html Google: Ortsbezogene Suche kommt nach Deutschland]
  
=GIS-Extension=
 
  
Die GIS-Erweiterung auf der [http://meta.wikimedia.org/wiki/Gis 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"=
 
=Koordinatentool "hjl_get_Coor"=

Version vom 13. August 2005, 14:40 Uhr

Google Maps Extensions

Google Maps ist der Karten- und Routing-Service von Google.

Marker Extension

Code


<?php

# Map WikiMedia extension
# 
# Uses Google Maps as a Map Server
#
# This extension displays a marker with further infos (when clicking)  on given coordinates
#
# Copy this text into a file called "hjlMap.php"
# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/hjlMap.php"); 
#
# Use the tags <map>Latitude|Longitude|ZoomFactor|URL|URL-Text|URL-Image|Image-Height</map> to display this map.
#
# Sample: "<map>53.053|7.803|10|http://www.giswiki.org/|GISWiki|http://www.giswiki.org/skins/common/images/wiki.png\|30</map>"
#
# Missing: error-handling, ....


$wgExtensionFunctions[] = "wfMapExtension";

function wfMapExtension() 
{
	global $wgParser;
	$wgParser->setHook( "Map", "renderMap" );
}

# The callback function for converting the input text to HTML output
function renderMap( $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=ABQIAAAAmSaaWiH-UdM6X8GKUpwrShRxST-HWBdKUWLFy_5rr1CqF7sELxRXeY9OVogKb86vpauaaMAdd8JMQQ' 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(".$varLon.", ".$varLat."), ".$varZoom.");
map.setMapType(_SATELLITE_TYPE);
var point = new GPoint(".$varLon.",".$varLat.");
var marker = createMarker(point, '".$varInfo."');
map.addOverlay(marker);
</script>
";

return $aMap;
}
?>



Beispiel / Sample

Eingabe / Input

<map>53.0419921875|8.85000228881836|10|http://www.giswiki.org/|GISWiki|http://www.giswiki.org/skins/common/images/wiki.png\|30</map>

Ergebnis / Result

<Map>53.0419921875|8.85000228881836|10|http://www.giswiki.org/%7CGISWiki%7Chttp://www.giswiki.org/skins/common/images/wiki.png\%7C30</Map>

Infofenster-Extension

Code


<?php

# Map WikiMedia extension
# 
# Uses Google Maps as a Map Server
#
# This extension displays a map and an info on given coordinates
#
# Copy this text into a file called "hjlMapI.php"
# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/hjlMapI.php"); 
#
# Use the tags <MapI>Latitude|Longitude|ZoomFactor|InfoText<MapI> to display this map.
#
# Sample: "<MapI>53.053|7.803|10|GISWiki got a GoogleMap</MapI>"
#
# Missing: error-handling, ....


$wgExtensionFunctions[] = "wfMapIExtension";

function wfMapIExtension() 
{
	global $wgParser;
	$wgParser->setHook( "MapI", "renderMapI" );
}

# The callback function for converting the input text to HTML output
function renderMapI( $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=ABQIAAAAmSaaWiH-UdM6X8GKUpwrShRxST-HWBdKUWLFy_5rr1CqF7sELxRXeY9OVogKb86vpauaaMAdd8JMQQ' 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(".$varLon.", ".$varLat."), ".$varZoom.");
map.setMapType(_SATELLITE_TYPE);
map.openInfoWindow(map.getCenterLatLng(),
document.createTextNode('".$varInfo."'));
</script>
";

return $aMap;
}
?>

Beispiel / Sample

Eingabe / Input

<MapI>53.0419921875|8.85000228881836|10|GISWiki got a Map</MapI>

Ergebnis / Result

<MapI>53.0419921875|8.85000228881836|10|GISWiki got a Map</MapI>

Installation der GoogleMap-Extension

Entsprechend der Anleitung im SourceCode und MediaWiki Hacks and Extensions gehen Sie so vor:

  • Speichern Sie den Code in einer Datei, z.B. mit dem Namen hjlMapI.php oder hjlMap.php
  • Fügen sie ihren Key ein den Sie von GoogleMaps erhalten haben
  • Laden Sie die Datei auf ihren Server in das Verzeichnis /extensions/
  • Fügen Sie am Ende der Datei LocalSettings.php die Zeile
include("extensions/google-map-extension.php");

Installation of the GoogleMap-Extension

According to the text of the code above and MediaWiki Hacks and Extensions:

  • Save the code in a file e.g. called hjlMap
  • Copy and paste the Key you got from Google for your GoogleMaps (http://www.google.com/apis/maps/signup.html) into the GoogleMap Extension (search for key).
  • Save this file into the directory /extensions/
  • add include("extensions/google-map-extension.php"); to LocalSettings.php

Weblinks

Siehe auch

  • 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.)


Koordinatentool "hjl_get_Coor"

HjlgetCoor.jpg
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.