[Mapbender-commits] r6088 - in trunk/mapbender/http: javascripts php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu May 6 09:30:51 EDT 2010
Author: christoph
Date: 2010-05-06 09:30:51 -0400 (Thu, 06 May 2010)
New Revision: 6088
Modified:
trunk/mapbender/http/javascripts/mod_changeEPSG.js
trunk/mapbender/http/php/mod_changeEPSG_server.php
Log:
added ajaxChange
removed MySQL
improved error handling
Modified: trunk/mapbender/http/javascripts/mod_changeEPSG.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_changeEPSG.js 2010-05-06 10:19:45 UTC (rev 6087)
+++ trunk/mapbender/http/javascripts/mod_changeEPSG.js 2010-05-06 13:30:51 UTC (rev 6088)
@@ -37,11 +37,76 @@
* http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
*/
+(function ($) {
+ $.fn.ajaxChange = function () {
+ var args = arguments;
+ this.each(function () {
+ if (this.tagName.toUpperCase() !== "SELECT") return;
+
+ var $this = $(this);
+
+ // initialization
+ if (args.length >= 1 && typeof args[0] === "function") {
+ var f = args[0];
+
+ var options = {};
+ if (args.length >= 2 && typeof args[1] === "object") {
+ options = args[1];
+ }
+ options = $.extend({
+ disable: true,
+ undo: true
+ }, options);
+ $this
+ .data("ajaxChangeDisable", options.disable)
+ .data("ajaxChangeUndo", options.undo)
+ .data("ajaxChangeSelectedIndex", null)
+ .change(function () {
+ if ($this.data("ajaxChangeDisable") === true) {
+ $this.attr("disabled", "disabled");
+ }
+ f.apply(this, arguments);
+ })
+ .mousedown(function () {
+ if ($this.data("ajaxChangeSelectedIndex") === null
+ && $this.data("ajaxChangeUndo")
+ ) {
+ $this.data("ajaxChangeSelectedIndex", this.selectedIndex);
+ }
+ });
+ }
+ // control
+ else if (args.length >= 1 && typeof args[0] === "string") {
+ var command = args[0];
+ switch (command) {
+ case "abort":
+ if ($this.data("ajaxChangeDisable") === true) {
+ $this.removeAttr("disabled");
+ }
+ if ($this.data("ajaxChangeUndo")) {
+ this.selectedIndex = $this.data("ajaxChangeSelectedIndex");
+ $this.data("ajaxChangeSelectedIndex", null);
+ }
+ break;
+ case "done":
+ if ($this.data("ajaxChangeDisable") === true) {
+ $this.removeAttr("disabled");
+ }
+ if ($this.data("ajaxChangeUndo")) {
+ $this.data("ajaxChangeSelectedIndex", null);
+ }
+ break;
+ }
+ }
+ });
+ };
+}(jQuery));
+
var $changeEpsg = $(this);
-
-$changeEpsg.change(function () {
+$changeEpsg.ajaxChange(function () {
var srsValue = this.value;
if (srsValue === "") {
+ $(this).ajaxChange("abort");
return;
}
$changeEpsg.mapbender(function () {
@@ -96,9 +161,11 @@
var setSrsCallback = function (obj, success, message) {
if (!success) {
+ $changeEpsg.ajaxChange("abort");
new Mapbender.Exception(message);
return;
}
+ $changeEpsg.ajaxChange("done");
var newExtent = obj;
var mapObjNames = [];
Modified: trunk/mapbender/http/php/mod_changeEPSG_server.php
===================================================================
--- trunk/mapbender/http/php/mod_changeEPSG_server.php 2010-05-06 10:19:45 UTC (rev 6087)
+++ trunk/mapbender/http/php/mod_changeEPSG_server.php 2010-05-06 13:30:51 UTC (rev 6088)
@@ -48,43 +48,29 @@
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 = floatval(db_result($resMinx,0,"minx"));
-
- $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny";
- $resMiny = db_query($sqlMiny);
- $miny = floatval(db_result($resMiny,0,"miny"));
-
- $sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx";
- $resMaxx = db_query($sqlMaxx);
- $maxx = floatval(db_result($resMaxx,0,"maxx"));
-
- $sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy";
- $resMaxy = db_query($sqlMaxy);
- $maxy = floatval(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 = floatval(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 = floatval(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 = floatval(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 = floatval(pg_fetch_result($resMaxy,0,"maxy"));
+ $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 = floatval(db_result($resMinx,0,"minx"));
+
+ $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny";
+ $resMiny = db_query($sqlMiny);
+ $miny = floatval(db_result($resMiny,0,"miny"));
+
+ $sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx";
+ $resMaxx = db_query($sqlMaxx);
+ $maxx = floatval(db_result($resMaxx,0,"maxx"));
+
+ $sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy";
+ $resMaxy = db_query($sqlMaxy);
+ $maxy = floatval(db_result($resMaxy,0,"maxy"));
+
+ if (!$resMinx || !$resMiny || !$resMaxx || !$resMaxy) {
+ $ajaxResponse->setSuccess(false);
+ $ajaxResponse->setMessage(_mb("The coordinates could not be projected."));
+ $ajaxResponse->send();
}
+
$extenty = $maxy - $miny;
$extentx = $maxx - $minx;
$relation_px_x = $currentEpsg->width / $currentEpsg->height;
More information about the Mapbender_commits
mailing list