Point-Mapping Extension/Code

GISWiki - Das freie Portal für Geoinformatik (GIS)
Version vom 17. September 2009, 09:47 Uhr von HeinzJ (Diskussion | Beiträge) (Code)

(Unterschied) ← Nächstältere Version | Aktuelle Version ansehen (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Code

<?php
# MapPoints by Heinz-Josef Lücking h-j.luecking@t-online.de
#
# Copy this text into a file called "MapPoints.php" and save it into the directory "extensions"
# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/MapPoints.php");
# Hint: Do'nt mix up MapPoints with the older version MapPoint!
#
# 
# Licence: "Creative Commons", explicit http://creativecommons.org/licenses/by-sa/2.0/de/deed.en
# 
# visit http://www.giswiki.org
#
# Have fun
#
$wgExtensionFunctions[] = "wfMapPoints";
function wfMapPoints() {
 global $wgParser;
 $wgParser->setHook( "MapPoints", "renderMapPoints" );
}
function renderMapPoints( $input ) {
 #----------------------------------------#
	# Splits input into basic map and points #
 #----------------------------------------#
 $s = $input;
	$s = str_replace("\n\r","|",$s);
	$s = str_replace("\n","|",$s);
	$s = str_replace("\r","|",$s);
	$s = str_replace("[|","[",$s);
	$s = str_replace("|]","]",$s);
	$s = str_replace("{|","{",$s);
	$s = str_replace("|}","}",$s);
	$s = str_replace("]|{","]{",$s);
	$s = str_replace("}|","}",$s);
	
 preg_match_all('/([\[\]{}])(.*?)([\[\]{}])/', $s, $matches, PREG_SET_ORDER);
 # explode
 foreach($matches as $match) {
 $varAr[] = explode('|', $match[2]);
 }
 
 #------
 # MAP #
 #------
 # Image(Map) and Point-file
 $varURLMap = $varAr[0][0];
 $varURLPoint = $varAr[0][1];
 $PointExt = $varAr[0][2]; # PointSize (width = height)
 
 # Getting some image-information
 
 $varMapWidth = $varAr[0][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 = $varAr[0][4];
 $E = $varAr[0][5];
 $C = $varAr[0][6];
 $F = $varAr[0][7];
 #---------
 # POINTS #
 #---------
 foreach($varAr as $k=>$v) {
 if($k>0) {
 $varPointLon = $v[0];
 $varPointLat = $v[1];
 # Calculating the position of the point on the image
 
 $xImg = ((($varPointLon - $C) / $A) * $varZoom) - ($PointExt / 2);
 $yImg = ((($varPointLat - $F) / $E) * $varZoom) - ($PointExt / 2);
 
 # Adding an additional Link to the point;
 if ($v[2] == "") {$varHRef = "";} else {$varHRef = " href=\"".$v[2]."\""; }
 # for Hints (Mousover) and the <alt> tag
 if ($v[3] == "") {$varTitle = ""; $varAlt = "";} else {$varTitle = " title=\"".$v[3]."\""; $varAlt = " alt=\"".$v[3]."\""; }
 # add some random text to <div id="myMapPoints...
 $MapRand = rand(); 
 $aPoint .= "<div id=\"myMapPoints".$MapRand."\" class=\"\" style=\"position: relative; left: 0px; top: 0px; width: 0px; height: 0px; visibility: visible;\"> <a ".$varHRef." ".$varTitle."><img name=\"myMapPoints_\" style=\"opacity: 1.0; position: absolute; top: ".$yImg."px; left: ".$xImg."px;\" src=\"".$varURLPoint."\" height=\"".$PointExt."\" width=\"".$PointExt."\" ".$varAlt." ></a></div>";
 }
 }
 
 #---------------------#
 # Building the output #
 #---------------------#
 $MapRand = rand(); # add some random text to <div id="MapPoints...
 $output = "<div id=\"MapPoints".$MapRand."\" class=\"MapPoints\" 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."\"> ".$aPoint."</div>";
 return $output;
}
?>
Von „http://giswiki.org/index.php?title=Point-Mapping_Extension/Code&oldid=16811"