[Mapbender-commits] r4584 - in trunk/mapbender: core http/javascripts http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Sep 1 09:44:46 EDT 2009


Author: christoph
Date: 2009-09-01 09:44:44 -0400 (Tue, 01 Sep 2009)
New Revision: 4584

Added:
   trunk/mapbender/http/php/mod_coordsLookup_server.php
Modified:
   trunk/mapbender/core/system.php
   trunk/mapbender/http/javascripts/map_obj.js
   trunk/mapbender/http/javascripts/mod_coordsLookup.js
Log:
http://trac.osgeo.org/mapbender/ticket/525

Modified: trunk/mapbender/core/system.php
===================================================================
--- trunk/mapbender/core/system.php	2009-08-31 14:22:30 UTC (rev 4583)
+++ trunk/mapbender/core/system.php	2009-09-01 13:44:44 UTC (rev 4584)
@@ -41,5 +41,5 @@
 	"scaleBar,scaleSelect,setBBOX,setPOI2Scale,reload,overview,addWMS," . 
 	"repaint,changeEPSG,User,AdminTabs,GroupEditor,GuiEditor,UserEditor,".
 	"scalebar,dialogManager,addWMSfromTree,mousewheelZoom,doubleclickZoom," . 
-	"overviewToggle,resizeMapsize"
+	"overviewToggle,resizeMapsize,coordsLookup"
 );

Modified: trunk/mapbender/http/javascripts/map_obj.js
===================================================================
--- trunk/mapbender/http/javascripts/map_obj.js	2009-08-31 14:22:30 UTC (rev 4583)
+++ trunk/mapbender/http/javascripts/map_obj.js	2009-09-01 13:44:44 UTC (rev 4584)
@@ -497,6 +497,12 @@
 		
 	};
 	
