[Mapbender-commits] r1024 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jan 24 08:04:13 EST 2007


Author: christoph
Date: 2007-01-24 08:04:13 -0500 (Wed, 24 Jan 2007)
New Revision: 1024

Modified:
   trunk/mapbender/http/php/mod_wfs_result.php
Log:
ajax style wfs result

Modified: trunk/mapbender/http/php/mod_wfs_result.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_result.php	2007-01-24 12:57:10 UTC (rev 1023)
+++ trunk/mapbender/http/php/mod_wfs_result.php	2007-01-24 13:04:13 UTC (rev 1024)
@@ -17,13 +17,16 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-$req = urldecode($_REQUEST["url"]).urlencode(stripslashes($_REQUEST["filter"]));
-require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
-require_once(dirname(__FILE__)."/../classes/class_stripRequest.php");
+$filter = stripslashes($_REQUEST["filter"]);
+$url = stripslashes($_REQUEST['url']);
+//echo $filter; die();
+require_once("../../conf/mapbender.conf");
+require_once("../classes/class_stripRequest.php");
+require_once("../classes/class_connector.php");
 
 function sepNameSpace($s){
 	$c = strpos($s,":"); 
-	if($c>0){
+	if ($c > 0){
 		return substr($s,$c+1);
 	}
 	else{
@@ -31,110 +34,142 @@
 	}		
 }
 
-$gml = 'off';
-if($gml == 'on'){
-	header("Location: ".$req);
-}
-else{   
-	$geometries = array('Point', 'Polygon', 'LineString', 'MultiPolygon', 'MultiLineString');
-	$data = implode("",file($req)) or die("wfs not available");
-	$parser = xml_parser_create();
-	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);
-	xml_parser_free($parser);
-	$member = -1;
-	$section = false;
-	$geom = false;
-	$str = array();
-	$geomtype = array();
-	$el = -1;
-	$fid = -1;
-	echo "<html><head>\n";
-	echo "<meta http-equiv='Content-Type' content='text/html; charset=".CHARSET."'>\n";
-	echo "<script language='JavaScript' type='text/javascript'>\n<!--\n";
+function addParameterToFilter($filter) {
+	$doc = new DOMDocument('1.0');
+	$doc->encoding = CHARSET;
+	$doc->preserveWhiteSpace = false;
+	$doc->loadXML($filter);
+	return $doc->saveXML();
 
-	require_once(dirname(__FILE__)."/../javascripts/mod_geometryArray.js");
+	$andNode = $doc->createElement('And');
 	
-	$sr = new stripRequest($_REQUEST["url"]);
-	$typename = $sr->get("typename"); 
-	$element_str = "";
-	$geom_str = "";
-	$geom_str .= "var geom = new GeometryArray();\n";
+	// get all 'within' nodes
+	$nodeListWithin = $doc->getElementsByTagName('Within');
+	for ($i=0 ; $i < $nodeListWithin->length ; $i++) {
+		$currentNode = $doc->removeChild($nodeListWithin->item($i));
+		$andNode->appendChild($currentNode);
+	}
 
-	foreach ($values as $element) {
-		if(strtoupper($element[tag]) == strtoupper("gml:featureMember") && $element[type] == "open"){
-			$member++;
-			$section = true;
-			$cnt_geom = 0;
+	// get all 'ogc:BBOX' nodes
+	$nodeListBox = $doc->getElementsByTagNameNS('http://ogc.org', 'BBOX');
+	for ($i=0 ; $i < $nodeListBox->length ; $i++) {
+		$currentNode = $doc->removeChild($nodeListBox->item($i));
+		$andNode->appendChild($currentNode);
+	}
+
+	// generate 'propertyIsLike' Node
+	$propertyIsLikeNode = $doc->createElementNS('http://ogc.org', 'PropertyIsLike');
+	$propertyIsLikeNode->setAttribute('wildCard', '*');
+	$propertyIsLikeNode->setAttribute('singleChar', '.');
+	$propertyIsLikeNode->setAttribute('escape', '!');
+	
+	$propertyNameNode = $doc->createElementNS('http://ogc.org', 'PropertyName', 'ud_id');
+	$propertyIsLikeNode->appendChild($propertyNameNode);
+
+	$literalNode = $doc->createElementNS('http://ogc.org', 'Literal', '*'.$_SESSION['AstUdNr']);
+	$propertyIsLikeNode->appendChild($literalNode);
+	
+	$andNode->appendChild($propertyIsLikeNode);
+
+	// add 'And' node to XML
+	$nodeListFilter = $doc->getElementsByTagNameNS('http://ogc.org', 'Filter');
+	for ($i=0 ; $i < $nodeListFilter->length ; $i++) {
+		$currentNode = $nodeListFilter->item($i);
+		$currentNode->appendChild($andNode);
+	}
+	return $doc->saveXML();
+}
+
+//echo addParameterToFilter($filter);die();
+$wfsRequest = $url . urlencode($filter);
+$connection = new connector($wfsRequest);
+$data = $connection->file;
+if (!$data) die('wfs not available');
+
+$geometries = array('Point', 'Polygon', 'LineString', 'MultiPolygon', 'MultiLineString');
+
+
+//TODO: 
+// parsing via class_gml
+// add method toJSON to classGML
+$parser = xml_parser_create();
+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);
+xml_parser_free($parser);
+$member = -1;
+$section = false;
+$geom = false;
+$str = array();
+$geomtype = array();
+$el = -1;
+$fid = -1;
+
+$typename = $_REQUEST["typename"];
+$element_str = "";
+$geom_str = "";
+foreach ($values as $element) {
+	if(strtoupper($element[tag]) == strtoupper("gml:featureMember") && $element[type] == "open"){
+		$member++;
+		$section = true;
+		$cnt_geom = 0;
+	}
+	else if(strtoupper($element[tag]) == strtoupper($typename) && $element[type] == "open") {
+		$fid = $element[attributes][fid];
+	}
+	else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "open" && $section == true){
+		$geom = true;
+		if (sepNameSpace($element[tag]) == "MultiLineString") {
+			$geom_str .= "geom.addMember(geomTypeLine);\n";
 		}
-		else if(strtoupper($element[tag]) == strtoupper($typename) && $element[type] == "open") {
-			$fid = $element[attributes][fid];
+		else if (sepNameSpace($element[tag]) == "MultiPolygon" ) {
+			$geom_str .= "geom.addMember(geomTypePolygon);\n";
 		}
-		else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "open" && $section == true){
-			$geom = true;
-			if (sepNameSpace($element[tag]) == "MultiLineString") {
-				$geom_str .= "geom.addMember(geomTypeLine);\n";
-			}
-			else if (sepNameSpace($element[tag]) == "MultiPolygon" ) {
-				$geom_str .= "geom.addMember(geomTypePolygon);\n";
-			}
-			elseif (sepNameSpace($element[tag]) == "Point") {
-				$geom_str .= "geom.addMember(geomTypePoint);\n";
-				$geom_str .= "geom.get(-1).addGeometry();\n";
-			}
-			elseif (sepNameSpace($element[tag]) == "LineString") {
-				$geom_str .= "geom.get(-1).addGeometry();\n";
-			}
-			else if (sepNameSpace($element[tag]) == "Polygon" ) {
-				$geom_str .= "geom.get(-1).addGeometry();\n";
-			}
-			else {
-				$geom_str .= "alert('unknown geomtype ".sepNameSpace($element[tag])."');";
-			}
-			$element_str .= "geom.get(" . $member . ").e.setElement('fid', '".$fid."');\n";
+		elseif (sepNameSpace($element[tag]) == "Point") {
+			$geom_str .= "geom.addMember(geomTypePoint);\n";
+			$geom_str .= "geom.get(-1).addGeometry();\n";
 		}
-		else if(strtoupper($element[tag]) == strtoupper("gml:coordinates") && $geom == true){
-			$tmp =  str_replace(",,","",str_replace(" ",",",trim($element[value])));
-			$geom_str .= "var tmp1 = '".$tmp."';\n";
-			$geom_str .= "var tmp = tmp1.split(',');\n";
-			$geom_str .= "for (var i = 0 ; i < tmp.length ; i+=2) {\n";
-			$geom_str .= "\tgeom.getGeometry(-1,-1).addPointByCoordinates(parseFloat(tmp[i]), parseFloat(tmp[i+1]));\n";
-			$geom_str .= "}\n";
-			$geom_str .= "geom.close();\n";
-            $cnt_geom++;
-            
+		elseif (sepNameSpace($element[tag]) == "LineString") {
+			$geom_str .= "geom.get(-1).addGeometry();\n";
 		}
-		else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "close"){			
-			$geom = false;
+		else if (sepNameSpace($element[tag]) == "Polygon" ) {
+			$geom_str .= "geom.get(-1).addGeometry();\n";
 		}
-		else if($section == true && $geom == false && $element[value]){
-			$el++;
-			$str = $element[value];
-			$element_str .= "geom.get(" . $member . ").e.setElement('".sepNameSpace($element[tag])."', '".addslashes(str_replace(chr(13), "", str_replace(chr(10), "", $str)))."');\n";
+		else {
+			$geom_str .= "alert('unknown geomtype ".sepNameSpace($element[tag])."');";
 		}
-		else if(strtoupper($element[tag]) == strtoupper("gml:featureMember") && $element[type] == "close"){
-			$section = false;	
-			$el = -1;			
-		}
-   	}
-   	echo $geom_str;
-   	echo $element_str;
-}   	
-?> 
-function mb_wfs_reg(){
-	if(geom.count() > 0){
-		parent.mb_wfs_register('<?php echo $_REQUEST['id'] ?>',geom);
+		$element_str .= "geom.get(" . $member . ").e.setElement('fid', '".$fid."');\n";
+		$element_str .= "geom.get(" . $member . ").wfs_conf = ".$_REQUEST['wfs_conf_id'].";\n";
 	}
-	else{ 
-		parent.mb_wfs_register('<?php echo $_REQUEST['id'] ?>',false);
+	else if(strtoupper($element[tag]) == strtoupper("gml:coordinates") && $geom == true){
+		$tmp =  str_replace(",,","",str_replace(" ",",",trim($element[value])));
+		$geom_str .= "var tmp1 = '".$tmp."';\n";
+		$geom_str .= "var tmp = tmp1.split(',');\n";
+		$geom_str .= "for (var i = 0 ; i < tmp.length ; i+=2) {\n";
+		$geom_str .= "\tgeom.getGeometry(-1,-1).addPointByCoordinates(parseFloat(tmp[i]), parseFloat(tmp[i+1]));\n";
+		$geom_str .= "}\n";
+		$geom_str .= "geom.close();\n";
+        $cnt_geom++;
+        
 	}
+	else if(in_array(sepNameSpace($element[tag]),$geometries) && $element[type] == "close"){			
+		$geom = false;
+	}
+	else if($section == true && $geom == false && $element[value]){
+		$el++;
+		$str = $element[value];
+		$element_str .= "geom.get(" . $member . ").e.setElement('".sepNameSpace($element[tag])."', '".addslashes($str)."');\n";
+	}
+	else if(strtoupper($element[tag]) == strtoupper("gml:featureMember") && $element[type] == "close"){
+		$section = false;	
+		$el = -1;			
+	}
 }
-//-->
-</script>
-</head>
-<body onLoad='mb_wfs_reg()'>
-</body>
-</html>
-
+if ($geom_str != "") {
+	$geom_str = "var geom = new GeometryArray();\n" . $geom_str;
+}
+header('Content-type: text/html');
+echo $geom_str;
+echo $element_str;
+?> 
\ No newline at end of file



More information about the Mapbender_commits mailing list