[Mapbender-commits] r4969 - in trunk/mapbender: http/javascripts lib
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Nov 9 12:08:22 EST 2009
Author: christoph
Date: 2009-11-09 12:08:22 -0500 (Mon, 09 Nov 2009)
New Revision: 4969
Added:
trunk/mapbender/lib/history.js
Modified:
trunk/mapbender/http/javascripts/map_obj.js
trunk/mapbender/http/javascripts/mod_box1.js
trunk/mapbender/lib/extent.js
Log:
Modified: trunk/mapbender/http/javascripts/map_obj.js
===================================================================
--- trunk/mapbender/http/javascripts/map_obj.js 2009-11-09 17:07:53 UTC (rev 4968)
+++ trunk/mapbender/http/javascripts/map_obj.js 2009-11-09 17:08:22 UTC (rev 4969)
@@ -1,16 +1,15 @@
/**
* Package: Map
- *
+ *
* Description:
* This is the central module for displaying the composite map overlay.
- *
+ *
* Help:
* http://www.mapbender.org/Mapframe
*/
-
/**
* Constructor: Map
- *
+ *
* Parameters:
* frameName - *[deprecated]* the name of the iframe, for backwards
* compatibility only, use "" for maps in DIVs
@@ -20,1241 +19,1381 @@
* wms_index - restrict the WMS in the map to the WMS with this ID
* (useful for overview maps)
*/
-Mapbender.Map = function (frameName, elementName, width, height, wms_index) {
+Mapbender.Map = function(frameName, elementName, width, height, wms_index){
- var mapMsgObj;
-
- eventLocalize.register(function () {
- localizeMap();
+ var mapMsgObj;
+
+ eventLocalize.register(function(){
+ localizeMap();
+ });
+
+ eventInit.register(function(){
+ localizeMap();
+ });
+
+ var localizeMap = function(){
+ $.post("../php/mod_map_messages.php", function(obj, status){
+ mapMsgObj = eval('(' + obj + ')');
+ });
+ };
+
+ this.history = new Mapbender.History();
+ this.history.events.beforeAdd.register(function () {
+ for (var i = that.history.getCurrentIndex() + 1; i <= that.history.count(); i++) {
+ $("#" + that.elementName + "_request_" + i).remove();
+ }
});
+
+ /**
+ * Method: setExtent
+ *
+ * Description:
+ * set the extent of the wms
+ *
+ * Parameters:
+ * minx - x of south west
+ * miny - y of south west
+ * maxx - x of north east
+ * maxy - y of north east
+ */
+ this.setExtent = function(minx, miny, maxx, maxy){
+ if (typeof this.extent !== "undefined") {
+ this.oldExtent = new Extent(this.extent);
- eventInit.register(function () {
- localizeMap();
- });
-
- var localizeMap = function () {
- $.post("../php/mod_map_messages.php", function(obj, status){
- mapMsgObj = eval('(' + obj + ')');
- });
- };
-
- /**
- * Method: setExtent
- *
- * Description:
- * set the extent of the wms
- *
- * Parameters:
- * minx - x of south west
- * miny - y of south west
- * maxx - x of north east
- * maxy - y of north east
- */
- this.setExtent = function(minx, miny, maxx, maxy){
- if (!this.extent) {
- this.extent = new Mapbender.Extent(minx, miny, maxx, maxy);
- }
- else {
- this.extent.set(new Point(minx, miny), new Point(maxx, maxy));
- }
- };
-
-/*
- this.restrictedExtent = function (extent) {
- this.restrictedExtent = extent;
- };
-*/
- /**
- * get the width of the mapObj
- *
- * @member Map
- * @return width of the mapObj
- * @type integer
- */
- this.getWidth = function(){
- return parseInt(this.width, 10);
- };
-
- /**
- * set the width of the mapObj
- *
- * @param {integer} widht the width of the mapObj
- */
- this.setWidth = function(width){
- this.width = parseInt(width, 10);
-
- //apply new width
- if(this.frameName){
- document.getElementById(this.frameName).style.width = this.width;
- }
- var domElement = this.getDomElement();
- domElement.style.width = this.width;
- };
-
- /**
- * get the height of the mapObj
- *
- * @member Map
- * @return width of the mapObj
- * @type integer
- */
- this.getHeight = function(){
- return parseInt(this.height, 10);
- };
-
- this.getDomElement = function(){
- if(this.frameName){
- return window.frames[this.frameName].document.getElementById(this.elementName);
- }
- return document.getElementById(this.elementName);
- };
-
- /**
- * set the height of the mapObj
- *
- * @param {integer} height the height of the mapObj
- */
- this.setHeight = function(height){
- this.height = parseInt(height, 10);
- //apply new height
- if(this.frameName){
- document.getElementById(this.frameName).style.height = this.height;
- }
- var domElement = this.getDomElement();
- domElement.style.height = this.height;
- };
-
- this.getMousePosition = function (e) {
- var clickX, clickY;
-
- if ($.browser.msie) {
- clickX = parseInt(window.event.offsetX, 10);
- clickY = parseInt(window.event.offsetY, 10);
- }
- else{
- clickX = e.pageX;
- clickY = e.pageY;
- }
-
- var currentPos = null;
- if (this.type == "DIV" && !$.browser.msie) {
- var mapDomElement = this.getDomElement();
- currentPos = new Point(
- clickX - parseInt(mapDomElement.style.left, 10),
- clickY - parseInt(mapDomElement.style.top, 10)
- );
- // if the mouse position is not on top of the map, return null
- if (currentPos.x < 0 || currentPos.x > this.width ||
- currentPos.y < 0 || currentPos.y > this.height) {
- return null;
+ // pixel coordinates of new extent in old extent
+ if (arguments.length === 1) {
+ var oldpixll = this.convertRealToPixel(minx.min);
+ var oldpixur = this.convertRealToPixel(minx.max);
+ this.oldExtentPix = new Extent(oldpixll.x, oldpixll.y, oldpixur.x, oldpixur.y);
}
- }
- else {
- currentPos = new Point(
- clickX,
- clickY
- );
-
- // sometimes there are divs within the map (like copyright)
- // then offsetX and offsetY are not valid.
- if (window.event.srcElement.tagName.toUpperCase() !== "IMG") {
- var top = parseInt(window.event.srcElement.style.top, 10);
- var left = parseInt(window.event.srcElement.style.left, 10);
- currentPos = currentPos.plus(new Point(left,top));
+ else if (arguments.length === 4) {
+ var oldpixll = this.convertRealToPixel(new Point(parseFloat(minx), parseFloat(miny)));
+ var oldpixur = this.convertRealToPixel(new Point(parseFloat(maxx), parseFloat(maxy)));
+ this.oldExtentPix = new Extent(oldpixll.x, oldpixll.y, oldpixur.x, oldpixur.y);
}
-
- }
- return currentPos;
- };
-
- /**
- * converts the extent of the mapobject so that the maximum extent will be displayed
- */
- this.calculateExtent = function(ext){
- var relation_px_x = this.getWidth() / this.getHeight();
- var relation_px_y = this.getHeight() / this.getWidth();
- var relation_bbox_x = ext.extentx / ext.extenty;
- if (relation_bbox_x <= relation_px_x) {
- ext.minx = ext.centerx - relation_px_x * ext.extenty / 2;
- ext.maxx = ext.centerx + relation_px_x * ext.extenty / 2;
- }
- if (relation_bbox_x > relation_px_x) {
- ext.miny = ext.centery - relation_px_y * ext.extentx / 2;
- ext.maxy = ext.centery + relation_px_y * ext.extentx / 2;
- }
-
- // Check if ext is within restricted extent
- // If not, calculate a new extent according
- // to restricted extent.
- /*
- if ( this.restrictedExtent ) {
- if ( ext.minx < this.restrictedExtent.minx ) {
- ext.minx = this.restrictedExtent.minx;
- ext.maxx = ext.minx + (relation_px_x * ext.extenty);
- }
- if ( ext.miny < this.restrictedExtent.miny ) {
- ext.miny = this.restrictedExtent.miny;
- ext.maxy = ext.miny + (relation_px_y * ext.extentx);
- }
- if ( ext.maxx > this.restrictedExtent.maxx ) {
- ext.maxx = this.restrictedExtent.maxx;
- ext.minx = ext.maxx - (relation_px_x * ext.extenty);
- }
- if ( ext.maxy > this.restrictedExtent.maxy ) {
- ext.maxy = this.restrictedExtent.maxy;
- ext.miny = ext.maxy - (relation_px_y * ext.extentx);
- }
- }
- */
- this.setExtent(ext.minx, ext.miny, ext.maxx, ext.maxy);
- return ext;
- };
- var ignoredWms;
-
- var undoIgnoreWms = function () {
- ignoredWms = [];
- };
-
- var ignoreWms = function (wms) {
- ignoredWms.push({
- id: wms.wms_id,
- title: wms.wms_title
- });
- };
-
- var isIgnoredWms = function (wms) {
- for (var j = 0; j < ignoredWms.length; j++) {
- if (ignoredWms[j].id === wms.wms_id) {
- return true;
- }
+ }
+ else {
+ this.oldExtentPix = new Extent(0, this.height, this.width, 0);
}
- return false;
- };
-
- var getIgnoredWms = function () {
- return ignoredWms;
- };
-
- this.setSrs = function (options) {
- if (typeof options.srs !== "string") {
- new Mb_exception("Mapbender.Map.setSrs: SRS is not a string: " + options.srs);
- return null;
- }
- if (!options.extent || options.extent.constructor !== Mapbender.Extent) {
- new Mb_exception("Mapbender.Map.setSrs: Extent is not a Mapbender.Extent: " + options.extent);
- return null;
- }
- if (this.epsg !== options.srs) {
- // check which WMS support the new SRS
- undoIgnoreWms();
- for (var i = 0; i < this.wms.length; i++) {
- var found = false;
- for (var j = 0; j < this.wms[i].gui_epsg.length; j++) {
- if (options.srs === this.wms[i].gui_epsg[j] && this.wms[i].gui_epsg_supported[j]) {
- found = true;
- break;
- }
- }
- if (!found) {
- ignoreWms(this.wms[i]);
- }
- }
- var ignoredWms = getIgnoredWms();
-
- // ...and optionally display a message
- if (options.displayWarning && ignoredWms.length > 0) {
-
- var msg = mapMsgObj.srsNotSupported + ": <br><br>";
-
- for (var key in ignoredWms) {
- msg += "<b>" + ignoredWms[key].title + "</b><br>";
- }
- try {
- Mapbender.modules.dialogManager.openDialog({
- content: msg,
- modal: false,
- effectShow: 'puff'
- });
- }
- catch (e) {
- new Mb_warning(e.message + ". " + msg);
- }
- }
-
- // actually set the new values and return extent
- this.epsg = options.srs;
-
- }
- return this.calculateExtent(options.extent);
- };
+
- this.setWms = function (wms_index) {
- this.wms = [];
- var index = 0;
- for (var i = 0; i < wms.length; i++) {
- var isValidWms = (wms_index === null) || (wms_index == i);
- if (isValidWms) {
- // MAJOR CHANGE!
- // formerly, this was a reference!
- // Now, this is a copy!
- // Each map object has its own set of WMS.
- // I expect some things to break :-)
- this.wms[index] = cloneObject(wms[i]);
- this.wms[index].mapURL = false;
- index++;
+ if (arguments.length === 1) {
+ this.extent = arguments[0];
+ }
+ else if (arguments.length === 4) {
+ if (!this.extent) {
+ this.extent = new Mapbender.Extent(arguments[0], arguments[1], arguments[2], arguments[3]);
+ }
+ else {
+ this.extent.set(new Point(arguments[0], arguments[1]), new Point(arguments[2], arguments[3]));
+ }
+ }
+ };
+
+ /*
+ this.restrictedExtent = function (extent) {
+ this.restrictedExtent = extent;
+ };
+ */
+ /**
+ * get the width of the mapObj
+ *
+ * @member Map
+ * @return width of the mapObj
+ * @type integer
+ */
+ this.getWidth = function(){
+ return parseInt(this.width, 10);
+ };
+
+ /**
+ * set the width of the mapObj
+ *
+ * @param {integer} widht the width of the mapObj
+ */
+ this.setWidth = function(width){
+ this.width = parseInt(width, 10);
+
+ //apply new width
+ if (this.frameName) {
+ document.getElementById(this.frameName).style.width = this.width;
+ }
+ var domElement = this.getDomElement();
+ domElement.style.width = this.width;
+ };
+
+ /**
+ * get the height of the mapObj
+ *
+ * @member Map
+ * @return width of the mapObj
+ * @type integer
+ */
+ this.getHeight = function(){
+ return parseInt(this.height, 10);
+ };
+
+ this.getDomElement = function(){
+ if (this.frameName) {
+ return window.frames[this.frameName].document.getElementById(this.elementName);
+ }
+ return document.getElementById(this.elementName);
+ };
+
+ /**
+ * set the height of the mapObj
+ *
+ * @param {integer} height the height of the mapObj
+ */
+ this.setHeight = function(height){
+ this.height = parseInt(height, 10);
+ //apply new height
+ if (this.frameName) {
+ document.getElementById(this.frameName).style.height = this.height;
+ }
+ var domElement = this.getDomElement();
+ domElement.style.height = this.height;
+ };
+
+ this.getMousePosition = function(e){
+ var clickX, clickY;
+
+ if ($.browser.msie) {
+ clickX = parseInt(window.event.offsetX, 10);
+ clickY = parseInt(window.event.offsetY, 10);
+ }
+ else {
+ clickX = e.pageX;
+ clickY = e.pageY;
+ }
+
+ var currentPos = null;
+ if (this.type == "DIV" && !$.browser.msie) {
+ var mapDomElement = this.getDomElement();
+ currentPos = new Point(clickX - parseInt(mapDomElement.style.left, 10), clickY - parseInt(mapDomElement.style.top, 10));
+ // if the mouse position is not on top of the map, return null
+ if (currentPos.x < 0 || currentPos.x > this.width ||
+ currentPos.y < 0 ||
+ currentPos.y > this.height) {
+ return null;
+ }
+ }
+ else {
+ currentPos = new Point(clickX, clickY);
+
+ // sometimes there are divs within the map (like copyright)
+ // then offsetX and offsetY are not valid.
+ if (window.event.srcElement.tagName.toUpperCase() !== "IMG") {
+ var top = parseInt(window.event.srcElement.style.top, 10);
+ var left = parseInt(window.event.srcElement.style.left, 10);
+ currentPos = currentPos.plus(new Point(left, top));
+ }
+
+ }
+ return currentPos;
+ };
+
+ /**
+ * converts the extent of the mapobject so that the maximum extent will be displayed
+ */
+ this.calculateExtent = function(ext){
+ var relation_px_x = this.getWidth() / this.getHeight();
+ var relation_px_y = this.getHeight() / this.getWidth();
+ var relation_bbox_x = ext.extentx / ext.extenty;
+ if (relation_bbox_x <= relation_px_x) {
+ ext.minx = ext.centerx - relation_px_x * ext.extenty / 2;
+ ext.maxx = ext.centerx + relation_px_x * ext.extenty / 2;
+ }
+ if (relation_bbox_x > relation_px_x) {
+ ext.miny = ext.centery - relation_px_y * ext.extentx / 2;
+ ext.maxy = ext.centery + relation_px_y * ext.extentx / 2;
+ }
+
+ // Check if ext is within restricted extent
+ // If not, calculate a new extent according
+ // to restricted extent.
+ /*
+ if ( this.restrictedExtent ) {
+ if ( ext.minx < this.restrictedExtent.minx ) {
+ ext.minx = this.restrictedExtent.minx;
+ ext.maxx = ext.minx + (relation_px_x * ext.extenty);
+ }
+ if ( ext.miny < this.restrictedExtent.miny ) {
+ ext.miny = this.restrictedExtent.miny;
+ ext.maxy = ext.miny + (relation_px_y * ext.extentx);
+ }
+ if ( ext.maxx > this.restrictedExtent.maxx ) {
+ ext.maxx = this.restrictedExtent.maxx;
+ ext.minx = ext.maxx - (relation_px_x * ext.extenty);
+ }
+ if ( ext.maxy > this.restrictedExtent.maxy ) {
+ ext.maxy = this.restrictedExtent.maxy;
+ ext.miny = ext.maxy - (relation_px_y * ext.extentx);
+ }
+ }
+ */
+ this.setExtent(ext.minx, ext.miny, ext.maxx, ext.maxy);
+ return ext;
+ };
+
+ var ignoredWms;
+
+ var undoIgnoreWms = function(){
+ ignoredWms = [];
+ };
+
+ var ignoreWms = function(wms){
+ ignoredWms.push({
+ id: wms.wms_id,
+ title: wms.wms_title
+ });
+ };
+
+ var isIgnoredWms = function(wms){
+ for (var j = 0; j < ignoredWms.length; j++) {
+ if (ignoredWms[j].id === wms.wms_id) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+ var getIgnoredWms = function(){
+ return ignoredWms;
+ };
+
+ this.setSrs = function(options){
+ if (typeof options.srs !== "string") {
+ new Mb_exception("Mapbender.Map.setSrs: SRS is not a string: " + options.srs);
+ return null;
+ }
+ if (!options.extent || options.extent.constructor !== Mapbender.Extent) {
+ new Mb_exception("Mapbender.Map.setSrs: Extent is not a Mapbender.Extent: " + options.extent);
+ return null;
+ }
+ if (this.epsg !== options.srs) {
+ // check which WMS support the new SRS
+ undoIgnoreWms();
+ for (var i = 0; i < this.wms.length; i++) {
+ var found = false;
+ for (var j = 0; j < this.wms[i].gui_epsg.length; j++) {
+ if (options.srs === this.wms[i].gui_epsg[j] && this.wms[i].gui_epsg_supported[j]) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ ignoreWms(this.wms[i]);
+ }
+ }
+ var ignoredWms = getIgnoredWms();
+
+ // ...and optionally display a message
+ if (options.displayWarning && ignoredWms.length > 0) {
+
+ var msg = mapMsgObj.srsNotSupported + ": <br><br>";
+
+ for (var key in ignoredWms) {
+ msg += "<b>" + ignoredWms[key].title + "</b><br>";
+ }
+ try {
+ Mapbender.modules.dialogManager.openDialog({
+ content: msg,
+ modal: false,
+ effectShow: 'puff'
+ });
+ }
+ catch (e) {
+ new Mb_warning(e.message + ". " + msg);
+ }
+ }
+
+ // actually set the new values and return extent
+ this.epsg = options.srs;
+
+ }
+ return this.calculateExtent(options.extent);
+ };
+
+ this.setWms = function(wms_index){
+ this.wms = [];
+ var index = 0;
+ for (var i = 0; i < wms.length; i++) {
+ var isValidWms = (wms_index === null) || (wms_index == i);
+ if (isValidWms) {
+ // MAJOR CHANGE!
+ // formerly, this was a reference!
+ // Now, this is a copy!
+ // Each map object has its own set of WMS.
+ // I expect some things to break :-)
+ this.wms[index] = cloneObject(wms[i]);
+ this.wms[index].mapURL = false;
+ index++;
+ }
+ }
+ };
+
+ this.initializeWms = function(){
+ var cnt_layers;
+ var cnt_querylayers;
+ var styles;
+ var layers;
+ var querylayers = "";
+ for (i = 0; i < this.wms.length; i++) {
+ cnt_layers = 0;
+ cnt_querylayers = 0;
+ styles = "";
+ layers = "";
+ querylayers = "";
+
+ for (var ii = 0; ii < this.wms[i].objLayer.length; ii++) {
+ // layer is visible and not root layer
+ if (this.wms[i].objLayer[ii].gui_layer_visible == 1 && ii > 0) {
+ if (cnt_layers > 0) {
+ layers += ",";
+ styles += ",";
+ }
+ layers += this.wms[i].objLayer[ii].layer_name;
+ styles += "";
+ cnt_layers++;
+ }
+ // layer is queryable and not root layer
+ if (this.wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii > 0) {
+ if (cnt_querylayers > 0) {
+ querylayers += ",";
+ }
+ querylayers += this.wms[i].objLayer[ii].layer_name;
+ cnt_querylayers++;
+ }
+ }
+ this.layers[i] = layers;
+ this.styles[i] = styles;
+ this.querylayers[i] = querylayers;
+ }
+ };
+ /**
+ * get the extent of the mapObj
+ *
+ * @member Map
+ * @return extent of the mapObj as commaseparated minx,minx,maxx,maxy
+ * @type string
+ */
+ this.getExtent = function(){
+ return this.extent.toString();
+ };
+
+ /**
+ * get the extent as minx, maxx, miny, maxy
+ *
+ * @return extent and additional informations of the mapObj
+ * @type Object
+ */
+ this.getExtentInfos = function(){
+ var c = this.extent.toString().split(",");
+ var ext = new Mapbender.Extent(c[0], c[1], c[2], c[3]);
+ return ext;
+ };
+
+ /**
+ * Sets the list of layers, styles and querylayers for a specified WMS
+ */
+ this.restateLayers = function(wms_id){
+ for (var i = 0; i < this.wms.length; i++) {
+ if (this.wms[i].wms_id == wms_id) {
+ var currentWms = this.wms[i];
+ var cnt_layers = 0;
+ var cnt_querylayers = 0;
+ var layers = "";
+ var styles = "";
+ var querylayers = "";
+ for (var ii = 0; ii < currentWms.objLayer.length; ii++) {
+ var currentLayer = currentWms.objLayer[ii];
+ if (currentLayer.gui_layer_visible == 1 && !currentLayer.has_childs) {
+ if (cnt_layers > 0) {
+ layers += ",";
+ styles += ",";
+ }
+ layers += currentLayer.layer_name;
+ styles += "";
+ cnt_layers++;
+ }
+ if (currentLayer.gui_layer_querylayer == 1 && !currentLayer.has_childs) {
+ if (cnt_querylayers > 0) {
+ querylayers += ",";
+ }
+ querylayers += currentLayer.layer_name;
+ cnt_querylayers++;
+ }
+ }
+ this.layers[i] = layers;
+ this.querylayers[i] = querylayers;
+ this.styles[i] = styles;
+ }
+ }
+ // this.setExtent(ext.minx,ext.miny,ext.maxx,ext.maxy);
+ };
+
+ /**
+ *
+ * @param {Object} direction
+ */
+ this.pan = function(direction){
+ var arrayBBox = this.getExtent().split(",");
+ var minx = parseFloat(arrayBBox[0]);
+ var miny = parseFloat(arrayBBox[1]);
+ var maxx = parseFloat(arrayBBox[2]);
+ var maxy = parseFloat(arrayBBox[3]);
+ var xtentx = maxx - minx;
+ var xtenty = maxy - miny;
+ var factor = 0.5;
+
+ switch (direction) {
+ case "NW":
+ minx -= (xtentx * factor);
+ maxx -= (xtentx * factor);
+ miny += (xtenty * factor);
+ maxy += (xtenty * factor);
+ break;
+ case "N":
+ miny += (xtenty * factor);
+ maxy += (xtenty * factor);
+ break;
+ case "NE":
+ minx += (xtentx * factor);
+ maxx += (xtentx * factor);
+ miny += (xtenty * factor);
+ maxy += (xtenty * factor);
+ break;
+ case "E":
+ minx += (xtentx * factor);
+ maxx += (xtentx * factor);
+ break;
+ case "SE":
+ minx += (xtentx * factor);
+ maxx += (xtentx * factor);
+ miny -= (xtenty * factor);
+ maxy -= (xtenty * factor);
+ break;
+ case "S":
+ miny -= (xtenty * factor);
+ maxy -= (xtenty * factor);
+ break;
+ case "SW":
+ minx -= (xtentx * factor);
+ maxx -= (xtentx * factor);
+ miny -= (xtenty * factor);
+ maxy -= (xtenty * factor);
+ break;
+ case "W":
+ minx -= (xtentx * factor);
+ maxx -= (xtentx * factor);
+ break;
+ }
+ this.setExtent(minx, miny, maxx, maxy);
+ // this.restrictedExtent;
+ this.setMapRequest();
+
+ };
+
+ this.setCenter = function(aPoint){
+ this.extent.set(aPoint);
+ this.calculateExtent(this.extent);
+ this.setMapRequest();
+ };
+
+ this.zoomFull = function(){
+
+ if (this.restrictedExtent) {
+ this.calculateExtent(this.restrictedExtent);
+ this.setMapRequest();
+ }
+ else {
+ for (var i = 0; i < this.wms[0].gui_epsg.length; i++) {
+ if (this.epsg == this.wms[0].gui_epsg[i]) {
+ var bbox_minx = parseFloat(this.wms[0].gui_minx[i]);
+ var bbox_miny = parseFloat(this.wms[0].gui_miny[i]);
+ var bbox_maxx = parseFloat(this.wms[0].gui_maxx[i]);
+ var bbox_maxy = parseFloat(this.wms[0].gui_maxy[i]);
+
+ var wmsExtent = new Mapbender.Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy);
+ this.calculateExtent(wmsExtent);
+ this.setMapRequest();
+ break;
+ }
+ }
+ }
+ };
+
+ /**
+ * zoom the map with a zoomfactor and optional to x,y coords
+ *
+ * @param {boolean} in_ in = true, out = false
+ * @param {float} factor the zoomfactor 1 equals 100%
+ * @param {float} x center to x-position
+ * @param {float} y center to y-position
+ */
+ this.zoom = function(in_, factor, x, y){
+ factor = parseFloat(factor);
+ if (!in_) {
+ factor = 1 / factor;
+ }
+
+ var extent = this.getExtentInfos();
+ var distx = extent.maxx - extent.minx;
+ var disty = extent.maxy - extent.miny;
+
+ if (typeof x === "object" && x.constructor === Mapbender.Point) {
+ y = x.y;
+ x = x.x;
+ }
+
+ if (x && y) {
+ var centerx = parseFloat(x);
+ var centery = parseFloat(y);
+ }
+ else {
+ var centerx = extent.minx + distx / 2;
+ var centery = extent.miny + disty / 2;
+ }
+
+ var new_distx = distx / factor;
+ var new_disty = disty / factor;
+ var minx = centerx - new_distx / 2;
+ var miny = centery - new_disty / 2;
+ var maxx = centerx + new_distx / 2;
+ var maxy = centery + new_disty / 2;
+ // Check if ext is within restricted extent
+ // If not, calculate a new extent according
+ // to restricted extent.
+ /*
+ var relation_px_x = this.getWidth() / this.getHeight();
+ var relation_px_y = this.getHeight() / this.getWidth();
+ if ( this.restrictedExtent ) {
+ if ( minx < this.restrictedExtent.minx ) {
+ minx = this.restrictedExtent.minx;
+ maxx = minx + (relation_px_x * new_disty);
+ }
+ if ( miny < this.restrictedExtent.miny ) {
+ miny = this.restrictedExtent.miny;
+ maxy = miny + (relation_px_y * new_distx);
+ }
+ if ( maxx > this.restrictedExtent.maxx ) {
+ maxx = this.restrictedExtent.maxx;
+ minx = maxx - (relation_px_x * new_distx);
+ }
+ if ( maxy > this.restrictedExtent.maxy ) {
+ maxy = this.restrictedExtent.maxy;
+ miny = maxy - (relation_px_y * new_disty);
+ }
+ }
+ */
+ this.setExtent(minx, miny, maxx, maxy);
+ this.setMapRequest();
+ };
+
+ var performUnknownCalculation = function(value){
+ return Math.pow(10, (Math.round(Math.log(value) /
+ Math.log(10))));
+ };
+
+ this.convertPixelToReal = function(aPoint){
+ var arrayBBox = this.getExtent().split(",");
+ var minX = parseFloat(arrayBBox[0]);
+ var minY = parseFloat(arrayBBox[1]);
+ var maxX = parseFloat(arrayBBox[2]);
+ var maxY = parseFloat(arrayBBox[3]);
+ var xtentx = maxX - minX;
+ var xtenty = maxY - minY;
+ var deltaX = xtentx / this.width;
+ var deltaY = xtenty / this.height;
+ var roundx, roundy;
+
+ if (deltaX > 0) {
+ roundx = 1 / performUnknownCalculation(deltaX);
+ }
+ else {
+ roundx = performUnknownCalculation(deltaX);
+ }
+ if (deltaY > 0) {
+ roundy = 1 / performUnknownCalculation(deltaY);
+ }
+ else {
+ roundy = performUnknownCalculation(deltaY);
+ }
+ var posX = parseFloat(minX + (aPoint.x / this.width) * xtentx);
+ var posY = parseFloat(maxY - (aPoint.y / this.height) * xtenty);
+ posX = Math.round(posX * roundx) / roundx;
+ posY = Math.round(posY * roundy) / roundy;
+ return new Point(posX, posY);
+ };
+
+ /**
+ * Convert real world coordinates to pixel coordinates
+ */
+ this.convertRealToPixel = function(aPoint){
+ var arrayBBox = this.extent.toString().split(",");
+ var minX = parseFloat(arrayBBox[0]);
+ var minY = parseFloat(arrayBBox[1]);
+ var maxX = parseFloat(arrayBBox[2]);
+ var maxY = parseFloat(arrayBBox[3]);
+ return new Point(Math.round((aPoint.x - minX) * this.width / (maxX - minX)), Math.round((maxY - aPoint.y) * this.height / (maxY - minY)));
+ };
+
+ /**
+ * get the srs of the mapObj
+ *
+ * @return srs as epsg:number
+ * @type string
+ */
+ this.getSRS = function(){
+ return this.epsg;
+ };
+
+ /**
+ * get all mapRequests
+ *
+ * @return array of mapRequests of this map object
+ * @type string[]
+ */
+ this.getMapRequests = function(){
+ var allRequests = [];
+ //loop through all wms to get the mapRequests
+ for (var i = 0; i < this.wms.length; i++) {
+ var currentRequest = this.wms[i].getMapRequest(this);
+ if (currentRequest) {
+ allRequests.push(currentRequest);
+ }
+ }
+ if (allRequests.length > 0) {
+ return allRequests;
+ }
+ return false;
+ };
+
+ /**
+ * Return the map URL of the WMS at index i
+ * @param {Object} currentWmsIndex
+ */
+ this.getMapUrl = function(ii){
+ var currentWms = this.wms[ii];
+ var validLayers = currentWms.getLayers(this);
+ if (validLayers.length === 0) {
+ return false;
+ }
+ for (var i = 0; i < validLayers.length; i++) {
+ validLayers[i] = encodeURIComponent(validLayers[i]);
+ }
+ var layerNames = validLayers.join(",");
+
+ url = currentWms.wms_getmap;
+ url += mb_getConjunctionCharacter(currentWms.wms_getmap);
+
+ if (currentWms.wms_version == "1.0.0") {
+ url += "WMTVER=" + currentWms.wms_version + "&REQUEST=map&";
+ }
+ else {
+ url += "VERSION=" + currentWms.wms_version + "&REQUEST=GetMap&SERVICE=WMS&";
+ }
+
+ url += "LAYERS=" + layerNames + "&";
+ url += "STYLES=";
+ var layer = layerNames.split(",");
+ for (var j = 0; j < layer.length; j++) {
+ if (j > 0) {
+ url += ",";
+ }
+
+ if (currentWms.getCurrentStyleByLayerName(layer[j]) !== false &&
+ typeof currentWms.getCurrentStyleByLayerName(layer[j]) !== "undefined") {
+ url += currentWms.getCurrentStyleByLayerName(layer[j]);
+ }
+ }
+ url += "&";
+ url += "SRS=" + this.epsg + "&";
+ url += "BBOX=" + this.getExtent() + "&";
+ url += "WIDTH=" + this.width + "&";
+ url += "HEIGHT=" + this.height + "&";
+ url += "FORMAT=" + currentWms.gui_wms_mapformat + "&";
+ url += "BGCOLOR=0xffffff&";
+
+ if (currentWms.gui_wms_mapformat.search(/gif/i) > -1 ||
+ currentWms.gui_wms_mapformat.search(/png/i) > -1) {
+ url += "TRANSPARENT=TRUE&";
+ }
+
+ url += "EXCEPTIONS=" + currentWms.gui_wms_exceptionformat + "&";
+
+ // add vendor-specific
+ for (var v = 0; v < mb_vendorSpecific.length; v++) {
+ var functionName = 'setMapRequest';
+ var vendorSpecificString = eval(mb_vendorSpecific[v]);
+ // if eval doesn't evaluate a function, the result is undefined.
+ // Sometimes it is necessary not to evaluate a function, for
+ // example if you want to change a variable from the current
+ // scope (see mod_addSLD.php)
+ if (typeof(vendorSpecificString) != "undefined") {
+ url += vendorSpecificString + "&";
+ }
+ }
+ // add Filter
+ if (currentWms.wms_filter !== "") {
+ url += "&SLD=" + currentWms.wms_filter + "?id=" + mb_styleID + "&";
+ }
+ // add sld
+ if (currentWms.gui_wms_sldurl !== "") {
+ url += "&SLD=" + escape(currentWms.gui_wms_sldurl) + "&";
+ }
+ //remove the last ampersant (&) of the mapurl
+ url = url.substr(0, url.length - 1);
+
+ return url;
+ };
+
+ /**
+ * get all featureInfoRequests
+ *
+ * @member Map
+ * @param float x the x-value of the click position in pixel
+ * @param float y the y-value of the click position in pixel
+ * @return array of all featureInfoRequests of this map object
+ * @type string[]
+ */
+ this.getFeatureInfoRequests = function(clickPoint, ignoreWms){
+ var allRequests = [];
+ //loop through all wms to get the FeatureInfoRequests
+ for (var i = 0; i < this.wms.length; i++) {
+ var ignoreThisWms = false;
+ if (typeof ignoreWms !== "undefined" &&
+ ignoreWms.constructor === Array) {
+
+ for (var j = 0; j < ignoreWms.length; j++) {
+ if (ignoreWms[j] == this.wms[i].wms_id) {
+ ignoreThisWms = true;
+ break;
+ }
+ }
+ }
+ if (!ignoreThisWms) {
+ var currentRequest = this.wms[i].getFeatureInfoRequest(this, clickPoint);
+ if (currentRequest) {
+ allRequests.push(currentRequest);
+ }
+ }
+ }
+ if (allRequests.length > 0) {
+ return allRequests;
+ }
+ return false;
+ };
+
+ /**
+ * calculation of the mapscale
+ *
+ * @member Map
+ * @return scale
+ * @type integer
+ */
+ this.getScale = function(){
+ var scale;
+ var bbox = this.extent.toString().split(",");
+ var xtenty;
+ if (this.epsg == "EPSG:4326") {
+ var pxLenx = (parseFloat(bbox[2]) - parseFloat(bbox[0])) / this.width;
+ var pxLeny = (parseFloat(bbox[3]) - parseFloat(bbox[1])) / this.height;
+ var lat_from = ((parseFloat(bbox[3]) - parseFloat(bbox[1]) / 2) * Math.PI) / 180;
+ var lat_to = ((parseFloat(bbox[3]) - parseFloat(bbox[1]) / 2 + pxLeny) * Math.PI) / 180;
+ var lon_from = ((parseFloat(bbox[2]) - parseFloat(bbox[0]) / 2) * Math.PI) / 180;
+ var lon_to = ((parseFloat(bbox[2]) - parseFloat(bbox[0]) / 2 + pxLeny) * Math.PI) / 180;
+ var dist = 6371229 * Math.acos(Math.sin(lat_from) * Math.sin(lat_to) + Math.cos(lat_from) * Math.cos(lat_to) * Math.cos(lon_from - lon_to));
+ scale = (dist / Math.SQRT2) * (mb_resolution * 100);
+ }
+ else {
+ xtenty = parseFloat(bbox[3]) - parseFloat(bbox[1]);
+ scale = (xtenty / this.height) * (mb_resolution * 100);
+ }
+ return parseInt(Math.round(scale), 10);
+ };
+
+ /**
+ *
+ */
+ this.checkScale = function(wmsIndex){
+ var thisLayer = this.layers[wmsIndex].split(",");
+ var thisScale = this.getScale();
+ var str_layer = "";
+ var cnt_layer = 0;
+ for (var i = 0; i < this.wms[wmsIndex].objLayer.length; i++) {
+ var currentLayer = this.wms[wmsIndex].objLayer[i];
+ var myLayername = currentLayer.layer_name;
+
+ var myMinscale = currentLayer.gui_layer_minscale;
+ var myMaxscale = currentLayer.gui_layer_maxscale;
+
+ for (var ii = 0; ii < thisLayer.length; ii++) {
+ if (thisLayer[ii] == myLayername && !currentLayer.has_childs) {
+ if (myMinscale !== 0 && thisScale < myMinscale) {
+ continue;
+ }
+ if (myMaxscale !== 0 && thisScale > myMaxscale) {
+ continue;
+ }
+ if (cnt_layer > 0) {
+ str_layer += ",";
+ }
+ str_layer += thisLayer[ii];
+ cnt_layer++;
+ }
+ }
+ }
+ var str_layerstyles = [];
+ str_layerstyles[0] = str_layer;
+ return str_layerstyles;
+
+ };
+
+ this.repaintScale = function(x, y, scale){
+ if (x === null && y === null) {
+ var arrayBBox = this.extent.toString().split(",");
+ x = parseFloat(arrayBBox[0]) +
+ ((parseFloat(arrayBBox[2]) - parseFloat(arrayBBox[0])) /
+ 2);
+ y = parseFloat(arrayBBox[1]) +
+ ((parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1])) /
+ 2);
+ }
+ var minx = parseFloat(x) - (this.width / (mb_resolution * 100 * 2) * scale);
+ var miny = parseFloat(y) - (this.height / (mb_resolution * 100 * 2) * scale);
+ var maxx = parseFloat(x) + (this.width / (mb_resolution * 100 * 2) * scale);
+ var maxy = parseFloat(y) + (this.height / (mb_resolution * 100 * 2) * scale);
+ this.repaint(new Point(minx, miny), new Point(maxx, maxy));
+ };
+
+ this.repaint = function(min, max){
+ if (typeof min !== "undefined" && typeof max !== "undefined") {
+ this.extent = this.calculateExtent(new Extent(min, max));
+ }
+ this.setMapRequest();
+ };
+
+ this.setSingleMapRequest = function(wms_id){
+ eventBeforeMapRequest.trigger({
+ map: this
+ });
+
+ var ts = mb_timestamp();
+
+ for (var ii = 0; ii < this.wms.length; ii++) {
+ var currentWms = this.wms[ii];
+
+ try {
+ if (this.skipWmsIfSrsNotSupported && isIgnoredWms(currentWms)) {
+ continue;
+ }
+ }
+ catch (e) {
+ new Mb_warning(e.message);
+ }
+
+ if (currentWms.wms_id != wms_id) {
+ continue;
+ }
+ var newMapRequest = getLayerHtmlCode(ii);
+
+ if (Mapbender.log) {
+ var tmp = eval(Mapbender.log + "('" +
+ newMapURL +
+ "','" +
+ ts +
+ "')");
+ }
+ var myDivId = this.elementName + "_div_" + ii;
+ var $wmsDiv = $("#" + myDivId);
+ if ($wmsDiv.size() > 0) {
+ $wmsDiv.remove();
+ }
+ var $newDiv = $(newMapRequest);
+ $("#" + this.elementName + "_maps").append($newDiv);
+
+ var myMapId = this.elementName + "_map_" + ii;
+ eventAfterMapRequest.trigger({
+ map: this,
+ myMapId: myMapId,
+ url: [this.getMapUrl(ii)]
+ });
+ this.afterMapRequest.trigger({
+ map: this,
+ myMapId: myMapId,
+ url: [this.getMapUrl(ii)]
+ });
+ return true;
+ }
+ return false;
+
+ };
+
+ this.mb_setFutureObj = function(mod_back_cnt){
+ var cnt = this.mb_MapFutureObj.length;
+ this.mb_MapFutureObj[cnt] = {};
+ this.mb_MapFutureObj[cnt].reqCnt = mod_back_cnt;
+ this.mb_MapFutureObj[cnt].width = this.width;
+ this.mb_MapFutureObj[cnt].height = this.height;
+ this.mb_MapFutureObj[cnt].epsg = this.epsg;
+ this.mb_MapFutureObj[cnt].extent = this.extent;
+ this.mb_MapFutureObj[cnt].layers = [];
+
+ for (var i = 0; i < this.layers.length; i++) {
+ this.mb_MapFutureObj[cnt].layers[i] = this.layers[i];
+ }
+
+ this.mb_MapFutureObj[cnt].styles = [];
+
+ for (var i = 0; i < this.styles.length; i++) {
+ this.mb_MapFutureObj[cnt].styles[i] = this.styles[i];
+ }
+
+ this.mb_MapFutureObj[cnt].querylayers = [];
+
+ for (var i = 0; i < this.querylayers.length; i++) {
+ this.mb_MapFutureObj[cnt].querylayers[i] = this.querylayers[i];
+ }
+ };
+
+ var drawMaps = function(idArray, index){
+ var numRequests = that.history.count();
+ var requestCnt = index;
+// console.log(requestCnt + " - " + numRequests);
+ // existing history item
+ if (requestCnt + 1 < numRequests && numRequests > 1 || $("#" + that.elementName + "_request_" + requestCnt).size() > 0) {
+// console.log("exist");
+ $("#" + that.elementName + "_request_" + requestCnt).hide();
+ for (var i = 0; i < requestCnt; i++) {
+ $("#" + that.elementName + "_request_" + i).hide();
}
- }
- };
-
- this.initializeWms = function () {
- var cnt_layers;
- var cnt_querylayers;
- var styles;
- var layers;
- var querylayers = "";
- for (i = 0; i < this.wms.length; i++) {
- cnt_layers = 0;
- cnt_querylayers = 0;
- styles = "";
- layers = "";
- querylayers = "";
-
- for (var ii = 0; ii < this.wms[i].objLayer.length; ii++) {
- // layer is visible and not root layer
- if (this.wms[i].objLayer[ii].gui_layer_visible == 1 && ii > 0) {
- if (cnt_layers > 0) {
- layers += ",";
- styles += ",";
- }
- layers += this.wms[i].objLayer[ii].layer_name;
- styles += "";
- cnt_layers++;
- }
- // layer is queryable and not root layer
- if (this.wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii > 0) {
- if (cnt_querylayers > 0) {
- querylayers += ",";
- }
- querylayers += this.wms[i].objLayer[ii].layer_name;
- cnt_querylayers++;
- }
+ for (var i = requestCnt + 1; i <= numRequests; i++) {
+ $("#" + that.elementName + "_request_" + i).hide();
}
- this.layers[i] = layers;
- this.styles[i] = styles;
- this.querylayers[i] = querylayers;
}
- };
- /**
- * get the extent of the mapObj
- *
- * @member Map
- * @return extent of the mapObj as commaseparated minx,minx,maxx,maxy
- * @type string
- */
- this.getExtent = function(){
- return this.extent.toString();
- };
-
- /**
- * get the extent as minx, maxx, miny, maxy
- *
- * @return extent and additional informations of the mapObj
- * @type Object
- */
- this.getExtentInfos = function(){
- var c = this.extent.toString().split(",");
- var ext = new Mapbender.Extent(c[0], c[1], c[2], c[3]);
- return ext;
- };
-
- /**
- * Sets the list of layers, styles and querylayers for a specified WMS
- */
- this.restateLayers = function(wms_id){
- for (var i = 0; i < this.wms.length; i++) {
- if (this.wms[i].wms_id == wms_id) {
- var currentWms = this.wms[i];
- var cnt_layers = 0;
- var cnt_querylayers = 0;
- var layers = "";
- var styles = "";
- var querylayers = "";
- for (var ii = 0; ii < currentWms.objLayer.length; ii++) {
- var currentLayer = currentWms.objLayer[ii];
- if (currentLayer.gui_layer_visible == 1 && !currentLayer.has_childs) {
- if (cnt_layers > 0) {
- layers += ",";
- styles += ",";
- }
- layers += currentLayer.layer_name;
- styles += "";
- cnt_layers++;
- }
- if (currentLayer.gui_layer_querylayer == 1 && !currentLayer.has_childs) {
- if (cnt_querylayers > 0) {
- querylayers += ",";
- }
- querylayers += currentLayer.layer_name;
- cnt_querylayers++;
- }
- }
- this.layers[i] = layers;
- this.querylayers[i] = querylayers;
- this.styles[i] = styles;
- }
- }
-// this.setExtent(ext.minx,ext.miny,ext.maxx,ext.maxy);
- };
-
- /**
- *
- * @param {Object} direction
- */
- this.pan = function (direction) {
- var arrayBBox = this.getExtent().split(",");
- var minx = parseFloat(arrayBBox[0]);
- var miny = parseFloat(arrayBBox[1]);
- var maxx = parseFloat(arrayBBox[2]);
- var maxy = parseFloat(arrayBBox[3]);
- var xtentx = maxx - minx;
- var xtenty = maxy - miny;
- var factor = 0.5;
-
- switch (direction) {
- case "NW" :
- minx -= (xtentx * factor);
- maxx -= (xtentx * factor);
- miny += (xtenty * factor);
- maxy += (xtenty * factor);
- break;
- case "N" :
- miny += (xtenty * factor);
- maxy += (xtenty * factor);
- break;
- case "NE" :
- minx += (xtentx * factor);
- maxx += (xtentx * factor);
- miny += (xtenty * factor);
- maxy += (xtenty * factor);
- break;
- case "E" :
- minx += (xtentx * factor);
- maxx += (xtentx * factor);
- break;
- case "SE" :
- minx += (xtentx * factor);
- maxx += (xtentx * factor);
- miny -= (xtenty * factor);
- maxy -= (xtenty * factor);
- break;
- case "S" :
- miny -= (xtenty * factor);
- maxy -= (xtenty * factor);
- break;
- case "SW" :
- minx -= (xtentx * factor);
- maxx -= (xtentx * factor);
- miny -= (xtenty * factor);
- maxy -= (xtenty * factor);
- break;
- case "W" :
- minx -= (xtentx * factor);
- maxx -= (xtentx * factor);
- break;
- }
- this.setExtent(minx, miny, maxx, maxy);
-// this.restrictedExtent;
- this.setMapRequest();
-
- };
-
- this.setCenter = function (aPoint) {
- this.extent.set(aPoint);
- this.calculateExtent(this.extent);
- this.setMapRequest();
- };
-
- this.zoomFull = function () {
-
- if (this.restrictedExtent) {
- this.calculateExtent(this.restrictedExtent);
- this.setMapRequest();
- }
+ // new history item
else {
- for (var i = 0; i < this.wms[0].gui_epsg.length; i++) {
- if (this.epsg == this.wms[0].gui_epsg[i]) {
- var bbox_minx = parseFloat(this.wms[0].gui_minx[i]);
- var bbox_miny = parseFloat(this.wms[0].gui_miny[i]);
- var bbox_maxx = parseFloat(this.wms[0].gui_maxx[i]);
- var bbox_maxy = parseFloat(this.wms[0].gui_maxy[i]);
-
- var wmsExtent = new Mapbender.Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy);
- this.calculateExtent(wmsExtent);
- this.setMapRequest();
- break;
- }
- }
- }
- };
-
- /**
- * zoom the map with a zoomfactor and optional to x,y coords
- *
- * @param {boolean} in_ in = true, out = false
- * @param {float} factor the zoomfactor 1 equals 100%
- * @param {float} x center to x-position
- * @param {float} y center to y-position
- */
- this.zoom = function(in_, factor, x, y){
- factor = parseFloat(factor);
- if (!in_) {
- factor = 1 / factor;
- }
-
- var extent = this.getExtentInfos();
- var distx = extent.maxx - extent.minx;
- var disty = extent.maxy - extent.miny;
-
- if (typeof x === "object" && x.constructor === Mapbender.Point) {
- y = x.y;
- x = x.x;
- }
-
- if (x && y) {
- var centerx = parseFloat(x);
- var centery = parseFloat(y);
- }
- else {
- var centerx = extent.minx + distx / 2;
- var centery = extent.miny + disty / 2;
- }
-
- var new_distx = distx / factor;
- var new_disty = disty / factor;
- var minx = centerx - new_distx / 2;
- var miny = centery - new_disty / 2;
- var maxx = centerx + new_distx / 2;
- var maxy = centery + new_disty / 2;
- // Check if ext is within restricted extent
- // If not, calculate a new extent according
- // to restricted extent.
- /*
- var relation_px_x = this.getWidth() / this.getHeight();
- var relation_px_y = this.getHeight() / this.getWidth();
- if ( this.restrictedExtent ) {
- if ( minx < this.restrictedExtent.minx ) {
- minx = this.restrictedExtent.minx;
- maxx = minx + (relation_px_x * new_disty);
+// console.log("new");
+ var newMapRequest = "";
+ for (var i = 0; i < idArray.length; i++) {
+ newMapRequest += getLayerHtmlCode(idArray[i]);
}
- if ( miny < this.restrictedExtent.miny ) {
- miny = this.restrictedExtent.miny;
- maxy = miny + (relation_px_y * new_distx);
- }
- if ( maxx > this.restrictedExtent.maxx ) {
- maxx = this.restrictedExtent.maxx;
- minx = maxx - (relation_px_x * new_distx);
- }
- if ( maxy > this.restrictedExtent.maxy ) {
- maxy = this.restrictedExtent.maxy;
- miny = maxy - (relation_px_y * new_disty);
- }
- }
- */
-
- this.setExtent(minx, miny, maxx, maxy);
- this.setMapRequest();
- };
-
- var performUnknownCalculation = function (value) {
- return Math.pow(10,(
- Math.round(
- Math.log(value)/
- Math.log(10)
- )
- ));
- };
-
- this.convertPixelToReal = function (aPoint) {
- var arrayBBox = this.getExtent().split(",");
- var minX = parseFloat(arrayBBox[0]);
- var minY = parseFloat(arrayBBox[1]);
- var maxX = parseFloat(arrayBBox[2]);
- var maxY = parseFloat(arrayBBox[3]);
- var xtentx = maxX - minX;
- var xtenty = maxY - minY;
- var deltaX = xtentx/this.width;
- var deltaY = xtenty/this.height;
- var roundx, roundy;
-
- if(deltaX > 0){
- roundx = 1/performUnknownCalculation(deltaX);
- }
- else{
- roundx = performUnknownCalculation(deltaX);
- }
- if(deltaY > 0){
- roundy = 1/performUnknownCalculation(deltaY);
- }
- else{
- roundy = performUnknownCalculation(deltaY);
- }
- var posX = parseFloat(minX + (aPoint.x / this.width) * xtentx);
- var posY = parseFloat(maxY - (aPoint.y / this.height) * xtenty);
- posX = Math.round(posX * roundx) / roundx;
- posY = Math.round(posY * roundy) / roundy;
- return new Point(posX, posY);
- };
-
- /**
- * Convert real world coordinates to pixel coordinates
- */
- this.convertRealToPixel = function (aPoint) {
- var arrayBBox = this.extent.toString().split(",");
- var minX = parseFloat(arrayBBox[0]);
- var minY = parseFloat(arrayBBox[1]);
- var maxX = parseFloat(arrayBBox[2]);
- var maxY = parseFloat(arrayBBox[3]);
- return new Point(
- Math.round((aPoint.x - minX) * this.width /(maxX - minX)),
- Math.round((maxY - aPoint.y) * this.height/(maxY - minY))
- );
- };
-
- /**
- * get the srs of the mapObj
- *
- * @return srs as epsg:number
- * @type string
- */
- this.getSRS = function(){
- return this.epsg;
- };
-
- /**
- * get all mapRequests
- *
- * @return array of mapRequests of this map object
- * @type string[]
- */
- this.getMapRequests = function(){
- var allRequests = [];
- //loop through all wms to get the mapRequests
- for (var i = 0; i < this.wms.length; i++) {
- var currentRequest = this.wms[i].getMapRequest(this);
- if (currentRequest) {
- allRequests.push(currentRequest);
- }
- }
- if (allRequests.length > 0) {
- return allRequests;
- }
- return false;
- };
-
- /**
- * Return the map URL of the WMS at index i
- * @param {Object} currentWmsIndex
- */
- this.getMapUrl = function(ii){
- var currentWms = this.wms[ii];
- var validLayers = currentWms.getLayers(this);
- if(validLayers.length === 0) {
- return false;
- }
- for (var i = 0; i < validLayers.length; i++) {
- validLayers[i] = encodeURIComponent(validLayers[i]);
- }
- var layerNames = validLayers.join(",");
-
- url = currentWms.wms_getmap;
- url += mb_getConjunctionCharacter(currentWms.wms_getmap);
-
- if (currentWms.wms_version == "1.0.0") {
- url += "WMTVER=" + currentWms.wms_version + "&REQUEST=map&";
- }
- else {
- url += "VERSION=" + currentWms.wms_version + "&REQUEST=GetMap&SERVICE=WMS&";
- }
-
- url += "LAYERS=" + layerNames + "&";
- url += "STYLES=";
- var layer = layerNames.split(",");
- for (var j = 0; j < layer.length; j++) {
- if (j > 0) {
- url += ",";
- }
+ var $currentRequest = $("<div id='" + that.elementName + "_request_" + (requestCnt) + "'></div>").hide().append($(newMapRequest));
- if (currentWms.getCurrentStyleByLayerName(layer[j]) !== false &&
- typeof currentWms.getCurrentStyleByLayerName(layer[j]) !== "undefined") {
- url += currentWms.getCurrentStyleByLayerName(layer[j]);
+ $("#" + that.elementName + "_maps").append($currentRequest);
+ for (var i = 0; i < requestCnt; i++) {
+ $("#" + that.elementName + "_request_" + i).hide().each(function () {
+ $(this).children().each(function () {
+ this.style.zIndex = this.style.zIndex - 1;
+ });
+ });
}
}
- url += "&";
- url += "SRS=" + this.epsg + "&";
- url += "BBOX=" + this.getExtent() + "&";
- url += "WIDTH=" + this.width + "&";
- url += "HEIGHT=" + this.height + "&";
- url += "FORMAT=" + currentWms.gui_wms_mapformat + "&";
- url += "BGCOLOR=0xffffff&";
-
- if (currentWms.gui_wms_mapformat.search(/gif/i) > -1 ||
- currentWms.gui_wms_mapformat.search(/png/i) > -1) {
- url += "TRANSPARENT=TRUE&";
- }
-
- url += "EXCEPTIONS=" + currentWms.gui_wms_exceptionformat + "&";
-
- // add vendor-specific
- for (var v = 0; v < mb_vendorSpecific.length; v++) {
- var functionName = 'setMapRequest';
- var vendorSpecificString = eval(mb_vendorSpecific[v]);
- // if eval doesn't evaluate a function, the result is undefined.
- // Sometimes it is necessary not to evaluate a function, for
- // example if you want to change a variable from the current
- // scope (see mod_addSLD.php)
- if (typeof(vendorSpecificString) != "undefined") {
- url += vendorSpecificString + "&";
- }
- }
- // add Filter
- if (currentWms.wms_filter !== "") {
- url += "&SLD=" + currentWms.wms_filter + "?id=" + mb_styleID + "&";
- }
- // add sld
- if (currentWms.gui_wms_sldurl !== "") {
- url += "&SLD=" + escape(currentWms.gui_wms_sldurl) + "&";
- }
- //remove the last ampersant (&) of the mapurl
- url = url.substr(0, url.length-1);
-
- return url;
- };
+ };
+
+ var displayMaps = function(index){
+ var ret = eventBeforeMapRequest.trigger({
+ map: that
+ }, "AND");
+ if (ret === false) {
+ return true;
+ }
+ var myMapId = [];
+ var mapUrlArray = [];
+ var visibleWms = [];
+ for (var ii = 0; ii < that.wms.length; ii++) {
+ var currentWms = that.wms[ii];
+
+ try {
+ if (that.skipWmsIfSrsNotSupported && isIgnoredWms(currentWms)) {
+ new Mb_notice(currentWms.wms_title + " is ignored.");
+ continue;
+ }
+ }
+ catch (e) {
+ new Mb_warning(e.message);
+ }
+ if (!(currentWms.gui_wms_visible > 0)) {
+ new Mb_notice(currentWms.title + " is not visible, will not be requested.");
+ continue;
+ }
+ myMapId.push(that.elementName + "_map_" + ii);
+ mapUrlArray.push(that.getMapUrl(ii));
+ visibleWms.push(ii);
+ }
+
+ drawMaps(visibleWms, index);
+
+ eventAfterMapRequest.trigger({
+ map: that,
+ myMapId: myMapId.join(","),
+ url: mapUrlArray
+ });
+ that.afterMapRequest.trigger({
+ map: that,
+ myMapId: myMapId.join(","),
+ url: mapUrlArray
+ });
+
+ };
+
+ var doAnimation = false;
- /**
- * get all featureInfoRequests
- *
- * @member Map
- * @param float x the x-value of the click position in pixel
- * @param float y the y-value of the click position in pixel
- * @return array of all featureInfoRequests of this map object
- * @type string[]
- */
- this.getFeatureInfoRequests = function(clickPoint, ignoreWms){
- var allRequests = [];
- //loop through all wms to get the FeatureInfoRequests
- for (var i = 0; i < this.wms.length; i++) {
- var ignoreThisWms = false;
- if (typeof ignoreWms !== "undefined"
- && ignoreWms.constructor === Array) {
-
- for (var j = 0; j < ignoreWms.length; j++) {
- if (ignoreWms[j] == this.wms[i].wms_id) {
- ignoreThisWms = true;
- break;
- }
- }
- }
- if (!ignoreThisWms) {
- var currentRequest = this.wms[i].getFeatureInfoRequest(this, clickPoint);
- if (currentRequest) {
- allRequests.push(currentRequest);
- }
- }
- }
- if (allRequests.length > 0) {
- return allRequests;
- }
- return false;
- };
+ var animateMaps = function (index) {
+// console.log(that.oldExtentPix);
+//
+ if (doAnimation) {
+ $("#" + that.elementName + "_request_" + index).children().children().css({
+ visibility: "hidden"
+ }).load(function () {
+ this.style.visibility = "visible";
+ });
+ $("#" + that.elementName + "_request_" + index).css({
+ position: "absolute",
+ top: that.oldExtentPix.max.y,
+ left: that.oldExtentPix.min.x
+ }).show().animate({
+ left: "0px",
+ top: "0px"
+ }, {
+ duration: "slow"
+ });
- /**
- * calculation of the mapscale
- *
- * @member Map
- * @return scale
- * @type integer
- */
- this.getScale = function(){
- var scale;
- var bbox = this.extent.toString().split(",");
- var xtenty;
- if (this.epsg == "EPSG:4326") {
- var pxLenx = (parseFloat(bbox[2]) - parseFloat(bbox[0])) / this.width;
- var pxLeny = (parseFloat(bbox[3]) - parseFloat(bbox[1])) / this.height;
- var lat_from = ((parseFloat(bbox[3]) - parseFloat(bbox[1]) / 2) * Math.PI) / 180;
- var lat_to = ((parseFloat(bbox[3]) - parseFloat(bbox[1]) / 2 + pxLeny) * Math.PI) / 180;
- var lon_from = ((parseFloat(bbox[2]) - parseFloat(bbox[0]) / 2) * Math.PI) / 180;
- var lon_to = ((parseFloat(bbox[2]) - parseFloat(bbox[0]) / 2 + pxLeny) * Math.PI) / 180;
- var dist = 6371229 * Math.acos(Math.sin(lat_from) * Math.sin(lat_to) + Math.cos(lat_from) * Math.cos(lat_to) * Math.cos(lon_from - lon_to));
- scale = (dist / Math.SQRT2) * (mb_resolution * 100);
- }
- else {
- xtenty = parseFloat(bbox[3]) - parseFloat(bbox[1]);
- scale = (xtenty / this.height) * (mb_resolution * 100);
- }
- return parseInt(Math.round(scale), 10);
- };
-
- /**
- *
- */
- this.checkScale = function(wmsIndex){
- var thisLayer = this.layers[wmsIndex].split(",");
- var thisScale = this.getScale();
- var str_layer = "";
- var cnt_layer = 0;
- for (var i = 0; i < this.wms[wmsIndex].objLayer.length; i++) {
- var currentLayer = this.wms[wmsIndex].objLayer[i];
- var myLayername = currentLayer.layer_name;
+ // animate previous request div and images
+ var oldLLPix = that.convertRealToPixel(that.oldExtent.min);
+ var oldURPix = that.convertRealToPixel(that.oldExtent.max);
- var myMinscale = currentLayer.gui_layer_minscale;
- var myMaxscale = currentLayer.gui_layer_maxscale;
-
- for (var ii = 0; ii < thisLayer.length; ii++) {
- if (thisLayer[ii] == myLayername && !currentLayer.has_childs) {
- if (myMinscale !== 0 && thisScale < myMinscale) {
- continue;
- }
- if (myMaxscale !== 0 && thisScale > myMaxscale) {
- continue;
- }
- if (cnt_layer > 0) {
- str_layer += ",";
- }
- str_layer += thisLayer[ii];
- cnt_layer++;
- }
- }
- }
- var str_layerstyles = [];
- str_layerstyles[0] = str_layer;
- return str_layerstyles;
-
- };
+ var left = oldLLPix.x;
+ var top = oldURPix.y;
+ var width = oldURPix.x - oldLLPix.x;
+ var height = oldLLPix.y - oldURPix.y;
- this.repaintScale = function(x, y, scale){
- if (x === null && y === null) {
- var arrayBBox = this.extent.toString().split(",");
- x = parseFloat(arrayBBox[0]) +
- ((parseFloat(arrayBBox[2]) - parseFloat(arrayBBox[0])) /
- 2);
- y = parseFloat(arrayBBox[1]) +
- ((parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1])) /
- 2);
- }
- var minx = parseFloat(x) - (this.width / (mb_resolution * 100 * 2) * scale);
- var miny = parseFloat(y) - (this.height / (mb_resolution * 100 * 2) * scale);
- var maxx = parseFloat(x) + (this.width / (mb_resolution * 100 * 2) * scale);
- var maxy = parseFloat(y) + (this.height / (mb_resolution * 100 * 2) * scale);
- this.repaint(new Point(minx, miny), new Point(maxx, maxy));
- };
-
- this.repaint = function(min, max){
- if (typeof min !== "undefined" && typeof max !== "undefined") {
- this.extent = this.calculateExtent(new Extent(min, max));
- }
- this.setMapRequest();
- };
-
- this.setSingleMapRequest = function (wms_id) {
- eventBeforeMapRequest.trigger({map:this});
-
- var ts = mb_timestamp();
-
- for (var ii = 0; ii < this.wms.length; ii++){
- var currentWms = this.wms[ii];
-
- try {
- if (this.skipWmsIfSrsNotSupported && isIgnoredWms(currentWms)) {
- continue;
- }
- }
- catch (e) {
- new Mb_warning(e.message);
- }
-
- if (currentWms.wms_id != wms_id) {
- continue;
- }
- var newMapRequest = getLayerHtmlCode(ii);
-
- if (Mapbender.log) {
- var tmp = eval(Mapbender.log + "('" +
- newMapURL + "','" + ts + "')");
- }
- var myDivId = this.elementName + "_div_" + ii;
- var $wmsDiv = $("#" + myDivId);
- if ($wmsDiv.size() > 0) {
- $wmsDiv.remove();
- }
- var $newDiv = $(newMapRequest);
- $("#" + this.elementName + "_maps").append($newDiv);
-
- var myMapId = this.elementName + "_map_" + ii;
- eventAfterMapRequest.trigger({
- map: this,
- myMapId: myMapId,
- url: [this.getMapUrl(ii)]
+ $("#" + that.elementName + "_request_" + (index-1)).css({
+ position: "absolute",
+ top: "0px",
+ left: "0px"
+ }).show().animate({
+ left: left + "px",
+ top: top + "px"
+ }, {
+ duration: "slow"
});
- this.afterMapRequest.trigger({
- map: this,
- myMapId: myMapId,
- url: [this.getMapUrl(ii)]
- });
- return true;
- }
- return false;
-
- };
-
- this.mb_setFutureObj = function(mod_back_cnt){
- var cnt = this.mb_MapFutureObj.length;
- this.mb_MapFutureObj[cnt] = {};
- this.mb_MapFutureObj[cnt].reqCnt = mod_back_cnt;
- this.mb_MapFutureObj[cnt].width = this.width;
- this.mb_MapFutureObj[cnt].height = this.height;
- this.mb_MapFutureObj[cnt].epsg = this.epsg;
- this.mb_MapFutureObj[cnt].extent = this.extent;
- this.mb_MapFutureObj[cnt].layers = [];
-
- for(var i=0; i<this.layers.length;i++){
- this.mb_MapFutureObj[cnt].layers[i] = this.layers[i];
}
-
- this.mb_MapFutureObj[cnt].styles = [];
-
- for(var i=0; i < this.styles.length;i++){
- this.mb_MapFutureObj[cnt].styles[i] = this.styles[i];
+ else {
+ $("#" + that.elementName + "_request_" + index).show();
}
-
- this.mb_MapFutureObj[cnt].querylayers = [];
-
- for(var i=0; i < this.querylayers.length; i++) {
- this.mb_MapFutureObj[cnt].querylayers[i] = this.querylayers[i];
- }
};
- this.setMapRequest = function(){
- var ret = eventBeforeMapRequest.trigger({
- map: this
- }, "AND");
- if (ret === false) {
- return true;
- }
- var ts = mb_timestamp();
- var myMapId = [];
-
- var newMapRequest = "";
-
- var mapUrlArray = [];
- for (var ii = 0; ii < this.wms.length; ii++) {
- var currentWms = this.wms[ii];
-
- try {
- if (this.skipWmsIfSrsNotSupported && isIgnoredWms(currentWms)) {
- new Mb_notice(currentWms.wms_title + " is ignored.");
- continue;
- }
+ this.setMapRequest = function(){
+ // initialize history
+ (function(){
+ var extent = new Extent(that.extent);
+ if (typeof that.oldExtent === "undefined") {
+ that.setExtent(extent, false);
+ displayMaps(0);
+ animateMaps(0);
}
- catch (e) {
- new Mb_warning(e.message);
- }
- if (!(currentWms.gui_wms_visible > 0)) {
- new Mb_notice(currentWms.title + " is not visible, will not be requested.");
- continue;
- }
- myMapId.push(this.elementName + "_map_" + ii);
- newMapRequest += getLayerHtmlCode(ii);
- mapUrlArray.push(this.getMapUrl(ii));
- }
- writeTag(this.frameName, this.elementName+"_maps", newMapRequest);
-
- eventAfterMapRequest.trigger({
- map: this,
- myMapId: myMapId.join(","),
- url: mapUrlArray
- });
- this.afterMapRequest.trigger({
- map: this,
- myMapId: myMapId.join(","),
- url: mapUrlArray
- });
- };
-
- var getLayerHtmlCode = function (ii) {
- var currentWms = that.wms[ii];
-
- var myDivId = that.elementName + "_div_" + ii;
- var myMapId = that.elementName + "_map_" + ii;
- var ts = mb_timestamp();
-
- //disable Layer which are out of scale
- var validLayers = that.checkScale(ii);
- var layerNames = validLayers.toString();
-
- var newMapURL = false;
- var opacityString = "";
-
- if (that.layers[ii] !== "" && layerNames !== ''){
- // get map URL
- newMapURL = that.getMapUrl(ii);
-
- var currentOpacity = currentWms.gui_wms_mapopacity;
- if (currentOpacity != 1) {
- opacityString += "opacity:" + currentOpacity + "; ";
- opacityString += "Filter: Alpha(Opacity=" + currentOpacity*100 + "); ";
- opacityString += "-moz-opacity:" + currentOpacity + " ; ";
- opacityString += "-khtml-opacity:" + currentOpacity;
- }
- }
-
- var imageString = "";
- if (newMapURL) {
- imageString = "<img id='"+myMapId+"' name='mapimage' ";
- imageString += "src='" + newMapURL + "' ";
- imageString += "width='"+that.width+"' ";
- imageString += "height='"+that.height+"' ";
- imageString += "border='0'>";
- }
-
- var newMapRequest = "<div id='"+myDivId+"' ";
- newMapRequest += "style=\"position:absolute; top:0px; left:0px; ";
-// newMapRequest += "style=\"";
- newMapRequest += "z-index:" + ii + ";" + opacityString + "\">";
- newMapRequest += imageString;
- newMapRequest += "</div>";
-
- that.mapURL[ii]= newMapURL;
- currentWms.mapURL = newMapURL;
-
- if (Mapbender.log && currentWms.mapURL) {
- var tmp = eval(Mapbender.log + "('" +
- newMapURL + "','" + ts + "')");
- }
-
- return newMapRequest;
- };
-
- this.getWmsIdByTitle = function (title) {
- for (var i=0; i < this.wms.length; i++) {
- if (this.wms[i].wms_title == title) {
- return this.wms[i].wms_id;
- }
- }
- return null;
- };
-
- this.getWmsIndexById = function (wms_id) {
- for (var i=0; i< this.wms.length; i++){
- if(this.wms[i].wms_id == wms_id){
- return i;
- }
- }
- return null;
- };
-
- this.getWmsById = function (wms_id) {
- for (var i=0; i< this.wms.length; i++){
- if(this.wms[i].wms_id == wms_id){
- return this.wms[i];
- }
- }
- return null;
- };
-
- this.removeWms = function (wmsIndex) {
- var wms_ID = null;
- var i;
- var new_wmsarray = [];
- var new_layerarray = [];
- var new_querylayerarray = [];
- var new_stylesarray = [];
- var new_mapURLarray = [];
-
- for (i = 0; i < this.wms.length; i++) {
- if (i != wmsIndex) {
- new_wmsarray.push(this.wms[i]);
- new_layerarray.push(this.layers[i]);
- new_querylayerarray.push(this.querylayers[i]);
- new_stylesarray.push(this.styles[i]);
- new_mapURLarray.push(this.mapURL[i]);
- }
else {
- wms_ID = this.wms[i].wms_id;
+ var oldExtent = new Extent(that.oldExtent);
+ that.history.addItem({
+ forward: function(setExtent){
+ var index = that.history.getCurrentIndex();
+// console.log("FORWARD: " + that.history.getCurrentIndex());
+ if (typeof setExtent === "undefined" || setExtent === true) {
+ that.setExtent(extent);
+ }
+ displayMaps(index + 1);
+ animateMaps(index + 1);
+ },
+ back: function(){
+ var index = that.history.getCurrentIndex();
+// console.log("BACK: " + that.history.getCurrentIndex());
+ that.setExtent(oldExtent);
+ displayMaps(index);
+ animateMaps(index);
+ }
+ });
+
}
- }
- this.wms = new_wmsarray;
- this.layers = new_layerarray;
- this.querylayers = new_querylayerarray;
- this.styles = new_stylesarray;
- this.mapURL = new_mapURLarray;
-
- var another_new_wmsarray = [];
-
- for (i = 0; i < window.wms.length; i++) {
- if (window.wms[i].wms_id != wms_ID) {
- another_new_wmsarray.push(window.wms[i]);
- }
- }
- window.wms = another_new_wmsarray;
- };
-
- /**
- * move a wms or layer
- *
- * @param int wms_id id of wms to move
- * @param int layer_id id of layer to move
- * @return true of successful
- * @type boolean
- */
- this.move = function(wms_id, layer_id, moveUp){
- var i,j;
- for(i=0;i<this.wms.length;i++){
- if (wms_id == this.wms[i].wms_id) {
- break;
- }
- }
+ })();
- //check if only one wms is affected?
- if (layer_id && layer_id != this.wms[i].objLayer[0].layer_id) {
- return this.wms[i].moveLayer(layer_id, moveUp);
- }
-
- //else swap wms
- j = i + (moveUp?-1:1);
- if (!(i != j && i >= 0 && i < this.wms.length && j >= 0 && j < this.wms.length)) {
- return false;
- }
-
- upper = this.wms[i];
- this.wms[i] = this.wms[j];
- this.wms[j] = upper;
- var upperLayers = this.layers[i];
- var upperStyles = this.styles[i];
- var upperQuerylayers = this.querylayers[i];
- this.layers[i] = this.layers[j];
- this.styles[i] = this.styles[j];
- this.querylayers[i] = this.querylayers[j];
- this.layers[j] = upperLayers;
- this.styles[j] = upperStyles;
- this.querylayers[j] = upperQuerylayers;
-
- return true;
- };
-
- this.getMousePos = function(e){
- if(ie){
- if(this.frameName){
- clickX = window.frames[fName].event.clientX;
- clickY = window.frames[fName].event.clientY;
- }
- else{
- clickX = event.clientX;
- clickY = event.clientY;
- }
- }
- else{
- clickX = e.pageX;
- clickY = e.pageY;
- }
-
- //remove divtag offset
- clickX -= parseInt(this.getDomElement().style.left, 10);
- clickY -= parseInt(this.getDomElement().style.top, 10);
-
- return new Point(clickX, clickY);
- };
-
- var that = this;
- // private
- this.width = width;
- // private
- this.height = height;
- this.frameName = frameName;
- this.type = (frameName !== "") ? "IFRAME" : "DIV";
- this.elementName = elementName;
- this.mapURL = [];
- var domElement = this.getDomElement();
- domElement.style.width = this.width;
- domElement.style.height = this.height;
-
- ignoredWms = [];
- this.layers = [];
- this.styles = [];
- this.querylayers = [];
- this.geom = "";
- this.gml = "";
- this.wms = [];
-
- var bbox_minx, bbox_miny, bbox_maxx, bbox_maxy;
-
- /**
- * Triggered after the map has been resized
- */
- this.eventResizeMap = new MapbenderEvent();
-
- //
- // Add pointers to WMS objects which are in this map.
- // If wms_index is set (=map is overview), only this
- // WMS is being pointed to.
- //
- this.setWms(wms_index);
- //
- // set list of visible layers, active querylayers
- // and styles for each WMS in this map
- //
- this.initializeWms();
-
-
- for (var i = 0; i < wms[0].gui_epsg.length; i++) {
- if (wms[0].gui_wms_epsg == wms[0].gui_epsg[i]) {
- bbox_minx = parseFloat(wms[0].gui_minx[i]);
- bbox_miny = parseFloat(wms[0].gui_miny[i]);
- bbox_maxx = parseFloat(wms[0].gui_maxx[i]);
- bbox_maxy = parseFloat(wms[0].gui_maxy[i]);
- break;
- }
- }
-
- this.setSrs({
- srs: wms[0].gui_wms_epsg,
- extent: new Mapbender.Extent(
- bbox_minx,
- bbox_miny,
- bbox_maxx,
- bbox_maxy
- )
- });
-
-
- this.afterMapRequest = new MapbenderEvent();
-
+ this.history.forward(false);
+ };
+
+ var getLayerHtmlCode = function(ii){
+ var currentWms = that.wms[ii];
+
+ var myDivId = that.elementName + "_div_" + ii;
+ var myMapId = that.elementName + "_map_" + ii;
+ var ts = mb_timestamp();
+
+ //disable Layer which are out of scale
+ var validLayers = that.checkScale(ii);
+ var layerNames = validLayers.toString();
+
+ var newMapURL = false;
+ var opacityString = "";
+
+ if (that.layers[ii] !== "" && layerNames !== '') {
+ // get map URL
+ newMapURL = that.getMapUrl(ii);
+
+ var currentOpacity = currentWms.gui_wms_mapopacity;
+ if (currentOpacity != 1) {
+ opacityString += "opacity:" + currentOpacity + "; ";
+ opacityString += "Filter: Alpha(Opacity=" + currentOpacity * 100 + "); ";
+ opacityString += "-moz-opacity:" + currentOpacity + " ; ";
+ opacityString += "-khtml-opacity:" + currentOpacity;
+ }
+ }
+
+ var imageString = "";
+ if (newMapURL) {
+ imageString = "<img id='" + myMapId + "' name='mapimage' ";
+ imageString += "src='" + newMapURL + "' ";
+ imageString += "width='" + that.width + "' ";
+ imageString += "height='" + that.height + "' ";
+ imageString += "border='0'>";
+ }
+
+ var newMapRequest = "<div id='" + myDivId + "' ";
+ newMapRequest += "style=\"position:absolute; top:0px; left:0px; ";
+ // newMapRequest += "style=\"";
+ newMapRequest += "z-index:" + (2 * ii + 20) + ";" + opacityString + "\">";
+ newMapRequest += imageString;
+ newMapRequest += "</div>";
+
+ that.mapURL[ii] = newMapURL;
+ currentWms.mapURL = newMapURL;
+
+ if (Mapbender.log && currentWms.mapURL) {
+ var tmp = eval(Mapbender.log + "('" +
+ newMapURL +
+ "','" +
+ ts +
+ "')");
+ }
+
+ return newMapRequest;
+ };
+
+ this.getWmsIdByTitle = function(title){
+ for (var i = 0; i < this.wms.length; i++) {
+ if (this.wms[i].wms_title == title) {
+ return this.wms[i].wms_id;
+ }
+ }
+ return null;
+ };
+
+ this.getWmsIndexById = function(wms_id){
+ for (var i = 0; i < this.wms.length; i++) {
+ if (this.wms[i].wms_id == wms_id) {
+ return i;
+ }
+ }
+ return null;
+ };
+
+ this.getWmsById = function(wms_id){
+ for (var i = 0; i < this.wms.length; i++) {
+ if (this.wms[i].wms_id == wms_id) {
+ return this.wms[i];
+ }
+ }
+ return null;
+ };
+
+ this.removeWms = function(wmsIndex){
+ var wms_ID = null;
+ var i;
+ var new_wmsarray = [];
+ var new_layerarray = [];
+ var new_querylayerarray = [];
+ var new_stylesarray = [];
+ var new_mapURLarray = [];
+
+ for (i = 0; i < this.wms.length; i++) {
+ if (i != wmsIndex) {
+ new_wmsarray.push(this.wms[i]);
+ new_layerarray.push(this.layers[i]);
+ new_querylayerarray.push(this.querylayers[i]);
+ new_stylesarray.push(this.styles[i]);
+ new_mapURLarray.push(this.mapURL[i]);
+ }
+ else {
+ wms_ID = this.wms[i].wms_id;
+ }
+ }
+ this.wms = new_wmsarray;
+ this.layers = new_layerarray;
+ this.querylayers = new_querylayerarray;
+ this.styles = new_stylesarray;
+ this.mapURL = new_mapURLarray;
+
+ var another_new_wmsarray = [];
+
+ for (i = 0; i < window.wms.length; i++) {
+ if (window.wms[i].wms_id != wms_ID) {
+ another_new_wmsarray.push(window.wms[i]);
+ }
+ }
+ window.wms = another_new_wmsarray;
+ };
+
+ /**
+ * move a wms or layer
+ *
+ * @param int wms_id id of wms to move
+ * @param int layer_id id of layer to move
+ * @return true of successful
+ * @type boolean
+ */
+ this.move = function(wms_id, layer_id, moveUp){
+ var i, j;
+ for (i = 0; i < this.wms.length; i++) {
+ if (wms_id == this.wms[i].wms_id) {
+ break;
+ }
+ }
+
+ //check if only one wms is affected?
+ if (layer_id && layer_id != this.wms[i].objLayer[0].layer_id) {
+ return this.wms[i].moveLayer(layer_id, moveUp);
+ }
+
+ //else swap wms
+ j = i + (moveUp ? -1 : 1);
+ if (!(i != j && i >= 0 && i < this.wms.length && j >= 0 && j < this.wms.length)) {
+ return false;
+ }
+
+ upper = this.wms[i];
+ this.wms[i] = this.wms[j];
+ this.wms[j] = upper;
+ var upperLayers = this.layers[i];
+ var upperStyles = this.styles[i];
+ var upperQuerylayers = this.querylayers[i];
+ this.layers[i] = this.layers[j];
+ this.styles[i] = this.styles[j];
+ this.querylayers[i] = this.querylayers[j];
+ this.layers[j] = upperLayers;
+ this.styles[j] = upperStyles;
+ this.querylayers[j] = upperQuerylayers;
+
+ return true;
+ };
+
+ this.getMousePos = function(e){
+ if (ie) {
+ if (this.frameName) {
+ clickX = window.frames[fName].event.clientX;
+ clickY = window.frames[fName].event.clientY;
+ }
+ else {
+ clickX = event.clientX;
+ clickY = event.clientY;
+ }
+ }
+ else {
+ clickX = e.pageX;
+ clickY = e.pageY;
+ }
+
+ //remove divtag offset
+ clickX -= parseInt(this.getDomElement().style.left, 10);
+ clickY -= parseInt(this.getDomElement().style.top, 10);
+
+ return new Point(clickX, clickY);
+ };
+
+ var that = this;
+ // private
+ this.width = width;
+ // private
+ this.height = height;
+ this.frameName = frameName;
+ this.type = (frameName !== "") ? "IFRAME" : "DIV";
+ this.elementName = elementName;
+ this.mapURL = [];
+ var domElement = this.getDomElement();
+ domElement.style.width = this.width;
+ domElement.style.height = this.height;
+
+ ignoredWms = [];
+ this.layers = [];
+ this.styles = [];
+ this.querylayers = [];
+ this.geom = "";
+ this.gml = "";
+ this.wms = [];
+
+ var bbox_minx, bbox_miny, bbox_maxx, bbox_maxy;
+
+ /**
+ * Triggered after the map has been resized
+ */
+ this.eventResizeMap = new MapbenderEvent();
+
+ //
+ // Add pointers to WMS objects which are in this map.
+ // If wms_index is set (=map is overview), only this
+ // WMS is being pointed to.
+ //
+ this.setWms(wms_index);
+ //
+ // set list of visible layers, active querylayers
+ // and styles for each WMS in this map
+ //
+ this.initializeWms();
+
+
+ for (var i = 0; i < wms[0].gui_epsg.length; i++) {
+ if (wms[0].gui_wms_epsg == wms[0].gui_epsg[i]) {
+ bbox_minx = parseFloat(wms[0].gui_minx[i]);
+ bbox_miny = parseFloat(wms[0].gui_miny[i]);
+ bbox_maxx = parseFloat(wms[0].gui_maxx[i]);
+ bbox_maxy = parseFloat(wms[0].gui_maxy[i]);
+ break;
+ }
+ }
+
+ this.setSrs({
+ srs: wms[0].gui_wms_epsg,
+ extent: new Mapbender.Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy)
+ });
+
+
+ this.afterMapRequest = new MapbenderEvent();
+
};
-Mapbender.Map.prototype.getWfsConfIds = function (wfs_config) {
- var db_wfs_conf_id = [];
- var js_wfs_conf_id = [];
-
- //search configurations that are selected (and in scale)
- for (var i=0; i < this.wms.length; i++){
- for(var ii=0; ii < this.wms[i].objLayer.length; ii++){
- var o = this.wms[i].objLayer[ii];
- if(o.gui_layer_wfs_featuretype != '' && o.gui_layer_querylayer == '1'){
- if (!checkscale || o.checkScale(this)) {
- db_wfs_conf_id[db_wfs_conf_id.length] = o.gui_layer_wfs_featuretype;
- }
- }
- }
- }
- for(var i=0; i < db_wfs_conf_id.length; i++){
- for(var ii=0; ii < wfs_config.length; ii++){
- if(wfs_config[ii].wfs_conf_id == db_wfs_conf_id[i]){
- js_wfs_conf_id[js_wfs_conf_id.length] = ii;
- break;
- }
- }
- }
- return js_wfs_conf_id;
+Mapbender.Map.prototype.getWfsConfIds = function(wfs_config){
+ var db_wfs_conf_id = [];
+ var js_wfs_conf_id = [];
+
+ //search configurations that are selected (and in scale)
+ for (var i = 0; i < this.wms.length; i++) {
+ for (var ii = 0; ii < this.wms[i].objLayer.length; ii++) {
+ var o = this.wms[i].objLayer[ii];
+ if (o.gui_layer_wfs_featuretype != '' && o.gui_layer_querylayer == '1') {
+ if (!checkscale || o.checkScale(this)) {
+ db_wfs_conf_id[db_wfs_conf_id.length] = o.gui_layer_wfs_featuretype;
+ }
+ }
+ }
+ }
+ for (var i = 0; i < db_wfs_conf_id.length; i++) {
+ for (var ii = 0; ii < wfs_config.length; ii++) {
+ if (wfs_config[ii].wfs_conf_id == db_wfs_conf_id[i]) {
+ js_wfs_conf_id[js_wfs_conf_id.length] = ii;
+ break;
+ }
+ }
+ }
+ return js_wfs_conf_id;
};
Modified: trunk/mapbender/http/javascripts/mod_box1.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_box1.js 2009-11-09 17:07:53 UTC (rev 4968)
+++ trunk/mapbender/http/javascripts/mod_box1.js 2009-11-09 17:08:22 UTC (rev 4969)
@@ -141,7 +141,8 @@
topNode.style.width = "0px";
topNode.style.height = "0px";
topNode.style.overflow = "hidden";
- topNode.style.zIndex = parseInt(map_el.style.zIndex, 10) + 1;
+// topNode.style.zIndex = parseInt(map_el.style.zIndex, 10) + 1;
+ topNode.style.zIndex = 100;
topNode.style.visibility = "visible";
topNode.style.cursor = "crosshair";
topNode.style.backgroundColor = color;
Modified: trunk/mapbender/lib/extent.js
===================================================================
--- trunk/mapbender/lib/extent.js 2009-11-09 17:07:53 UTC (rev 4968)
+++ trunk/mapbender/lib/extent.js 2009-11-09 17:08:22 UTC (rev 4969)
@@ -101,6 +101,13 @@
return false;
};
+ var isExtent = function (param) {
+ if (typeof param === "object" && param.constructor === Mapbender.Extent) {
+ return true;
+ }
+ return false;
+ };
+
this.getSouthWest = function () {
return this.min;
};
@@ -109,7 +116,10 @@
return this.max;
};
- if (isPoint(minx) && isPoint(miny) &&
+ if (isExtent(minx)) {
+ this.set(cloneObject(minx.min), cloneObject(minx.max));
+ }
+ else if (isPoint(minx) && isPoint(miny) &&
typeof maxx === "undefined" &&
typeof maxy === "undefined") {
@@ -124,4 +134,4 @@
new Point(parseFloat(maxx), parseFloat(maxy))
);
}
-}
+};
Added: trunk/mapbender/lib/history.js
===================================================================
--- trunk/mapbender/lib/history.js (rev 0)
+++ trunk/mapbender/lib/history.js 2009-11-09 17:08:22 UTC (rev 4969)
@@ -0,0 +1,63 @@
+Mapbender.History = function () {
+ var historyItemArray = [];
+ var currentIndex = 0;
+
+ this.events = {
+ beforeAdd : new Mapbender.Event(),
+ beforeBack : new Mapbender.Event(),
+ beforeForward : new Mapbender.Event(),
+ afterBack : new Mapbender.Event(),
+ afterForward : new Mapbender.Event()
+ };
+
+ this.getCurrentIndex = function () {
+ return currentIndex;
+ };
+
+ this.count = function () {
+ return historyItemArray.length;
+ };
+ this.addItem = function (obj) {
+ if (typeof obj == "object"
+ && obj.back && typeof obj.back === "function"
+ && obj.forward && typeof obj.forward === "function"
+ ) {
+ this.events.beforeAdd.trigger();
+ for (var i = currentIndex; i < historyItemArray.length; i++) {
+ delete historyItemArray[i];
+ }
+ historyItemArray.length = currentIndex;
+ historyItemArray.push({
+ back: obj.back,
+ forward: obj.forward,
+ data: obj.data
+ });
+ return true;
+ }
+ return false;
+ };
+
+ this.back = function (obj) {
+ if (currentIndex > 0) {
+ this.events.beforeBack.trigger();
+ currentIndex --;
+ historyItemArray[currentIndex].back(obj);
+// console.log("BACK: " + historyItemArray[currentIndex].back);
+ this.events.afterBack.trigger();
+ return true;
+ }
+ return false;
+ };
+
+ this.forward = function (obj) {
+ if (currentIndex < historyItemArray.length) {
+ this.events.beforeForward.trigger();
+ historyItemArray[currentIndex].forward(obj);
+// console.log("FORWARD: " + historyItemArray[currentIndex].forward);
+ currentIndex ++;
+ this.events.afterForward.trigger();
+ return true;
+ }
+ return false;
+ };
+};
\ No newline at end of file
More information about the Mapbender_commits
mailing list