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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Sep 19 10:28:36 EDT 2008


Author: nimix
Date: 2008-09-19 10:28:36 -0400 (Fri, 19 Sep 2008)
New Revision: 2993

Added:
   branches/nimix_dev/http/classes/class_georss.php
   branches/nimix_dev/http/javascripts/mod_georss.php
   branches/nimix_dev/http/php/geoRSSToGeoJSON.php
Modified:
   branches/nimix_dev/http/classes/class_gml2.php
Log:
geoRss Module

Added: branches/nimix_dev/http/classes/class_georss.php
===================================================================
--- branches/nimix_dev/http/classes/class_georss.php	                        (rev 0)
+++ branches/nimix_dev/http/classes/class_georss.php	2008-09-19 14:28:36 UTC (rev 2993)
@@ -0,0 +1,203 @@
+<?php
+# $Id: class_gml2.php 2915 2008-09-05 08:16:07Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_gml2.php");
+
+class geoRSS {
+	var $doc;
+	var $importItems = array("title","link","description");
+	
+	function parseFile($req){
+		#$data = implode("",file($req));
+		$x = new connector($req);
+		$data = $x->file;
+		$data = $this->removeWhiteSpace($data);
+		return $this->parseXML($data);		
+		#$e = new mb_exception("data = ".$data); 		
+	}
+	
+	/**
+	 * Set the Rss Elements that should go to the property tags of geoJSON
+	 * default is "title","link" and "description"
+	 */
+	public function setImportTags($tags){
+		$importItems = $tags;
+	}
+	
+	function parseXML($data) {
+		$this->doc = $data;
+		return $this->toGeoJSON();
+	}
+
+	function removeWhiteSpace ($string) {
+		return preg_replace("/\>(\s)+\</", "><", trim($string));
+	}
+	
+	function toGeoJSON () {
+		$rssDoc = new SimpleXMLElement($this->doc);
+		
+		$rssDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
+		$rssDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+		$rssDoc->registerXPathNamespace('georss', 'http://www.georss.org/georss');
+		
+		// build feature collection
+		$featureCollection = new FeatureCollection();
+		
+		// elements of rss document
+		$rssItems = $rssDoc->xpath("//item");
+		
+		if(count($rssItems)>0){
+			foreach($rssItems as $item){
+				$rssItem_dom = dom_import_simplexml($item);
+				
+				$feature = new geoRSSItem();
+				$feature->parse($rssItem_dom, $this->importItems);
+				if (isset($feature->geometry)) {
+					$featureCollection->addFeature($feature);
+				}
+			}
+
+			return $featureCollection->toGeoJSON();
+		}
+		else{
+			return "{'errorMessage':'Kein Ergebnis'}";
+		}
+	}
+}
+
+class geoRSSItem extends Feature{
+	public function parse($domNode, $importItems = array("title","link","description")) {
+		$currentSibling = $domNode->firstChild;
+		
+		while ($currentSibling) {
+			$tag = $currentSibling->nodeName;
+			if(in_array($tag, $importItems)){
+				$this->properties[$tag] = $currentSibling->nodeValue;
+			}
+			else{
+				switch ($tag) {
+				case "georss:where":
+					$this->parseGML($currentSibling);
+					break;
+				case "georss:point":
+					$this->geometry = new geoRSSPoint();
+					$this->geometry->parsePoint($currentSibling);
+					break;
+				case "georss:line":
+					$this->geometry = new geoRSSLine();
+					$this->geometry->parseLine($currentSibling);
+					break;
+				case "georss:box":
+					$this->geometry = new geoRSSBox();
+					$this->geometry->parseBox($currentSibling);
+					break;
+				case "georss:polygon":
+					$this->geometry = new geoRSSPolygon();
+					$this->geometry->parsePolygon($currentSibling);
+					break;
+				default:
+					break;
+				}
+			}			
+			$currentSibling = $currentSibling->nextSibling;
+		}		
+	}
+	
+	function parseGML($domNode){
+		$currentSibling = $domNode->firstChild;
+	
+		while ($currentSibling) {
+			$geomType = $currentSibling->nodeName;
+			switch ($geomType) {
+				case "gml:Polygon" :
+					$this->geometry = new GMLPolygon();
+					$this->geometry->parsePolygon($currentSibling);
+					break;
+				case "gml:LineString" :
+					$this->geometry = new GMLLine();
+					$this->geometry->parseLine($currentSibling);
+					break;
+				case "gml:Point" :
+					$this->geometry = new GMLPoint();
+					$this->geometry->parsePoint($currentSibling);
+					break;
+				case "gml:MultiLineString" :
+					$this->geometry = new GMLMultiLine();
+					$this->geometry->parseMultiLine($currentSibling);
+					break;
+				case "gml:MultiPolygon" :
+					$this->geometry = new GMLMultiPolygon();
+					$this->geometry->parseMultiPolygon($currentSibling);
+					break;
+				default:
+					break;
+			}
+			$currentSibling = $currentSibling->nextSibling;
+		}
+	}
+}
+
+class geoRSSPoint extends GMLPoint{
+	public function parsePoint($domNode){
+		list($y, $x) = explode(" ", $domNode->nodeValue);
+		$this->setPoint($x, $y);
+	}
+}
+
+class geoRSSLine extends GMLLine{
+	public function parseLine ($domNode) {
+		$cnt = 0;
+		$y = 0;
+		foreach(explode(' ',$domNode->nodeValue) as $cord){
+			if($cnt % 2)
+				$this->addPoint($cord, $y);
+			$y = $cord;
+			$cnt++;
+		}
+	}
+}
+
+class geoRSSPolygon extends GMLPolygon{
+	public function parsePolygon ($domNode) {
+		$cnt = 0;
+		$y = 0;
+		foreach(explode(' ',$domNode->nodeValue) as $cord){
+			if($cnt % 2)
+				$this->addPoint($cord, $y);
+			$y = $cord;
+			$cnt++;
+		}
+	}
+}
+
+class geoRSSBox extends GMLPolygon{
+	public function parseBox ($domNode) {
+		list($y1,$x1,$y2,$x2) = explode(' ',$domNode->nodeValue);
+		$this->addPoint($x1, $y1);
+		$this->addPoint($x1, $y2);
+		$this->addPoint($x2, $y2);
+		$this->addPoint($x2, $y1);
+		$this->addPoint($x1, $y1);
+	}
+}
+
+?>
\ No newline at end of file

