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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Mar 3 10:05:37 EST 2011


Author: armin11
Date: 2011-03-03 07:05:37 -0800 (Thu, 03 Mar 2011)
New Revision: 7683

Modified:
   trunk/mapbender/http/php/mod_wmc2ol.php
Log:
Bugfix: The namespace of mapbenders wmc extension has changed somewhen - this fixes the export to openlayers client. All urls from the mapbender database are now changed when requesting the client. The getmap urls are exchanged by the versions in the wms table - they maybe more recent ;-)

Modified: trunk/mapbender/http/php/mod_wmc2ol.php
===================================================================
--- trunk/mapbender/http/php/mod_wmc2ol.php	2011-03-03 14:58:31 UTC (rev 7682)
+++ trunk/mapbender/http/php/mod_wmc2ol.php	2011-03-03 15:05:37 UTC (rev 7683)
@@ -16,13 +16,14 @@
 #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_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");
-
+//$userId = Mapbender::session()->get("mb_user_id");
+$user = new User();
+$userId = $user->id;
 //check for parameter wmc_id
 if(!isset($_GET["wmc_id"])){
 	echo 'Error: wmc_id not requested<br>';
@@ -130,6 +131,17 @@
 			return false;
 		}
 	}
+function getWmsGetMapUrl($wmsId){
+	$sql = "SELECT wms_getmap FROM wms WHERE wms_id =$1";
+	$v = array($wmsId);
+	$t = array("i");
+	$res = db_prep_query($sql,$v,$t);
+	if ($row = db_fetch_array($res)){
+		return $row['wms_getmap'];
+	} else {
+		return false;
+	}
+}
 function getGuisByPermission($mb_user_id,$ignoreublic){
 	$arrayGuis = array();
 	$mb_user_groups = array();
@@ -180,7 +192,7 @@
 #**************************************************************************
 //Function to create an OpenLayers Javascript from a mapbender wmc document
 function createOlFromWMC_id($wmc_id, $pointRadius, $fillColor){
-	$myWmc = new wmc();
+	//$myWmc = new wmc();
 	global $userId;
 	//Get WMC out of mb Database
 	$sql = "SELECT wmc, wmc_serial_id FROM mb_user_wmc WHERE wmc_serial_id = $1";
@@ -196,11 +208,11 @@
 	}
 	//generate wmc object and update urls of services in this object:
 	$wmcId = $wmc[1];
-	$myWmc->createFromDb($wmcId);
-	$updatedWmc = $myWmc->updateUrlsFromDb();
+	//$myWmc->createFromDb($wmcId);
+	//$updatedWmc = $myWmc->updateUrlsFromDb();//TODO: check why this functions need a session??
 	
 	//Read out WMC into XML object
-	$xml=simplexml_load_string($updatedWmc, "SimpleXMLElement", LIBXML_NOBLANKS);
+	$xml=simplexml_load_string($wmc[0], "SimpleXMLElement", LIBXML_NOBLANKS);
 	if ($_REQUEST['withoutBody'] == '1') { 
 
 	} else {
@@ -268,7 +280,7 @@
 	$someLayerQueryable=false;
 	for ($i=0; $i<count($layer_array); $i++) {
 		$html.="var layer".$i.";\n";
-		$mb_extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org');
+		$mb_extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org/context');
 		$layer_array_queryable[$i]=$mb_extensions->querylayer;
 		if (($layer_array_queryable[$i]=='1') and ($xml->LayerList->Layer[$i]->attributes()->hidden=='0')){
 			$someLayerQueryable=true;
@@ -392,13 +404,17 @@
 		}
 		$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');
+		$extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org/context');
 		$layer_id=dom_import_simplexml($extensions->layer_id)->nodeValue;
-		$wms_id=$extensions->wms_id;
+		$wms_id=dom_import_simplexml($extensions->wms_id)->nodeValue;
 		$has_permission=getLayerPermission($wms_id,$layer_id,$userId);//problem: guest user must have fix id
 		//echo $layer_id."<br>";
 		if ($has_permission || $layer_id==''){
 			$getMapUrl = $xml->LayerList->Layer[$i]->Server->OnlineResource->attributes('http://www.w3.org/1999/xlink')->href;
+			if (getWmsGetMapUrl($wms_id) != false) {
+				$e = new mb_notice("mod_wmc2ol.php: update GetMap found in database - change url to :".$getMapUrl);
+				$getMapUrl = getWmsGetMapUrl($wms_id);
+			}
 			$html.="		\"".$getMapUrl."\",\n";
 			$html.="		{\n";
 			$html.="		layers: \"".$xml->LayerList->Layer[$i]->Name."\",\n";
@@ -422,7 +438,7 @@
 			$html.="		numZoomLevels: ".$numberZoomLevels.",\n";
 			$minScale=dom_import_simplexml($extensions->gui_minscale)->nodeValue;
 			$maxScale=dom_import_simplexml($extensions->gui_maxscale)->nodeValue;
-			$maxScale=$extensions->guiScaleHint->attributes()->max;
+			$maxScale=$extensions->guiScaleHint->attributes()->max;//this set the maxscale to unknown - for the baselayer
 			if (!$maxScale){
 				$maxScale='10000000';
 			}
@@ -442,16 +458,21 @@
 	//create the overlay layers for which the user guest has permissions
 	$startLayerId = $firstLayerId+1;
 	for ($i=$startLayerId; $i<count($layer_array); $i++) {
-		$extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org');
+		$extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org/context');
 		#$layer_id=$extensions->layer_id;
 		$wms_id=$extensions->wms_id;
 		$layer_id=dom_import_simplexml($extensions->layer_id)->nodeValue;
-
+		$wms_id=dom_import_simplexml($extensions->wms_id)->nodeValue;
 		$has_permission=getLayerPermission($wms_id,$layer_id,$userId);//problem: guest user must have fix id TODO
 		if (($xml->LayerList->Layer[$i]->attributes()->hidden=='0' && $has_permission) ||
 			($layer_id=='' && $xml->LayerList->Layer[$i]->attributes()->hidden=='0')){
 			$html.="	layer".$i." = new OpenLayers.Layer.WMS( \"".$xml->LayerList->Layer[$i]->Title."\",\n";
-			$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;
+			if (getWmsGetMapUrl($wms_id) != false) {
+				$e = new mb_notice("mod_wmc2ol.php: update GetMap found in database - change url to :".$getMapUrl);
+				$getMapUrl = getWmsGetMapUrl($wms_id);
+			}
+			$html.="		\"".$getMapUrl."\",\n";
 			$html.="		{\n";
 			$html.="		layers: \"".$xml->LayerList->Layer[$i]->Name."\",\n";
 			//Get FormatList and the current active format
@@ -472,7 +493,7 @@
 			$html.="		units: \"m\",\n"; 
 			$html.="		singleTile: true,\n";
 			$html.="		numZoomLevels: ".$numberZoomLevels.",\n";
-			//$extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org');
+			//$extensions=$xml->LayerList->Layer[$i]->Extension->children('http://www.mapbender.org/context');
 			$minScale=dom_import_simplexml($extensions->gui_minscale)->nodeValue;
 			$maxScale=dom_import_simplexml($extensions->gui_maxscale)->nodeValue;
 			if (!$maxScale){



More information about the Mapbender_commits mailing list