[Mapbender-commits] r5366 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Jan 20 08:01:56 EST 2010
Author: christoph
Date: 2010-01-20 08:01:56 -0500 (Wed, 20 Jan 2010)
New Revision: 5366
Modified:
trunk/mapbender/http/javascripts/mod_changeEPSG.js
Log:
Modified: trunk/mapbender/http/javascripts/mod_changeEPSG.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_changeEPSG.js 2010-01-20 13:01:35 UTC (rev 5365)
+++ trunk/mapbender/http/javascripts/mod_changeEPSG.js 2010-01-20 13:01:56 UTC (rev 5366)
@@ -37,233 +37,214 @@
* http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
*/
-var that = this;
-var exists = false;
+var $changeEpsg = $(this);
-eventAfterMapRequest.register(function () {
- $("#"+options.id+" option").each(function () {
- if (this.value == mb_mapObj[0].epsg) {
- isEPSG = true;
- $(this).attr("selected", "selected");
- }
- });
-});
-
-$(this).change(function () {
- var srsValue = $("#"+options.id).get(0).value;
+$changeEpsg.change(function () {
+ var srsValue = this.value;
if (srsValue === "") {
return;
}
- Mapbender.modules[options.id].setSrs({
- srs: srsValue
- });
+ $changeEpsg.mapbender(function () {
+ this.setSrs(srsValue);
+ });
});
var ChangeEpsg = function () {
- /**
- * Method: setSrs
- *
- * Description:
- * Sets the SRS for all maps and WMS in the current application.
- * The new bounding boxes are calculated with PostGIS!
- * After this, the maps are immediately requested in the new SRS.
- *
- * Parameters:
- * options.srs - (String) An SRS identifier, for example "EPSG:4326"
- * options.callback - (Function) A callback function. Should include the
- */
- this.setSrs = function (options) {
- var srsValue;
- if (typeof options === "object" && typeof options.srs === "string") {
- srsValue = options.srs;
- }
- if (typeof srsValue === "undefined") {
- new Mb_exception("setSrs: must specify an SRS.");
- return;
- }
- var recalculateExtentOnly;
- if (typeof options === "object" && typeof options.recalculateExtentOnly === "object") {
- recalculateExtentOnly = options.recalculateExtentOnly;
- if (typeof recalculateExtentOnly.target !== "string") {
- new Mb_exception("setSrs: must specify a target if recalculateExtentOnly is set.");
- return;
- }
- if (typeof recalculateExtentOnly.extent !== "object") {
- new Mb_exception("setSrs: must specify an extent if recalculateExtentOnly is set.");
- return;
- }
- }
+ var compileSrsArray = function () {
+
var srsArray = [];
- if (recalculateExtentOnly) {
- recalculateExtentOnly.map = Mapbender.modules[recalculateExtentOnly.target];
- if (typeof recalculateExtentOnly.map !== "object" || recalculateExtentOnly.map === null) {
- new Mb_exception("setSrs: invalid target set for recalculateExtentOnly.");
- return;
- }
- var currentSrs = {
- "frameName": recalculateExtentOnly.map.elementName,
- "epsg": srsValue,
- "extent": recalculateExtentOnly.extent.toString(),
- "width": recalculateExtentOnly.map.width,
- "height": recalculateExtentOnly.map.height
- };
- srsArray.push(currentSrs);
- }
- //
- // calculate extents for all maps...
- //
- else {
- 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.toString(),
- "width": mb_mapObj[i].width,
- "height": mb_mapObj[i].height
- };
- srsArray.push(currentSrs);
- }
- }
- //
- // ... and all WMS.
- //
- if (!recalculateExtentOnly) {
- for (var i = 0; i < wms.length; i++) {
- var ext = wms[i].getBoundingBoxBySrs(mb_mapObj[0].epsg);
+ var wmsArray = [];
+
+ // this is kind of inconsistent...for WMS, only the new extent of
+ // the FIRST main map is calculated
+ var mainMap = $(":mainMaps").eq(0).mapbender();
+
+ $("div:maps").mapbender(function () {
+ srsArray.push({
+ frameName: this.elementName,
+ epsg: this.epsg,
+ extent: this.extent.toString(),
+ width: this.width,
+ height: this.height
+ });
+
+ for (var i = 0; i < this.wms.length; i++) {
+ var wms = this.wms[i];
+ // unique entries only
+ if ($.inArray(wms.wms_id, wmsArray) !== -1) {
+ continue;
+ }
+ // only wms with bounding box in current SRS
+ var ext = wms.getBoundingBoxBySrs(this.epsg);
if (ext === null) {
continue;
}
- var currentSrs = {
- "wms" : wms[i].wms_id,
- "epsg" : mb_mapObj[0].epsg,
- "extent" : ext.toString(),
- "width" : mb_mapObj[0].width,
- "height" : mb_mapObj[0].height
- };
- srsArray.push(currentSrs);
+
+ srsArray.push({
+ wms: wms.wms_id,
+ epsg: mainMap.epsg,
+ extent: ext.toString(),
+ width: mainMap.width,
+ height: mainMap.height
+ });
+ wmsArray.push(wms.wms_id);
}
-
- }
-
- //
- // perform transformation
- //
- var req = new Mapbender.Ajax.Request({
- url: "../php/mod_changeEPSG_server.php",
- method: "changeEpsg",
- parameters: {
- srs: srsArray,
- newSrs: recalculateExtentOnly ? recalculateExtentOnly.map.epsg : srsValue
- },
- callback: function (obj, success, message) {
- if (!success) {
- new Mapbender.Exception(message);
- return;
- }
+ });
+ return srsArray;
+ };
+
+ var setSrsCallback = function (obj, success, message) {
+ if (!success) {
+ new Mapbender.Exception(message);
+ return;
+ }
+
+ var newExtent = obj;
+ var mapObjNames = [];
+ var myTarget = options.target[0];
+ var exists = false;
+
+
+ var i, j;
+ for (i = 0; i < newExtent.length; i++) {
+ if (newExtent[i].frameName) {
+ mapObjNames.push("#" + newExtent[i].frameName);
+ }
+ }
+
+ for (i = 0; i < newExtent.length; i++) {
+ if (newExtent[i].wms) {
+ // global wms object is deprecated.
+ // this loop can be removed once the
+ // wms object has been removed.
+ // redundant.
- var newExtent = obj;
- var mapObjNames = [];
- for(var i = 0; i < newExtent.length; i++) {
- if (newExtent[i].frameName) {
- mapObjNames.push(newExtent[i].frameName);
+ for (j = 0; j < wms.length; j++) {
+ if (wms[j].wms_id == newExtent[i].wms) {
+ wms[j].setBoundingBoxBySrs(
+ newExtent[i].newSrs,
+ new Extent(
+ parseFloat(newExtent[i].minx),
+ parseFloat(newExtent[i].miny),
+ parseFloat(newExtent[i].maxx),
+ parseFloat(newExtent[i].maxy)
+ )
+ );
}
}
- for (var i = 0; i < newExtent.length; i++) {
- if (newExtent[i].wms && !recalculateExtentOnly) {
- for (var j = 0; j < wms.length; j++) {
- if (parseInt(wms[j].wms_id, 10) === parseInt(newExtent[i].wms, 10)) {
- wms[j].setBoundingBoxBySrs(
- newExtent[i].newSrs,
- new Extent(
- parseFloat(newExtent[i].minx),
- parseFloat(newExtent[i].miny),
- parseFloat(newExtent[i].maxx),
- parseFloat(newExtent[i].maxy)
- )
- );
-
- for (var k = 0; k < mapObjNames.length; k++) {
-
- var map = getMapObjByName(mapObjNames[k]);
- map.wms[j].setBoundingBoxBySrs(
- newExtent[i].newSrs,
- new Extent(
- parseFloat(newExtent[i].minx),
- parseFloat(newExtent[i].miny),
- parseFloat(newExtent[i].maxx),
- parseFloat(newExtent[i].maxy)
- )
- );
- }
- break;
- }
- }
- continue;
- }
-
- //
- // use the previous extent of the overview
- //
- if(!recalculateExtentOnly && newExtent[i].frameName == options.target){
-
- var map = Mapbender.modules[options.target];
-
- var goback = false;
- for (var ii = 0; ii < map.mb_MapHistoryObj.length; ii++) {
- if (map.mb_MapHistoryObj[ii].epsg == newExtent[i].newSrs) {
- exists = ii;
- goback = true;
- }
- }
-
- if (goback) {
- map.setSrs({
- srs: newExtent[i].newSrs,
- extent: map.mb_MapHistoryObj[exists].extent,
- displayWarning: false
- });
- }
- else{
- map.setSrs({
- srs: newExtent[i].newSrs,
- extent: new Mapbender.Extent(
- parseFloat(newExtent[i].minx),
+ $(mapObjNames.join(",")).mapbender(function(){
+ for (j = 0; j < this.wms.length; j++) {
+ if (this.wms[j].wms_id == newExtent[i].wms) {
+ this.wms[j].setBoundingBoxBySrs(
+ newExtent[i].newSrs,
+ new Extent(
+ parseFloat(newExtent[i].minx),
parseFloat(newExtent[i].miny),
- parseFloat(newExtent[i].maxx),
+ parseFloat(newExtent[i].maxx),
parseFloat(newExtent[i].maxy)
- ),
- displayWarning: false
- });
+ )
+ );
}
+ break;
}
- else {
- var map = Mapbender.modules[newExtent[i].frameName];
- map.setSrs({
- srs: newExtent[i].newSrs,
- extent: new Mapbender.Extent(
- parseFloat(newExtent[i].minx),
- parseFloat(newExtent[i].miny),
- parseFloat(newExtent[i].maxx),
- parseFloat(newExtent[i].maxy)
- ),
- displayWarning: true
- });
+ });
+ }
+ //
+ // Overview map
+ //
+ if (newExtent[i].frameName === myTarget){
+ var map = $("#" + myTarget).mapbender();
+
+ for (var ii = 0; ii < map.mb_MapHistoryObj.length; ii++) {
+ if (map.mb_MapHistoryObj[ii].epsg == newExtent[i].newSrs) {
+ exists = ii;
+ var goback = true;
}
}
- if (typeof options.callback === "function") {
- options.callback();
+
+ if (goback) {
+ var extArray = map.mb_MapHistoryObj[exists].extent.split(",");
+ var newExt = new Extent(
+ parseFloat(extArray[0]),
+ parseFloat(extArray[1]),
+ parseFloat(extArray[2]),
+ parseFloat(extArray[3])
+ );
+ map.setSrs({
+ srs: newExtent[i].newSrs,
+ extent: newExt,
+ displayWarning: false
+ });
}
- for (var i = 0; i < mb_mapObj.length; i++) {
- mb_mapObj[i].setMapRequest();
+ else{
+ map.setSrs({
+ srs: newExtent[i].newSrs,
+ extent: new Extent(
+ parseFloat(newExtent[i].minx),
+ parseFloat(newExtent[i].miny),
+ parseFloat(newExtent[i].maxx),
+ parseFloat(newExtent[i].maxy)
+ ),
+ displayWarning: false
+ });
}
+ }
+ //
+ // Main maps
+ //
+ else {
+ $("#" + newExtent[i].frameName).mapbender(function () {
+ this.setSrs({
+ srs: newExtent[i].newSrs,
+ extent: new Extent(
+ parseFloat(newExtent[i].minx),
+ parseFloat(newExtent[i].miny),
+ parseFloat(newExtent[i].maxx),
+ parseFloat(newExtent[i].maxy)
+ ),
+ displayWarning: true
+ });
+ });
+ }
+ }
+ setTimeout(function () {
+ $(":maps").mapbender(function () {
+ this.setMapRequest();
+ });
+ }, 200);
+ };
- }
+ this.setSrs = function (val) {
+ var srsArray = compileSrsArray();
+ var req = new Mapbender.Ajax.Request({
+ method: "changeEpsg",
+ url: "../php/mod_changeEPSG_server.php",
+ callback: setSrsCallback,
+ parameters:{
+ srs: srsArray,
+ newSrs: val
+ }
});
req.send();
};
-};
-Mapbender.modules[options.id] = $.extend(new ChangeEpsg(), Mapbender.modules[options.id]);
+ // update epsg in select box after any map request
+ Mapbender.events.init.register(function () {
+ $("div:mainMaps").mapbender(function () {
+ var map = this;
+ map.events.afterMapRequest.register(function () {
+ $changeEpsg.children("option").each(function () {
+ if (this.value === map.epsg) {
+ $(this).attr("selected", "selected");
+ }
+ });
+ });
+
+ });
+ });
+};
+
+$changeEpsg.mapbender(new ChangeEpsg());
More information about the Mapbender_commits
mailing list