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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Jan 2 10:17:03 EST 2009


Author: christoph
Date: 2009-01-02 10:17:03 -0500 (Fri, 02 Jan 2009)
New Revision: 3395

Added:
   trunk/mapbender/http/php/mod_changeEPSG_server.php
Modified:
   trunk/mapbender/http/php/mod_changeEPSG.php
Log:
http://trac.osgeo.org/mapbender/ticket/360

Modified: trunk/mapbender/http/php/mod_changeEPSG.php
===================================================================
--- trunk/mapbender/http/php/mod_changeEPSG.php	2009-01-02 15:13:16 UTC (rev 3394)
+++ trunk/mapbender/http/php/mod_changeEPSG.php	2009-01-02 15:17:03 UTC (rev 3395)
@@ -18,194 +18,92 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 require(dirname(__FILE__)."/mb_validateSession.php");
-?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
-<html>
-<head>
-<meta name="author-mail" content="info at ccgis.de">
-<meta name="author" content="U. Rothstein">
-<meta http-equiv="cache-control" content="no-cache">
-<meta http-equiv="pragma" content="no-cache">
-<meta http-equiv="expires" content="0">
-<?php
-echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
-?>
-<title>Change Spatial Reference System EPSG Code</title>
-<?php
-$e_id_css = 'changeEPSG';
-echo "<script type='text/javascript'>";
 include(dirname(__FILE__)."/../include/dyn_js.php");
-echo "</script>";
 
-$sql = "SELECT e_target FROM gui_element WHERE e_id = 'changeEPSG' AND fkey_gui_id = $1";
-$v = array($gui_id);
-$t = array('s');
-$res = db_prep_query($sql,$v,$t);
+echo "var myTarget = '".$e_target[0]."';";
+echo "var myId = '".$e_id."';";
+?>
+var exists = false;
 
-echo "<script type='text/javascript'>";
-echo "var myTarget = '".db_result($res,0,"e_target")."';";
-echo "</script>";
+eventAfterMapRequest.register(function () {
+	mod_changeEPSG_setBox();
+});
 
