[Mapbender-commits] r10392 - in trunk/mapbender: http/classes http/javascripts lib

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jan 27 08:47:42 PST 2020


Author: armin11
Date: 2020-01-27 08:47:42 -0800 (Mon, 27 Jan 2020)
New Revision: 10392

Modified:
   trunk/mapbender/http/classes/class_map.php
   trunk/mapbender/http/javascripts/initWmcObj.php
   trunk/mapbender/lib/class_GetApi.php
Log:
First draft for extending get-parameter for ZOOM=x,y,scale - only possible for projected crs at the moment

Modified: trunk/mapbender/http/classes/class_map.php
===================================================================
--- trunk/mapbender/http/classes/class_map.php	2020-01-27 08:30:31 UTC (rev 10391)
+++ trunk/mapbender/http/classes/class_map.php	2020-01-27 16:47:42 UTC (rev 10392)
@@ -165,7 +165,56 @@
 		return round($scale);
 	}
 
+	/**
+	 *
+	 * @return new box for given poi (array) and scale (int)
+	 */
+	public function getBboxFromPoiScale($point, $scale, $pointEpsg = false, $mapResolutionDpi = MB_RESOLUTION){
+		$geographicEpsgArray = array("EPSG:4326","EPSG:3857","EPSG:900913");
+		/*$scale;
+		$xtenty;
+		$bbox = $this->getExtentInfo();*/
+		$mapSetEpsg = $this->getEpsg();
+        	if ($pointEpsg == false) { // point is interpreted as given in epsg of gui/wmc
+		    if (in_array($mapSetEpsg, $geographicEpsgArray)) {
+			//wms 1.3.0 spec 
+			//$scale = $distanceInDeegree * ((6378137 * M_PI) / 180) / $this->getHeight() / 0.00028;
+			//calculate it from height of image cause lat direction always has right great circle distances
+			$distanceInDeegree = $this->getHeight() * 0.00028 * (double)$scale * 360.0 / (2.0 * M_PI * 6378137.0);
 
+			//$e = new mb_exception("distance in deegree: ".$distanceInDeegree. " - scale: ".$scale. " - height: ".$this->getHeight());			
+			$bbox[0] = $point[0] - ($distanceInDeegree / 2);
+		        $bbox[1] = $point[1] - ($distanceInDeegree / 2);
+		        $bbox[2] = $point[0] + ($distanceInDeegree / 2);
+		        $bbox[3] = $point[1] + ($distanceInDeegree / 2);
+		    } else {
+		        $xtenty = $scale / ($mapResolutionDpi * 100) * $this->getWidth(); //x width in m
+		        $ytenty = $scale / ($mapResolutionDpi * 100) * $this->getHeight();
+		        $bbox[0] = $point[0] - ($xtenty / 2);
+		        $bbox[1] = $point[1] - ($ytenty / 2);
+		        $bbox[2] = $point[0] + ($xtenty / 2);
+		        $bbox[3] = $point[1] + ($ytenty / 2);
+		    }
+		    return $bbox;
+		}
+
+		/*if ($this->getEpsg() == "EPSG:4326") {
+			$pxLenx = ($bbox[2] - $bbox[0]) / $this->getWidth();
+			$pxLeny = ($bbox[3] - $bbox[1]) / $this->getHeight();
+			$lat_from = ((($bbox[3] - $bbox[1]) / 2) * M_PI) / 180;
+			$lat_to = ((($bbox[3] - $bbox[1]) / 2 + $pxLeny) * M_PI) / 180;
+			$lon_from = ((($bbox[2] - $bbox[0]) / 2) * M_PI) / 180;
+			$lon_to = ((($bbox[2] - $bbox[0]) / 2 + $pxLeny) * M_PI) / 180;
+			$dist = 6371229 * acos(sin($lat_from) * sin($lat_to) + cos($lat_from) * cos($lat_to) * cos($lon_from - $lon_to));
+			$scale = ($dist / sqrt(2)) * ($mapResolutionDpi * 100);
+		}
+		else {
+			$xtenty = $bbox[3] - $bbox[1];
+			$scale = ($xtenty / $this->getHeight()) * ($mapResolutionDpi * 100);
+		}
+		return round($scale);*/
+	}
+
 	/**
 	 *
 	 * @return String EPSG code of the map.

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2020-01-27 08:30:31 UTC (rev 10391)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2020-01-27 16:47:42 UTC (rev 10392)
@@ -838,6 +838,27 @@
 if(is_array($zoom)) {
     $e = new mb_notice("javascripts/initWmcObj.php: check ZOOM API: ".implode(',', $zoom));
 }
+if (count($zoom) == 3) {
+    //add zoom[2] to x and y and set bbox
+    //calculate new extent from scale -  
+    //
+    $point = array($zoom[0], $zoom[1]);
+    $scale = $zoom[2];
+    $newExtent = $wmcGetApi->mainMap->getBboxFromPoiScale($point, $scale);
+    //Problem: TODO setExtent does not work properly for geographic EPSGs!!! test line 519 - if a point geometry is given by geojson 
+    //$e = new mb_exception(json_encode($newExtent));
+    //$e = new mb_exception(json_encode($wmcGetApi->mainMap->getEpsg()));
+    $bbox = new Mapbender_bbox(
+	$newExtent[0],
+	$newExtent[1],
+	$newExtent[2],
+	$newExtent[3],
+	$epsg = $wmcGetApi->mainMap->getEpsg());
+
+    $wmcGetApi->mainMap->setExtent($bbox);
+    //render point at middle position
+    
+}
 if (count($zoom) == 4 || count($zoom) == 5) {
 	$e = new mb_notice("javascripts/initWmcObject.php: found EXTENT");
 	if (count($zoom) == 5){
@@ -848,15 +869,21 @@
 			$zoom[3],
 			$epsg = $zoom[4]);
 	} else {
-		// get current epsg from wmc bounding box
-		// ViewContext->General->BoundingBox->SRS
-		$e = new mb_notice("javascripts/initWmcObject.php: SRS found in current WMC: ".$wmcGetApi->mainMap->getEpsg());
-		$bbox = new Mapbender_bbox(
-			$zoom[0],
-			$zoom[1],
-			$zoom[2],
-			$zoom[3],
-			$epsg = $wmcGetApi->mainMap->getEpsg());
+		//check if zoom with scale and epsg is requested 
+		if (strpos(strtolower($zoom[3], "epsg:") === 0 ) && is_numeric($zoom[0]) && is_numeric($zoom[1]) && is_numeric($zoom[2])) {
+			$e = new mb_notice("javascripts/initWmcObject.php: SRS found in zoom parameter: ".$zoom[4]);
+			//calculate bbox from central point with scale (or offset in m) - depends on epsg
+		} else {		
+			// get current epsg from wmc bounding box
+			// ViewContext->General->BoundingBox->SRS
+			$e = new mb_notice("javascripts/initWmcObject.php: SRS found in current WMC: ".$wmcGetApi->mainMap->getEpsg());
+			$bbox = new Mapbender_bbox(
+				$zoom[0],
+				$zoom[1],
+				$zoom[2],
+				$zoom[3],
+				$epsg = $wmcGetApi->mainMap->getEpsg());
+		}
 	}
 	$wmcGetApi->mainMap->setExtent($bbox);
 }

Modified: trunk/mapbender/lib/class_GetApi.php
===================================================================
--- trunk/mapbender/lib/class_GetApi.php	2020-01-27 08:30:31 UTC (rev 10391)
+++ trunk/mapbender/lib/class_GetApi.php	2020-01-27 16:47:42 UTC (rev 10392)
@@ -285,20 +285,34 @@
 		$inputArray = explode(",", $input);
 		$input = array();
 		switch (count($inputArray)) {
+			case 3:
+				if (is_numeric($inputArray[0]) && is_numeric($inputArray[1]) && is_numeric($inputArray[2])) {
+					return $inputArray;
+				} else {
+					$e = new mb_exception("lib/class_GetApi.php: found non numeric value in zoom parameter!");
+				}
+				break;
 			case 4:
-				//read out coordinates - have to be numeric values
-				$i = 0;
-				foreach ($inputArray as $id) {
-					if (is_numeric($id)) {
-						//do nothing
-					} else {
-						$e = new mb_exception("lib/class_GetApi.php: found non numeric value in zoom parameter: at pos ".$i." : ".$id);
-						return false;	
+				//check if last element begins with epsg: - then it will be the case, that zoom to coordinate with scale and special epsg is requested
+				if (strpos(strtolower($inputArray[3], "epsg:") === 0 ) && is_numeric($inputArray[0]) && is_numeric($inputArray[1]) && is_numeric($inputArray[2])) {
+					//extract epsg code ...
+					//create point object with scale ...
+					return $inputArray;
+				} else {
+					//read out coordinates - have to be numeric values
+					$i = 0;
+					foreach ($inputArray as $id) {
+						if (is_numeric($id)) {
+							//do nothing
+						} else {
+							$e = new mb_exception("lib/class_GetApi.php: found non numeric value in zoom parameter: at pos ".$i." : ".$id);
+							return false;	
+						}
+						$i++;
 					}
-					$i++;
+					return $inputArray;
 				}
-				return $inputArray;
-			break;
+				break;
 			case 5:
 				//read out coordinates and epsg
 				for ($i=0; $i < 4; $i++) {
@@ -317,11 +331,11 @@
 					return false;	
  				}
 				return $inputArray;
-			break;
+				break;
 			default:
 				//count doesn't match
 				return false;
-			break;
+				break;
 		}
 		/*$i = 0;
 		foreach ($inputArray as $id) {



More information about the Mapbender_commits mailing list