[Mapbender-commits] r3099 - in branches/nimix_dev/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Oct 2 11:29:24 EDT 2008


Author: nimix
Date: 2008-10-02 11:29:23 -0400 (Thu, 02 Oct 2008)
New Revision: 3099

Added:
   branches/nimix_dev/http/javascripts/usemap.js
Modified:
   branches/nimix_dev/http/classes/class_georss.php
   branches/nimix_dev/http/classes/class_gml2.php
   branches/nimix_dev/http/javascripts/mod_georss.php
   branches/nimix_dev/http/php/geoRSSToGeoJSON.php
Log:
various work on GeoRSS

Modified: branches/nimix_dev/http/classes/class_georss.php
===================================================================
--- branches/nimix_dev/http/classes/class_georss.php	2008-10-02 15:28:13 UTC (rev 3098)
+++ branches/nimix_dev/http/classes/class_georss.php	2008-10-02 15:29:23 UTC (rev 3099)
@@ -31,6 +31,8 @@
 		$x = new connector($req);
 		$data = $x->file;
 		$data = $this->removeWhiteSpace($data);
+		if($data=="")
+			return false;
 		return $this->parseXML($data);		
 		#$e = new mb_exception("data = ".$data); 		
 	}
@@ -71,7 +73,7 @@
 				
 				$feature = new geoRSSItem();
 				$feature->parse($rssItem_dom, $this->importItems);
-				if (isset($feature->geometry)) {
+				if (isset($feature->geometry) && $feature->geometry!==false) {
 					$featureCollection->addFeature($feature);
 				}
 			}
@@ -114,6 +116,20 @@
 					$this->geometry = new geoRSSPolygon();
 					$this->geometry->parsePolygon($currentSibling);
 					break;
+				case "geo:point":
+					$this->geometry = new geoPoint();
+					$this->geometry->parsePoint($currentSibling);
+					break;
+				case "geo:lat":
+					if(!$this->geometry)
+						$this->geometry = new geoPoint();
+					$this->geometry->parseLat($currentSibling);
+					break;
+				case "geo:long":
+					if(!$this->geometry)
+						$this->geometry = new geoPoint();
+					$this->geometry->parseLong($currentSibling);
+					break;
 				default:
 					break;
 				}
@@ -148,6 +164,9 @@
 					$this->geometry = new GMLMultiPolygon();
 					$this->geometry->parseMultiPolygon($currentSibling);
 					break;
+				case "gml:Envelope" :
+					$this->geometry = new GMLEnvelope();
+					$this->geometry->parseEnvelope($currentSibling);					
 				default:
 					break;
 			}
@@ -163,6 +182,37 @@
 	}
 }
 
+class geoPoint extends GMLPoint{
+	public function parsePoint($domNode){
+		$currentSibling = $domNode->firstChild;
+		while ($currentSibling) {			
+			switch ($currentSibling->nodeName){
+			case "geo:lat":
+				$this->parseLat($currentSibling);
+				break;
+			case "geo:lat":
+				$this->parseLat($currentSibling);
+				break;
+			}
+			$currentSibling = $currentSibling->nextSibling;
+		}
+	}
+	public function parseLat($node){
+		if(!$this->point)
+			$this->point=array();
+		
+		$this->point["y"] = $node->nodeValue;
+	}
+	public function parseLong($node){
+		if(!$this->point)
+			$this->point=array();
+		
+		$this->point["x"] = $node->nodeValue;
+	}
+}
+
+
+
 class geoRSSLine extends GMLLine{
 	public function parseLine ($domNode) {
 		$cnt = 0;

Modified: branches/nimix_dev/http/classes/class_gml2.php
===================================================================
--- branches/nimix_dev/http/classes/class_gml2.php	2008-10-02 15:28:13 UTC (rev 3098)
+++ branches/nimix_dev/http/classes/class_gml2.php	2008-10-02 15:29:23 UTC (rev 3099)
@@ -519,6 +519,9 @@
 							$this->geometry = new GMLMultiPolygon();
 							$this->geometry->parseMultiPolygon($geomNode);
 							break;
+						case "gml:Envelope" :
+							$this->geometry = new GMLEnvelope();
+							$this->geometry->parseEnvelope($geomNode);
 						default:
 							$this->properties[$columnName] = $value;
 							break;
@@ -699,6 +702,29 @@
 	}
 }
 
