[Mapbender-commits] r8195 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Nov 8 08:38:00 EST 2011


Author: armin11
Date: 2011-11-08 05:38:00 -0800 (Tue, 08 Nov 2011)
New Revision: 8195

Modified:
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/http/php/mod_wmc2ol.php
Log:
Extension for wmc2ol handler to show terms of use. New possibility to generate entries in layer_epsg table for all supported epsg - the inheritance from root and other parent layers is used.

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2011-11-03 15:33:58 UTC (rev 8194)
+++ trunk/mapbender/http/classes/class_wms.php	2011-11-08 13:38:00 UTC (rev 8195)
@@ -1929,11 +1929,11 @@
 	//get all supported srs as an intersection of the supported srs of the root layer and the SRS_ARRAY defined in mapbender.conf  
 	function getSupportedSRS($layerId, $confSrsArray) {
 		//request the original capabilities from service
-        $sql = "SELECT layer.layer_name AS layer_name, wms.wms_getcapabilities_doc AS cap FROM layer, wms ".
+        	$sql = "SELECT layer.layer_name AS layer_name, wms.wms_getcapabilities_doc AS cap, wms.wms_id as wms_id FROM layer, wms ".
         		"WHERE layer.fkey_wms_id IN (SELECT layer.fkey_wms_id FROM layer WHERE layer.layer_id = " . $layerId . ") ".
         		"AND layer.layer_parent = '' AND layer.fkey_wms_id=wms.wms_id";
-        $res = db_query($sql);
-        $row = db_fetch_array($res);
+        	$res = db_query($sql);
+        	$row = db_fetch_array($res);
         
 		//parse capabilities to php object - check if it is still loaded to db
 		if ($row['cap'] == '') {
@@ -1947,53 +1947,108 @@
 			$n = new mb_exception("Problem while parsing capabilities document with simplexml");
 			echo "Problem while parsing capabilities document with simplexml<br>";
 			return false;
-       }
-		
-       //layer name from DB
-		$layerName=$row['layer_name'];
-		//defining the xpath for getting all Layer-tags
-		$xpathLayerName="//Layer[./Name =\"".$layerName."\"]";
-		
-		$layerObject=$wmsCapXml->xpath($xpathLayerName);
-		
-		//for none named layer (only title is set)
-                if (empty($layerObject)){
-                        $xpathLayerName="//Layer[./Title =\"".$layerName."\"]";
-                    $layerObject=$wmsCapXml->xpath($xpathLayerName);
-                }
+       		}
+       		$wmsId = $row['wms_id'];	
+		//$n = new mb_exception("wms_id: ".$wmsId);
+		//return false;
+		//$this->xpath('parent::*')- problematic, cause some services have duplicated layer names!
+		//there must be an other solution, which goes over the layer_title element :-(
+		//get all layer titles which are parents of the current and push them into a list
+		$e = new mb_notice("Searching parents for layer: ".$layerId);
+		//$e = new mb_exception("SRS from conf: ".print_r($confSrsArray));
+		$layerHasParent = true;
+		$countParent = 0;
+		$layerParentArray = array();
+		$sql = "SELECT layer_title, layer_parent, layer_name FROM layer ".
+        			"WHERE layer.layer_id = $layerId";
+        	$res = db_query($sql);
+        	$row = db_fetch_array($res);
+		//initialize with layer itself
+		$layerParentArray[0]['id'] = $layerId;
+		$layerParentArray[0]['name'] = $row['layer_name'];
+		$layerParentArray[0]['title'] = $row['layer_title'];
 
