[Mapbender-commits] r9499 - trunk/mapbender/http/geoportal

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri May 27 02:37:39 PDT 2016


Author: armin11
Date: 2016-05-27 02:37:39 -0700 (Fri, 27 May 2016)
New Revision: 9499

Added:
   trunk/mapbender/http/geoportal/class_gml3.php
Modified:
   trunk/mapbender/http/geoportal/mb_gazetteerFlst.php
   trunk/mapbender/http/geoportal/mb_gazetteerFlst_server.php
Log:
Neue Flurst?\195?\188ckssuche GML3/Mapserver WFS

Added: trunk/mapbender/http/geoportal/class_gml3.php
===================================================================
--- trunk/mapbender/http/geoportal/class_gml3.php	                        (rev 0)
+++ trunk/mapbender/http/geoportal/class_gml3.php	2016-05-27 09:37:39 UTC (rev 9499)
@@ -0,0 +1,1093 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z 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");
+	
+	
+class gml3 {
+	var $geomtype_point = 'Point';					
+	var $geomtype_polygon = 'Polygon';
+	var $geomtype_line = 'LineString';
+	var $geomtype_multipolygon = 'MultiSurface'; 
+	var $geomtype_multiline = 'MultiLine';
+	var $geometries = array();	
+	var $member = -1;
+	var $geomtype = array();	
+	var $keys = array();
+	var $values = array();
+	var $geometry = array();
+	var $bbox = array();
+	var $doc;
+	var $geomFeaturetypeElement = null;
+	
+	
+	function gml3(){
+		$this->geometries = array($this->geomtype_point, $this->geomtype_polygon, $this->geomtype_line, $this->geomtype_multipolygon, $this->geomtype_multiline);
+	}
+	function getGml($req){
+		$x = new connector($req);
+		return $x->file;
+	}
+
+	function parseFile($req){
+		#$data = implode("",file($req));
+		$x = new connector($req);
+		$data = $x->file;
+		$data = $this->removeWhiteSpace($data);
+		$this->parseXML($data);		
+		#$e = new mb_exception("data = ".$data); 		
+	}
+	
+    function parseGeometry($req){
+		#$data = implode("",file($req));
+		$x = new connector($req);
+		$data = $x->file;
+		$e = new mb_exception("data = ".$data);
+		$data = $this->removeWhiteSpace($data);
+		//$envelopeGeom = $this->parseGeom($data);
+		$geom = $this->parseXML($data);
+		
+		return $geom;
+	}
+	
+	function parseGeom($data) {
+	    $this->doc = $this->removeWhiteSpace($data);
+	    $gmlDoc = new SimpleXMLElement($this->doc);
+		
+		$gmlDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
+		$gmlDoc->registerXPathNamespace('wfs', 'http://www.opengis.net/wfs');
+		$gmlDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+		
+		// build feature collection
+		$featureCollection = new FeatureCollection();
+		
+		// gmlBounding
+		//$gmlBounding = $gmlDoc->xpath("//gml:boundedBy/gml:Envelope/gml:pos");
+		//$gmlBounding = $gmlDoc->xpath("//gml:boundedBy/gml:Box/gml:coordinates");
+		$gmlFeatureMembers = $gmlDoc->xpath("//wfs:member");
+
+		if (count($gmlFeatureMembers) > 0) {
+		$cnt=0;				 
+		foreach ($gmlFeatureMembers as $gmlFeatureMember) {
+				$featureMember_dom = dom_import_simplexml($gmlFeatureMember);
+				
+				$feature = new Feature();
+				if ($this->geomFeaturetypeElement != null) {
+					$feature->parse($featureMember_dom, $this->geomFeaturetypeElement);
+				}
+				else {
+					$feature->parse($featureMember_dom);
+				}
+				if (isset($feature->geometry)) {
+					$featureCollection->addFeature($feature);
+				}
+				$cnt++;		
+			}
+			
+			return $featureCollection->toGeoJSON();
+		}
+		else{
+			return "";
+		}
+	}
+	
+	function parseXML($data) {
+		if (func_num_args() == 2) {
+			$this->geomFeaturetypeElement = func_get_arg(1);
+		}
+		$this->doc = $this->removeWhiteSpace($data);
+		return $this->toGeoJSON();
+	}
+
+	function removeWhiteSpace ($string) {
+		return preg_replace("/\>(\s)+\</", "><", trim($string));
+	}
+	
+	function sepNameSpace($s){
+		$c = mb_strpos($s,":"); 
+		if($c>0){
+			return mb_substr($s,$c+1);
+		}
+		else{
+			return $s;
+		}		
+	}
+	
+	function toGeoJSON () {
+		$gmlDoc = new SimpleXMLElement($this->doc);
+		
+		$gmlDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
+		$gmlDoc->registerXPathNamespace('wfs', 'http://www.opengis.net/wfs');
+		$gmlDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+		
+		// build feature collection
+		$featureCollection = new FeatureCollection();
+		
+		// segments of the featzreCollection
+		$gmlFeatureMembers = $gmlDoc->xpath("//wfs:member");
+		
+		if(count($gmlFeatureMembers)>0){
+			$cnt=0;
+			foreach ($gmlFeatureMembers as $gmlFeatureMember) {
+				$featureMember_dom = dom_import_simplexml($gmlFeatureMember);
+				
+				$feature = new Feature();
+				if ($this->geomFeaturetypeElement != null) {
+					$feature->parse($featureMember_dom, $this->geomFeaturetypeElement);
+				}
+				else {
+					$feature->parse($featureMember_dom);
+				}
+				if (isset($feature->geometry)) {
+					$featureCollection->addFeature($feature);
+				}
+				$cnt++;
+			}
+
+			
+			return $featureCollection->toGeoJSON();
+		}
+		else{
+			return "{}";
+		}
+	}
+
+		public static function getDimensionFromNode ($domNode) {
+		if (!$domNode->hasAttribute("srsDimension")) {
+			return 2;
+		}
+		$dim = intval($domNode->getAttribute("srsDimension"), 10);
+		if (2 == $dim || 3 == $dim) {
+			return $dim;
+		}
+		return 2;
+		
+		}
+	
+	/**
+	 * @deprecated
+	 */
+	function parsegml($req){
+		#$data = implode("",file($req));
+		$x = new connector($req);
+		$this->parse_xml($x->file);		 		
+	}
+
+	/**
+	 * @deprecated
+	 */
+	function parse_xml($data){
+
+
+		$this->doc = $data;
+
+		$section = false;
+		$geom = false;
+		$boundedBy = false;
+		$coordinates = false;
+		$el = -1;
+		$parser = xml_parser_create(CHARSET);
+		xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+		xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+		xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+		xml_parse_into_struct($parser,$data,$values,$tags);
+		$code = xml_get_error_code ($parser);
+		if ($code) {
+			$line = xml_get_current_line_number($parser); 
+			$mb_exception = new mb_exception(xml_error_string($code) .  " in line " . $line);
+		}
+		xml_parser_free($parser);
+		
+		foreach ($values as $element) {
+			#$e = new mb_exception($element['tag']);
+			if(strtoupper($this->sepNameSpace($element['tag'])) == strtoupper("boundedBy") && $element['type'] == "open"){
+				$boundedBy = true;
+			}
+			if ($boundedBy) {
+				if(strtoupper($this->sepNameSpace($element['tag'])) == strtoupper("envelope")){
+					
+					$epsgAttr = "";
+					if(isset($element['attributes'])){
+						$epsgAttr = isset($element['attributes']['srsName']) ? $element['attributes']['srsName'] : "";
+					}
+		
+					if(strstr($epsgAttr,'#') !== false){
+						// http://www.opengis.net/gml/srs/epsg.xml#4326
+						$parts = explode('#',$epsgAttr);
+						$epsg == isset($parts[1]) ? $parts[1] : "";
+					}else if (strstr($epsgAttr,':') !== false){
+						// EPSG:31466
+						// urn:ogc:def:crs:EPSG:6.5:4326 
+						$parts = explode(':',$epsgAttr);
+						$parts = array_reverse($parts);
+						 if(isset($parts[0])){
+						 	$epsg =  $parts[0];
+						}else{
+							$epsg = "";
+						}
+						new mb_exception(print_r(isset($parts[0]),true));
+						new mb_exception(print_r($epsg,true));
+					}else {
+						$epsg="";
+					}
+					$this->epsg = $epsg;
+				}
+				if(strtoupper($this->sepNameSpace($element['tag'])) == strtoupper("lowercorner")){
+					$this->bbox = explode(",", str_replace(",,","",str_replace(" ",",",trim($element['value']))));
+					$boundedBy=false;
+				}
+                                if(strtoupper($this->sepNameSpace($element['tag'])) == strtoupper("uppercorner")){
+                                        $this->bbox .= explode(",", str_replace(",,","",str_replace(" ",",",trim($element['value']))));
+                                        $boundedBy=false;
+                                }
+
+			}
+			if(strtoupper($this->sepNameSpace($element['tag'])) == strtoupper("Member") && $element['type'] == "open"){
+				$this->member++;
+				$this->keys[$this->member] = array();
+				$this->value[$this->member] = array();
+				$this->geometry[$this->member] = array();
+				$section = true;
+				$cnt_geom = 0;
+			}
+			if($section == true){
+				if( in_array($this->sepNameSpace($element['tag']),$this->geometries) && $element['type'] == "open"){
+					$geom = true;
+					$this->geomtype[$this->member] = $this->sepNameSpace($element['tag']);
+				}
+				else if(in_array($this->sepNameSpace($element['tag']),$this->geometries) && $element['type'] == "close"){
+					$cnt_geom++;
+					$geom = false;
+				}
+				if($geom == true){
+					if (strtoupper($this->sepNameSpace($element['tag'])) == strtoupper("poslist")) {
+						$this->geometry[$this->member][$cnt_geom] =  str_replace(",,","",str_replace(" ",",",trim($element['value'])));
+						$coordinates = true;
+						// XXX: Increment counter to get all geometries of a feature member, 
+						// comment it out to only show first geometry of featuremember
+						$cnt_geom++;
+					}
+					else if (!$coordinates && trim($element['value'])) {
+						$coords = str_replace(",,","",str_replace(" ",",",trim($element['value'])));
+						$tmp_array = explode(",", $coords);
+						if (count($tmp_array > 1)) {
+							$this->geometry[$this->member][$cnt_geom] =  $coords;
+							$coordinates = true;
+						   // XXX: Increment counter to get all geometries of a feature member, 
+						   // comment it out to only show first geometry of featuremember
+							$cnt_geom++;
+						}
+					}
+				}
+				else if(strtoupper($this->sepNameSpace($element['tag'])) == strtoupper("Member") && $element['type'] == "close"){
+					$section = false;	
+					$el = -1;
+				}
+				else{
+					$el++;
+					$this->values[$this->member][$el] = $element['value'];
+					$this->keys[$this->member][$el] = $element['tag'];	
+				}
+			}
+		}
+	}	
+
+	/**
+	 * @deprecated
+	 */
+	function getMemberCount(){
+		return ($this->member+1);	
+	}
+	
+	/**
+	 * @deprecated
+	 */
+	function getValueBySeparatedKey($memberCount,$keyName){
+		for($i=0; $i<count($this->keys[$memberCount]); $i++){
+			if($this->sepNameSpace($this->keys[$memberCount][$i]) == $keyName){
+				return $this->values[$memberCount][$i];
+			}	
+		}
+	}
+	
+	/**
+	 * @deprecated
+	 */
+	function getValueByKey($memberCount,$keyName){
+		for($i=0; $i<count($this->keys[$memberCount]); $i++){
+			if($this->keys[$memberCount][$i] == $keyName){
+				return $this->values[$memberCount][$i];
+			}	
+		}
+	}
+	
+	/**
+	 * @deprecated
+	 */
+	function getXfromMemberAsString($memberCount,$geomCount){
+		$t = explode(",",$this->geometry[$memberCount][$geomCount]);
+		$x = array();
+		for($i=0; $i<(count($t)-1); $i=$i+2){
+			array_push($x,$t[$i]);
+		}
+		return implode(",",$x);
+	}
+	
+	/**
+	 * @deprecated
+	 */
+	function getYfromMemberAsString($memberCount,$geomCount){
+		$t = explode(",",$this->geometry[$memberCount][$geomCount]);
+		$y = array();
+		for($i=1; $i<=(count($t)-1); $i=$i+2){
+			array_push($y,$t[$i]);
+		}
+		return implode(",",$y);
+	}
+	
+	/**
+	 * @deprecated
+	 */
+	function getGeometriesFromMember($memberCount){
+		return $this->geometry[$memberCount];	
+	}
+	
+	/**
+	 * @deprecated
+	 */
+	function getGeometryTypeFromMember($memberCount){
+		return 	$this->geomtype[$memberCount];
+	}
+
+	/**
+	 * @deprecated
+	 */
+	function exportGeometriesToJS ($isInFrame) {
+		$prefix = "";
+		if ($isInFrame == true) {
+			$prefix = "parent.";
+		}
+		$js = "";
+		$js .= "var geom = new ".$prefix."GeometryArray();\n";
+		for ($i=0; $i<count($this->geometry); $i++) {
+			$js .= $this->exportMemberToJS($i, $isInFrame);
+			$js .= "geom.addCopy(q);\n";
+		}
+		return $js;
+	}
+	
+	/**
+	 * @deprecated
+	 */
+	function exportMemberToJS ($i, $isInFrame) {
+		$prefix = "";
+		if ($isInFrame == true) {
+			$prefix = "parent.";
+		}
+		$js = "";
+		if ($this->getGeometryTypeFromMember($i) == $this->geomtype_point) {
+			$js .= "var current_geomtype = ".$prefix."geomType.point;\n";
+		}
+		elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_line || $this->getGeometryTypeFromMember($i) == $this->geomtype_multiline) {
+			$js .= "var current_geomtype = ".$prefix."geomType.line;\n";
+		}
+		elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_polygon || $this->getGeometryTypeFromMember($i) == $this->geomtype_multipolygon) {
+			$js .= "var current_geomtype = ".$prefix."geomType.polygon;\n";
+		}
+		else {
+			$e = new mb_notice("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."' or no geometry existing");
+			return "";
+		}	
+		
+		$js .= "var q = new ".$prefix."MultiGeometry(current_geomtype);\n";
+		
+		for ($j=0; $j<count($this->geometry[$i]); $j++) {
+			$js .= "q.addGeometry(current_geomtype);\n";
+			
+			$x_array = explode(",", $this->getXfromMemberAsString($i, $j));
+			$y_array = explode(",", $this->getYfromMemberAsString($i, $j));
+			
+			for ($k=0; $k<count($x_array); $k++) {
+				$js .= "q.get(-1).addPointByCoordinates(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));\n";
+				//$js .= "alert(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));";
+			}
+			$js .= "q.get(-1).close();\n";
+		}
+//		$js .= "alert(q);\n";
+		return $js;
+	}
+
+}
+
+
+
+
+class FeatureCollection {
+	var $type = "FeatureCollection";
+	var $featureArray = array();
+	
+	public function __construct() {
+		
+	}
+	
+	public function addFeature ($aFeature) {
+		array_push($this->featureArray, $aFeature);
+	}
+	
+	public function toGeoJSON () {
+		$str = "";
+		$len = count($this->featureArray); 
+		if ($len > 0) {
+			$str .= "{\"type\": \"FeatureCollection\", \"features\": [";
+			for ($i=0; $i < $len; $i++) {
+				if ($i > 0) {
+					$str .= ",";
+				}	
+				$str .= $this->featureArray[$i]->toGeoJSON();
+			}
+			$str .= "]}";
+		}
+		return $str;
+	}
+}
+
+class Feature {
+	var $type = "Feature";
+	var $fid;
+	var $geometry = false;
+	var $properties = array();
+	var $geomFeaturetypeElement = null;
+	
+	public function __construct() {
+	}
+	
+	function sepNameSpace($s){
+		list($ns,$FeaturePropertyName) = split(":",$s);
+		$nodeName = array('ns' => $ns, 'value' => $FeaturePropertyName);
+		return $nodeName;
+	}
+	
+		/**
+	 * Parses the feature segment of a GML and stores the geometry in the
+	 * $geometry variable of the class.
+	 * 	
+	 * Example of a feature segment of a GML. 
+	 * 
+	 * <gml:featureMember>
+	 * 	<ms:my_polygons gml:id="my_polygons.624">
+	 * 		<gml:boundedBy>
+	 * 			<gml:Envelope srsName="epsg:4326">
+	 * 				<gml:lowerCorner>39.700000 29.400000</gml:lowerCorner>
+	 * 				<gml:upperCorner>46.400000 35.400000</gml:upperCorner>
+	 * 			</gml:Envelope>
+	 * 		</gml:boundedBy>
+	 * 		<ms:the_geom>
+	 * 			<gml:MultiSurface srsName="epsg:4326">
+	 * 				<gml:surfaceMembers>
+	 * 					<gml:Polygon>
+	 * 						<gml:exterior>
+	 * 							<gml:LinearRing>
+	 * 								<gml:posList srsDimension="2">
+	 * 									43.200000 35.400000 
+	 * 									46.400000 31.700000 
+	 * 									44.100000 31.000000 
+	 * 									41.700000 29.400000 
+	 * 									39.700000 31.400000 
+	 * 									43.300000 32.300000 
+	 * 									43.200000 35.400000 
+	 * 								</gml:posList>
+	 * 							</gml:LinearRing>
+	 * 						</gml:exterior>
+	 * 					</gml:Polygon>
+	 * 				</gml:surfaceMembers>
+	 * 			</gml:MultiSurface>
+	 * 		</ms:the_geom>
+	 * 		<ms:oid>16752039</ms:oid>
+	 * 		<ms:gid>624</ms:gid>
+	 * 		<ms:name>inter_08</ms:name>
+	 * 		<ms:angle/>
+	 * 		<ms:annotation/>
+	 * 		<ms:style>3</ms:style>
+	 * 		</ms:my_polygons>
+	 * 	</gml:featureMember>
+	 * 
+	 * @return void
+	 * @param $domNode DOMNodeObject the feature tag of the GML 
+	 * 							(<gml:featureMember> in the above example)	
+	 */
+	public function parse($domNode) {
+		if (func_num_args() == 2) {
+			$this->geomFeaturetypeElement = func_get_arg(1);
+		}
+
+		$currentSibling = $domNode->firstChild;
+		
+		$this->fid = $currentSibling->getAttribute("fid");
+		
+		$currentSibling = $currentSibling->firstChild;
+		
+		while ($currentSibling) {
+		
+			$name = $currentSibling->nodeName;
+			$value = $currentSibling->nodeValue;
+			
+			$namespace = $this->sepNameSpace($name);
+			$ns = $namespace['ns'];
+			$columnName = $namespace['value'];
+			$isGeomColumn = ($this->geomFeaturetypeElement == null || $columnName == $this->geomFeaturetypeElement);
+			
+			// check if this node is a geometry node.
+			// however, even if it is a property node, 
+			// it has a child node, the text node!
+			// So we might need to do something more 
+			// sophisticated here...
+			if ($currentSibling->hasChildNodes() && $isGeomColumn){
+				$geomNode = $currentSibling->firstChild; 
+
+			$geomType = $geomNode->nodeName;
+			if ($geomNode->nodeType == XML_ELEMENT_NODE) {
+	                if ($geomNode->hasAttribute("srsName")) {
+                         $srs = $geomNode->getAttribute("srsName");
+                        }
+                }
+				 
+				 
+					switch ($geomType) {
+						case "gml:Polygon" :
+							$this->geometry = new GMLPolygon();
+							$this->geometry->srs = $srs;
+							$this->geometry->parsePolygon($geomNode);
+							break;
+						case "gml:LineString" :
+							$this->geometry = new GMLLine();
+							$this->geometry->srs = $srs;
+							$this->geometry->parseLine($geomNode);
+							break;
+						case "gml:Point" :
+							$this->geometry = new GMLPoint();
+							$this->geometry->srs = $srs;
+							$this->geometry->parsePoint($geomNode);
+							break;
+						case "gml:MultiLineString" :
+							$this->geometry = new GMLMultiLine();
+							$this->geometry->srs = $srs;
+							break;
+						case "gml:MultiSurface" :
+							$this->geometry = new GMLMultiPolygon();
+							$this->geometry->srs = $srs;
+							$this->geometry->parseMultiPolygon($geomNode);
+							break;
+						case "gml:Envelope" :
+							$this->geometry = new GMLEnvelope();
+							$this->geometry->srs = $srs;
+							$this->geometry->parseEnvelope($geomNode);
+							break;
+						default:
+							$this->properties[$columnName] = $value;
+							break;
+					}
+			} 
+			else {
+					$this->properties[$columnName] = $value;
+			}
+			
+			$currentSibling = $currentSibling->nextSibling;
+		}
+	}
+	
+	public function toGeoJSON () {
+		$str = "";
+        $str .= "{\"type\":\"Feature\", \"id\":\"".$this->fid."\", \"crs\":";
+	               
+	    if (!$this->geometry || !$this->geometry->srs) {
+	        $str .= "null, ";
+	    }
+	     else {
+	         $str .= "{\"type\":\"name\", \"properties\":{\"name\":\"" . $this->geometry->srs . "\"}}, ";
+       }
+	               
+	                $str .= "\"geometry\": ";
+		if ($this->geometry) {
+			$str .= $this->geometry->toGeoJSON();
+		}
+		else {
+			$str .= "\"\"";
+		}
+
+		
+		$prop = array();
+		
+		$str .= ", \"properties\": ";
+		$cnt = 0;
+		foreach ($this->properties as $key => $value) {
+				$prop[$key] = $value;
+				$cnt ++;
+		}
+
+		$json = new Mapbender_JSON();
+		$str .= $json->encode($prop); 
+		$str .= "}";
+		
+		return $str;
+	}
+}
+
+class GMLLine {
+
+	var $pointArray = array();
+
+	public function __construct() {
+		
+	}
+
+	public function parseLine ($domNode) {
+		$currentSibling = $domNode->firstChild;
+		while ($currentSibling) {
+
+			$dim = self::getDimensionFromNode($currentSibling);
+			$coordArray = explode(' ', trim($currentSibling->nodeValue));
+			for ($i = 0; $i < count($coordArray); $i += $dim) {
+				$x = $coordArray[$i];
+				$y = $coordArray[$i+1];
+				$gmlLine->addPoint($x, $y);
+			}
+			$currentSibling = $currentSibling->nextSibling;
+		}
+	}
+	
+	protected function addPoint ($x, $y) {
+		array_push($this->pointArray, array("x" => $x, "y" => $y));
+	}
+	
+	public function toGeoJSON () {
+		$numberOfPoints = count($this->pointArray);
+		$str = "";
+		if ($numberOfPoints > 0) {
+			$str .= "{\"type\": \"LineString\", \"coordinates\":[";
+			for ($i=0; $i < $numberOfPoints; $i++) {
+				if ($i > 0) {
+					$str .= ",";
+				}
+				$str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+			}
+			$str .= "]}";
+		}
+		else {
+			$e = new mb_exception("GMLLine: toGeoJSON: this point is null.");
+		}
+		return $str;
+	}
+}
+
+class GMLPoint {
+
+	var $point;
+
+	public function __construct() {
+		
+	}
+
+	public function parsePoint ($domNode) {
+		$currentSibling = $domNode->firstChild;
+		while ($currentSibling) {
+			$coordArray = explode(" ", $currentSibling->nodeValue);
+			$gmlPoint->setPoint($coordArray[0], $coordArray[1]);
+			$currentSibling = $currentSibling->nextSibling;
+		}
+	}
+	
+	protected function setPoint ($x, $y) {
+#		echo "x: " . $x . " y: " . $y . "\n";
+		if (strstr($this->srs,'EPSG::')==True)  {
+			$this->point = array("x" => $y, "y" => $x);
+		} else {
+			$this->point = array("x" => $x, "y" => $y);
+		}
+	}
+	
+	public function toGeoJSON () {
+		$str = "";
+		if ($this->point) {
+			$str .= "{\"type\": \"Point\", \"coordinates\":";
+			$str .= "[".$this->point["x"].",".$this->point["y"]."]";
+			$str .= "}";
+		}
+		else {
+			$e = new mb_exception("GMLPoint: toGeoJSON: this point is null.");
+		}
+		return $str;
+	}
+}
+
+class GMLPolygon {
+
+	var $pointArray = array();
+	var $innerRingArray = array();
+
+	public function __construct() {
+		
+	}
+	public static function getDimensionFromNode ($domNode) {
+		if (!$domNode->hasAttribute("srsDimension")) {
+			return 2;
+		}
+		$dim = intval($domNode->getAttribute("srsDimension"), 10);
+		if (2 == $dim || 3 == $dim) {
+			return $dim;
+		}
+		return 2;
+		
+		}
+	public function parsePolygon ($domNode) {
+		$simpleXMLNode = simplexml_import_dom($domNode);
+
+		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+		
+		$allCoords = $simpleXMLNode->xpath("gml:exterior/gml:LinearRing/gml:posList");
+			
+		$cnt=0;
+		foreach ($allCoords as $Coords) {
+			$coordsDom = dom_import_simplexml($Coords);
+			
+			$dim = self::getDimensionFromNode($coordsDom);
+			$coordArray = explode(' ', trim($coordsDom->nodeValue));
+			for ($i = 0; $i < count($coordArray); $i += $dim) {
+				$x = $coordArray[$i];
+				$y = $coordArray[$i+1];
+				$this->addPoint($x, $y);
+			}
+			$cnt++;
+		}
+		
+		$innerRingNodeArray = $simpleXMLNode->xpath("gml:innerBoundaryIs/gml:LinearRing");
+		if ($innerRingNodeArray) {
+			$ringCount = 0;
+			foreach ($innerRingNodeArray as $ringNode) {
+				$coordinates = $ringNode->xpath("gml:coordinates");
+				foreach ($coordinates as $coordinate) {
+					$coordsDom = dom_import_simplexml($coordinate);
+						
+					$dim = self::getDimensionFromNode($coordsDom);
+					$coordArray = explode(' ', trim($coordsDom->nodeValue));
+					for ($i = 0; $i < count($coordArray); $i += $dim) {
+						$x = $coordArray[$i];
+						$y = $coordArray[$i+1];
+						$this->addPointToRing($ringCount, $x, $y);
+					}
+				}
+				$ringCount++;
+			}
+		}
+	}
+	
+	protected function addPoint ($x, $y) {
+		if (strstr($this->srs,'EPSG::')==True)  {
+			array_push($this->pointArray, array("x" => $y, "y" => $x));
+		} else {
+			array_push($this->pointArray, array("x" => $x, "y" => $y));
+		}
+	}
+	
+	protected function addPointToRing ($i, $x, $y) {
+		if (count($this->innerRingArray) <= $i) {
+			array_push($this->innerRingArray, array());
+		}
+		$index = count($this->innerRingArray);
+		$currentIndex = ($i < $index ? $i : $index);
+		if (strstr($this->srs,'EPSG::')==True)  {
+			array_push($this->innerRingArray[$currentIndex], array("x" => $y, "y" => $x));
+		} else {
+			array_push($this->innerRingArray[$currentIndex], array("x" => $x, "y" => $y));
+		}			
+	}
+	
+	public function toGeoJSON () {
+		$numberOfPoints = count($this->pointArray);
+		$str = "";
+		if ($numberOfPoints > 0) {
+			$str .= "{\"type\": \"Polygon\", \"coordinates\":[[";
+			for ($i=0; $i < $numberOfPoints; $i++) {
+				if ($i > 0) {
+					$str .= ",";
+				}
+				$str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+			}
+			$str .= "]";
+			
+			for ($i=0; $i < count($this->innerRingArray); $i++) {
+				$str .= ",[";
+				for ($j=0; $j < count($this->innerRingArray[$i]); $j++) {
+					if ($j > 0) {
+						$str .= ",";
+					}
+					$str .= "[".$this->innerRingArray[$i][$j]["x"].",".$this->innerRingArray[$i][$j]["y"]."]";
+				}
+				$str .= "]";
+			}
+			$str .= "]}";
+		}
+		else {
+			$e = new mb_exception("GMLPolygon: toGeoJSON: this point is null.");
+		}
+		return $str;
+	}
+}
+
+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();
+
+	public function __construct() {
+		
+	}
+
+	public function parseMultiLine ($domNode) {
+		$simpleXMLNode = simplexml_import_dom($domNode);
+
+		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+		
+		$allCoords = $simpleXMLNode->xpath("gml:lineStringMember/gml:LineString/gml:coordinates");
+			
+		$cnt=0;
+		foreach ($allCoords as $Coords) {
+			
+			$this->lineArray[$cnt] = array();
+			
+			$coordsDom = dom_import_simplexml($Coords);
+				
+//			$name = $coordsDom->nodeName;
+//			$value = $coordsDom->nodeValue;				
+//			echo "===> name: ".$name. ", Value: ".$value."<br>";
+			
+			foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+				list($x,$y,$z) = explode(',',$pointCoords);
+				$this->addPoint($x, $y, $cnt);
+				}
+			
+			$cnt++;
+		}
+		
+	}
+	
+	protected function addPoint ($x, $y) {
+		if (strstr($this->srs,'EPSG::')==True)  {
+			array_push($this->lineArray[$i], array("x" => $y, "y" => $x));
+		} else {
+			array_push($this->lineArray[$i], array("x" => $x, "y" => $y));
+		}
+	}
+	
+	
+	public function toGeoJSON () {
+		$numberlineArray = count($this->lineArray);
+		$str = "";
+		if ($numberlineArray > 0) {
+			$str .= "{\"type\": \"MultiLineString\", \"coordinates\":[";
+			
+			for ($cnt =0; $cnt < $numberlineArray; $cnt++){
+				if ($cnt > 0) {
+						$str .= ",";
+					}
+					$str .="[";
+			
+				for ($i=0; $i < count($this->lineArray[$cnt]); $i++) {
+					if ($i > 0) {
+						$str .= ",";
+					}
+					$str .= "[".$this->lineArray[$cnt][$i]["x"].",".$this->lineArray[$cnt][$i]["y"]."]";
+				}
+				$str .="]";
+			}
+			$str .= "]}";
+			
+		}
+		else {
+			$e = new mb_exception("GMLMultiLine: toGeoJSON: this multiLine is null.");
+		}
+		return $str;
+	}
+}
+
+class GMLMultiPolygon {
+
+	var $polygonArray = array();
+	var $innerRingArray = array();
+
+	public function __construct() {
+		
+	}
+	public static function getDimensionFromNode ($domNode) {
+		if (!$domNode->hasAttribute("srsDimension")) {
+			return 2;
+		}
+		$dim = intval($domNode->getAttribute("srsDimension"), 10);
+		if (2 == $dim || 3 == $dim) {
+			return $dim;
+		}
+		return 2;
+		
+		}
+
+	protected function addPointToRing ($i, $j, $x, $y) {
+		if (count($this->innerRingArray[$i]) <= $j) {
+			array_push($this->innerRingArray[$i], array());
+		}
+		if (strstr($this->srs,'EPSG::')==True)  {
+			array_push($this->innerRingArray[$i][$j], array("x" => $y, "y" => $x));
+		} else {
+			array_push($this->innerRingArray[$i][$j], array("x" => $x, "y" => $y));
+		}	
+	}
+	
+
+	public function parseMultiPolygon ($domNode) {
+//		echo $domNode->nodeName."<br>";
+		$simpleXMLNode = simplexml_import_dom($domNode);
+
+		$simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+
+		$allPolygons = $simpleXMLNode->xpath("gml:surfaceMember/gml:Polygon");
+		if (count($allPolygons) === 0) {
+			$allPolygons = $simpleXMLNode->xpath("gml:surfaceMembers/gml:Polygon");
+		}
+		
+		$cnt=0;
+		foreach ($allPolygons as $polygon) {
+			$allCoords = $polygon->xpath("gml:exterior/gml:LinearRing/gml:posList");
+				
+			$this->polygonArray[$cnt] = array();
+			foreach ($allCoords as $Coords) {
+				
+				$coordsDom = dom_import_simplexml($Coords);
+					
+				$dim = self::getDimensionFromNode($coordsDom);
+				$coordArray = explode(' ', trim($coordsDom->nodeValue));
+				for ($i = 0; $i < count($coordArray); $i += $dim) {
+					$x = $coordArray[$i];
+					$y = $coordArray[$i+1];
+					$this->addPoint($x, $y, $cnt);
+				}
+			}	
+			
+			$this->innerRingArray[$cnt] = array();
+			$innerRingNodeArray = $polygon->xpath("gml:interior");
+			if ($innerRingNodeArray) {
+				$ringCount = 0;
+				foreach ($innerRingNodeArray as $ringNode) {
+					$currentRingNode = $ringNode->xpath("gml:LinearRing");
+					foreach ($currentRingNode as $node) {
+						$coordinates = $node->xpath("gml:posList");
+						foreach ($coordinates as $coordinate) {
+							$coordsDom = dom_import_simplexml($coordinate);
+								
+							$dim = self::getDimensionFromNode($coordsDom);
+							$coordArray = explode(' ', trim($coordsDom->nodeValue));
+							for ($i = 0; $i < count($coordArray); $i += $dim) {
+								$x = $coordArray[$i];
+								$y = $coordArray[$i+1];
+								$this->addPointToRing($cnt, $ringCount, $x, $y);
+							}
+						}
+						$ringCount++;
+					}
+				}
+			}
+			$cnt++;
+			new mb_notice("create multipolygon " . serialize($this->innerRingArray));
+		}		
+	}
+	
+       protected function addPoint ($x, $y, $i) {
+		if (strstr($this->srs,'EPSG::')==True)  {
+			array_push($this->polygonArray[$i], array("x" => $y, "y" => $x));
+		} else {
+			array_push($this->polygonArray[$i], array("x" => $x, "y" => $y));
+		}
+	}
+	
+	
+	
+	public function toGeoJSON () {
+		$numberPolygonArray = count($this->polygonArray);
+		$str = "";
+		if ($numberPolygonArray > 0) {
+			$str .= "{\"type\": \"MultiPolygon\", \"coordinates\":[";
+			
+			for ($cnt =0; $cnt < $numberPolygonArray; $cnt++){
+				if ($cnt > 0) {
+					$str .= ",";
+				}
+				$str .= "[";
+
+				$str .= "[";
+				for ($i=0; $i < count($this->polygonArray[$cnt]); $i++) {
+					if ($i > 0) {
+						$str .= ",";
+					}
+					$str .= "[".$this->polygonArray[$cnt][$i]["x"].",".$this->polygonArray[$cnt][$i]["y"]."]";
+				}
+				$str .= "]";
+				
+				for ($i=0; $i < count($this->innerRingArray[$cnt]); $i++) {
+					$str .= ",[";
+					for ($j=0; $j < count($this->innerRingArray[$cnt][$i]); $j++) {
+						if ($j > 0) {
+							$str .= ",";
+						}
+						$str .= "[".$this->innerRingArray[$cnt][$i][$j]["x"].",".$this->innerRingArray[$cnt][$i][$j]["y"]."]";
+					}
+					$str .= "]";
+				}
+				$str .= "]";
+			}
+			$str .= "]}";
+			
+		}
+		else {
+			$e = new mb_exception("GMLMultiPolygon: toGeoJSON: this multiLine is null.");
+		}
+		return $str;
+	}
+}
+?>

