[Mapbender-commits] r9608 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Sep 29 08:18:05 PDT 2016


Author: armin11
Date: 2016-09-29 08:18:05 -0700 (Thu, 29 Sep 2016)
New Revision: 9608

Modified:
   trunk/mapbender/http/javascripts/initWmcObj.php
Log:
New possibility to integrate distributed or local geojson files in the initial wmc for the gui by using some get parameter

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2016-09-28 12:23:51 UTC (rev 9607)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2016-09-29 15:18:05 UTC (rev 9608)
@@ -173,6 +173,8 @@
 	"FEATURETYPE" => getConfiguration("FEATURETYPE"),
 	"GEORSS"=>getConfiguration("GEORSS"),
 	"KML"=>getConfiguration("KML"),
+	"GEOJSON"=>getConfiguration("GEOJSON"),
+	"GEOJSONZOOM"=>getConfiguration("GEOJSONZOOM"),
 	"ZOOM"=>getConfiguration("ZOOM")
 );
 $getApi = new GetApi($getParams);
@@ -397,15 +399,101 @@
 if($inputKmlArray){
 	$wmc->generalExtensionArray['KML'] = $inputKmlArray;
 }
+//
+//GEOJSON
+//
+$inputGeojsonArray = $getApi->getGeojson();
+//$e = new mb_exception("get parameter for geojsonzoom: ".$getApi->getGeojsonZoom());
+$zoomToExtent = $getApi->getGeojsonZoom();
+//$e = new mb_exception("zoomToExtent from initWmcObj: ".$zoomToExtent);
+if ($zoomToExtent == 'true') {
+	$minx = false;
+	$miny = false;
+	$maxx = false;
+	$maxy = false;
+}
+if(is_array($inputGeojsonArray) && count($inputGeojsonArray) > 0 && !empty($inputGeojsonArray[0])){
+	//create objects
+	$kmls = new stdClass();
+	unset($wmcGetApi->generalExtensionArray['kmls']);
+	unset($wmcGetApi->generalExtensionArray['kmlOrder']);
+	unset($wmcGetApi->generalExtensionArray['KMLORDER']);
+	unset($wmcGetApi->generalExtensionArray['KMLS']);
+	$kmlOrder = array();
+	foreach ($inputGeojsonArray as $inputGeojson) {
+		//load json files from distributed locations
+		//check if url directly geojson is given
+		if ($admin->validateUrl(urldecode($inputGeojson))) {
+			$e = new mb_notice("GEORSS parameter will be interpreted as url - try to resolve external json!");
+			//$e = new mb_exception("found url ".urldecode($inputGeojson));
+			//$e = new mb_exception("found url unencoded ".$inputGeojson);
+			$jsonFile = new connector($inputGeojson);
+			//$jsonFile = new connector("http://localhost/mb_trunk/geoportal/testpolygon.json");
+			$geojson = json_decode($jsonFile->file);
+		} else {
+			$e = new mb_notice("GEORSS parameter will be interpreted as string!");
+			$geojson = json_decode(urldecode($inputGeojson));
+		}
+		if ($geojson !== null && $geojson !== false) {
+			$kmlOrder[] = $geojson->title;
+			$kmls->{$geojson->title}->type = "geojson";
+			$kmls->{$geojson->title}->data = $geojson;
+			$kmls->{$geojson->title}->url = $geojson->title;
+			$kmls->{$geojson->title}->display = true;
+			if ($zoomToExtent == 'true') {
+				$latitudes = array();
+				$longitudes = array();
+				foreach($kmls->{$geojson->title}->data->features as $feature) {
+					switch ($feature->geometry->type) {
+						case "Polygon":
+							//$e = new mb_exception("Polygon found!");
+							foreach ($feature->geometry->coordinates as $coordinates2) {
+								foreach ($coordinates2 as $coordinates1) {
+									$longitudes[] = $coordinates1[0];
+									$latitudes[] = $coordinates1[1];
+								}
+							}
+							break;
+						case "Point":
+							//$e = new mb_exception("Point found!");
+							$longitudes[] = $feature->geometry->coordinates[0];
+							$latitudes[] = $feature->geometry->coordinates[1];
+							break;
+						case "LineString":
+							//$e = new mb_exception("LineString found!");
+							foreach ($feature->geometry->coordinates as $coordinates1) {
+								$longitudes[] = $coordinates1[0];
+								$latitudes[] = $coordinates1[1];
+							}
+							break;
+					}
+				}
+			}
+		}
+	}
+	if ($zoomToExtent == 'true') {
+		$minx = min($longitudes);
+		$miny = min($latitudes);
+		$maxx = max($longitudes);
+		$maxy = max($latitudes);
+		//overwrite extend from getApi
+		$bbox = new Mapbender_bbox($minx,$miny,$maxx,$maxy,"EPSG:4326");
+		$wmcGetApi->mainMap->setExtent($bbox);
+	}
+	if ($geojson !== null && $geojson !== false) {
+		$wmcGetApi->generalExtensionArray['kmls'] = json_encode($kmls);
+		$wmcGetApi->generalExtensionArray['kmlOrder'] = json_encode($kmlOrder);
+	}
+}
 //TODO test following
 //workaround to have a fully merged WMC for loading
 $xml = $wmcGetApi->toXml();
+//$e = new mb_exception("initWmcObj.php: XML after merging json: ".$xml);
 $wmcGetApi = new wmc();
 //debug
 //$e = new mb_notice("initWmcObj.php: wmc after merging: ".$xml);
 //new Object with merged layers and other features
-$wmcGetApi->createFromXml($xml);
-		
+$wmcGetApi->createFromXml($xml);	
 //
 // CONSTRAINTS
 //



More information about the Mapbender_commits mailing list