-		if(!isset($layerObject[0])) {
-			$n = new mb_notice("Layer has no name and title, BBOX will not be generated for ".$epsg);
-			return false;
+		$layerParent = $row['layer_parent'];
+		//$e = new mb_exception("Type of parent: ". gettype($row['layer_parent']));
+
+		if ($layerParent != '') {
+			$e = new mb_notice("parent found at pos: ".$layerParent);
+			$countParent = 1;
+			while ($layerHasParent) {
+				$sql = "SELECT layer_title, layer_id, layer_parent, layer_name FROM layer ".
+        				"WHERE fkey_wms_id = $wmsId AND layer.layer_pos = $layerParent";
+        			$res = db_query($sql);
+        			$row = db_fetch_array($res);
+
+				$layerParentArray[$countParent]['id'] = $row['layer_id'];
+				$layerParentArray[$countParent]['name'] = $row['layer_name'];
+				$layerParentArray[$countParent]['title'] = $row['layer_title'];
+
+				$layerParent = $row['layer_parent'];
+
+				$countParent++;
+				if ($layerParent == '') {
+					$layerHasParent = false;
+				}
+				
+			}
+		} else {
+			$e = new mb_notice("class_wms.php: no further parents available!");
 		}
-		
+
 		$supportedSrsArray = array();
+
+		for($j=0; $j<count($layerParentArray);$j++){
+			$layerName=$layerParentArray[$j]['name'];
+			//defining the xpath for getting all Layer-tags
+			$xpathLayerName="//Layer[./Name =\"".$layerName."\"]";
 		
-		//search for the SRS tag of specified layer		
-		$srsElementArray=$layerObject[0]->xpath("SRS");
+			$layerObject=$wmsCapXml->xpath($xpathLayerName);
 		
-		foreach($srsElementArray as $srsElement) {
-			//create an array of the given srsElements -> include also srs written as a space separated list  
-			$srsArray = explode(" ",$srsElement);
-			foreach($srsArray as $srs) {
-				if(in_array(strtoupper($srs),$confSrsArray)) {
-					array_push($supportedSrsArray, strtoupper($srs));
-					$n = new mb_notice("Requested SRS: ".$epsg." is supported by layer: ".$layerName." with layerId: ".$layerId);
-				}	
+			//for none named layer (only title is set)
+               	 	if (empty($layerObject)){
+                   	    	$xpathLayerName="//Layer[./Title =\"".$layerName."\"]";
+                  		$layerObject=$wmsCapXml->xpath($xpathLayerName);
+               		}
+
+			if(!isset($layerObject[0])) {
+				$n = new mb_exception("Layer has no name and title, BBOX will not be generated for ".$epsg);
+				return false;
 			}
+		
+			
+			
+			//search for the SRS tag of specified layer		
+			$srsElementArray=$layerObject[0]->xpath("SRS");
+			
+			foreach($srsElementArray as $srsElement) {
+				//create an array of the given srsElements -> include also srs written as a space separated list  
+				$srsArray = explode(" ",$srsElement);
+				foreach($srsArray as $srs) {
+					if(in_array(strtoupper($srs),$confSrsArray)) {
+						array_push($supportedSrsArray, strtoupper($srs));
+						
+						$n = new mb_exception("Requested SRS: ".$srs." is supported by layer: ".$layerName." with layer_id: ".$$layerParentArray[$j]['layer_id']);
+					}	
+				}
+			}
+		
 		}
-		
+		for($k=0; $k < count($supportedSrs);$k++) {
+			$e = new mb_exception("SRS ".$supportedSrs[$k]." supported for the layer: ".$layerId);
+		}
 		if(count($supportedSrsArray) == 0) {
-			$n = new mb_notice("Requested SRS: ".$epsg." is not supported by layer: ".$layerName." with layerId: ".$layerId);
+			$n = new mb_notice("class_wms.php: None of the defined srs are supported by the layer");
 		}
-		
 		return $supportedSrsArray;
 	}
 	function insertLayerEPSG($i) {
+		//$currentSrsArray = array();
 		$sql = "DELETE FROM layer_epsg WHERE fkey_layer_id = $1";
 		$v = array($this->objLayer[$i]->db_id);
 		$t = array('i');
 		$res = db_prep_query($sql,$v,$t);
+		//1. fill in srs from layers with given bboxes from capabilities
 		for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
 			$sql = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
 			$sql .= "VALUES($1,$2,$3,$4,$5,$6)";
@@ -2001,11 +2056,14 @@
 				$this->objLayer[$i]->layer_epsg[$j][minx],$this->objLayer[$i]->layer_epsg[$j][miny],
 				$this->objLayer[$i]->layer_epsg[$j][maxx],$this->objLayer[$i]->layer_epsg[$j][maxy]
 				); 
+			$e = new mb_exception("class_wms.php: insertLayerEPSG: INSERT SQL:".$sql. " for Layer ".$this->objLayer[$i]->db_id);
 			$t = array('i','s','d','d','d','d');
 			$res = db_prep_query($sql,$v,$t);
 			if(!$res){
 				db_rollback();	
 			}
+			//push this srs into the currentSrsArray!
+			//array_push($currentSrsArray,$this->objLayer[$i]->layer_epsg[$j][epsg]);
 		}
 		
 //		GET SRS_ARRAY of mapbender.conf
@@ -2018,7 +2076,7 @@
 		for ($index = 0; $index < sizeof($confSrsArray); $index++) {
 			$confSrsArray[$index] = "EPSG:" . $confSrsArray[$index];
 		}
-		
+		//read the epsg entries which have been filled in before 
 		$sql_epsg = "SELECT * FROM layer_epsg WHERE fkey_layer_id = $1";
 		$v_epsg = array($this->objLayer[$i]->db_id);
 		$t_epsg = array('i');
@@ -2029,6 +2087,7 @@
 		$maxx = array();
 		$maxy = array();
 		$cnt = 0;
+		//write this results into an array  
 		while($row_epsg = db_fetch_array($res_epsg)){
 			array_push($epsg,strtoupper($row_epsg['epsg']));
 			array_push($minx,$row_epsg['minx']);
@@ -2039,9 +2098,17 @@
 		}
 
 		//get all srs which are supported by the parent layer and in array SRS_ARRAY from mapbender.conf
+		//TODO: not only for the root layer but read also all srs from all parent layers!!!
 		$supportedSrs = $this->getSupportedSRS($this->objLayer[$i]->db_id, $confSrsArray);
+		$supportedSrs = array_unique($supportedSrs);
+    		foreach ($supportedSrs as $srs) {
+        		$supportedSrsNew[] = $srs;
+    		}
+		$supportedSrs = $supportedSrsNew;
 		
 		for($k=0; $k < count($supportedSrs);$k++) {
+			$e = new mb_exception("SRS ".$supportedSrs[$k]." for the layer: ".$this->objLayer[$i]->db_id);
+			//compute this only, if the srs was not already in the current layer - see array epsg!
 			if(!in_array($supportedSrs[$k],$epsg) && $supportedSrs[$k] != '') {
 				$n = new mb_notice("Calculation for: ".$supportedSrs[$k]);
 				$pointMin = new Mapbender_point($minx[0], $miny[0], $epsg[0]);

Modified: trunk/mapbender/http/php/mod_wmc2ol.php
===================================================================
--- trunk/mapbender/http/php/mod_wmc2ol.php	2011-11-03 15:33:58 UTC (rev 8194)
+++ trunk/mapbender/http/php/mod_wmc2ol.php	2011-11-08 13:38:00 UTC (rev 8195)
@@ -164,6 +164,22 @@
 	$html.="font-size: 80%;\n";
 	$html.="color: #444;\n";
 	$html.="}\n";
+	$html.=" #logo {\n";
+	$html.="font-size: 50%;\n";
+	$html.="color: black;\n";
+	$html.="}\n";
+	$html.=".olControlAttribution {\n";
+  	$html.="	bottom: 2px !important;\n";
+	#$html.="	color:black;\n";
+	$html.="	font-size:7px;\n";
+	$html.="	z-index:1000;\n";
+  	#$html.="	left: 6px;\n";
+  	#$html.="	position: relative;\n";
+	$html.="}\n";
+
+
+
+
 	$html.="</style>\n";
 	//don't show any html, title and/or body tag when integrate it into external website
 	if ($_REQUEST['withoutBody'] == '1') { 	
@@ -200,6 +216,9 @@
 	}
 	//initialize markers
 	$html.="var markers = new OpenLayers.Layer.Markers(\"Markers\", {'calculateInRange': function() { return true; }});\n";
+	//initialize logo
+	$html.="var logo = \"<a href = 'http://www.mapbender.org' target='_blank'><img src='../img/Mapbender_logo_and_text.png' height='20' width='120' alt='Mapbender Logo'/></a><br><a href = 'mod_getWmcDisclaimer.php?&id=".$wmcId."&languageCode=de&hostName=".$hostName."' target='_blank'>"._mb('Terms of use')."</a>\";\n";
+	//$html.="var logo = \"<a href = 'http://www.geoportal.rlp.de' target='_blank'><img src='../img/logo_geoportal_neu.png' height='20' width='120' alt='Geoportal Logo'/></a><br><a href = 'mod_getWmcDisclaimer.php?&id=".$wmcId."&languageCode=de&hostName=".$hostName."' target='_blank'>"._mb('Terms of use')."</a>\";\n";
 	//check for some queryable layer in web map context document
 	$someLayerQueryable=false;
 	for ($i=0; $i<count($layer_array); $i++) {
@@ -382,7 +401,8 @@
 			}
 			$html.="		minScale: ".$minScale.",\n"; 
 			$html.="		maxScale: ".$maxScale.",\n"; 
-			$html.="		singleTile: true\n";
+			$html.="		singleTile: true,\n";
+			$html.="		attribution: logo\n";
 			//Only necessary for working with scales.
 			$html.="	} );\n";
 			$html.="	map.addLayer(layer0);\n";
@@ -525,7 +545,7 @@
 				$html.="	 window.open(url".$i.",target=\"_blank\",\"scrollbars=1,width=250,height=400,left=100,top=200\");\n";	
 			}	
 		}
-		$html.="	OpenLayers.Event.stop(e);\n";
+		#$html.="	OpenLayers.Event.stop(e);\n";
 		$html.="	});\n";
 	}
 	
@@ -767,7 +787,8 @@
 		}
 	}
 	//*******************************
-	//echo "<a href = 'http://www.geoportal.rlp.de' target='_blank'> <img src = '".$_SERVER['HTTP_HOST']."/mapbender/img/geoportal_rlp.png' title=\"GeoPortal Rheinland-Pfalz\" border=0></a>";
+        //placeholder for use constraints
+	//echo "<a href = 'http://www.geoportal.rlp.de' target='_blank'> <img src = '".$_SERVER['HTTP_HOST']."/mapbender/http/img/logo_geoportal_neu.png' title=\"GeoPortal Rheinland-Pfalz\" border=0></a>";
 		$html.="<div id='docs'>\n";
 		$html.="\n";
 		$html.="</div>\n";



More information about the Mapbender_commits mailing list