+class GMLEnvelope extends GMLPolygon{
+/*      <gml:Envelope>
+         <gml:lowerCorner>42.943 -71.032</gml:lowerCorner>
+         <gml:upperCorner>43.039 -69.856</gml:upperCorner>
+      </gml:Envelope>
+*/
+	public function parseEnvelope ($domNode) {
+		$corner1 = $domNode->firstChild;
+		$corner2 = $corner1->nextSibling;
+		
+		list($y1,$x1) = explode(' ',$corner1->nodeValue);
+		list($y2,$x2) = explode(' ',$corner2->nodeValue);
+
+		$this->addPoint($x1, $y1);
+		$this->addPoint($x1, $y2);
+		$this->addPoint($x2, $y2);
+		$this->addPoint($x2, $y1);
+		$this->addPoint($x1, $y1);
+	}
+}
+
+
+
 class GMLMultiLine {
 
 	var $lineArray = array();

Modified: branches/nimix_dev/http/javascripts/mod_georss.php
===================================================================
--- branches/nimix_dev/http/javascripts/mod_georss.php	2008-10-02 15:28:13 UTC (rev 3098)
+++ branches/nimix_dev/http/javascripts/mod_georss.php	2008-10-02 15:29:23 UTC (rev 3099)
@@ -19,65 +19,99 @@
 
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 ?>
+var georssTargetArray = [];
+<?php
+for ($i = 0; $i < count($e_target); $i++) {
+	echo "georssTargetArray.push('".$e_target[$i]."');";
+}
+?>
 var georssWin=null;
-var highlighter;
+var georssHighlighter;
+var georssUsemap;
 var geoms=null;
+
 function loadGeoRSS(url){
 	$.post("../php/geoRSSToGeoJSON.php",{url:url}, function(jsCode, status){
 			if(status=='success'){
+				if(jsCode==""){
+					alert("<?php echo _mb("No GeoRSS feed information found. Please check your URL.");?>");
+					return;
+				}
 				var geoObj = eval('(' + jsCode + ')');	
-	       		if (jsCode) {
-		        	if (typeof(geoObj) == 'object') {
-		        		if(geoms)
-		        			delete geoms;
-						geoms = new GeometryArray();
-		           		geoms.importGeoJSON(geoObj);
-		           		if(typeof(highlighter)==='undefined')
-							highlighter = new Highlight(new Array("mapframe1"), "geoRssHL", {"position":"absolute", "top":"0px", "left":"0px", "z-index":30}, 2);
-						else
-							highlighter.clean();
-						for( var i=0;i<geoms.count();i++){
-							highlighter.add(geoms.get(i),"red");
-						}
-						highlighter.paint();
-						eventAfterMapRequest.register("highlighter.paint();");
+	        	if (typeof(geoObj) == 'object'&&typeof(geoObj.errorMessage)=='undefined') {
+	           		//create georssHighlighter and usemap
+	           		if(typeof(georssHighlighter)==='undefined'){
+						georssHighlighter = new Highlight(georssTargetArray, "geoRssHL", {"position":"absolute", "top":"0px", "left":"0px", "z-index":30}, 2);
+						georssUsemap = new Usemap(georssTargetArray, "geoRssUM", 120, 5, 2);
+	           		}
+	           		else{
+						georssHighlighter.clean();
+						georssUsemap.clean();
+	           		}
+	           		
+	           		//Import Geometries
+					geoms = new GeometryArray();
+	           		geoms.importGeoJSON(geoObj);
+	           		
+	           		//Zoom to Extent of Geometries
+	           		extent = geoms.getBBox();
+	           		mb_calculateExtent(georssTargetArray[0], extent[0].x, extent[0].y, extent[1].x, extent[1].y);
+	           		extent = enlargeExtent(extent, 10, georssTargetArray[0]);
+	           		mb_calculateExtent(georssTargetArray[0], extent[0].x, extent[0].y, extent[1].x, extent[1].y);
+	           		setMapRequest(georssTargetArray[0]);
+					
+					//Add geometries to usemap and georssHighlighter
+					for( var i=0;i<geoms.count();i++){
+						georssHighlighter.add(geoms.get(i),"red");
+						georssUsemap.add(geoms.get(i), geoms.get(i).e.getElementValueByName("title"),null,null,showGeorssTooltip);
 					}
-					else {
-					}
+					georssHighlighter.paint();
+					georssUsemap.setUsemap();
+					eventAfterMapRequest.register("georssHighlighter.paint();");
+					eventAfterMapRequest.register("georssUsemap.setUsemap();");
+
+					//Delete geometries as they are now in georssHighlighter and Usemap
+					delete geoms;
 				}
-	       		else {
+				else {
+					alert("<?php echo _mb("No GeoRSS feed information found. Please check your URL.");?>");
+					return;
 				}
 	       	}
 		});
 }
 
-function mod_georssInit(){
-	$(window.frames["mapframe1"].document).mousemove(function(event){
-		mb_getMousePos(event,"mapframe1");
-		mod_georss_run();
-	}).mouseout(mod_georss_run);
+function enlargeExtent(extent, pixel, frame){
+	var min = realToMap(frame, extent[0]);
+	var max = realToMap(frame, extent[1]);
+	min.x-=pixel;
+	min.y-=pixel;
+	max.x+=pixel;
+	max.y+=pixel;
+	extent[0] = mapToReal(frame, min)
+	extent[1] = mapToReal(frame, max)
+	return extent;
 }
-eventInit.register( mod_georssInit);
 
-function mod_georss_run(){
-	if(geoms){
-		var clPoint = new Point(clickX,clickY);
-		for( var i=0;i<geoms.count();i++){
-//TODO respect type of geometry (now only points are supported)
-			pt = realToMap("mapframe1", geoms.getPoint(i,0,0));
-			if(pt.dist(clPoint)<5){
-				if(georssWin && georssWin.isVisible()){
-					georssWin.destroy();
-				}
-				x=parseInt(document.getElementById("mapframe1").style.left);
-				y=parseInt(document.getElementById("mapframe1").style.top);
-			
-				georssWin = new mb_popup({title:geoms.get(i).e.getElementValueByName("title"),
-					html:geoms.get(i).e.getElementValueByName("description"),balloon:true,left:pt.x+x,top:pt.y+y});
-				georssWin.show();
-				return;
-			}
-		}
+function showGeorssTooltip(){
+	actGeom = this.geom;
+	if(!actGeom)
+		return;
+	
+	actFrame = georssTargetArray[0];
+	
+	//Get Mapframe Position
+	x=parseInt(document.getElementById(actFrame).style.left);
+	y=parseInt(document.getElementById(actFrame).style.top);
+	
+	//Hide old Window
+	if(georssWin && georssWin.isVisible()){
+		georssWin.destroy();
 	}
-}
-
+	
+	//Show Modal Popup
+	pt=realToMap(actFrame, actGeom.getPoint(0,0));
+	georssWin = new mb_popup({title:actGeom.e.getElementValueByName("title"),
+		html:actGeom.e.getElementValueByName("description"),balloon:true,left:clickX+x,top:clickY+y,modal:true});
+	georssWin.show();
+}
\ No newline at end of file

Added: branches/nimix_dev/http/javascripts/usemap.js
===================================================================
--- branches/nimix_dev/http/javascripts/usemap.js	                        (rev 0)
+++ branches/nimix_dev/http/javascripts/usemap.js	2008-10-02 15:29:23 UTC (rev 3099)
@@ -0,0 +1,167 @@
+/* 
+* $Id:$
+* COPYRIGHT: (C) 2001 by ccgis. This program is free software under the GNU General Public
+* License (>=v2). Read the file gpl.txt that comes with Mapbender for details. 
+*/
+
+function Usemap(usemapTargets, name, zIndex, pointBuffer, lineBuffer) {
+	var targets = usemapTargets;
+	this.name = name;
+	this.zIndex = zIndex;
+	this.pointBuffer = pointBuffer;
+	this.lineBuffer = lineBuffer;
+	
+	//add a geometry to the actual usemap
+	this.add = function(geom, title, mouseover, mouseout, click, mousemove){
+		gA.addCopy(geom);
+		if (typeof(title) != 'undefined') {gA.get(-1).title = title;} 
+		else {gA.get(-1).title = "";}
+		if (typeof(mouseover) != 'undefined') {gA.get(-1).mouseover = mouseover;} 
+		else {gA.get(-1).mouseover = null;}
+		if (typeof(mouseout) != 'undefined') {gA.get(-1).mouseout = mouseout;} 
+		else {gA.get(-1).mouseout = null;}
+		if (typeof(click) != 'undefined') {gA.get(-1).click = click;} 
+		else {gA.get(-1).click = null;}
+		if (typeof(mousemove) != 'undefined') {gA.get(-1).mousemove = mousemove;} 
+		else {gA.get(-1).mousemove = null;}
+	};
+	
+	//(re)generate Usemap
+	this.setUsemap = function(){
+		
+		//first clean the Usemap
+		this.hide();
+		
+		var actualMapObj;
+		var actualImageMap;
+		var actualImage;
+		var actualDoc;
+		
+		//go throught the maps
+		for(var t=0;t<targets.length;t++){
+			
+			//initialize actual dom elements
+			actualMapObj = getMapObjIndexByName(targets[t]);
+			actualDoc = window.frames[targets[t]].document;
+			actualImageMap = actualDoc.getElementById(this.name);
+			actualImage = actualDoc.getElementById(this.name+"_img");
+
+			//if the usemap doesn't exist create it
+			if(!actualImageMap){
+				actualImageMap = actualDoc.createElement("map");
+				actualImage = actualDoc.createElement("img");
+				actualImage.id = this.name+"_img";
+				actualImageMap.id = this.name;
+				actualImage.name = this.name+"_img";
+				actualImageMap.name = this.name;
+				actualImage.setAttribute("useMap", "#"+this.name);
+				actualImage.style.position = "absolute";
+				actualImage.style.left = "0px";
+				actualImage.style.top = "0px";
+				actualImage.style.border = "none";
+				actualDoc.body.appendChild(actualImage);
+				actualDoc.body.appendChild(actualImageMap);
+				actualImage.src = "../img/transparent.gif";
+			}
+			//set Usemap Image dimensions
+			actualImage.style.zIndex = this.zIndex;
+			actualImage.style.width = mb_mapObj[actualMapObj].width;
+			actualImage.style.height = mb_mapObj[actualMapObj].height;
+			
+			//generate areas
+			for(var i=0;i<gA.count();i++){
+				var m = gA.get(i);
+				for(j=0;j<m.count();j++){
+					var area = actualDoc.createElement("area");
+					//add pointer to geometry object
+					area.geom = m;
+					
+					//apply shape
+					g = m.get(j);
+					switch(g.geomType){
+					case geomType.point:
+						this.setPointAttributes(area, g, targets[t]);
+						break;
+					case geomType.line:
+						this.setLineAttributes(area, g, targets[t]);
+						break;
+					case geomType.polygon:
+						this.setPolygonAttributes(area, g, targets[t]);
+						break;
+					}
+					
+					//append to dom and set event handelers
+/*					if($.browser.msie){
+						alert(actualImageMap.areas.length)
+				        actualImageMap.areas[actualImageMap.areas.length] = area;
+					}
+					else
+*/					actualImageMap.appendChild(area);
+
+					area.title = m.title;
+					area.onmouseover = m.mouseover;
+					area.onmouseout = m.mouseout;
+					area.onmousemove = m.mousemove;
+				 	area.onclick = m.click;
+				}
+			}
+		}
+	};
+	
+	this.setPointAttributes = function(area, m, target){
+		//apply point shape to area
+		m = realToMap(target, m.get(0));
+		area.setAttribute("shape", 'circle');
+		area.setAttribute("coords", parseInt(m.x)+","+parseInt(m.y)+","+this.pointBuffer);
+	};
+	this.setLineAttributes = function(area, m, target){
+		//apply line shape to area
+		area.setAttribute("shape", 'poly');
+//TODO calculate buffered line	
+	};
+	this.setPolygonAttributes = function(area, m, target){
+		//apply polygon shape to area
+		area.setAttribute("shape", 'poly');
+		coords = [];
+		for (var i=0; i<m.count(); i++) {
+			pos = realToMap(target, m.get(i));
+			coords.push(String(parseInt(pos.x)));
+			coords.push(String(parseInt(pos.y)));
+		}
+		area.setAttribute("coords", coords.join(","));
+	};
+	
+	
+	this.hide = function(){
+		//hide the Usemap
+		var actualImageMap;
+		var actualImage;
+		var actualDoc;
+		for(var i=0;i<targets.length;i++){
+			//get actual frame
+			actualDoc = window.frames[targets[i]].document;
+			
+			//clear map
+			actualImageMap = actualDoc.getElementById(this.name);
+			if(actualImageMap)
+				actualImageMap.innerHTML = "";
+			
+			//hide hidden image
+			actualImage = actualDoc.getElementById(this.name+"_img");
+			if(actualImage){
+				actualImage.style.width = "0px";
+				actualImage.style.height = "0px";
+			}
+		}
+	};
+	
+	this.clean = function(){
+		this.hide();
+		if (gA.count() > 0) {
+			delete gA;
+			gA = new GeometryArray();
+		}
+	};
+	
+	var gA = new GeometryArray();
+}

Modified: branches/nimix_dev/http/php/geoRSSToGeoJSON.php
===================================================================
--- branches/nimix_dev/http/php/geoRSSToGeoJSON.php	2008-10-02 15:28:13 UTC (rev 3098)
+++ branches/nimix_dev/http/php/geoRSSToGeoJSON.php	2008-10-02 15:29:23 UTC (rev 3099)
@@ -24,5 +24,9 @@
 header("Content-Type: text/x-json");
 $geoRSS = new geoRSS();
 $geoRSS->setImportTags(array("title","description"));
-echo $geoRSS->parseFile($_REQUEST["url"]);
+try {
+	echo $geoRSS->parseFile($_REQUEST["url"]);
+} catch (Exception $e) {
+	die;
+}
 ?>
\ No newline at end of file



More information about the Mapbender_commits mailing list