Modified: branches/nimix_dev/http/classes/class_gml2.php
===================================================================
--- branches/nimix_dev/http/classes/class_gml2.php	2008-09-19 13:14:15 UTC (rev 2992)
+++ branches/nimix_dev/http/classes/class_gml2.php	2008-09-19 14:28:36 UTC (rev 2993)
@@ -580,7 +580,7 @@
 		}
 	}
 	
-	private function addPoint ($x, $y) {
+	protected function addPoint ($x, $y) {
 		array_push($this->pointArray, array("x" => $x, "y" => $y));
 	}
 	
@@ -621,7 +621,7 @@
 		}
 	}
 	
-	private function setPoint ($x, $y) {
+	protected function setPoint ($x, $y) {
 #		echo "x: " . $x . " y: " . $y . "\n";
 		$this->point = array("x" => $x, "y" => $y);
 	}
@@ -675,7 +675,7 @@
 		
 	}
 	
-	private function addPoint ($x, $y) {
+	protected function addPoint ($x, $y) {
 		array_push($this->pointArray, array("x" => $x, "y" => $y));
 	}
 	
@@ -735,7 +735,7 @@
 		
 	}
 	
-	private function addPoint ($x, $y, $i) {
+	protected function addPoint ($x, $y, $i) {
 
 		array_push($this->lineArray[$i], array("x" => $x, "y" => $y));
 	}
@@ -807,7 +807,7 @@
 		
 	}
 	
-	private function addPoint ($x, $y, $i) {
+	protected function addPoint ($x, $y, $i) {
 
 		array_push($this->polygonArray[$i], array("x" => $x, "y" => $y));
 	}

Added: branches/nimix_dev/http/javascripts/mod_georss.php
===================================================================
--- branches/nimix_dev/http/javascripts/mod_georss.php	                        (rev 0)
+++ branches/nimix_dev/http/javascripts/mod_georss.php	2008-09-19 14:28:36 UTC (rev 2993)
@@ -0,0 +1,83 @@
+<?php
+# $Id:$
+# http://www.mapbender.org/index.php/mod_georss.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+?>
+var georssWin=null;
+var highlighter;
+var geoms=null;
+function loadGeoRSS(url){
+	$.post("../php/geoRSSToGeoJSON.php",{url:url}, function(jsCode, status){
+			if(status=='success'){
+				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();");
+					}
+					else {
+					}
+				}
+	       		else {
+				}
+	       	}
+		});
+}
+
+function mod_georssInit(){
+	$(window.frames["mapframe1"].document).mousemove(function(event){
+		mb_getMousePos(event,"mapframe1");
+		mod_georss_run();
+	}).mouseout(mod_georss_run);
+}
+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;
+			}
+		}
+	}
+}
+

Added: branches/nimix_dev/http/php/geoRSSToGeoJSON.php
===================================================================
--- branches/nimix_dev/http/php/geoRSSToGeoJSON.php	                        (rev 0)
+++ branches/nimix_dev/http/php/geoRSSToGeoJSON.php	2008-09-19 14:28:36 UTC (rev 2993)
@@ -0,0 +1,28 @@
+<?php
+# $Id: mod_wfs_result.php 2144 2008-02-26 23:16:14Z christoph $
+# http://www.mapbender.org/index.php/Administration
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+require_once(dirname(__FILE__) . "/../classes/class_connector.php");
+require_once(dirname(__FILE__) . "/../classes/class_georss.php");
+
+header("Content-Type: text/x-json");
+$geoRSS = new geoRSS();
+$geoRSS->setImportTags(array("title","description"));
+echo $geoRSS->parseFile($_REQUEST["url"]);
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list