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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Mar 3 05:50:08 EST 2011


Author: armin11
Date: 2011-03-03 02:50:08 -0800 (Thu, 03 Mar 2011)
New Revision: 7679

Modified:
   trunk/mapbender/http/php/mod_wmc2ol.php
Log:
Bugfix: Use only layer as baselayer for ol which is not hidden in the wmc doc. Exchange urls of wms that are stored in the mapbender database - they may have changed!

Modified: trunk/mapbender/http/php/mod_wmc2ol.php
===================================================================
--- trunk/mapbender/http/php/mod_wmc2ol.php	2011-03-03 10:31:44 UTC (rev 7678)
+++ trunk/mapbender/http/php/mod_wmc2ol.php	2011-03-03 10:50:08 UTC (rev 7679)
@@ -16,7 +16,11 @@
 #http://www.geoportal.rlp.de/mapbender/php/mod_wmc2ol.php?wmc_id=45_1291218568&GEORSS=1&LayerSwitcher=1
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
-
+require_once(dirname(__FILE__)."/../classes/class_wmc.php");
+//require_once(dirname(__FILE__)."/../classes/class_user.php");
+//require_once(dirname(__FILE__)."/../classes/class_json.php");
+//require_once(dirname(__FILE__)."/../classes/class_administration.php");
+//require_once(dirname(__FILE__)."/../classes/class_wmcToXml.php");
 $userId = Mapbender::session()->get("mb_user_id");
 
 //check for parameter wmc_id
@@ -176,21 +180,27 @@
 #**************************************************************************
 //Function to create an OpenLayers Javascript from a mapbender wmc document
 function createOlFromWMC_id($wmc_id, $pointRadius, $fillColor){
+	$myWmc = new wmc();
 	global $userId;
 	//Get WMC out of mb Database
-	$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_serial_id = $1";
+	$sql = "SELECT wmc, wmc_serial_id FROM mb_user_wmc WHERE wmc_serial_id = $1";
 	$res = db_prep_query($sql, array($wmc_id), array("s"));
 	$wmc = db_fetch_row($res);
 	//control if wmc was found else use old wmc_id
 	if (!$wmc[0]) {
-		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1";
+		$sql = "SELECT wmc, wmc_serial_id FROM mb_user_wmc WHERE wmc_id = $1";
 		$res = db_prep_query($sql, array($wmc_id), array("s"));
 		$wmc = db_fetch_row($res);
 		//echo "Wmc with this id was not found in Database!<br>";
 		//die;
 	}
+	//generate wmc object and update urls of services in this object:
+	$wmcId = $wmc[1];
+	$myWmc->createFromDb($wmcId);
+	$updatedWmc = $myWmc->updateUrlsFromDb();
+	
 	//Read out WMC into XML object
-	$xml=simplexml_load_string($wmc[0], "SimpleXMLElement", LIBXML_NOBLANKS);
+	$xml=simplexml_load_string($updatedWmc, "SimpleXMLElement", LIBXML_NOBLANKS);
 	if ($_REQUEST['withoutBody'] == '1') { 
 
 	} else {
@@ -372,7 +382,15 @@
 	$html.="	var bounds = new OpenLayers.Bounds(".$minx.",".$miny.",".$maxx.",".$maxy.");\n";
 	//if some layer defined, create base layer -> first layer in the wmc document
 	if (count($layer_array) != 0){
-		$i=0;
+		//get layer id for the base layer - this should be the first layer which is not hidden - in the wmc this should be visible (active)!!
+		//first get this id:
+		for ($i=0; $i<count($layer_array); $i++) {
+			if ($xml->LayerList->Layer[$i]->attributes()->hidden=='0'){ 
+				$firstLayerId = $i;
+				break;
+			}
+		}
+		$i = $firstLayerId;
 		$html.="	layer0 = new OpenLayers.Layer.WMS( \"".$xml->LayerList->Layer[$i]->Title."\",\n";
 		$extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org');
 		$layer_id=dom_import_simplexml($extensions->layer_id)->nodeValue;
@@ -380,7 +398,8 @@
 		$has_permission=getLayerPermission($wms_id,$layer_id,$userId);//problem: guest user must have fix id
 		//echo $layer_id."<br>";
 		if ($has_permission || $layer_id==''){
-			$html.="		\"".$xml->LayerList->Layer[$i]->Server->OnlineResource->attributes('http://www.w3.org/1999/xlink')->href."\",\n";
+			$getMapUrl = $xml->LayerList->Layer[$i]->Server->OnlineResource->attributes('http://www.w3.org/1999/xlink')->href;
+			$html.="		\"".$getMapUrl."\",\n";
 			$html.="		{\n";
 			$html.="		layers: \"".$xml->LayerList->Layer[$i]->Name."\",\n";
 			//get FormatList and the current active format -> TODO: make a function for getting actual format for request
@@ -421,7 +440,8 @@
 		}
 	}
 	//create the overlay layers for which the user guest has permissions
-	for ($i=1; $i<count($layer_array); $i++) {
+	$startLayerId = $firstLayerId+1;
+	for ($i=$startLayerId; $i<count($layer_array); $i++) {
 		$extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org');
 		#$layer_id=$extensions->layer_id;
 		$wms_id=$extensions->wms_id;



More information about the Mapbender_commits mailing list