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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 27 08:40:00 EDT 2011


Author: armin11
Date: 2011-07-27 05:40:00 -0700 (Wed, 27 Jul 2011)
New Revision: 8009

Modified:
   trunk/mapbender/http/php/mod_wmc2ol.php
Log:
Enhancement of georss handling. The georss entries may now have imageUrls and their size defined. Also a possibility to prohibit mousewheel scroll is implemented.

Modified: trunk/mapbender/http/php/mod_wmc2ol.php
===================================================================
--- trunk/mapbender/http/php/mod_wmc2ol.php	2011-07-26 21:35:16 UTC (rev 8008)
+++ trunk/mapbender/http/php/mod_wmc2ol.php	2011-07-27 12:40:00 UTC (rev 8009)
@@ -219,6 +219,8 @@
 	$miny = $xml->General->BoundingBox['miny'];
 	$maxx = $xml->General->BoundingBox['maxx'];
 	$maxy = $xml->General->BoundingBox['maxy'];
+	//Get epsg code out of WMC
+	$xml_epsg=str_replace('EPSG:','',$xml->General->BoundingBox['SRS']);
 	$centralx=floor(($maxx+$minx)/2);
 	$centraly=floor(($maxy+$miny)/2);
 	$dx=$maxx-$minx;//in meters
@@ -236,7 +238,16 @@
 	//start function for initialize client
 	$html.="function initGeoportal(){\n";
 	//define ol central map object	
-	$html.="	map = new OpenLayers.Map('map');\n";
+	$html.="	map = new OpenLayers.Map('map', { controls: [\n";
+	$html.="		new OpenLayers.Control.Navigation(\n";
+	if ($_REQUEST["disableMouseScroll"] == '1') {
+		$html.="			{zoomWheelEnabled : false}\n";
+	}
+	$html.="			),\n";
+	$html.="		new OpenLayers.Control.PanZoom(),\n";
+	$html.="		new OpenLayers.Control.ArgParser(),\n";
+        $html.="		new OpenLayers.Control.Attribution()\n";
+	$html.="		] });\n";
 	//define options for ol map object	
 	$html.="	var options = {\n";
 	$html.="		projection: \"".$xml->General->BoundingBox['SRS']."\",\n";
@@ -273,8 +284,6 @@
 					return;
 				}
 				//Check if epsg is equal to BBOXEpsg