-# transform coordinates
-if(isset($_REQUEST["srs"])){
-	require_once(dirname(__FILE__) . "/../../conf/mapbender.conf");
-	$arraymapObj = mb_split("###", $_REQUEST["srs"]);
-	echo "<script type='text/javascript'>";
-	echo "var newExtent = new Array();";
-	for($i=0; $i < count($arraymapObj); $i++){
-		$temp = mb_split(",",$arraymapObj[$i]);
+eventInit.register(function () {
+//	mod_changeEPSG_init();
+});
 
-		// check if parameters are valid geometries to 
-		// avoid SQL injections
-
-		$oldEPSG = preg_replace("/EPSG:/","",$temp[1]);
-		$newEPSG = preg_replace("/EPSG:/","",$_REQUEST["newSRS"]);
-		 
-		if (is_numeric($temp[2]) && is_numeric($temp[3]) && is_numeric($temp[4]) && is_numeric($temp[5]) && is_numeric($oldEPSG) && is_numeric($newEPSG)) {
-		
-			if(SYS_DBTYPE=='pgsql'){
-				$con = db_connect($DBSERVER,$OWNER,$PW);
-				$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$temp[2]." ".$temp[3].")',".$oldEPSG."),".$newEPSG.")) as minx";
-				$resMinx = db_query($sqlMinx);
-				$minx = db_result($resMinx,0,"minx");
-				
-				$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$temp[2]." ".$temp[3].")',".$oldEPSG."),".$newEPSG.")) as miny";
-				$resMiny = db_query($sqlMiny);
-				$miny = db_result($resMiny,0,"miny");
-				
-				$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$temp[4]." ".$temp[5].")',".$oldEPSG."),".$newEPSG.")) as maxx";
-				$resMaxx = db_query($sqlMaxx);
-				$maxx = db_result($resMaxx,0,"maxx");
-				
-				$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$temp[4]." ".$temp[5].")',".$oldEPSG."),".$newEPSG.")) as maxy";
-				$resMaxy = db_query($sqlMaxy);
-				$maxy = db_result($resMaxy,0,"maxy");
-			}else{
-				$con_string = "host=$GEOS_DBSERVER port=$GEOS_PORT dbname=$GEOS_DB user=$GEOS_OWNER password=$GEOS_PW";
-				$con = pg_connect($con_string) or die ("Error while connecting database");
-				
-				$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$temp[2]." ".$temp[3].")',".$oldEPSG."),".$newEPSG.")) as minx";
-				$resMinx = pg_query($con,$sqlMinx);
-				$minx = pg_fetch_result($resMinx,0,"minx");
-				
-				$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$temp[2]." ".$temp[3].")',".$oldEPSG."),".$newEPSG.")) as miny";
-				$resMiny = pg_query($con,$sqlMiny);
-				$miny = pg_fetch_result($resMiny,0,"miny");
-				
-				$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$temp[4]." ".$temp[5].")',".$oldEPSG."),".$newEPSG.")) as maxx";
-				$resMaxx = pg_query($con,$sqlMaxx);
-				$maxx = pg_fetch_result($resMaxx,0,"maxx");
-				
-				$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$temp[4]." ".$temp[5].")',".$oldEPSG."),".$newEPSG.")) as maxy";
-				$resMaxy = pg_query($con,$sqlMaxy);
-				$maxy = pg_fetch_result($resMaxy,0,"maxy");
-			}
-			$extenty = $maxy - $miny;
-			$extentx = $maxx - $minx;
-			$relation_px_x = $temp[6] / $temp[7];
-			$relation_px_y = $temp[7] / $temp[6];
-			$relation_bbox_x = $extentx / $extenty;
-	
-			if($relation_bbox_x <= $relation_px_x){
-				$centerx = $minx + ($extentx/2);
-				$minx = $centerx - $relation_px_x * $extenty / 2;
-				$maxx = $centerx + $relation_px_x * $extenty / 2;
-			}
-			if($relation_bbox_x > $relation_px_x){
-				$centery = $miny + ($extenty/2);
-				$miny = $centery - $relation_px_y * $extentx / 2;
-				$maxy = $centery + $relation_px_y * $extentx / 2;
-			}
-			echo "newExtent[".$i."] = '".$temp[0].",".$_REQUEST["newSRS"].",".$minx.",".$miny.",".$maxx.",".$maxy."';";
+function mod_changeEPSG_setBox(){
+	$("#"+myId+" option").each(function () {
+		if (this.value == mb_mapObj[0].epsg) {
+			isEPSG = true;
+			$(this).attr("selected", "selected");
 		}
-		else {
-			echo "var e = new parent.Mb_exception('mod_changeEPSG.php: invalid input parameter (p1 = (" . $temp[2] . "," . $temp[3] . "), p2 = (" . $temp[4] . "," . $temp[5] . "), old EPSG: " . $oldEPSG . ", new EPSG: " . $newEPSG . ", ).');";
-		}		
-	}
-	echo "</script>";
+	});
 }
-else{
-	echo "<script type='text/javascript'>var newExtent = false;</script>";
-}
-?>
-<script type='text/javascript'>
-<!--
-if(newExtent == false){
-	parent.mb_registerSubFunctions("window.frames['changeEPSG'].mod_changeEPSG_setBox()");
-}
 
-function mod_changeEPSG_init(){
-//frameName, EPSG, minx, miny, maxx, maxy, width, height
-	var exists = false;
-	if(newExtent){
-		for(var i=0; i<newExtent.length; i++){
-			var temp = newExtent[i].split(",");
-			if(temp[0] == myTarget){
-				for(var ii=0; ii<parent.mb_MapHistoryObj[temp[0]].length; ii++){
-					if(parent.mb_MapHistoryObj[temp[0]][ii].epsg == temp[1]){
+$("#"+myId).change(function () {
+	var srsArray = [];
+	for (var i = 0; i < mb_mapObj.length; i++) {
+		var currentSrs = {
+			"frameName" : mb_mapObj[i].elementName,
+			"epsg" : mb_mapObj[i].epsg,
+			"extent" : mb_mapObj[i].extent,
+			"width" : mb_mapObj[i].width,
+			"height" : mb_mapObj[i].height
+		};
+		srsArray.push(currentSrs);
+	}
+
+	var req = new Mapbender.Ajax.Request({
+		"method":"changeEpsg",
+		"parameters":{
+			"srs":srsArray,
+			"newSrs": $("#"+myId).get(0).value
+		}
+	});
+	req.send("../php/mod_changeEPSG_server.php", function (obj, success, message) {
+		if (!success) {
+			new Mb_exception("!!!!!!"+message);
+			return;
+		}
+		
+		var newExtent = obj;
+		
+		for(var i = 0; i < newExtent.length; i++) {
+			if(newExtent[i].frameName == myTarget){
+
+				var ind = getMapObjIndexByName(myTarget);
+				
+				for(var ii = 0; ii < mb_mapObj[ind].mb_MapHistoryObj.length; ii++) {
+					if (mb_mapObj[ind].mb_MapHistoryObj[ii].epsg == newExtent[i].newSrs) {
 						exists = ii;
 						var goback = true;
 					}
 				}
-				var ind = parent.getMapObjIndexByName(temp[0]);
-				if(goback){
-					parent.mb_mapObj[ind].epsg = temp[1];
-					parent.mb_mapObj[ind].extent = parent.mb_MapHistoryObj[temp[0]][exists].extent;
-					parent.setMapRequest(temp[0]);
+
+				if (goback) {
+					mb_mapObj[ind].epsg = newExtent[i].newSrs;
+					mb_mapObj[ind].extent = mb_mapObj[ind].mb_MapHistoryObj[exists].extent;
+					setMapRequest(newExtent[i].frameName);
 				}
 				else{
-					parent.mb_mapObj[ind].epsg = temp[1];
-					parent.mb_mapObj[ind].extent = parseFloat(temp[2]) + "," + parseFloat(temp[3]) + "," + parseFloat(temp[4]) + "," + parseFloat(temp[5]);
-					parent.setMapRequest(temp[0]);
+					mb_mapObj[ind].epsg = newExtent[i].newSrs;
+					mb_mapObj[ind].extent = parseFloat(newExtent[i].minx) + "," + parseFloat(newExtent[i].miny) + "," + 
+						parseFloat(newExtent[i].maxx) + "," + parseFloat(newExtent[i].maxy);
+				setMapRequest(newExtent[i].frameName);
 				}
 			}
-			if(temp[0] != myTarget){
-				var ind = parent.getMapObjIndexByName(temp[0]);
-				parent.mb_mapObj[ind].epsg = temp[1];
-				parent.mb_mapObj[ind].extent = parseFloat(temp[2]) + "," + parseFloat(temp[3]) + "," + parseFloat(temp[4]) + "," + parseFloat(temp[5]);
-				parent.setMapRequest(temp[0]);
+			else {
+				var ind = getMapObjIndexByName(newExtent[i].frameName);
+				mb_mapObj[ind].epsg = newExtent[i].newSrs;
+				mb_mapObj[ind].extent = parseFloat(newExtent[i].minx) + "," + parseFloat(newExtent[i].miny) + "," + 
+					parseFloat(newExtent[i].maxx) + "," + parseFloat(newExtent[i].maxy);
+				setMapRequest(newExtent[i].frameName);
 			}
 		}
-	}
-}
 
-function mod_changeEPSG_setBox(){
-	var myEPSG = parent.mb_mapObj[0].epsg;
-	for(var i=0; i<document.forms[0].epsg.length; i++){
-		if(document.forms[0].epsg.options[i].value == myEPSG){
-			document.forms[0].epsg.selectedIndex = i;
-			isEPSG = true;
-		}
-	}
-}
 
-function mod_changeEPSG(){
-	str_srs = "";
-	for(var i=0; i<parent.mb_mapObj.length; i++){
-		if(i>0){str_srs += "###";}
-		str_srs += parent.mb_mapObj[i].frameName + "," + parent.mb_mapObj[i].epsg + "," + parent.mb_mapObj[i].extent + ","+parent.mb_mapObj[i].width+","+parent.mb_mapObj[i].height;
-	}
-	document.forms[0].srs.value = str_srs;
-	var ind = document.forms[0].epsg.selectedIndex;
-	document.forms[0].newSRS.value = document.forms[0].epsg.options[ind].value;
-	document.forms[0].submit();
-}
-// -->
-</script>
-</head>
-<body leftmargin="1" topmargin="1" onload="mod_changeEPSG_init()" bgcolor="red">
-<form action="<?php echo $self;  ?>" method='POST'>
-<select class='epsg' name='epsg' onchange='mod_changeEPSG()'>
-<option value="">undefined</option>
-<option value="EPSG:4326">EPSG:4326</option>
-<option value="EPSG:31466">EPSG:31466</option>
-<option value="EPSG:31467">EPSG:31467</option>
-<option value="EPSG:31468">EPSG:31468</option>
-<option value="EPSG:31469">EPSG:31469</option>
-</select>
-<input type="hidden" name="srs" value="">
-<input type="hidden" name="newSRS" value="">
-</form>
-</body>
-</html>
\ No newline at end of file
+	});
+});
\ No newline at end of file

Added: trunk/mapbender/http/php/mod_changeEPSG_server.php
===================================================================
--- trunk/mapbender/http/php/mod_changeEPSG_server.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_changeEPSG_server.php	2009-01-02 15:17:03 UTC (rev 3395)
@@ -0,0 +1,123 @@
+<?php
+# $Id: mod_changeEPSG.php 2413 2008-04-23 16:21:04Z christoph $
+# http://www.mapbender.org/index.php/mod_changeEPSG.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require(dirname(__FILE__)."/mb_validateSession.php");
+
+$epsgObj = array();
+
+$ajaxResponse = new AjaxResponse($_REQUEST);
+
+switch ($ajaxResponse->getMethod()) {
+	case "changeEpsg" :
+		$epsgArray = $ajaxResponse->getParameter("srs");
+		$newSrs = $ajaxResponse->getParameter("newSrs");
+
+		for($i=0; $i < count($epsgArray); $i++){
+			// check if parameters are valid geometries to 
+			// avoid SQL injections
+			$currentEpsg = $epsgArray[$i];
+	
+			$oldEPSG = preg_replace("/EPSG:/","", $currentEpsg->epsg);
+			$newEPSG = preg_replace("/EPSG:/","", $newSrs);
+			 
+			$extArray = explode(",", $currentEpsg->extent);
+			if (is_numeric($extArray[0]) && is_numeric($extArray[1]) && 
+				is_numeric($extArray[2]) && is_numeric($extArray[3]) && 
+				is_numeric($oldEPSG) && is_numeric($newEPSG)) {
+			
+			
+				if(SYS_DBTYPE=='pgsql'){
+					$con = db_connect($DBSERVER,$OWNER,$PW);
+					$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as minx";
+					$resMinx = db_query($sqlMinx);
+					$minx = db_result($resMinx,0,"minx");
+					
+					$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny";
+					$resMiny = db_query($sqlMiny);
+					$miny = db_result($resMiny,0,"miny");
+					
+					$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx";
+					$resMaxx = db_query($sqlMaxx);
+					$maxx = db_result($resMaxx,0,"maxx");
+					
+					$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy";
+					$resMaxy = db_query($sqlMaxy);
+					$maxy = db_result($resMaxy,0,"maxy");
+				}else{
+					$con_string = "host=$GEOS_DBSERVER port=$GEOS_PORT dbname=$GEOS_DB user=$GEOS_OWNER password=$GEOS_PW";
+					$con = pg_connect($con_string) or die ("Error while connecting database");
+					
+					$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as minx";
+					$resMinx = pg_query($con,$sqlMinx);
+					$minx = pg_fetch_result($resMinx,0,"minx");
+					
+					$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny";
+					$resMiny = pg_query($con,$sqlMiny);
+					$miny = pg_fetch_result($resMiny,0,"miny");
+					
+					$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx";
+					$resMaxx = pg_query($con,$sqlMaxx);
+					$maxx = pg_fetch_result($resMaxx,0,"maxx");
+					
+					$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy";
+					$resMaxy = pg_query($con,$sqlMaxy);
+					$maxy = pg_fetch_result($resMaxy,0,"maxy");
+				}
+				$extenty = $maxy - $miny;
+				$extentx = $maxx - $minx;
+				$relation_px_x = $currentEpsg->width / $currentEpsg->height;
+				$relation_px_y = $currentEpsg->height / $currentEpsg->width;
+				$relation_bbox_x = $extentx / $extenty;
+		
+				if($relation_bbox_x <= $relation_px_x){
+					$centerx = $minx + ($extentx/2);
+					$minx = $centerx - $relation_px_x * $extenty / 2;
+					$maxx = $centerx + $relation_px_x * $extenty / 2;
+				}
+				if($relation_bbox_x > $relation_px_x){
+					$centery = $miny + ($extenty/2);
+					$miny = $centery - $relation_px_y * $extentx / 2;
+					$maxy = $centery + $relation_px_y * $extentx / 2;
+				}
+				$epsgObj[$i] = array(
+					"frameName" => $currentEpsg->frameName,
+					"newSrs" => $newSrs,
+					"minx" => $minx,
+					"miny" => $miny,
+					"maxx" => $maxx,
+					"maxy" => $maxy
+				);
+			}
+			else {
+				$ajaxResponse->setSuccess(false);
+				$ajaxResponse->setMessage(_mb("An unknown error occured."));
+				$ajaxResponse->send();
+			}
+		}
+		$ajaxResponse->setSuccess(true);
+		$ajaxResponse->setResult($epsgObj);
+		break;
+	default :
+		$ajaxResponse->setSuccess(false);
+		$ajaxResponse->setMessage(_mb("An unknown error occured."));
+		break;
+}
+
+$ajaxResponse->send();
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list