[Mapbender-commits] r10068 - in trunk/mapbender/http: classes plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Mar 6 11:54:56 PST 2019


Author: armin11
Date: 2019-03-06 11:54:56 -0800 (Wed, 06 Mar 2019)
New Revision: 10068

Modified:
   trunk/mapbender/http/classes/class_stripRequest.php
   trunk/mapbender/http/classes/class_weldMaps2JPEG.php
   trunk/mapbender/http/plugins/mb_metadata_layerPreview.php
Log:
Fix problem with generating getlegendgraphic preview image if width and height parameter are not given in getlegendgraphic request. TODO: get size of legend elements when capabilities are parsed.

Modified: trunk/mapbender/http/classes/class_stripRequest.php
===================================================================
--- trunk/mapbender/http/classes/class_stripRequest.php	2019-03-06 17:33:08 UTC (rev 10067)
+++ trunk/mapbender/http/classes/class_stripRequest.php	2019-03-06 19:54:56 UTC (rev 10068)
@@ -74,7 +74,7 @@
 			}
 		}
 		if($exists == false){
-			$e = new mb_exception("stripRequest: key '".$key."' lacks");
+			$e = new mb_notice("stripRequest: key '".$key."' lacks");
 			return false;
 		}
 	}
@@ -188,4 +188,4 @@
 		return $this->url;
 	}
 }
-?>
\ No newline at end of file
+?>

Modified: trunk/mapbender/http/classes/class_weldMaps2JPEG.php
===================================================================
--- trunk/mapbender/http/classes/class_weldMaps2JPEG.php	2019-03-06 17:33:08 UTC (rev 10067)
+++ trunk/mapbender/http/classes/class_weldMaps2JPEG.php	2019-03-06 19:54:56 UTC (rev 10068)
@@ -28,7 +28,6 @@
 require_once(dirname(__FILE__)."/class_connector.php");
 
 class weldMaps2JPEG{
-
 	function __construct($urls,$filename, $encode = true){
 		if(!$urls || $urls == ""){
 			$e = new mb_exception("weldMaps2JPEG: no maprequests delivered");
@@ -41,11 +40,10 @@
 			}
 		}
 		//following is only possible, if parameters with and height are given :-( - when getlegendgraphic is used - otherwise we have to get the original width and height from capabilities - or mapbender database itself!
-		//$e = new mb_exception("width: ".$width);
 		//check if url is of type getlegendgraphic or getmap - these are considered here
 		$request = strtoupper($obj1->get("REQUEST"));
-		//$e = new mb_exception(strtoupper($obj1->get("REQUEST")));
-		//$e = new mb_exception("count url: ".count($url));
+//$e = new mb_exception(strtoupper($obj1->get("REQUEST")));
+//$e = new mb_exception("count url: ".count($url));
 		if ($request !== "GETMAP" && $request !== "GETLEGENDGRAPHIC") {
 			//no width or height exists - e.g. legend graphics
 			//$e = new mb_exception("No GetMap or GetLegendGraphic");
@@ -72,23 +70,30 @@
 				return true;
 			}
 		} else {
-			$e = new mb_exception("Normal GetMap or GetLegendGraphic");
 			$width = $obj1->get("width");
 			$height = $obj1->get("height");
+			if (!$width || $width == '' || !$height || $height == '') {
+				$e = new mb_exception("classes/class_weldMaps2JPEG.php: Paremeters width and/or height are not given in $request request! Try to get it from image size.");
+				if ($url[0] != false){
+					$url[0] = urldecode($url[0]);
+					//$e = new mb_exception("class_weldMaps2JPEG.php: ".$url[0]);
+					//list($width, $height, $type, $attr) = getimagesizefromstring($this->loadpng($url[0]));
+					$img = $this->loadpng($url[0]);	
+					$width = imagesx($img);
+					$height = imagesy($img);
+				}
+			}
 		}
 		$image = imagecreatetruecolor($width, $height);
 		$white = ImageColorAllocate($image,255,255,255); 
 		ImageFilledRectangle($image,0,0,$width,$height,$white); 