-				//Get epsg code out of WMC
-				$xml_epsg=str_replace('EPSG:','',$xml->General->BoundingBox['SRS']);
 				if ($_REQUEST["mb_myBBOXEpsg"]!=$xml_epsg){
 					//Transform the given BBOX to epsg of WMC
 					$sql= "select asewkt(transform(GeometryFromText ( 'LINESTRING ( ".$array_bbox[0]." ".$array_bbox[1].",".$array_bbox[2]." ".$array_bbox[3]." )', $targetEpsg ),".intval($xml_epsg)."))";
@@ -477,10 +486,10 @@
 	if(isset($_REQUEST["GEORSS"])){
 		if($_REQUEST["GEORSS"]!=''){
 			$html.="	var pointVectorLayer = new OpenLayers.Layer.Vector(\"Vector Layer\", {\n";
-			$html.="		styleMap: new OpenLayers.StyleMap({\n";
-			$html.="    			pointRadius: \"".$pointRadius."\", // based on feature.attributes.type\n";
-			$html.="   			fillColor: \"".$fillColor."\"\n";
-			$html.="		})\n";
+			//$html.="		styleMap: new OpenLayers.StyleMap({\n";
+			//$html.="    			pointRadius: \"".$pointRadius."\", // based on feature.attributes.type\n";
+			//$html.="   			fillColor: \"".$fillColor."\"\n";
+			//$html.="		})\n";
 			$html.="	});\n";
 			//end of definition of the point vector layer 
 			//push the features to the layer
@@ -594,26 +603,52 @@
 						$coords = explode(" ", $gmlElements->Point->pos);
 						$geoRssEpsg = $gmlElements->Point->attributes()->srsName;
 						$geoRssEpsgId = str_replace('EPSG:','',$geoRssEpsg);
-						//transform coordinates if other epsg was choosen
 						if ($geoRssEpsgId != $xml_epsg){
-							//coords have to be transformed
-							$sql= "select asewkt(transform(GeometryFromText ( 'POINT ( ";
-							$sql .= $coords[0]." ".$coords[1]." )',". $geoRssEpsgId ."),".intval($xml_epsg)."))";
-							//select asewkt(transform(GeometryFromText ( 'POINT ( 7 50 )', 4326 ),31466));
-							$e = new mb_notice("mod_wms2ol.php: sql (transform)=".$sql);
-							$res = db_query($sql);
-							//read out result
-							$pointNew = db_fetch_row($res);
-							$e = new mb_notice("mod_wms2ol.php: pointNew=".$pointNew[0]);
-							$pattern = '~POINT\((.*)\)~i';
-							preg_match($pattern, $pointNew[0], $subpattern);
-							$e = new mb_notice("mod_wms2ol.php: subpattern=".$subpattern[1]);
-							$coords = explode(' ',$subpattern[1]);
+							//validate parameters:
+							if (is_numeric($coords[0]) && is_numeric($coords[1]) && is_numeric($geoRssEpsgId)  && is_numeric(intval($xml_epsg))) {
+								//coords have to be transformed
+								$sql= "select asewkt(transform(GeometryFromText ( 'POINT ( ";
+								$sql .= $coords[0]." ".$coords[1]." )',". $geoRssEpsgId ."),".intval($xml_epsg)."))";
+								//select asewkt(transform(GeometryFromText ( 'POINT ( 7 50 )', 4326 ),31466));
+
+								$e = new mb_notice("mod_wms2ol.php: sql (transform)=".$sql);
+								$res = db_query($sql);
+								//read out result
+								$pointNew = db_fetch_row($res);
+								$e = new mb_notice("mod_wms2ol.php: pointNew=".$pointNew[0]);
+								$pattern = '~POINT\((.*)\)~i';
+								preg_match($pattern, $pointNew[0], $subpattern);
+								$e = new mb_notice("mod_wms2ol.php: subpattern=".$subpattern[1]);
+								$coords = explode(' ',$subpattern[1]);
+							} else {
+								echo _mb("Some georss entries does not have numeric values for CRS or coordinates! For security reasons the script will die!");
+								die();
+							}
 						}
-						
+						//extract styles for single features
+						$imageUrl = $georssXml->entry[$i]->imageUrl->attributes()->href;
+						$imageSize = $georssXml->entry[$i]->imageSize;
+						//style
+						$html .= "	var pointStyle = {\n";
+						//validate imageUrl to url
+						if (isset($imageUrl) && $imageUrl != '' && parse_url($imageUrl)) {
+							if (isset($imageSize) && $imageSize != '' && is_int((integer)$imageSize)) {
+								$html .= "			 pointRadius: \"".$imageSize."\",\n";
+							} else {
+								$html .= "			 pointRadius: \"".$pointRadius."\",\n";
+							}
+							$html .= "	 		 externalGraphic: \"$imageUrl\"";
+							
+						} else {
+							$html .= "			 pointRadius: \"".$pointRadius."\",\n";
+							$html.="   			 fillColor: \"".$fillColor."\"\n";
+						}
+						$html .= "	             };\n";
+						//generate point objects
 						$html.="	var point = new OpenLayers.Geometry.Point(";
 						$html.="".$coords[0].",".$coords[1].");\n";
-						$html.="	pointFeatures[".$i."] = new OpenLayers.Feature.Vector(point, {title: \"".$georssXml->entry[$i]->title."\", description : \"".str_replace("\"", "'",$georssXml->entry[$i]->content)."\", link : \"".$georssXml->entry[$i]->link->attributes()->href."\"});\n";	
+						$html.="	pointFeatures[".$i."] = new OpenLayers.Feature.Vector(point, {title: \"".$georssXml->entry[$i]->title."\", description : \"".str_replace("\"", "'",$georssXml->entry[$i]->content)."\", link : \"".$georssXml->entry[$i]->link->attributes()->href."\"}, pointStyle);\n";
+						
 					}
 					$html.="	return pointFeatures;\n"; 
 					$html.="}\n"; 
@@ -634,12 +669,55 @@
 						$georssElements = $georssXml->entry[$i]->children('http://www.georss.org/georss');
 						$gmlElements = $georssElements->children('http://www.opengis.net/gml');
 						$coords = explode(" ", $gmlElements->Point->pos);
-					
-					$html.="	var point = new OpenLayers.Geometry.Point(";
+						$geoRssEpsg = $gmlElements->Point->attributes()->srsName;
+						$geoRssEpsgId = str_replace('EPSG:','',$geoRssEpsg);
+						//transform coordinates if other epsg was choosen
+						if ($geoRssEpsgId != $xml_epsg){
+							//validate parameters:
+							if (is_numeric($coords[0]) && is_numeric($coords[1]) && is_numeric($geoRssEpsgId)  && is_numeric(intval($xml_epsg))) {
+								//coords have to be transformed
+								$sql= "select asewkt(transform(GeometryFromText ( 'POINT ( ";
+								$sql .= $coords[0]." ".$coords[1]." )',". $geoRssEpsgId ."),".intval($xml_epsg)."))";
+								//select asewkt(transform(GeometryFromText ( 'POINT ( 7 50 )', 4326 ),31466));
+
+								$e = new mb_notice("mod_wms2ol.php: sql (transform)=".$sql);
+								$res = db_query($sql);
+								//read out result
+								$pointNew = db_fetch_row($res);
+								$e = new mb_notice("mod_wms2ol.php: pointNew=".$pointNew[0]);
+								$pattern = '~POINT\((.*)\)~i';
+								preg_match($pattern, $pointNew[0], $subpattern);
+								$e = new mb_notice("mod_wms2ol.php: subpattern=".$subpattern[1]);
+								$coords = explode(' ',$subpattern[1]);
+							} else {
+								echo _mb("Some georss entries does not have numeric values for CRS or coordinates! For security reasons the script will die!");
+								die();
+							}
+						}
+						//extract styles for single features
+						$imageUrl = $georssXml->entry[$i]->imageUrl->attributes()->href;
+						$imageSize = $georssXml->entry[$i]->imageSize;
+						//style
+						$html .= "	var pointStyle = {\n";
+						//validate imageUrl to url
+						if (isset($imageUrl) && $imageUrl != '' && parse_url($imageUrl)) {
+							if (isset($imageSize) && $imageSize != '' && is_int((integer)$imageSize)) {
+								$html .= "			 pointRadius: \"".$imageSize."\",\n";
+							} else {
+								$html .= "			 pointRadius: \"".$pointRadius."\",\n";
+							}
+							$html .= "	 		 externalGraphic: \"$imageUrl\"";
+							
+						} else {
+							$html .= "			 pointRadius: \"".$pointRadius."\",\n";
+							$html.="   			 fillColor: \"".$fillColor."\"\n";
+						}
+						$html .= "	             };\n";
+						$html.="	var point = new OpenLayers.Geometry.Point(";
 						$html.="".$coords[0].",".$coords[1].");\n";
-						$html.="	pointFeatures[".$i."] = new OpenLayers.Feature.Vector(point, {title: \"".$georssXml->entry[$i]->title."\", description : \"".str_replace("\"", "'",$georssXml->entry[$i]->content)."\", link : \"".$georssXml->entry[$i]->link->attributes()->href."\"});\n";	
+						$html.="	pointFeatures[".$i."] = new OpenLayers.Feature.Vector(point, {title: \"".$georssXml->entry[$i]->title."\", description : \"".str_replace("\"", "'",$georssXml->entry[$i]->content)."\", link : \"".$georssXml->entry[$i]->link->attributes()->href."\"}, pointStyle);\n";	
 					}
-					//***Generate Dummy Point for testing
+					//***Generate Dummy Point for testing //no styles given
 					$html.="	var point = new OpenLayers.Geometry.Point(2594468.92,5530693.03);\n";
 				
 					$html.="	pointFeatures[".$featureCount."] = new OpenLayers.Feature.Vector(point, {description : \"Testbeschreibung\", link : \"Testlink\"});\n"; 
@@ -662,6 +740,14 @@
 			//generate the single attributes for the layer presentation
 		}
 	}
+	/*if ($_REQUEST["disableMouseScroll"] == 'true') {
+		//$html .= "var movemap = new OpenLayers.Control.Navigation({zoomWheelEnabled : false});\n";
+		//$html .= "movemap.disableZoomWheel();\n";
+		$html .= "controls = map.getControlsByClass('OpenLayers.Control.Navigation');\n";
+		$html .= "for(var i = 0; i<controls.length; ++i) {\n";
+		$html .= "    controls[i].disableZoomWheel();\n";
+		$html .= "}\n";
+	}*/
 	//end of javascripting part 
 	$html.="</script>\n";
 	if ($_REQUEST['withoutBody'] == '1') { 	



More information about the Mapbender_commits mailing list