+	this.setCenter = function (aPoint) {
+		this.extent.set(aPoint);
+		this.calculateExtent(this.extent);
+		this.setMapRequest();
+	};
+	
 	this.zoomFull = function () {
 		
 		if (this.restrictedExtent) {

Modified: trunk/mapbender/http/javascripts/mod_coordsLookup.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_coordsLookup.js	2009-08-31 14:22:30 UTC (rev 4583)
+++ trunk/mapbender/http/javascripts/mod_coordsLookup.js	2009-09-01 13:44:44 UTC (rev 4584)
@@ -1,27 +1,42 @@
 /**
- * Package: <Application element name>
+ * Package: coordsLookup
  *
  * Description:
- * <A description>
+ * The user enters a coordinate tuple and selects the corresponding SRS 
+ * from a select box. After submitting this form, Mapbender transforms
+ * the coordinate tuple to the current SRS and zooms to the location.
  * 
  * Files:
- *  - <path and filename, like http/javascripts/mod_zoomIn1.php>
+ *  - http/javascripts/mod_coordsLookup.js
+ *  - http/php/mod_coordsLookup_server.php
  *
  * SQL:
-INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) VALUES('gui_toni','coordsLookup',10,1,'','','div','','',1000,0,NULL ,NULL ,NULL ,'border:1px solid red;z-index:9999;','','div','mod_coordsLookup.js','../extensions/proj4js/lib/proj4js-combined.js','mapframe1','','');
-INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type) VALUES('gui_toni', 'coordsLookup', 'perimeters', '[50,200,1000,10000]', '' ,'var');
-INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type) VALUES('gui_toni', 'coordsLookup', 'projections', '[''EPSG:31467'',''EPSG:31468'',''EPSG:31469'']', '' ,'var');
-
+ * > INSERT INTO gui_element (fkey_gui_id, e_id, e_pos, e_public, e_comment, 
+ * > e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, 
+ * > e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, 
+ * > e_mb_mod, e_target, e_requires, e_url) VALUES ('<app_id>','coordsLookup',
+ * > 10,1,'','','div','','',1000,0,NULL ,NULL ,NULL ,
+ * > 'border:1px solid red;z-index:9999;','','div','mod_coordsLookup.js','',
+ * > 'mapframe1','','');
+ * >
+ * > INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name, 
+ * > var_value, context, var_type) VALUES ('<app_id>', 'coordsLookup', 
+ * > 'perimeters', '[50,200,1000,10000]', '' ,'var');
+ * >
+ * > INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name, 
+ * > var_value, context, var_type) VALUES('<app_id>', 'coordsLookup', 
+ * > 'projections', '[''EPSG:31467'',''EPSG:31468'',''EPSG:31469'']', '' ,
+ * > 'var');
+ *
  * Help:
- * http://www.mapbender.org/<wiki site name>
+ * http://www.mapbender.org/coordsLookup
  *
  * Maintainer:
- * http://www.mapbender.org/User:<user>
+ * http://www.mapbender.org/User:Christoph_Baudson
  * 
  * Parameters:
- * <normal element var name>      - <type and description>
- * <optional element var name>    - *[optional]* <type and description>
- * <deprecated element var name>  - *[deprecated]* <type and description>
+ * perimeters		- Array of perimeters in m, like [50,200,1000,10000]
+ * projections		- Array of EPSG names, like ['EPSG:31467','EPSG:31468']
  *
  * License:
  * Copyright (c) 2009, Open Source Geospatial Foundation
@@ -33,8 +48,9 @@
 //
 // http://trac.osgeo.org/proj4js/wiki/UserGuide
 //
-
+// 3802000 / 5825000
 var CoordsLookup = function() {
+	var that = this;
 
 	if(
 		typeof options.target      === 'undefined' || options.target.length      === 0 || 
@@ -89,46 +105,90 @@
 	};
 	
 	this.zoomToCoordinates = function() {
-		this.coords = {}
+		this.coords = {};
 
 		this.coords.x                = this.coordXInput.val().replace(',','.');
 		this.coords.y                = this.coordYInput.val().replace(',','.');
-		this.coords.sourceProjection = (this.projectionSelect.val().length) ? this.projectionSelect.val() : false;
+		this.coords.sourceProjection = (this.projectionSelect.val()) ? 
+			this.projectionSelect.val() : null;
 		this.coords.targetProjection = Mapbender.modules[options.target].getSRS();
-		this.coords.perimeter        = (this.perimeterSelect.val().length) ? this.perimeterSelect.val() : false;
+		this.coords.perimeter        = (this.perimeterSelect.val()) ? 
+			parseFloat(this.perimeterSelect.val()) : null;
 
 		if(
 			this.coords.x.length === 0 || isNaN(this.coords.x) ||
 			this.coords.y.length === 0 || isNaN(this.coords.y)
 		) {
-			alert('Bitte geben Sie ein Koordinatenpaar ein.');
+			alert('Invalid coordinates!');
 			return;
 		}
 
+		if (this.coords.sourceProjection === null) {
+			alert('Invalid SRS!');
+			return;
+		}
+
 		if(this.coords.sourceProjection && (this.coords.sourceProjection != this.coords.targetProjection)) {
 			this.transformProjection();
 		}
 
-		zoom(options.target,true,1.0,this.coords.x,this.coords.y);
 	};
 	
 	this.transformProjection = function() {
-//		proj4js debug	
-		Proj4js.reportError = function(msg) {
-			console.log('proj4js debug message: %s',msg);
+		var parameters = {
+			fromSrs: this.coords.sourceProjection,
+			toSrs: this.coords.targetProjection
+		};
+		if (this.coords.perimeter === null) {
+			parameters.x = this.coords.x;
+			parameters.y = this.coords.y;
 		}
-
-		var sourceProjection = new Proj4js.Proj(this.coords.sourceProjection);
-		var targetProjection = new Proj4js.Proj(this.coords.targetProjection);
-		var coords           = new Proj4js.Point(this.coords.x,this.coords.y);
-
-		Proj4js.transform(sourceProjection,targetProjection,coords);
-
-		console.log('coords before transformation: %s/%s',this.coords.x,this.coords.y);
-		this.coords.x = coords.x;
-		this.coords.y = coords.y;
-		console.log('coords after transformation: %s/%s',this.coords.x,this.coords.y);
-	}
+		else {
+			parameters.bbox = (
+				parseFloat(this.coords.x) - parseFloat(this.coords.perimeter)
+				) + "," + (
+				parseFloat(this.coords.y) - parseFloat(this.coords.perimeter)
+				) + "," + (
+				parseFloat(this.coords.x) + parseFloat(this.coords.perimeter)
+				) + "," + (
+				parseFloat(this.coords.y) + parseFloat(this.coords.perimeter));
+		}
+		var req = new Mapbender.Ajax.Request({
+			url: "../php/mod_coordsLookup_server.php",
+			method: "transform",
+			parameters: parameters,
+			callback: function (obj, success, message) {
+				if (!success) {
+					new Mapbender.Exception(message);
+					return;
+				}
+				
+				var map = Mapbender.modules[options.target];
+				
+				if (obj.points) {
+					
+					if (obj.points.length === 1) {
+						map.setCenter(new Point(
+							obj.points[0].x,
+							obj.points[0].y
+						));
+					}
+					else if (obj.points.length === 2) {
+						var newExtent = new Extent(
+							obj.points[0].x,
+							obj.points[0].y,
+							obj.points[1].x,
+							obj.points[1].y
+						);
+						map.calculateExtent(newExtent);
+						map.setMapRequest();
+						
+					}
+				}
+			} 
+		});
+		req.send();
+	};
 	
 	this.buildForm();
 	this.initForm();

Added: trunk/mapbender/http/php/mod_coordsLookup_server.php
===================================================================
--- trunk/mapbender/http/php/mod_coordsLookup_server.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_coordsLookup_server.php	2009-09-01 13:44:44 UTC (rev 4584)
@@ -0,0 +1,139 @@
+<?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($_POST);
+
+function transform ($x, $y, $oldEPSG, $newEPSG) {
+	if (is_null($x) || !is_numeric($x) || 
+		is_null($y) || !is_numeric($y) ||
+		is_null($oldEPSG) || !is_numeric($oldEPSG) ||
+		is_null($newEPSG) || !is_numeric($newEPSG)) {
+		return null;
+	}
+	if(SYS_DBTYPE=='pgsql'){
+		$con = db_connect(DBSERVER, OWNER, PW);
+		$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$x." ".$y.")',".$oldEPSG."),".$newEPSG.")) as minx";
+		$resMinx = db_query($sqlMinx);
+		$minx = floatval(db_result($resMinx,0,"minx"));
+		
+		$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$x." ".$y.")',".$oldEPSG."),".$newEPSG.")) as miny";
+		$resMiny = db_query($sqlMiny);
+		$miny = floatval(db_result($resMiny,0,"miny"));
+		
+	}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(".$x." ".$y.")',".$oldEPSG."),".$newEPSG.")) as minx";
+		$resMinx = pg_query($con,$sqlMinx);
+		$minx = floatval(pg_fetch_result($resMinx,0,"minx"));
+		
+		$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$x." ".$y.")',".$oldEPSG."),".$newEPSG.")) as miny";
+		$resMiny = pg_query($con,$sqlMiny);
+		$miny = floatval(pg_fetch_result($resMiny,0,"miny"));
+	}
+	return array("x" => $minx, "y" => $miny);
+	
+}
+
+switch ($ajaxResponse->getMethod()) {
+	case "transform" :
+		if (!Mapbender::postgisAvailable()) {
+			$ajaxResponse->setSuccess(false);
+			$ajaxResponse->setMessage(_mb("PostGIS is not available. Please contact the administrator."));
+			$ajaxResponse->send();
+		}
+
+		$fromSrs = $ajaxResponse->getParameter("fromSrs");
+		$toSrs = $ajaxResponse->getParameter("toSrs");
+		$x = $ajaxResponse->getParameter("x");
+		$y = $ajaxResponse->getParameter("y");
+		$bboxStr = $ajaxResponse->getParameter("bbox");
+		$bbox = explode(",", $bboxStr);
+		$response = null;
+
+		$oldEPSG = preg_replace("/EPSG:/","", $fromSrs);
+		$newEPSG = preg_replace("/EPSG:/","", $toSrs);
+		
+		if (!is_null($bbox) && is_array($bbox) && count($bbox) === 4) {
+
+			$response = array(
+				"newSrs" => $toSrs,
+				"points" => array()
+			);
+			for ($i = 0; $i < count($bbox); $i+=2) {
+				$pt = transform(
+					floatval($bbox[$i]), 
+					floatval($bbox[$i+1]), 
+					$oldEPSG, 
+					$newEPSG
+				);
+		
+				if (!is_null($pt)) {
+					$response["points"][]= array(
+						"x" => $pt["x"],
+						"y" => $pt["y"]
+					);
+				}
+				else {
+					$response = null;
+					break;
+				}
+			}
+			
+		}	 
+		else {
+			
+			$pt = transform($x, $y, $oldEPSG, $newEPSG);
+	
+			if (!is_null($pt)) {
+				$response = array(
+					"newSrs" => $toSrs,
+					"points" => array(array(
+						"x" => $pt["x"],
+						"y" => $pt["y"]
+					))
+				);
+			}
+		}
+		
+		if (is_null($response)) {
+			$ajaxResponse->setSuccess(false);
+			$ajaxResponse->setMessage(_mb("An unknown error occured."));
+			$ajaxResponse->send();
+		}
+		else {
+			$ajaxResponse->setSuccess(true);
+			$ajaxResponse->setResult($response);
+		}
+		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