Point-Mapping Extension

GISWiki - Das freie Portal für Geoinformatik (GIS)
Wechseln zu: Navigation, Suche

Sample

<MapPoint>http://www.giswiki.org/images/b/b0/DeutschlandGeoref.png%7Chttp://www.giswiki.org/images/1/1b/Reddot.gif%7C6%7C140%7C0.028662571242%7C-0.017977324880%7C5.499161111111%7C55.115925000000%7C11.5750%7C48.1400</MapPoint>

Code


<?php
# MapPoint by Heinz-Josef Lücking h-j.luecking@t-online.de
#
# Copy this text into a file called "MapPoint.php" and save it into the directory "extensions"
# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/MapPoint.php");
#
# visit http://www.giswiki.org
#
#
# Have fun
#
$wgExtensionFunctions[] = "wfMapPoint";

function wfMapPoint() {
  global $wgParser;
  $wgParser->setHook( "MapPoint", "renderMapPoint" );
}

function renderMapPoint( $input ) {

   
  $varAr = explode("|", $input);
    
  # Image(Map) and Point-files 
  # e.g.:
  # $varURLMap   = "http://www.giswiki.org/images/c/c1/DeutschlandRef.png";
  # $varURLPoint = "http://www.giswiki.org/images/1/1b/Reddot.gif";
  # $varMapWidth = 140;

  $varURLMap   = $varAr[0];
  $varURLPoint = $varAr[1];
  $PointExt    = $varAr[2]; # PointSize (width = height)
   
  # Getting some image-information
   
  $varMapWidth  = $varAr[3];                 # the width the image should be displayed
  $size         = getimagesize("$varURLMap");# the real size of the image
  $height       = $size[1];                  # real height
  $width        = $size[0];                  # real width
  $varZoom      = $varMapWidth / $width;     # zoom-factor
  $varMapHeigth = $height * $varZoom;        # computed image-heigth
   
  # Georeferencing the image (see http://en.wikipedia.org/wiki/World_file)
  #
  # A: meters/pixel in horizontal x Easting direction
  # D: rotation about y axis, always 0
  # B: rotation about x axis, always 0
  # E: meters/pixel in vertical y Northing direction
  # C: x Easting UTM coordinate of center of upper left pixel in meters
  # F: y Northing UTM coordinate of center of upper left pixel in meters
  #
  # Use a dot for commas!
  #
  # Sample for the image above
  #
  # $A = 0.028662571242;
  # $D = 0.000000000000;
  # $B = 0.000000000000;
  # $E = -0.017977324880;
  # $C = 5.499161111111;
  # $F = 55.115925000000;

  $A = $varAr[4];
  $D = 0;
  $B = 0;
  $E = $varAr[5];
  $C = $varAr[6];
  $F = $varAr[7];

  # The point which shall be displayed on the map
  # Coordinates must be Longitude and Latitude with decimal degrees
  # Use a dot for commas!
  #
  # e.g. Munich:
  # $varPointLon = 11.5750
  # $varPointLat = 48.1400;
   
  $varPointLon = $varAr[8];
  $varPointLat = $varAr[9];

  # Calculating the position of the point on the image
  # $varPointX = ((11.5750 - 5.499161111111) / 0.028662571242) - 5;
  # $varPointY = ((48.1400 - 55.115925000000) / -0.017977324880) - 5;
   
  $xImg = ((($varPointLon - $C) / $A) * $varZoom) - ($PointExt / 2);
  $yImg = ((($varPointLat - $F) / $E) * $varZoom) - ($PointExt / 2);
    
  # Building the output

  $output = "<div id=\"myMap\" class=\"\" style=\"position: relative; left: 0px; top: 0px; width: ".$varMapWidth."px; height: ".$varMapHeigth."px; visibility: visible; background-color: white;\"> <img name=\"myMap\" style=\"position: absolute; top: 0pt; left: 0pt;\" src=\"".$varURLMap."\" height=\"".$varMapHeigth."\" width=\"".$varMapWidth."\"> <div id=\"myMapPoint\" class=\"\" style=\"position: relative; left: 0px; top: 0px; width: ".$varMapWidth."px; height: ".$varMapHeigth."px; visibility: visible;\"> <img name=\"myMapPoint_\" style=\"opacity: 1.0; position: absolute; top: ".$yImg."px; left: ".$xImg."px;\" src=\"".$varURLPoint."\" height=\"".$PointExt."\" width=\"".$PointExt."\"> </div></div>";

  return $output;
}
?>