Modified: trunk/mapbender/http/geoportal/mb_gazetteerFlst.php
===================================================================
--- trunk/mapbender/http/geoportal/mb_gazetteerFlst.php	2016-05-27 08:42:51 UTC (rev 9498)
+++ trunk/mapbender/http/geoportal/mb_gazetteerFlst.php	2016-05-27 09:37:39 UTC (rev 9499)
@@ -1,237 +1,271 @@
-<?php
-/**
- * Package: mb_gazetteerFlst.php
- *
- * Description:
- * Gazetteer for Flurstücke
- *
- *
- * Files:
- *  - http/geoportal/mb_gazetteerFlst.php
- *  - http/geoportal/mb_gazetteerFlst_server.php
- *  - conf/gazetteerFlst.conf
- *
- * SQL:
- * > INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) VALUES('<gui_id>','gazetteerFlst',2,1,'gazetteer for Flurstuecke','Flurstücksuche','div','','',1,1,1,1,4,'visibility:hidden;padding-left:10px;','<div class="ui-widget">
- * > 	<label for="GMK_NAME">Gemarkungsname:</label>
- * >	<input title="Pflichtfeld, bitte geben Sie mindestens 3 Anfangsbuchstaben im Feld Gemarkungsname ein, nach Auswahl wird die Gemarkungsnummer automatisch eingetragen." id="GMK_NAME" style="width:120px;"/><span title="Pflichtfeld, bitte geben Sie mindestens 3 Anfangsbuchstaben im Feld Gemarkungsname ein, nach Auswahl wird die Gemarkungsnummer automatisch eingetragen.">*</span>
- * > </div>
- * > <div class="ui-widget">
- * >	<label for="GMK_NR">Gemarkungsnummer:</label>
- * >	<input id="GMK_NR" style="width:120px;"/>
- * > </div>
- * > <div class="ui-widget">
- * >	<label style="width:180px;" for="FLUR_NR">Flurnummer:</label>
- * >	<select id="FLUR_NR">
- * >		<option value="">---</option>		
- * >	</select>
- * > </div>
- * > <div class="ui-widget">
- * >	<label style="width:180px;" for="FLZ">Zähler/Nenner</label>
- * >	<select id="FLZ">
- * >		<option value="">---</option>		
- * >	</select>
- * >	<select id="FLN">
- * >		<option value="">---</option>		
- * >	</select>
- * > </div>
- * ><div class="ui-widget">
- * >	<input disabled="disabled" style="margin-top:5px" type="button" value="Gehe zu" id="zoomToObj" />
- * >	<input style="margin-top:5px" type="button" value="Auswahl aufheben" id="removeSelection" />
- * > </div>','div','../geoportal/mb_gazetteerFlst.php','','mapframe1,overview','wz-graphics','');
- * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type) VALUES('<gui_id>', 'gazetteerFlst', 'searchCss', '.ui-autocomplete-loading { background: white url(''../img/indicator_wheel.gif'') right center no-repeat; }', '' ,'text/css');
- *
- *
- * License:
- * Copyright (c) 2009, Open Source Geospatial Foundation
- * This program is dual licensed under the GNU General Public License
- * and Simplified BSD license.
- * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
- */
-
-require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
-include '../include/dyn_js.php';
-?>
-
-Mapbender.events.init.register(function () {
-	//lösche alle abhängigen Eingaben bei Klick in Feld gemarkungsschlüssel
-	$("#GMK_NR").click(function () {
-		$("#GMK_NR").val("");
-		$("#GMK_NAME").val("");
-		$("#FLUR_NR").empty().append("<option value=''>---</option>");
-		$("#FLZ").empty().append("<option value=''>---</option>");
-		$("#FLN").empty().append("<option value=''>---</option>");
-		$("#zoomToObj").attr("disabled","true");
-	});
-	
-	//lösche alle abhängigen Eingaben bei Klick in Feld gemarkungsname
-	$("#GMK_NAME").click(function () {
-		$("#GMK_NR").val("");
-		$("#GMK_NAME").val("");
-		$("#FLUR_NR").empty().append("<option value=''>---</option>");
-		$("#FLZ").empty().append("<option value=''>---</option>");
-		$("#FLN").empty().append("<option value=''>---</option>");
-		$("#zoomToObj").attr("disabled","true");
-	});
-	
-	//lösche alle Eingaben + Highlight
-	$("#removeSelection").click(function () {
-		$("#GMK_NR").val("");
-		$("#GMK_NAME").val("");
-		$("#FLUR_NR").empty().append("<option value=''>---</option>");
-		$("#FLZ").empty().append("<option value=''>---</option>");
-		$("#FLN").empty().append("<option value=''>---</option>");
-		$("#zoomToObj").attr("disabled","true");
-	});
-	
-	//autocomplete auf Gemarkungsschlüssel
-	$("#GMK_NR").autocomplete({
-		disabled: false,
-		source: "../geoportal/mb_gazetteerFlst_server.php?command=getGmkNr",
-		minLength: 3,
-		select: function( event, ui ) {
-			$("#GMK_NR").val(ui.item.value);
-			$("#GMK_NAME").val(ui.item.gmkName);
-			
-			//selektiere Fluren
-			getFluren();
-		}
-	});
-	
-	//autocomplete auf Gemarkung
-	$("#GMK_NAME").autocomplete({
-		disabled: false,
-		source: "../geoportal/mb_gazetteerFlst_server.php?command=getGmkName",
-		minLength: 3,
-		select: function( event, ui ) {
-			$("#GMK_NAME").val(ui.item.value);
-			$("#GMK_NR").val(ui.item.gmkNr);
-			
-			//selektiere Fluren
-			getFluren();
-		}
-	});	
-	
-	//auf Auswahl der Flur selektiere Flz aus WFS
-	$("#FLUR_NR").change(function () {
-		getFlz();
-	});
-	
-	//auf Auswahl Flz selektiere Fln aus WFS
-	$("#FLZ").change(function () {
-		getFln();
-	});
-	
-	//auf Klick Gehe zu zoome auf hinterlegte Geometrie
-	$("#zoomToObj").click(function () {
-		$.post("../geoportal/mb_gazetteerFlst_server.php", {
-                command : "getGeomForFlst",
-        		gmkNr : $("#GMK_NR").val(),
-        		flurNr : $("#FLUR_NR").val(),
-                flz : $("#FLZ").val(),
-                fln : $("#FLN").val(),
-                srs : Mapbender.modules.mapframe1.getSRS()
-            }, function (jsCode, status) {
-            if(jsCode) {	
-            	var coord = jsCode.split(" ");
-            	mb_repaintScale('mapframe1',coord[0],coord[1],2500);
-            	highlight(coord[0],coord[1]);
-            	//zoom("mapframe1",true,100,coord[0], coord[1]);
-            }
-        });	
-    });
-	
-	function highlight(x,y){
-        parent.mb_showHighlight("mapframe1",x,y);
-        parent.mb_showHighlight("overview",x,y);
-    } 
-	
-	function getFluren() {
-		$.post("../geoportal/mb_gazetteerFlst_server.php", {
-                command : "getFluren",
-        		gmkNr : $("#GMK_NR").val()
-            }, function (jsCode, status) {
-            if(jsCode) {	
-            	if(typeof jsCode == "object") {
-            		$("#FLUR_NR").empty();
-            		for (var i = 0; i < jsCode.length; i++) {
-						var optionVal = jsCode[i];
-		                var optionName = jsCode[i];
-		                var optionHtml = "<option value='" + optionVal + "'>" + optionName + "</option>";
-		                $("#FLUR_NR").append(optionHtml);
-				 	}
-				 	
-				 	getFlz();
-            	}
-            	else {
-            		alert(jsCode);
-                    return false;
-            	}
-           	}
-        });	
-	}
-	
-	function getFlz() {
-		$.post("../geoportal/mb_gazetteerFlst_server.php", {
-                command : "getFlz",
-                gmkNr : $("#GMK_NR").val(),
-                flurNr : $("#FLUR_NR").val()
-            }, function (jsCode, status) {
-            if(jsCode) {	
-            	if(typeof jsCode == "object") {
-            		$("#FLZ").empty();
-            		for (var i = 0; i < jsCode.length; i++) {
-						var optionVal = jsCode[i];
-		                var optionName = jsCode[i];
-		                var optionHtml = "<option value='" + optionVal + "'>" + optionName + "</option>";
-		                $("#FLZ").append(optionHtml);
-				 	}
-				 	
-				 	getFln();
-            	}
-            	else {
-            		alert(jsCode);
-                    return false;
-            	}
-           	}
-        });
-	}
-	
-	function getFln() {
-		$.post("../geoportal/mb_gazetteerFlst_server.php", {
-                command : "getFln",
-                gmkNr : $("#GMK_NR").val(),
-                flurNr : $("#FLUR_NR").val(),
-                flz : $("#FLZ").val()
-            }, function (jsCode, status) {
-            if(jsCode) {	
-            	if(typeof jsCode == "object") {
-            		$("#FLN").empty();
-            		for (var i = 0; i < jsCode.length; i++) {
-            			if(jsCode[i].id) {
-    						var optionVal = jsCode[i].id;
-    		                var optionName = jsCode[i].id;
-    		                var optionHtml = "<option value='" + optionVal + "'>" + optionName + "</option>";
-    		                $("#FLN").append(optionHtml);
-		                }
-		                else {
-		                	var optionHtml = "<option value=''>---</option>";
-    		                $("#FLN").append(optionHtml);
-		                }
-				 	}
-				 	$("#zoomToObj").removeAttr("disabled");
-				}
-            	else {
-            		alert(jsCode);
-                    return false;
-            	}
-           	}
-        });
-	}
-	
-	this.openSearchDialogFlst = function () {
-		alert("öffnen");
-	};
-});
-
-
+<?php
+/**
+ * Package: mb_gazetteerFlst.php
+ *
+ * Description:
+ * Gazetteer for Flurstücke
+ *
+ *
+ * Files:
+ *  - http/geoportal/mb_gazetteerFlst.php
+ *  - http/geoportal/mb_gazetteerFlst_server.php
+ *  - conf/gazetteerFlst.conf
+ *
+ * SQL:
+ * > INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) VALUES('<gui_id>','gazetteerFlst',2,1,'gazetteer for Flurstuecke','Flurstücksuche','div','','',1,1,1,1,4,'visibility:hidden;padding-left:10px;','<div class="ui-widget">
+ * > 	<label for="GMK_NAME">Gemarkungsname:</label>
+ * >	<input title="Pflichtfeld, bitte geben Sie mindestens 3 Anfangsbuchstaben im Feld Gemarkungsname ein, nach Auswahl wird die Gemarkungsnummer automatisch eingetragen." id="GMK_NAME" style="width:120px;"/><span title="Pflichtfeld, bitte geben Sie mindestens 3 Anfangsbuchstaben im Feld Gemarkungsname ein, nach Auswahl wird die Gemarkungsnummer automatisch eingetragen.">*</span>
+ * > </div>
+ * > <div class="ui-widget">
+ * >	<label for="GMK_NR">Gemarkungsnummer:</label>
+ * >	<input id="GMK_NR" style="width:120px;"/>
+ * > </div>
+ * > <div class="ui-widget">
+ * >	<label style="width:180px;" for="FLUR_NR">Flurnummer:</label>
+ * >	<select id="FLUR_NR">
+ * >		<option value="">---</option>		
+ * >	</select>
+ * > </div>
+ * > <div class="ui-widget">
+ * >	<label style="width:180px;" for="FLZ">Zähler/Nenner</label>
+ * >	<select id="FLZ">
+ * >		<option value="">---</option>		
+ * >	</select>
+ * >	<select id="FLN">
+ * >		<option value="">---</option>		
+ * >	</select>
+ * > </div>
+ * ><div class="ui-widget">
+ * >	<input disabled="disabled" style="margin-top:5px" type="button" value="Gehe zu" id="zoomToObj" />
+ * >	<input style="margin-top:5px" type="button" value="Auswahl aufheben" id="removeSelection" />
+ * > </div>','div','../geoportal/mb_gazetteerFlst.php','','mapframe1,overview','wz-graphics','');
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type) VALUES('<gui_id>', 'gazetteerFlst', 'searchCss', '.ui-autocomplete-loading { background: white url(''../img/indicator_wheel.gif'') right center no-repeat; }', '' ,'text/css');
+ *
+ *
+ * License:
+ * Copyright (c) 2009, Open Source Geospatial Foundation
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
+ * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+ */
+
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+include '../include/dyn_js.php';
+include '../include/dyn_php.php';
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+$sql = "SELECT e_target FROM gui_element WHERE e_id = 'gazetteerFlst' AND fkey_gui_id = $1";
+$v = array($gui_id);
+$t = array('s');
+$res = db_prep_query($sql, $v, $t);
+$cnt = 0;
+while($row = db_fetch_array($res)){
+	$e_target = $row["e_target"];
+	$cnt++;
+}
+echo "var targetString = '" . $e_target . "';";
+?>
+
+var gazetteerResultHighlight;
+var highlightColor = "#cc33cc";
+var targetArray = targetString.split(",");
+var styleProperties = {"position":"absolute", "top":"0px", "left":"0px", "z-index":70};
+
+
+
+Mapbender.events.init.register(function () {
+
+	requestGeometryHighlight = new Highlight(targetArray, "gazetteerFlst", styleProperties, 2);
+	//lösche alle abhängigen Eingaben bei Klick in Feld gemarkungsschlüssel
+	$("#GMK_NR").click(function () {
+		$("#GMK_NR").val("");
+		$("#GMK_NAME").val("");
+		$("#FLUR_NR").empty().append("<option value=''>---</option>");
+		$("#FLZ").empty().append("<option value=''>---</option>");
+		$("#FLN").empty().append("<option value=''>---</option>");
+		$("#zoomToObj").attr("disabled","true");
+	});
+	
+	//lösche alle abhängigen Eingaben bei Klick in Feld gemarkungsname
+	$("#GMK_NAME").click(function () {
+		$("#GMK_NR").val("");
+		$("#GMK_NAME").val("");
+		$("#FLUR_NR").empty().append("<option value=''>---</option>");
+		$("#FLZ").empty().append("<option value=''>---</option>");
+		$("#FLN").empty().append("<option value=''>---</option>");
+		$("#zoomToObj").attr("disabled","true");
+	});
+	
+	//lösche alle Eingaben + Highlight
+	$("#removeSelection").click(function () {
+		$("#GMK_NR").val("");
+		$("#GMK_NAME").val("");
+		$("#FLUR_NR").empty().append("<option value=''>---</option>");
+		$("#FLZ").empty().append("<option value=''>---</option>");
+		$("#FLN").empty().append("<option value=''>---</option>");
+		$("#zoomToObj").attr("disabled","true");
+		delhighlight();
+	});
+	
+	//autocomplete auf Gemarkungsschlüssel
+	$("#GMK_NR").autocomplete({
+		disabled: false,
+		source: "../geoportal/mb_gazetteerFlst_server.php?command=getGmkNr",
+		minLength: 3,
+		select: function( event, ui ) {
+			$("#GMK_NR").val(ui.item.value);
+			$("#GMK_NAME").val(ui.item.gmkName);
+			
+			//selektiere Fluren
+			getFluren();
+		}
+	});
+	
+	//autocomplete auf Gemarkung
+	$("#GMK_NAME").autocomplete({
+		disabled: false,
+		source: "../geoportal/mb_gazetteerFlst_server.php?command=getGmkName",
+		minLength: 3,
+		select: function( event, ui ) {
+			$("#GMK_NAME").val(ui.item.value);
+			$("#GMK_NR").val(ui.item.gmkNr);
+			
+			//selektiere Fluren
+			getFluren();
+		}
+	});	
+	
+	//auf Auswahl der Flur selektiere Flz aus WFS
+	$("#FLUR_NR").change(function () {
+		getFlz();
+	});
+	
+	//auf Auswahl Flz selektiere Fln aus WFS
+	$("#FLZ").change(function () {
+		getFln();
+	});
+	
+	//auf Klick Gehe zu zoome auf hinterlegte Geometrie
+	$("#zoomToObj").click(function () {
+		$.post("../geoportal/mb_gazetteerFlst_server.php", {
+                command : "getGeomForFlst",
+        		gmkNr : $("#GMK_NR").val(),
+        		flurNr : $("#FLUR_NR").val(),
+                flz : $("#FLZ").val(),
+                fln : $("#FLN").val(),
+                srs : Mapbender.modules.mapframe1.getSRS()
+            }, function (jsCode, status) {
+            if(jsCode) {
+		var geoObj = jsCode;
+		geomArrayFluren = new GeometryArray();
+		geomArrayFluren.importGeoJSON(geoObj);	
+		var currentGeom = geomArrayFluren.get(0);
+        mb_repaintScale('mapframe1',currentGeom.get(0).get(0).x,currentGeom.get(0).get(0).y,"2500");
+		requestGeometryHighlight.add(currentGeom);
+		requestGeometryHighlight.paint();
+        Mapbender.events.afterMapRequest.register(function () {
+            requestGeometryHighlight.paint()
+	        });
+            }
+        });	
+    });
+	
+	function delhighlight(){
+        if (requestGeometryHighlight !== null) {
+		requestGeometryHighlight.clean();
+		geomArrayFluren.empty(); 
+	    delete geomArrayFluren;
+		//delete requestGeometryHighlight;
+		//delete currentGeom;
+	};
+    } 
+	
+	function getFluren() {
+		$.post("../geoportal/mb_gazetteerFlst_server.php", {
+                command : "getFluren",
+        		gmkNr : $("#GMK_NR").val()
+            }, function (jsCode, status) {
+            if(jsCode) {	
+            	if(typeof jsCode == "object") {
+            		$("#FLUR_NR").empty();
+            		for (var i = 0; i < jsCode.length; i++) {
+						var optionVal = jsCode[i];
+		                var optionName = jsCode[i];
+		                var optionHtml = "<option value='" + optionVal + "'>" + optionName + "</option>";
+		                $("#FLUR_NR").append(optionHtml);
+				 	}
+				 	
+				 	getFlz();
+            	}
+            	else {
+            		alert(jsCode);
+                    return false;
+            	}
+           	}
+        });	
+	}
+	
+	function getFlz() {
+		$.post("../geoportal/mb_gazetteerFlst_server.php", {
+                command : "getFlz",
+                gmkNr : $("#GMK_NR").val(),
+                flurNr : $("#FLUR_NR").val()
+            }, function (jsCode, status) {
+            if(jsCode) {	
+            	if(typeof jsCode == "object") {
+            		$("#FLZ").empty();
+            		for (var i = 0; i < jsCode.length; i++) {
+						var optionVal = jsCode[i];
+		                var optionName = jsCode[i];
+		                var optionHtml = "<option value='" + optionVal + "'>" + optionName + "</option>";
+		                $("#FLZ").append(optionHtml);
+				 	}
+				 	
+				 	getFln();
+            	}
+            	else {
+            		alert(jsCode);
+                    return false;
+            	}
+           	}
+        });
+	}
+	
+	function getFln() {
+		$.post("../geoportal/mb_gazetteerFlst_server.php", {
+                command : "getFln",
+                gmkNr : $("#GMK_NR").val(),
+                flurNr : $("#FLUR_NR").val(),
+                flz : $("#FLZ").val()
+            }, function (jsCode, status) {
+            if(jsCode) {	
+            	if(typeof jsCode == "object") {
+            		$("#FLN").empty();
+            		for (var i = 0; i < jsCode.length; i++) {
+            			if(jsCode[i].id) {
+    						var optionVal = jsCode[i].id;
+    		                var optionName = jsCode[i].id;
+    		                var optionHtml = "<option value='" + optionVal + "'>" + optionName + "</option>";
+    		                $("#FLN").append(optionHtml);
+		                }
+		                else {
+		                	var optionHtml = "<option value=''>---</option>";
+    		                $("#FLN").append(optionHtml);
+		                }
+				 	}
+				 	$("#zoomToObj").removeAttr("disabled");
+				}
+            	else {
+            		alert(jsCode);
+                    return false;
+            	}
+           	}
+        });
+	}
+	
+	this.openSearchDialogFlst = function () {
+		alert("öffnen");
+	};
+});
+
+