-
 		for($i=0; $i<count($url); $i++){
 			if ($url[$i] != false) { //sometimes some false urls will be send? - don't use them
 				//before encode the url it should be decoded to be secure that a decoded url is used!
 				$url[$i] = urldecode($url[$i]);
-				//$e = new mb_exception("oldurl: ".$url[$i]);
 				$obj = new stripRequest($url[$i]);
 				$url[$i] = $obj->setPNG();
 				$url[$i] = $obj->encodeGET($encode);
-				//$e = new mb_exception("newurl: ".$url[$i]);
 				$img = $this->loadpng($url[$i]);
 				if($img != false){
 					imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
@@ -101,9 +106,7 @@
 		}
 		imagejpeg($image,$filename);
 		imagedestroy($image); 
-
 	}
-        
         /**
 	 * Old constructor to keep PHP downward compatibility
 	 */
@@ -126,20 +129,20 @@
 		//Connection	keep-alive
 		//Host	geodaten-luwg.rlp.de
 		//User-Agent	Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:25.0) Gecko/20100101 Firefox/25.0
-		$headers = array(
-				"GET: ".$path." HTTP/1.1",
-				"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:25.0) Gecko/20100101 Firefox/25.0",
-				"Accept-Encoding: gzip, deflate",
-				"Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3",
-           			"Host: geodaten-luwg.rlp.de",
-				"Cache-Control:	max-age=0",
-	           		"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
-				"Connection: Keep-Alive"
-		);
+		//$headers = array(
+		//		"GET: ".$path." HTTP/1.1",
+		//		"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:25.0) Gecko/20100101 Firefox/25.0",
+		//		"Accept-Encoding: gzip, deflate",
+		//		"Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3",
+           	//		"Host: geodaten-luwg.rlp.de",
+		//		"Cache-Control:	max-age=0",
+	        //  		"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
+		//		"Connection: Keep-Alive"
+		//);
 		//$x->set("curlSendCustomHeaders",true);
 		//$x->set("externalHeaders", $headers);
 		//$f = $obj->get("format");
-$e = new mb_exception($imgurl);
+//$e = new mb_exception($imgurl);
 		$im = imagecreatefromstring($x->load($imgurl));
 		if(!$im){
 			$im = false;

Modified: trunk/mapbender/http/plugins/mb_metadata_layerPreview.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_layerPreview.php	2019-03-06 17:33:08 UTC (rev 10067)
+++ trunk/mapbender/http/plugins/mb_metadata_layerPreview.php	2019-03-06 19:54:56 UTC (rev 10068)
@@ -6,8 +6,6 @@
 //define("LAYER_PREVIEW_BASE","../tmp/layerpreviews/");
 //define("LAYER_PREVIEW_BASE","../tmp/");
 
-
-
 $ajaxResponse  = new AjaxResponse($_REQUEST);
 $mapurl =  $ajaxResponse->getParameter("mapurl");
 $layerName =  $ajaxResponse->getParameter("layerName");
@@ -17,14 +15,11 @@
 $layerPreviewMapFileName = PREVIEW_DIR ."/".$layerId."_layer_map_preview.jpg";
 $layerPreviewLegendFileName = PREVIEW_DIR ."/".$layerId."_layer_legend_preview.jpg";
 
-
-
 if(!$mapurl){
 	$ajaxResponse->setSuccess(false);
 	$ajaxResponse->setMessage('mapURL not set');
 	$ajaxResponse->send();
 }
-
 /*
 if(!$legendurl){
 	$ajaxResponse->setSuccess(false);
@@ -42,10 +37,9 @@
 	$ajaxResponse->setMessage('layerName not set');
 	$ajaxResponse->send();
 }
-
 switch ($ajaxResponse->getMethod()) {
 	case "saveLayerPreview":
-		$e = new mb_notice("plugins/mb_metadatalayerPreview.php: weld map");
+		$e = new mb_notice("plugins/mb_metadatalayerPreview.php: weld map: ".$mapurl);
 		$mapImg = new weldMaps2JPEG($mapurl, $layerPreviewMapFileName);
 		if(!$mapImg) {
 			$ajaxResponse->setSuccess(false);
@@ -53,7 +47,7 @@
 			$ajaxResponse->send();
 		} 
 		if ($legendUrl) {
-			$e = new mb_notice("plugins/mb_metadatalayerPreview.php: weld legend");
+			$e = new mb_notice("plugins/mb_metadatalayerPreview.php: weld legend: ".$legendUrl);
 			$legendImg = new weldMaps2JPEG($legendUrl, $layerPreviewLegendFileName);
 			if(!$legendImg) {
 				$ajaxResponse->setSuccess(false);



More information about the Mapbender_commits mailing list