[Mapbender-commits] r10114 - in trunk/mapbender/http: javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Apr 30 01:36:41 PDT 2019


Author: armin11
Date: 2019-04-30 01:36:37 -0700 (Tue, 30 Apr 2019)
New Revision: 10114

Modified:
   trunk/mapbender/http/javascripts/initWmcObj.php
   trunk/mapbender/http/javascripts/mod_renderGML.php
   trunk/mapbender/http/php/mod_sessionWrapper.php
Log:
Enhance render gml from session - support for different crs and http interface for push gml into session

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2019-04-24 09:21:06 UTC (rev 10113)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2019-04-30 08:36:37 UTC (rev 10114)
@@ -642,24 +642,77 @@
 $e = new mb_notice("javascripts/initWmcObj.php: check for disclaimer done");
 /*
 GML in session
-check if Session contains a GML, and then zoom to it
+check if Session contains a GML, and then zoom to it - same code as in mod_renderGML.php - sync it!
 */
 $e = new mb_notice("javascripts/initWmcObj.php: check session for GML to zoom");
+//*************************************************************************************************
 $gml_string = Mapbender::session()->get("GML");
-if($gml_string){
-	$gml = new gml2();
-	$gml->parse_xml($gml_string);
-	$bbox = new Mapbender_bbox(
-	$gml->bbox[0],
-	$gml->bbox[1],
-	$gml->bbox[2],
-	$gml->bbox[3],
-	$epsg = "EPSG:".$gml->epsg);
-	$wmcGetApi->mainMap->setExtent($bbox);
-} else {
-	$e = new mb_notice("javascripts/initWmcObj.php: no GML found in session!");
+if ($gml_string) {
+	//To parse gml extent header
+	$gml2String = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>".$gml_string;
+	//$e = new mb_exception("javascripts/initWmcObj.php: ".$gml2String);
+	libxml_use_internal_errors(true);
+	try {
+		$gml2 = simplexml_load_string($gml2String);
+		if ($gml2 === false) {
+				foreach(libxml_get_errors() as $error) {
+					$err = new mb_exception("javascripts/mod_renderGML.php: ".$error->message);
+	    			}
+				throw new Exception("javascripts/initWmcObj.php: ".'Cannot parse GML from session!');
+				return false;
+		}
+	}
+	catch (Exception $e) {
+	    	$err = new mb_exception("javascripts/initWmcObj.php: ".$e->getMessage());
+		return false;
+	}			
+	//if parsing was successful			
+	if ($gml2 !== false) {
+		$gml2->addAttribute('xmlns:gml', 'http://www.opengis.net/gml');
+		$gml2->registerXPathNamespace("default", "http://www.opengis.net/gml");
+		$gml2->registerXPathNamespace("gml", "http://www.opengis.net/gml");
+		if ($gml2->xpath('/FeatureCollection/featureMember/*/*/MultiPolygon')) {
+			$e = new mb_notice("javascripts/initWmcObj.php:  MultiPolygon found!");
+			$multiPolygon = $gml2->xpath('/FeatureCollection/featureMember/*/*/MultiPolygon');
+			$multiPolygonGml = $multiPolygon[0]->asXML();
+			$e = new mb_notice("javascripts/initWmcObj.php: MultiPolygon: ".$multiPolygonGml);
+			$currentEpsg = Mapbender::session()->get("epsg");
+			$e = new mb_notice("javascripts/initWmcObj.php: currentEpsg: ".$currentEpsg);
+			if ($currentEpsg !== '4326') {
+				$sql = "SELECT st_box(st_transform(st_geomfromgml($1),$2::INT)) AS geom";
+				$v = array($multiPolygonGml, $currentEpsg);
+				$t = array('s', 'i');
+				$res = db_prep_query($sql,$v,$t);
+				db_fetch_row($res);
+				$bbox = db_result($res, 0, 'geom');
+			} else {
+				$sql = "SELECT st_box(st_geomfromgml($1)) AS geom";
+				$v = array($multiPolygonGml);
+				$t = array('s');
+				$res = db_prep_query($sql,$v,$t);
+				db_fetch_row($res);
+				$bbox = db_result($res, 0, 'geom');
+			}
+			//do other things:
+			//parse bbox values
+			$bbox = str_replace(")", "", str_replace("(", "", $bbox));
+			$bboxArray = explode(",", $bbox);
+			//create mapbender bbox object to zoom to
+			$bbox = new Mapbender_bbox(
+				$bboxArray[2],
+				$bboxArray[3],
+				$bboxArray[0],
+				$bboxArray[1],
+				$epsg = "EPSG:".$currentEpsg
+			);
+			$wmcGetApi->mainMap->setExtent($bbox);
+		} else {
+			$e = new mb_notice("javascripts/initWmcObj.php: no GML found in session!");
+		}
+	}
 }
 $e = new mb_notice("javascripts/initWmcObj.php: session GML zoom done");
+//*************************************************************************************************
 // overwrite extent of wmc with information from GetApi if given
 $e = new mb_notice("javascripts/initWmcObj.php: check ZOOM API");
 $zoom = $getApi->getZoom();
@@ -711,10 +764,14 @@
 	//$e = new mb_notice("initWmcObj.php: alternate js build successfully!");
 //*******************************************************
 	$output = $wmcGetApi->wmsToJavaScript();
-	// $e = new mb_notice("javascripts/initWmcObj.php: javascript mapset: ".implode(",",$output));
+	//$e = new mb_notice("javascripts/initWmcObj.php: javascript mapset: ".implode(",",$output));
 	$wmcJs = $wmcGetApi->toJavaScript(array());//old way - why give an empty array?
 	$wmcJs = implode(";\n", $wmcJs);
+//$e = new mb_exception($wmcJs);
+//$e = new mb_exception("initWmcObj.php: after wmcJs!****************************");
 	$extentJs = $wmcGetApi->extentToJavaScript();
+//$e = new mb_exception($extentJs);
+//$e = new mb_exception("initWmcObj.php: after extentJs!****************************");
 	$output[] = <<<JS
 		Mapbender.events.afterInit.register(function () {
 			$wmcJs;

Modified: trunk/mapbender/http/javascripts/mod_renderGML.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_renderGML.php	2019-04-24 09:21:06 UTC (rev 10113)
+++ trunk/mapbender/http/javascripts/mod_renderGML.php	2019-04-30 08:36:37 UTC (rev 10114)
@@ -20,11 +20,54 @@
 require_once(dirname(__FILE__)."/../classes/class_gml2.php");
 define("GML_HIGHLIGHT_Z_INDEX",1000);
 $gml_string = Mapbender::session()->get("GML");
-
 if ($gml_string) {
+	//To parse gml extent header
+	$gml2String = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>".$gml_string;
+	//$e = new mb_exception("renderGML:".$gml2String);
+	libxml_use_internal_errors(true);
+	try {
+		$gml2 = simplexml_load_string($gml2String);
+		if ($gml2 === false) {
+				foreach(libxml_get_errors() as $error) {
+					$err = new mb_exception("javascripts/mod_renderGML.php: ".$error->message);
+	    			}
+				throw new Exception("javascripts/mod_renderGML.php: ".'Cannot parse SESSION GML!');
+				return false;
+		}
+	}
+	catch (Exception $e) {
+	    	$err = new mb_exception("javascripts/mod_renderGML.php: ".$e->getMessage());
+		return false;
+	}			
+	//if parsing was successful			
+	if ($gml2 !== false) {
+		$gml2->addAttribute('xmlns:gml', 'http://www.opengis.net/gml');
+		$gml2->registerXPathNamespace("default", "http://www.opengis.net/gml");
+		$gml2->registerXPathNamespace("gml", "http://www.opengis.net/gml");
+		if ($gml2->xpath('/FeatureCollection/featureMember/*/*/MultiPolygon')) {
+			$e = new mb_notice("javascripts/mod_renderGML.php:  MultiPolygon found!");
+			$multiPolygon = $gml2->xpath('/FeatureCollection/featureMember/*/*/MultiPolygon');
+			$multiPolygonGml = $multiPolygon[0]->asXML();
+			$e = new mb_notice("javascripts/mod_renderGML.php: MultiPolygon: ".$multiPolygonGml);
+			$currentEpsg = Mapbender::session()->get("epsg");
+			$e = new mb_notice("javascripts/mod_renderGML.php: currentEpsg: ".$currentEpsg);
+			if ($currentEpsg !== '4326') {
+				$sql = "SELECT st_asgml(st_transform(st_geomfromgml($1),$2::INT),2) AS geom";
+				$v = array($multiPolygonGml, $currentEpsg);
+				$t = array('s', 'i');
+				$res = db_prep_query($sql,$v,$t);
+				db_fetch_row($res);
+				$multiPolygonGml = db_result($res, 0, 'geom');
+			}
+		}
+	}
+}
+//select asewkt(transform(st_geomfromgml('<MultiPolygon srsName="EPSG:4326"><polygonMember><Polygon><outerBoundaryIs><LinearRing><coordinates>6,48 8,48 8,51 6,51 6,48</coordinates></LinearRing></outerBoundaryIs></Polygon></polygonMember></MultiPolygon>'),25832));
+/*<FeatureCollection xmlns:gml="http://www.opengis.net/gml"><boundedBy><Box srsName="EPSG:4326"><coordinates>6,48 8,51</coordinates></Box></boundedBy><featureMember><gemeinde><title>BBOX</title><the_geom>*/
+//$e = new mb_exception("renderGml invoked!");
+if ($gml_string) {
 	$gml = new gml2();
-	$gml->parse_xml($gml_string);
-	$bbox = $gml->bbox;
+	$gml->parse_xml('<FeatureCollection xmlns:gml="http://www.opengis.net/gml"><featureMember><the_geom>'.$multiPolygonGml.'</the_geom></featureMember></FeatureCollection>');
 	echo "Mapbender.events.afterInit.register(highlight_init);\n";
 	echo "function highlight_init() {\n";
 	echo "var mf = new Array(";
@@ -39,11 +82,9 @@
 	echo "hl.paint();\n";
 	echo "mb_registerSubFunctions('hl.paint()');\n";
 	echo "}\n";
-	$e = new mb_notice("renderGML: GML: " . Mapbender::session()->get("GML") . "; EPSG: " . Mapbender::session()->get("epsg") . "; BBOX: " . implode(", ", $bbox));
+	$e = new mb_notice("renderGML: GML: " . $multiPolygonGml . "; EPSG:" . $currentEpsg);
 	Mapbender::session()->set("GML",NULL);
-
 	$e = new mb_notice("renderGML: deleting GML...");
-	
 }
 else {
 	$e = new mb_notice("renderGML: no GML.");

Modified: trunk/mapbender/http/php/mod_sessionWrapper.php
===================================================================
--- trunk/mapbender/http/php/mod_sessionWrapper.php	2019-04-24 09:21:06 UTC (rev 10113)
+++ trunk/mapbender/http/php/mod_sessionWrapper.php	2019-04-30 08:36:37 UTC (rev 10114)
@@ -6,7 +6,7 @@
 $key = "mb_user_id";
 $value = null;
 $allowedOperations = array("get", "set");
-$allowedKeys = array("mb_user_id", "gml");
+$allowedKeys = array("mb_user_id", "GML");
 
 $resultObj['result'] = '';
 $resultObj['success'] = false;
@@ -29,7 +29,7 @@
 }
 $existSession = Mapbender::session()->storageExists($_REQUEST["sessionId"]);
 if ($existSession) {
-    $e = new mb_exception("storage exists");
+    $e = new mb_notice("storage exists");
 } else {
     $e = new mb_exception("storage does not exist!");
     $resultObj['message'] ='Requested session does not exists on server - please use existing identifier!'; 
@@ -82,23 +82,11 @@
 	break;
     case "set":
 	switch ($key) {
-	    case "gml":
+	    case "GML":
                 //validate gml!
 		//parse operation
 		if (isset($_REQUEST["value"]) & $_REQUEST["value"] != "") {
 			$testMatch = $_REQUEST["value"];
-			//example from old portal solution:
-			/*
-$GML = "<FeatureCollection xmlns:gml='http://www.opengis.net/gml'><boundedBy><Box srsName='EPSG:".$newEPSG."'>";
-$GML .= "<coordinates>".$newBbox[0].",".$newBbox[1]." ".$newBbox[2];
-$GML .= ",".$newBbox[3]."</coordinates></Box>";
-$GML .= "</boundedBy><featureMember><gemeinde><title>BBOX</title><the_geom><MultiPolygon srsName=\"EPSG:";
-$GML .= $newEPSG."\"><polygonMember><Polygon><outerBoundaryIs><LinearRing><coordinates>";
-$GML .= $newBbox[0].",".$newBbox[1]." ".$newBbox[2].",";
-$GML .= $newBbox[1]." ".$newBbox[2].",".$newBbox[3]." ";
-$GML .= $newBbox[0].",".$newBbox[3]." ".$newBbox[0].",".$newBbox[1];
-$GML .= "</coordinates></LinearRing></outerBoundaryIs></Polygon></polygonMember></MultiPolygon></the_geom></gemeinde></featureMember></FeatureCollection>";
-			*/	
  			/*if (!in_array($testMatch, $allowedKeys)){ 
     				$resultObj['message'] = 'Parameter key is not valid '.implode(',', $allowedKeys); 
     				$resultObj['result'] = null;
@@ -108,6 +96,24 @@
 			$value = $testMatch;
 			$testMatch = NULL;
 		} else {
+//generate dummy gml and put it into session:
+/*$bbox = "6,48,8,51";
+$newBbox = explode(",", $bbox);
+$GML = '<FeatureCollection xmlns:gml="http://www.opengis.net/gml"><boundedBy><Box srsName="EPSG:4326">';
+$GML .= "<coordinates>".$newBbox[0].",".$newBbox[1]." ".$newBbox[2];
+$GML .= ",".$newBbox[3]."</coordinates></Box>";
+$GML .= '</boundedBy><featureMember><gemeinde><title>BBOX</title><the_geom><MultiPolygon srsName="EPSG:';
+$GML .= "4326".'"><polygonMember><Polygon><outerBoundaryIs><LinearRing><coordinates>';
+$GML .= $newBbox[0].",".$newBbox[1]." ".$newBbox[2].",";
+$GML .= $newBbox[1]." ".$newBbox[2].",".$newBbox[3]." ";
+$GML .= $newBbox[0].",".$newBbox[3]." ".$newBbox[0].",".$newBbox[1];
+$GML .= "</coordinates></LinearRing></outerBoundaryIs></Polygon></polygonMember></MultiPolygon></the_geom></gemeinde></featureMember></FeatureCollection>";
+Mapbender::session()->set('GML',$GML);
+$resultObj['success'] = true;
+$resultObj['message'] = 'Dummy GML written into session!'; 
+$resultObj['result'] = null;
+echo json_encode($resultObj);
+die();*/
     			$resultObj['message'] = 'Parameter value for key '.$key.' not given!'; 
     			$resultObj['result'] = null;
     			echo json_encode($resultObj);
@@ -114,6 +120,11 @@
 			die();
 		}
 		Mapbender::session()->set('GML',$value);
+		$resultObj['success'] = true;
+		$resultObj['message'] = 'GML written into session!'; 
+		$resultObj['result'] = null;
+		echo json_encode($resultObj);
+		die();
                 break;
 	    case "":
 	        break;



More information about the Mapbender_commits mailing list