Modified: trunk/mapbender/http/geoportal/mb_gazetteerFlst_server.php
===================================================================
--- trunk/mapbender/http/geoportal/mb_gazetteerFlst_server.php	2016-05-27 08:42:51 UTC (rev 9498)
+++ trunk/mapbender/http/geoportal/mb_gazetteerFlst_server.php	2016-05-27 09:37:39 UTC (rev 9499)
@@ -10,7 +10,7 @@
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
 require_once(dirname(__FILE__)."/../classes/class_json.php");
-include(dirname(__FILE__)."/../geoportal/class_gml2.php");
+include(dirname(__FILE__)."/../geoportal/class_gml3.php");
 include(dirname(__FILE__) . "/../../conf/gazetteerFlst.conf");
 
 //db connection
@@ -36,16 +36,20 @@
 
 $json = new Mapbender_JSON();
 
-function getGeoJson ($featureType, $filter) {
+function getGeoJson ($featureType, $filter, $srs) {
     global $wfsUrl, $nameSpace, $authUserName, $authUserPassword;
     $admin = new administration();
 
-    $wfsUrl = $wfsUrl . "&NAMESPACE=" . $nameSpace. "&username=" . $authUserName . "&password=" . $authUserPassword . "&typeName=" . $featureType."&filter=";
+	if ($srs == NULL) {
+	$wfsUrl = $wfsUrl . "&NAMESPACE=" . $nameSpace. "&username=" . $authUserName . "&password=" . $authUserPassword . "&typeName=" . $featureType."&filter=";
+	} else {
+    $wfsUrl = $wfsUrl . "&NAMESPACE=" . $nameSpace. "&username=" . $authUserName . "&password=" . $authUserPassword . "&typeName=" . $featureType."&srsName=".$srs."&filter=";
+	}
 	$req = urldecode($wfsUrl).urlencode($admin->char_decode(stripslashes($filter)));
 	#echo $req;
 	#$e = new mb_exception(urldecode($req));
 	
-	$mygml = new gml2();
+	$mygml = new gml3();
 	
 	#$auth = array();
 	#$auth['username'] = $authUserName; 
@@ -61,30 +65,7 @@
 	return $jsonObj;
 }
 
-function getGeomFromXml ($featureType, $filter,$srs) {
-    global $wfsUrl, $nameSpace, $authUserName, $authUserPassword;
-    $admin = new administration();
 
-    $wfsUrl = $wfsUrl . "&NAMESPACE=" . $nameSpace. "&username=" . $authUserName . "&password=" . $authUserPassword . "&typeName=" . $featureType."&srsName=".$srs."&filter=";
-	$req = urldecode($wfsUrl).urlencode($admin->char_decode(stripslashes($filter)));
-	#echo $req;
-	#$e = new mb_exception(urldecode($req));
-	
-	$mygml = new gml2();
-	
-	#$auth = array();
-	#$auth['username'] = $authUserName; 
-	#$auth['password'] = $authUserPassword;
-	#$auth['auth_type'] = "basic";
-	$geom = $mygml->parseGeometry($req);
-	#$e = new mb_exception(implode("----",$geom));	
-	#header("Content-type:application/x-json; charset=utf-8");
-	#$geoJson = $mygml->toGeoJSON();
-	
-	#$jsonObj = json_encode(array("geom" => implode(",",$geom)));
-	return implode(",",$geom);
-}
-
 if($command == "getGmkNr") {
 	$searchString = $_REQUEST['term'];
 	$pattern = "/[a-z0-9]/i";
@@ -117,19 +98,19 @@
 }
 
 if($command == "getGmkName") {
-	$searchString = $_REQUEST['term'];
-	$pattern = "/[a-z0-9]/i";
-	if (!preg_match($pattern, $searchString)) {
-		echo "Ungültiger Suchbegriff";
-        die();
-	}
+	$searchString = utf8_encode($_REQUEST['term']);
+	//$pattern = "/[a-z0-9]/i";
+	//if (!preg_match($pattern, $searchString)) {
+	//	echo "Ungültiger Suchbegriff";
+        //die();
+	//}
 	
     $searchFeaturetype = $featuretypeGmkNr;
     $filter = '<Filter xmlns="http://www.opengis.net/ogc" xmlns:app="http://www.deegree.org/app"><PropertyIsLike wildCard="*" singleChar="?" escape="#" matchCase="false">
             				<PropertyName>' . $gmkNameAttr . '</PropertyName>
                 			<Literal>*' . $searchString . '*</Literal>
         					</PropertyIsLike></Filter>';
-	
+ 	$e = new mb_exception($filter);	
 	$resultObj = getGeoJson($searchFeaturetype, $filter);
 	$resultArray = array();
 	
@@ -298,7 +279,7 @@
             '.$flnFilter.'
         </And></Filter>';
 		
-    $resultObj = getGeomFromXml($searchFeaturetype, $filter,$srs);
+    $resultObj = getGeoJSON($searchFeaturetype, $filter,$srs);
     header("Content-type:application/json; charset=utf-8");
     echo json_encode($resultObj);
 }



More information about the Mapbender_commits mailing list