[Mapbender-commits] r6121 - branches/3_dev/core/lib/js
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Sun May 9 12:04:06 EDT 2010
Author: astrid_emde
Date: 2010-05-09 12:04:06 -0400 (Sun, 09 May 2010)
New Revision: 6121
Added:
branches/3_dev/core/lib/js/history.js
branches/3_dev/core/lib/js/map_obj.js
branches/3_dev/core/lib/js/wfs_obj.js
branches/3_dev/core/lib/js/wms.js
Modified:
branches/3_dev/core/lib/js/extent.js
Log:
for template-basic from trunk,merges classes from trunk, file names not modified yet
Modified: branches/3_dev/core/lib/js/extent.js
===================================================================
--- branches/3_dev/core/lib/js/extent.js 2010-05-09 16:02:50 UTC (rev 6120)
+++ branches/3_dev/core/lib/js/extent.js 2010-05-09 16:04:06 UTC (rev 6121)
@@ -112,8 +112,8 @@
// input is "coordinate, coordinate, coordinate, coordinate"
// deprecated
this.set(
- new Point(parseFloat(minx), parseFloat(miny)),
- new Point(parseFloat(maxx), parseFloat(maxy))
+ new Mapbender.Point(parseFloat(minx), parseFloat(miny)),
+ new Mapbender.Point(parseFloat(maxx), parseFloat(maxy))
);
}
};
Added: branches/3_dev/core/lib/js/history.js
===================================================================
--- branches/3_dev/core/lib/js/history.js (rev 0)
+++ branches/3_dev/core/lib/js/history.js 2010-05-09 16:04:06 UTC (rev 6121)
@@ -0,0 +1,61 @@
+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);
+ this.events.afterBack.trigger();
+ return true;
+ }
+ return false;
+ };
+
+ this.forward = function (obj) {
+ if (currentIndex < historyItemArray.length) {
+ this.events.beforeForward.trigger();
+ historyItemArray[currentIndex].forward(obj);
+ currentIndex ++;
+ this.events.afterForward.trigger();
+ return true;
+ }
+ return false;
+ };
+};
\ No newline at end of file
Added: branches/3_dev/core/lib/js/map_obj.js
===================================================================
--- branches/3_dev/core/lib/js/map_obj.js (rev 0)
+++ branches/3_dev/core/lib/js/map_obj.js 2010-05-09 16:04:06 UTC (rev 6121)
@@ -0,0 +1,1639 @@
+/**
+ * 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
+ * elementName - the ID of the DOM node
+ * width - width of the map in pixel
+ * height - height of the map in pixel
+ * 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){
+
+ var mapMsgObj;
+ var extentHasChanged = false;
+ var srsHasChanged = false;
+
+ this.slippy = false;
+
+ Mapbender.events.localize.register(function(){
+ localizeMap();
+ });
+
+ Mapbender.events.init.register(function(){
+ localizeMap();
+ });
+
+ var localizeMap = function(){
+ $.post("../php/mod_map_messages.php", function(obj, status){
+ mapMsgObj = $.parseJSON(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 Mapbender.Extent(this.extent);
+
+ // pixel coordinates of new Mapbender.Extent in old extent
+ var oldpixll, oldpixur;
+ if (arguments.length === 1) {
+ oldpixll = this.convertRealToPixel(minx.min);
+ oldpixur = this.convertRealToPixel(minx.max);
+ this.oldExtentPix = new Mapbender.Extent(oldpixll.x, oldpixll.y, oldpixur.x, oldpixur.y);
+ }
+ else if (arguments.length === 4) {
+ oldpixll = this.convertRealToPixel(new Mapbender.Point(parseFloat(minx), parseFloat(miny)));
+ oldpixur = this.convertRealToPixel(new Mapbender.Point(parseFloat(maxx), parseFloat(maxy)));
+ this.oldExtentPix = new Mapbender.Extent(oldpixll.x, oldpixll.y, oldpixur.x, oldpixur.y);
+ }
+
+ }
+ else {
+ this.oldExtentPix = new Mapbender.Extent(0, this.getHeight(), this.getWidth(), 0);
+ }
+
+
+ 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 Mapbender.Point(arguments[0], arguments[1]), new Mapbender.Point(arguments[2], arguments[3]));
+ }
+ }
+ extentHasChanged = true;
+ };
+
+ /*
+ 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(){
+ var w = $(this.getDomElement()).innerWidth();
+ if (w !== 0) {
+ return w;
+ }
+ 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;
+
+ this.events.dimensionsChanged.trigger({
+ width: this.width,
+ height: this.height
+ });
+ };
+
+ this.setDimensions = function (w, h) {
+ this.width = parseInt(w, 10);
+ this.height = parseInt(h, 10);
+
+ if (this.frameName) {
+ document.getElementById(this.frameName).style.width = this.width;
+ document.getElementById(this.frameName).style.height = this.height;
+ }
+ var domElement = this.getDomElement();
+ domElement.style.width = this.width;
+ domElement.style.height = this.height;
+
+ this.calculateExtent(this.extent);
+ this.setMapRequest();
+
+ this.events.dimensionsChanged.trigger({
+ width: this.width,
+ height: this.height
+ });
+
+ };
+ /**
+ * get the height of the mapObj
+ *
+ * @member Map
+ * @return width of the mapObj
+ * @type integer
+ */
+ this.getHeight = function(){
+ var h = $(this.getDomElement()).innerHeight();
+ if (h !== 0) {
+ return h;
+ }
+ 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.events.dimensionsChanged.trigger({
+ width: this.width,
+ height: this.height
+ });
+ };
+
+ // using the normalized jQuery event
+ this.getPos = function (e) {
+ var $dom = $(this.getDomElement());
+ return new Mapbender.Point(
+ e.pageX - $dom.offset().left,
+ e.pageY - $dom.offset().top
+ );
+ };
+
+ this.getMousePosition = function (event) {
+ if (typeof event.originalEvent !== "undefined") {
+ return this.getPos(event);
+ }
+
+ var pageX, pageY, offsetX, offsetY;
+ var e = event || window.event;
+ var target = e.target || e.srcElement;
+
+ if (!e) {
+ return null;
+ }
+
+ // FIREFOX
+ if (typeof e.layerX !== "undefined") {
+ if (target.id === this.getDomElement().id) {
+ offsetX = e.layerX;
+ offsetY = e.layerY;
+ return new Mapbender.Point(offsetX, offsetY);
+ }
+ }
+
+ // FIREFOX w/ other target
+ if (typeof e.pageX !== "undefined") {
+ pageX = e.pageX;
+ pageY = e.pageY;
+ }
+ // IE
+ else if (typeof e.clientX !== "undefined") {
+ pageX = e.clientX + ((
+ window.document.body &&
+ typeof window.document.body.scrollLeft !== "undefined"
+ ) ?
+ window.document.body.scrollLeft : 0);
+ pageY = e.clientY + ((
+ window.document.body &&
+ typeof window.document.body.scrollTop !== "undefined"
+ ) ?
+ window.document.body.scrollTop : 0);
+ }
+ var x = 0;
+ var t = (typeof(target)=='string') ?
+ (document.getElementById ?
+ document.getElementById(e) :
+ (document.all ? document.all[e] : null)
+ ) : target;
+ t = this.getDomElement();
+ while (t) {
+ if ($(t).eq(0).attr("id") === this.getDomElement().id && typeof t.offsetLeft !== "undefined") {
+ x += t.offsetLeft;
+ }
+ t = (typeof t.offsetParent !== "undefined") ?
+ t.offsetParent : null;
+ }
+ pageX -= x;
+
+ var y = 0;
+ t = (typeof(target)=='string') ?
+ (document.getElementById ?
+ document.getElementById(e) :
+ (document.all ? document.all[e] : null)
+ ) : target;
+ t = this.getDomElement();
+ while (t) {
+ if ($(t).eq(0).attr("id") === this.getDomElement().id && typeof t.offsetTop !== "undefined") {
+ y += t.offsetTop;
+ }
+ t = (typeof t.offsetParent !== "undefined") ?
+ t.offsetParent : null;
+ }
+ pageY -= y;
+ return new Mapbender.Point(pageX, pageY);
+ };
+
+ /**
+ * 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;
+ var oldMin = ext.getSouthWest();
+ var oldMax = ext.getNorthEast();
+
+ if (relation_bbox_x <= relation_px_x) {
+ ext.set(new Mapbender.Point(
+ ext.centerx - relation_px_x * ext.extenty / 2,
+ oldMin.y
+ ), new Mapbender.Point(
+ ext.centerx + relation_px_x * ext.extenty / 2,
+ oldMax.y
+ ));
+ }
+ if (relation_bbox_x > relation_px_x) {
+ ext.set(new Mapbender.Point(
+ oldMin.x,
+ ext.centery - relation_px_y * ext.extentx / 2
+ ), new Mapbender.Point(
+ oldMax.x,
+ ext.centery + relation_px_y * ext.extentx / 2
+ ));
+ }
+
+ // Check if ext is within restricted extent
+ // If not, calculate a new Mapbender.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);
+ 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;
+
+ }
+ srsHasChanged = true;
+ 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] = Mapbender.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.toUpperCase()) {
+ 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;
+ }
+ }
+ }
+ };
+
+ this.calculateExtentAfterZoom = function (in_, factor, x, y) {
+ factor = parseFloat(factor);
+ if (!in_) {
+ factor = 1 / factor;
+ }
+
+ var extent = that.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;
+ }
+
+ var centerx, centery;
+ if (x && y) {
+ centerx = parseFloat(x);
+ centery = parseFloat(y);
+ }
+ else {
+ centerx = extent.minx + distx / 2;
+ 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 Mapbender.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);
+ }
+ }
+ */
+ return new Mapbender.Extent(minx, miny, maxx, maxy);
+ };
+
+ /**
+ * 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){
+ this.setExtent(this.calculateExtentAfterZoom(in_, factor, x, y));
+ this.setMapRequest();
+ };
+
+ this.convertPixelToReal = function(aPoint, referenceExtent){
+ var arrayBBox;
+ if (arguments.length === 2) {
+ arrayBBox = referenceExtent.toString().split(",");
+ }
+ else {
+ 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.getWidth();
+ var deltaY = xtenty / this.getHeight();
+
+ var digitsX = Math.round(Math.log(deltaX)/Math.log(10));
+ var digitsY = Math.round(Math.log(deltaY)/Math.log(10));
+ var roundX = Math.pow(10, -digitsX);
+ var roundY = Math.pow(10, -digitsY);
+
+ var posX = parseFloat(minX + (aPoint.x / this.getWidth()) * xtentx);
+ var posY = parseFloat(maxY - (aPoint.y / this.getHeight()) * xtenty);
+ posX = Math.round(posX * roundX) / roundX;
+ posY = Math.round(posY * roundY) / roundY;
+ var newX = posX, newY = posY;
+ if (digitsX < 0) {
+ newX = posX.toFixed(-digitsX);
+ }
+ if (digitsY < 0) {
+ newY = posY.toFixed(-digitsY);
+ }
+ var pt = new Mapbender.Point(newX, newY);
+ return pt;
+
+ };
+
+ /**
+ * Convert real world coordinates to pixel coordinates
+ */
+ this.convertRealToPixel = function(aPoint, referenceExtent){
+ var arrayBBox;
+ if (arguments.length === 2) {
+ arrayBBox = referenceExtent.toString().split(",");
+ }
+ else {
+ arrayBBox = this.getExtent().split(",");
+ }
+ var minX = parseFloat(arrayBBox[0]);
+ var minY = parseFloat(arrayBBox[1]);
+ var maxX = parseFloat(arrayBBox[2]);
+ var maxY = parseFloat(arrayBBox[3]);
+ return new Mapbender.Point(Math.round((aPoint.x - minX) * this.getWidth() / (maxX - minX)), Math.round((maxY - aPoint.y) * this.getHeight() / (maxY - minY)));
+ };
+
+ /**
+ * get the srs of the mapObj
+ *
+ * @return srs as epsg:number
+ * @type string
+ */
+ this.getSRS = function(){
+ return this.epsg;
+ };
+
+ this.getSrs = function(){
+ return this.epsg;
+ };
+
+ /**
+ * Return the map URL of the WMS at index i
+ * @param {Object} currentWmsIndex
+ */
+ this.getMapUrl = function(ii, extent){
+ var currentWms = this.wms[ii];
+ var validLayers = (arguments.length === 3 && typeof arguments[2] === "number") ?
+ currentWms.getLayers(this, arguments[2]) : currentWms.getLayers(this);
+ if (validLayers.length === 0) {
+ return false;
+ }
+ var validLayersEncoded = [];
+ for (var i = 0; i < validLayers.length; i++) {
+ validLayersEncoded[i] = encodeURIComponent(validLayers[i]);
+ }
+ var layerNames = validLayersEncoded.join(",");
+
+ url = currentWms.wms_getmap;
+ url += Mapbender.getConjunctionChar(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=";
+ for (var j = 0; j < validLayers.length; j++) {
+ if (j > 0) {
+ url += ",";
+ }
+
+ if (currentWms.getCurrentStyleByLayerName(validLayers[j]) !== false &&
+ typeof currentWms.getCurrentStyleByLayerName(validLayers[j]) !== "undefined") {
+ url += encodeURIComponent(currentWms.getCurrentStyleByLayerName(validLayers[j]));
+ }
+ }
+ url += "&";
+ url += "SRS=" + this.epsg + "&";
+ url += "BBOX=" + extent.toString() + "&";
+ url += "WIDTH=" + this.getWidth() + "&";
+ url += "HEIGHT=" + this.getHeight() + "&";
+ 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 currentWms_wms_title = currentWms.wms_title;
+ 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 + "&";
+
+ // not sure what this is, but it's evil
+ try {
+ if (currentWms.wms_title == removeLayerAndStylesAffectedWMSTitle) {
+ url = url.replace(/LAYERS=[^&]*&/, '');
+ url = url.replace(/STYLES=[^&]*&/, '');
+ }
+ }
+ catch (exc) {
+ new Mb_warning(exc.message);
+ }
+ }
+ }
+ // 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.getWidth();
+ var pxLeny = (parseFloat(bbox[3]) - parseFloat(bbox[1])) / this.getHeight();
+ 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) * (Mapbender.resolution * 100);
+ }
+ else {
+ xtenty = parseFloat(bbox[3]) - parseFloat(bbox[1]);
+ scale = (xtenty / this.getHeight()) * (Mapbender.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.getWidth() / (Mapbender.resolution * 100 * 2) * scale);
+ var miny = parseFloat(y) - (this.getHeight() / (Mapbender.resolution * 100 * 2) * scale);
+ var maxx = parseFloat(x) + (this.getWidth() / (Mapbender.resolution * 100 * 2) * scale);
+ var maxy = parseFloat(y) + (this.getHeight() / (Mapbender.resolution * 100 * 2) * scale);
+ this.repaint(new Mapbender.Point(minx, miny), new Mapbender.Point(maxx, maxy));
+ };
+
+ this.repaint = function(min, max){
+ if (typeof min !== "undefined" && typeof max !== "undefined") {
+ this.extent = this.calculateExtent(new Mapbender.Extent(min, max));
+ }
+ this.setMapRequest();
+ };
+
+ this.setSingleMapRequest = function(wms_id){
+ if (typeof wms_id === "object") {
+ this.setMapRequest(wms_id);
+ }
+ else {
+ this.setMapRequest([wms_id]);
+ }
+ };
+
+ this.mb_setFutureObj = function(mod_back_cnt){
+ var cnt = this.mb_MapFutureObj.length;
+ var i;
+ this.mb_MapFutureObj[cnt] = {};
+ this.mb_MapFutureObj[cnt].reqCnt = mod_back_cnt;
+ this.mb_MapFutureObj[cnt].width = this.getWidth();
+ this.mb_MapFutureObj[cnt].height = this.getHeight();
+ this.mb_MapFutureObj[cnt].epsg = this.epsg;
+ this.mb_MapFutureObj[cnt].extent = this.extent;
+ this.mb_MapFutureObj[cnt].layers = [];
+
+ for (i = 0; i < this.layers.length; i++) {
+ this.mb_MapFutureObj[cnt].layers[i] = this.layers[i];
+ }
+
+ this.mb_MapFutureObj[cnt].styles = [];
+
+ for (i = 0; i < this.styles.length; i++) {
+ this.mb_MapFutureObj[cnt].styles[i] = this.styles[i];
+ }
+
+ this.mb_MapFutureObj[cnt].querylayers = [];
+
+ for (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;
+ var i;
+
+ // existing history item
+ if (requestCnt + 1 < numRequests && numRequests > 1 || $("#" + that.elementName + "_request_" + requestCnt).size() > 0) {
+ $("#" + that.elementName + "_request_" + requestCnt).hide();
+ for (i = 0; i < requestCnt; i++) {
+ $("#" + that.elementName + "_request_" + i).hide();
+ }
+ for (i = requestCnt + 1; i <= numRequests; i++) {
+ $("#" + that.elementName + "_request_" + i).hide();
+ }
+ $("#" + that.elementName + "_request_" + requestCnt + " div img").css({
+ visibility: "visible"
+ });
+ }
+ // new history item
+ else {
+ var newMapRequest = "";
+ for (i = 0; i < idArray.length; i++) {
+ var currentWms = that.wms[idArray[i]];
+/*
+ if (that.slippy && currentWms.gui_wms_visible === 2) {
+ // request larger background image
+ var bgExtent = this.calculateExtentAfterZoom(false, 2.0, that.extent.center.x, that.extent.center.y);
+ var bgSwPix = that.convertRealToPixel(bgExtent.min);
+ var bgNePix = that.convertRealToPixel(bgExtent.max);
+
+ var left = bgSwPix.x;
+ var top = bgNePix.y;
+ var width = bgNePix.x - bgSwPix.x;
+ var height = bgSwPix.y - bgNePix.y;
+ var html = getLayerHtmlCode(idArray[i], bgExtent, width, height, top, left, requestCnt);
+ }
+*/
+ newMapRequest += getLayerHtmlCode(
+ idArray[i],
+ that.extent,
+ that.getWidth(),
+ that.getHeight(),
+ 0,
+ 0,
+ requestCnt
+ );
+ }
+ var $currentRequest = $(
+ "<div id='" + that.elementName + "_request_" + (requestCnt) +
+ "'></div>").hide().css({
+ position: "absolute",
+ top: "0px",
+ left: "0px"
+ })
+ if (newMapRequest !== "") {
+ $currentRequest.append(newMapRequest);
+ }
+
+ $("#" + that.elementName + "_maps").append($currentRequest);
+ for (i = 0; i < requestCnt; i++) {
+ $("#" + that.elementName + "_request_" + i).hide().each(function () {
+ $(this).children().each(function () {
+ this.style.zIndex = this.style.zIndex - 1;
+ });
+ });
+ }
+ }
+ $("#" + that.elementName + "_request_" + index).show();
+
+ };
+
+ var displayMaps = function(index, wmsArray){
+ var ret = Mapbender.events.beforeMapRequest.trigger({
+ map: that
+ }, "AND");
+ if (ret === false) {
+ return true;
+ }
+ var myMapId = [];
+ var mapUrlArray = [];
+ var visibleWms = [];
+ var restrictedWmsArray = typeof wmsArray === "object" && wmsArray.length ?
+ wmsArray : [];
+ for (var ii = 0; ii < that.wms.length; ii++) {
+ var currentWms = that.wms[ii];
+
+ if (restrictedWmsArray.length > 0) {
+ var found = true;
+ for (var j = 0; j < restrictedWmsArray.length; j++) {
+ if (restrictedWmsArray[j] === currentWms.wms_id) {
+ found = false;
+ break;
+ }
+ }
+ if (!found) {
+ continue;
+ }
+ }
+
+ 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 + "_request_" + index + "_map_" + ii);
+ mapUrlArray.push(that.getMapUrl(ii, that.extent));
+ visibleWms.push(ii);
+ }
+
+ drawMaps(visibleWms, index);
+
+ Mapbender.events.afterMapRequest.trigger({
+ map: that,
+ myMapId: myMapId.join(","),
+ url: mapUrlArray
+ });
+ that.afterMapRequest.trigger({
+ map: that,
+ myMapId: myMapId.join(","),
+ url: mapUrlArray
+ });
+
+ };
+
+ var deactivatePreviousMapImg = function (domNode, index) {
+ var tmpId = domNode.id;
+ var pattern = /_request_([0-9]+)_/;
+ var newId = tmpId.replace(pattern, "_request_" + (index-1) + "_");
+ $("#" + newId).css({
+ visibility: "hidden"
+ });
+ };
+
+ this.moveMap = function (x, y) {
+ var newX = x;
+ var newY = y;
+ var index = this.history.getCurrentIndex();
+
+ // do not reset the map
+ if (typeof newX !== "undefined") {
+ $("#" + this.elementName + "_request_" + index).css({
+ top: String(newY) + "px",
+ left: String(newX) + "px"
+ });
+ }
+
+ // reset pan sub elements only
+ // TO DO: this looks awkward when animation is turned on
+ if (typeof newX === "undefined") {
+ newX = 0;
+ newY = 0;
+ }
+ for(var i = 0; i < mb_PanSubElements.length; i++) {
+ mb_arrangeElement("", mb_PanSubElements[i], newX, newY);
+ }
+ };
+
+ var animateMaps = function (index) {
+
+ //
+ // show new map
+ //
+
+ if (that.slippy && extentHasChanged && !srsHasChanged) {
+ var previousRequest = $("#" + that.elementName + "_request_" + (index-1));
+ var wasPanned = parseInt(previousRequest.css("top"), 10) !== 0 ||
+ parseInt(previousRequest.css("left"), 10) !== 0;
+
+ var newWidth = that.oldExtentPix.max.x - that.oldExtentPix.min.x;
+ var newHeight = that.oldExtentPix.min.y - that.oldExtentPix.max.y;
+ var newTop = that.oldExtentPix.max.y;
+ var newLeft = that.oldExtentPix.min.x;
+
+ //
+ // abort if no animation is required
+ //
+ if (newLeft === 0 && newTop === 0 && newHeight === that.getHeight() && newWidth === that.getWidth()) {
+ return;
+ }
+
+ //
+ // show previous maps for animation
+ //
+ $("#" + that.elementName + "_request_" + (index - 1)).css().show();
+
+ //
+ // hide new images until complete, but perform pan animation
+ //
+ $("#" + that.elementName + "_request_" + index + " div img").css({
+ visibility: "hidden"
+ }).load(function () {
+ this.style.visibility = "visible";
+
+ $(this).data("loaded", true);
+ if ($(this).data("loaded") && (wasPanned || $(this).data("animationFinished"))) {
+ deactivatePreviousMapImg(this, index);
+ }
+ });
+
+ if (wasPanned) {
+ return;
+ }
+
+ //
+ // animate new images (zoom)
+ //
+ if (newWidth !== that.getWidth() || newHeight !== that.getHeight()) {
+ var currentMapImg = $("#" + that.elementName + "_request_" + index + " div img");
+ currentMapImg.css({
+ width: newWidth,
+ height: newHeight
+ }).animate(
+ {
+ width: that.getWidth() + "px",
+ height: that.getHeight() + "px"
+ }, "normal", "linear", function () {
+ $(this).data("animationFinished", true);
+ if ($(this).data("loaded") && ($(this).data("animationFinished"))) {
+ deactivatePreviousMapImg(this, index);
+ }
+ }
+ );
+ }
+
+ //
+ // animate new images (pan & zoom)
+ //
+ $("#" + that.elementName + "_request_" + index).css({
+ position: "absolute",
+ top: newTop,
+ left: newLeft
+ }).animate(
+ {
+ left: "0px",
+ top: "0px"
+ }, "normal", "linear", function () {
+ $(this).children().children().each(function () {
+ $(this).data("animationFinished", true);
+ if ($(this).data("loaded") && $(this).data("animationFinished")) {
+ deactivatePreviousMapImg(this, index);
+ }
+ });
+ }
+ );
+
+
+ //
+ // animate previous request div and images
+ //
+
+ // calculate old extent's pixel pos in new Mapbender.Extent
+ var oldLLPix = that.convertRealToPixel(that.oldExtent.min);
+ var oldURPix = that.convertRealToPixel(that.oldExtent.max);
+
+ var left = oldLLPix.x;
+ var top = oldURPix.y;
+ var width = oldURPix.x - oldLLPix.x;
+ var height = oldLLPix.y - oldURPix.y;
+
+ // zoom
+ if (width !== that.getWidth() || height !== that.getHeight()) {
+ // zoom
+ var oldMapImg = $("#" + that.elementName + "_request_" + (index-1) + " div img");
+ oldMapImg.css({
+ position: "absolute"
+ }).animate(
+ {
+ width: width + "px",
+ height: height + "px"
+ },
+ "normal",
+ "linear"
+ );
+ }
+
+ // pan & zoom
+ $("#" + that.elementName + "_request_" + (index - 1)).animate(
+ {
+ left: left + "px",
+ top: top + "px"
+ },
+ "normal",
+ "linear"
+ );
+ }
+ };
+
+ this.setMapRequest = function(wmsArray){
+ // initialize history
+ (function(){
+ var extent = new Mapbender.Extent(that.extent);
+ if (typeof that.oldExtent === "undefined") {
+ that.setExtent(extent, false);
+ displayMaps(0);
+ if (typeof wmsArray === "undefined") {
+ animateMaps(0);
+ }
+ }
+ else {
+ var oldExtent = new Mapbender.Extent(that.oldExtent);
+ that.history.addItem({
+ forward: function(setExtent){
+ var index = that.history.getCurrentIndex();
+ if (typeof setExtent === "undefined" || setExtent === true) {
+ that.setExtent(extent);
+ }
+ displayMaps(index + 1);
+ if (typeof wmsArray === "undefined") {
+ animateMaps(index + 1);
+ }
+ },
+ back: function(){
+ var index = that.history.getCurrentIndex();
+ that.setExtent(oldExtent);
+ displayMaps(index);
+ if (typeof wmsArray === "undefined") {
+ animateMaps(index);
+ }
+ }
+ });
+ }
+ })();
+
+ this.history.forward(false);
+ extentHasChanged = false;
+ srsHasChanged = false;
+ };
+
+ var getLayerHtmlCode = function(ii, extent, width, height, top, left, requestCnt){
+ var currentWms = that.wms[ii];
+
+ var myDivId = that.elementName + "_request_" + requestCnt + "_div_" + ii;
+ var myMapId = that.elementName + "_request_" + requestCnt + "_map_" + ii;
+ var ts = Mapbender.getTimestamp;
+
+ //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, that.extent);
+
+ 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='" + width + "' ";
+ imageString += "height='" + height + "' ";
+ imageString += "border='0'>";
+ }
+
+ var newMapRequest = "<div id='" + myDivId + "' ";
+ newMapRequest += "style=\"position:absolute; top:" + top + "px; left:" + left + "px; ";
+ //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;
+ };
+
+ /* DEPRECATED! */
+ this.getMousePos = function(e){
+ var pt = this.getMousePosition(e);
+ // set the globals for backwards compatibility
+ if (pt !== null) {
+ clickX = pt.x;
+ clickY = pt.y;
+ }
+ return pt;
+ };
+
+ 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();
+ if (this.width) {
+ domElement.style.width = this.width;
+ }
+ else {
+ this.width = this.getWidth();
+ }
+ if (this.height) {
+ domElement.style.height = this.height;
+ }
+ else {
+ this.height = this.getHeight();
+ }
+
+ 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 Mapbender.Event();
+ this.events = {
+ afterMapRequest: this.afterMapRequest,
+ dimensionsChanged: new Mapbender.Event()
+ };
+
+};
+
+Mapbender.Map.prototype.getWfsConfIds = function(wfs_config){
+ var db_wfs_conf_id = [];
+ var js_wfs_conf_id = [];
+ var i, ii;
+ //search configurations that are selected (and in scale)
+ for (i = 0; i < this.wms.length; i++) {
+ for (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 (i = 0; i < db_wfs_conf_id.length; i++) {
+ for (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;
+};
Added: branches/3_dev/core/lib/js/wfs_obj.js
===================================================================
--- branches/3_dev/core/lib/js/wfs_obj.js (rev 0)
+++ branches/3_dev/core/lib/js/wfs_obj.js 2010-05-09 16:04:06 UTC (rev 6121)
@@ -0,0 +1,75 @@
+//$Id: wfs_obj.js 2413 2008-04-23 16:21:04Z christoph $
+//$Header: /cvsroot/mapbender/mapbender/http/javascripts/wfs_obj.js,v 1.3 2005/09/13 14:38:11 bjoern_heuser Exp $
+//global variables
+var wfs = [];
+var wfs_featuretype_count = 0;
+var wfs_element_count = 0;
+//list of all wms-objects
+function add_wfs(
+ wfs_id,
+ wfs_version,
+ wfs_title,
+ wfs_abstract,
+ wfs_getcapabilities,
+ wfs_describefeaturetype){
+ wfs[wfs.length] = new wfs_const(
+ wfs_id,
+ wfs_version,
+ wfs_title,
+ wfs_abstract,
+ wfs_getcapabilities,
+ wfs_describefeaturetype);
+ //wfs_featuretype[wfs.length - 1] = [];
+}
+//the wms constructor
+function wfs_const(
+ wfs_id,
+ wfs_version,
+ wfs_title,
+ wfs_abstract,
+ wfs_getcapabilities,
+ wfs_describefeaturetype){
+
+ this.wfs_id = wfs_id;
+ this.wfs_version = wfs_version;
+ this.wfs_title = wfs_title;
+ this.wfs_abstract = wfs_abstract;
+ this.wfs_getcapabilities = wfs_getcapabilities;
+ this.wfs_describefeaturetype = wfs_describefeaturetype;
+
+ this.wfs_featuretype = [];
+ //alert(wfs_id + " , " +wfs_title + " , " +wfs_abstract + " , " +wfs_getcapabilities + " , " +wfs_describefeaturetype);
+}
+//featuretype
+function wfs_add_featuretype(
+ featuretype_name,
+ featuretype_title,
+ featuretype_srs,
+ featuretype_geomtype){
+
+ wfs[wfs.length-1].wfs_featuretype[wfs[wfs.length-1].wfs_featuretype.length] = new featuretype(
+ featuretype_name,
+ featuretype_title,
+ featuretype_srs,
+ featuretype_geomtype);
+//alert(featuretype_name + " , " +featuretype_title + " , " +featuretype_srs + " , " +featuretype_geomtype);
+}
+function featuretype(
+ featuretype_name,
+ featuretype_title,
+ featuretype_srs,
+ featuretype_geomtype){
+ this.featuretype_name = featuretype_name;
+ this.featuretype_title = featuretype_title;
+ this.featuretype_srs = featuretype_srs;
+ this.featuretype_geomtype = featuretype_geomtype;
+ this.element = [];
+ wfs_featuretype_count++;
+}
+//elements
+function wfs_add_featuretype_element(element_name, element_type, element_count, featuretype_count){
+ wfs[wfs.length-1].wfs_featuretype[featuretype_count].element[element_count] = [];
+ wfs[wfs.length-1].wfs_featuretype[featuretype_count].element[element_count].name = element_name;
+ wfs[wfs.length-1].wfs_featuretype[featuretype_count].element[element_count].type = element_type;
+ //alert(element_name +" , "+element_type);
+}
Added: branches/3_dev/core/lib/js/wms.js
===================================================================
--- branches/3_dev/core/lib/js/wms.js (rev 0)
+++ branches/3_dev/core/lib/js/wms.js 2010-05-09 16:04:06 UTC (rev 6121)
@@ -0,0 +1,855 @@
+/*
+ * $Id: map_obj.js 2413 2008-04-23 16:21:04Z christoph $
+ * COPYRIGHT: (C) 2001 by ccgis. This program is free software under the GNU General Public
+ * License (>=v2). Read the file gpl.txt that comes with Mapbender for details.
+ */
+
+//global variables
+var wms = [];
+var wms_layer_count = 0;
+
+/**
+ * global function to add wms to the wms-object
+ *
+ * @param {String} wms_id the unique id of the wms
+ * @param {String} wms_version the version assumed from capabilities
+ * @param {String} wms_title the title of the wms
+ * @param {String} wms_abstract the abstract of the wms
+ * @param {String} wms_getmap the url for map requests
+ * @param {String} wms_getfeatureinfo the url for featureInof requests
+ * @param {String} wms_getlegendurl the url for legend requests
+ * @param {String} wms_filter a filter (deprecated)
+ * @param {String} gui_wms_mapformat the image-format in the actual gui
+ * @param {String} gui_wms_featureinfoformat the current format for featureInfos
+ * @param {String} gui_wms_exceptionformat the exceptionformat for map requests
+ * @param {String} gui_wms_epsg the current srs
+ * @param {Integer} gui_wms_visible the visibility of this service
+ * @param {Integer} gui_wms_opacity the initial display opacity in percent
+ * @param {String} gui_wms_sldurl url to an actual sld
+ */
+function add_wms(
+ wms_id,
+ wms_version,
+ wms_title,
+ wms_abstract,
+ wms_getmap,
+ wms_getfeatureinfo,
+ wms_getlegendurl,
+ wms_filter,
+ gui_wms_mapformat,
+ gui_wms_featureinfoformat,
+ gui_wms_exceptionformat,
+ gui_wms_epsg,
+ gui_wms_visible,
+ gui_wms_opacity,
+ gui_wms_sldurl){
+ wms[wms.length] = new wms_const(
+ wms_id,
+ wms_version,
+ wms_title,
+ wms_abstract,
+ wms_getmap,
+ wms_getfeatureinfo,
+ wms_getlegendurl,
+ wms_filter,
+ gui_wms_mapformat,
+ gui_wms_featureinfoformat,
+ gui_wms_exceptionformat,
+ gui_wms_epsg,
+ parseInt(gui_wms_visible, 10),
+ parseInt(gui_wms_opacity),
+ gui_wms_sldurl);
+ wms_layer[wms.length - 1] = [];
+}
+/**
+ * @class A class representing the wms
+ *
+ * @constructor
+ * @param {String} wms_id the unique id of the wms
+ * @param {String} wms_version the version assumed from capabilities
+ * @param {String} wms_title the title of the wms
+ * @param {String} wms_abstract the abstract of the wms
+ * @param {String} wms_getmap the url for map requests
+ * @param {String} wms_getfeatureinfo the url for featureInof requests
+ * @param {String} wms_getlegendurl the url for legend requests
+ * @param {String} wms_filter a filter (deprecated)
+ * @param {String} gui_wms_mapformat the image-format in the actual gui
+ * @param {String} gui_wms_featureinfoformat the current format for featureInfos
+ * @param {String} gui_wms_exceptionformat the exceptionformat for map requests
+ * @param {String} gui_wms_epsg the current srs
+ * @param {String} gui_wms_visible the visibility of this service
+ * @param {Integer} gui_wms_opacity the initial display opacity in percent
+ * @param {String} gui_wms_sldurl url to an actual sld
+ *
+ */
+function wms_const(
+ wms_id,
+ wms_version,
+ wms_title,
+ wms_abstract,
+ wms_getmap,
+ wms_getfeatureinfo,
+ wms_getlegendurl,
+ wms_filter,
+ gui_wms_mapformat,
+ gui_wms_featureinfoformat,
+ gui_wms_exceptionformat,
+ gui_wms_epsg,
+ gui_wms_visible,
+ gui_wms_opacity,
+ gui_wms_sldurl){
+
+ if (!wms_id) {
+ var id_ok = false;
+ while (id_ok === false) {
+ wms_id = "a"+Math.round(10000*Math.random());
+ id_ok = true;
+ for (var i=0; i < wms.length && id_ok === true; i++) {
+ if (wms_id == wms[i].wms_id) {
+ id_ok = false;
+ }
+ }
+ }
+ }
+
+ this.wms_id = wms_id;
+ this.wms_version = wms_version;
+ this.wms_title = wms_title;
+ this.wms_currentTitle = wms_title;
+ this.wms_abstract = wms_abstract;
+ this.wms_getmap = wms_getmap;
+ this.wms_getfeatureinfo = wms_getfeatureinfo;
+ this.wms_getlegendurl = wms_getlegendurl;
+ this.wms_filter = wms_filter;
+ this.data_type = [];
+ this.data_format = [];
+ this.objLayer = [];
+ this.gui_wms_mapformat = gui_wms_mapformat;
+ this.gui_wms_featureinfoformat = gui_wms_featureinfoformat;
+ this.gui_wms_exceptionformat = gui_wms_exceptionformat;
+ this.gui_wms_epsg = gui_wms_epsg;
+ this.gui_wms_visible = gui_wms_visible;
+ this.gui_epsg = [];
+ this.gui_epsg_supported = [];
+ this.gui_minx = [];
+ this.gui_miny = [];
+ this.gui_maxx = [];
+ this.gui_maxy = [];
+
+ // opacity version
+ this.gui_wms_mapopacity = gui_wms_opacity/100;
+ // sld version
+ this.gui_wms_sldurl = gui_wms_sldurl;
+
+ this.setBoundingBoxBySrs = function (srs, ext) {
+ for (var i = 0; i < this.gui_epsg.length; i++) {
+ if (srs == this.gui_epsg[i]) {
+ this.gui_minx[i] = parseFloat(ext.minx);
+ this.gui_miny[i] = parseFloat(ext.miny);
+ this.gui_maxx[i] = parseFloat(ext.maxx);
+ this.gui_maxy[i] = parseFloat(ext.maxy);
+ return i;
+ }
+ }
+ this.gui_epsg.push(srs);
+ this.gui_epsg_supported.push(false);
+ this.gui_minx.push(ext.minx);
+ this.gui_miny.push(ext.miny);
+ this.gui_maxx.push(ext.maxx);
+ this.gui_maxy.push(ext.maxy);
+ return this.gui_epsg.length - 1;
+ };
+}
+
+wms_const.prototype.getBoundingBoxBySrs = function (srs) {
+ for (var i = 0; i < this.gui_epsg.length; i++) {
+ if (srs == this.gui_epsg[i]) {
+ var bbox_minx = parseFloat(this.gui_minx[i]);
+ var bbox_miny = parseFloat(this.gui_miny[i]);
+ var bbox_maxx = parseFloat(this.gui_maxx[i]);
+ var bbox_maxy = parseFloat(this.gui_maxy[i]);
+ if (bbox_minx !== null && !isNaN(bbox_minx) &&
+ bbox_miny !== null && !isNaN(bbox_miny) &&
+ bbox_maxx !== null && !isNaN(bbox_maxx) &&
+ bbox_maxy !== null && !isNaN(bbox_maxy)
+ ) {
+ return new Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy);
+ }
+ }
+ }
+ return null;
+};
+
+/**
+ * rephrases the featureInfoRequest
+ *
+ * @param {Object} mapObj the mapbender mapObject of the wms
+ * @param {Point} clickPoint map-click position {@link Point}
+ * @return featureInfoRequest, onlineresource + params
+ * @type string
+ */
+wms_const.prototype.getFeatureInfoRequest = function(mapObj, clickPoint){
+
+ //check layers and querylayers first
+ var layers = this.getLayers(mapObj);
+ var querylayers = this.getQuerylayers(mapObj);
+
+ if(!layers || !querylayers){
+ return false;
+ }
+
+ var rq = this.wms_getfeatureinfo;
+ rq += mb_getConjunctionCharacter(this.wms_getfeatureinfo);
+ if(this.wms_version === "1.0.0"){
+ rq += "WMTVER=" + this.wms_version + "&REQUEST=feature_info";
+ }
+ else{
+ rq += "VERSION=" + this.wms_version + "&REQUEST=GetFeatureInfo&SERVICE=WMS";
+ }
+
+ rq += "&LAYERS=" + layers.join(",");
+ rq += "&QUERY_LAYERS=" + querylayers.join(",");
+ rq += "&WIDTH=" + mapObj.getWidth();
+ rq += "&HEIGHT=" + mapObj.getHeight();
+ rq += "&SRS=" + mapObj.getSRS();
+ rq += "&BBOX=" + mapObj.getExtent();
+ rq += "&STYLES=" + this.getLayerstyles(mapObj).join(",");
+ rq += "&FORMAT=" + this.gui_wms_mapformat;
+ rq += "&INFO_FORMAT=" + this.gui_wms_featureinfoformat;
+ rq += "&EXCEPTIONS=application/vnd.ogc.se_xml";
+ rq += "&X=" + clickPoint.x;
+ rq += "&Y=" + clickPoint.y;
+ if(mb_feature_count > 0){
+ rq += "&FEATURE_COUNT="+mb_feature_count;
+ }
+ rq += "&";
+ // add vendor-specific
+ var currentWms = this;
+ for (var v = 0; v < mb_vendorSpecific.length; v++) {
+ var functionName = 'setFeatureInfoRequest';
+ var currentWms_wms_title = this.wms_title;
+ 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") {
+ rq += vendorSpecificString + "&";
+ try {
+ if (this.wms_title == removeLayerAndStylesAffectedWMSTitle) {
+ rq = url.replace(/LAYERS=[^&]*&/, '');
+ rq = url.replace(/STYLES=[^&]*&/, '');
+ }
+ }
+ catch (exc) {
+ new Mb_warning(exc.message);
+ }
+ }
+ }
+ return rq;
+};
+
+/**
+ * sets Opacity of WMS
+ *
+ * @param {Integer} new opacity percentage value
+ */
+wms_const.prototype.setOpacity = function(opacity){
+ //calc new opacity
+ this.gui_wms_mapopacity = parseInt(opacity)/100;
+ if(this.gui_wms_mapopacity>1||isNaN(this.gui_wms_mapopacity))
+ this.gui_wms_mapopacity=1;
+ if(this.gui_wms_mapopacity<0)
+ this.gui_wms_mapopacity=0;
+
+ if (this.gui_wms_visible > 0) {
+
+ //get div id
+ var divId = null;
+ for (var i=0; i < wms.length; i++) {
+ if (this.wms_id == wms[i].wms_id) {
+ var divId = 'div_'+i;
+ break;
+ }
+ }
+ if(!divId)
+ return;
+
+ //TODO: check if mapframe1 is the right mapframe
+ var ind = getMapObjIndexByName("mapframe1");
+ var el = mb_mapObj[ind].getDomElement();
+ wmsImage = el.ownerDocument.getElementById(divId);
+ if (wmsImage != null) {
+ wmsImage.style.opacity = this.gui_wms_mapopacity;
+ wmsImage.style.MozOpacity = this.gui_wms_mapopacity;
+ wmsImage.style.KhtmlOpacity = this.gui_wms_mapopacity;
+ wmsImage.style.filter = "alpha(opacity=" + this.gui_wms_mapopacity*100 + ")";
+ }
+ }
+}
+
+/**
+ * get all visible layers
+ *
+ * @return array of layernames
+ * @type string[]
+ */
+wms_const.prototype.getLayers = function(mapObj){
+ var scale = null;
+ if (arguments.length === 2) {
+ scale = arguments[1];
+ }
+ try {
+ //visibility of the wms
+ var wmsIsVisible = (this.gui_wms_visible > 0);
+ if(!wmsIsVisible){
+ return [];
+ }
+ visibleLayers = [];
+ for(var i=0; i< this.objLayer.length; i++){
+ var isVisible = (this.objLayer[i].gui_layer_visible === 1);
+ var hasNoChildren = (!this.objLayer[i].has_childs);
+ if (isVisible && hasNoChildren){
+ if(this.objLayer[i].checkScale(mapObj, scale)){
+ visibleLayers.push(this.objLayer[i].layer_name);
+ }
+ }
+ }
+ if(visibleLayers.length === 0){
+ return [];
+ }
+ return visibleLayers;
+ }
+ catch (e) {
+ alert(e);
+ }
+ return [];
+};
+
+/**
+ * get the actual style of all visible layers
+ *
+ * @return commaseparated list of actual layerstyles
+ * @type string
+ */
+wms_const.prototype.getLayerstyles = function(mapObj){
+
+ var layers = this.getLayers(mapObj);
+ var layerstyles = '';
+ var styles = [];
+ if(layers){
+ for(i = 0; i < layers.length; i++){
+ var style = this.getCurrentStyleByLayerName(layers[i]);
+ if(!style){
+ style = '';
+ }
+ styles.push(style);
+ }
+ return styles;
+ }
+ return false;
+};
+
+/**
+ * check if layer is parentLayer
+ *
+ * @param layername
+ * @return the parent value of the given layer
+ * @type integer
+ */
+wms_const.prototype.checkLayerParentByLayerName = function(layername){
+ for(var i=0; i< this.objLayer.length; i++){
+ if(this.objLayer[i].layer_name == layername){
+ return this.objLayer[i].layer_parent;
+ }
+ }
+};
+
+/**
+ * get the title of the current layer
+ *
+ * @param layername
+ * @return the title of the given layer
+ * @type string
+ */
+wms_const.prototype.getTitleByLayerName = function(layername){
+ for(var i=0; i< this.objLayer.length; i++){
+ if(this.objLayer[i].layer_name == layername){
+ return this.objLayer[i].layer_title;
+ }
+ }
+};
+
+wms_const.prototype.getLayerByLayerName = function(layername){
+ for(var i=0; i< this.objLayer.length; i++){
+ if(this.objLayer[i].layer_name === layername){
+ return this.objLayer[i];
+ }
+ }
+};
+
+/**
+ * get the current style of the layer
+ *
+ * @param layername
+ * @return the stylename of the given layer
+ * @type string
+ */
+wms_const.prototype.getCurrentStyleByLayerName = function(layername){
+ for(var i=0; i< this.objLayer.length; i++){
+ var currentLayer = this.objLayer[i];
+ if (currentLayer.layer_name === layername) {
+ if (currentLayer.gui_layer_style === '' || currentLayer.gui_layer_style === null){
+ return "default";
+// return false;
+ }
+ else{
+ return currentLayer.gui_layer_style;
+ }
+ }
+ }
+ return false;
+};
+
+/**
+ * get the legendurl of the gui layer style
+ *
+ * @param stylename
+ * @return the legendurl of the given style
+ * @type string
+ */
+wms_const.prototype.getLegendUrlByGuiLayerStyle = function(layername,guiLayerStyle){
+ for(var i=0; i< this.objLayer.length; i++){
+ if(this.objLayer[i].layer_name == layername){
+ if(this.objLayer[i].layer_style.length === 0){
+ return false;
+ }
+ for(var k=0; k< this.objLayer[i].layer_style.length; k++){
+ var legendUrl = '';
+ if(guiLayerStyle == '' && k == 0){
+ legendUrl = this.objLayer[i].layer_style[k].legendurl;
+ if (this.gui_wms_sldurl !== "") {
+ legendUrl += "&SLD="+escape(this.gui_wms_sldurl);
+ }
+ if(legendUrl !=='' && legendUrl !== null && typeof(legendUrl) != 'undefined'){
+ return legendUrl;
+ }
+ else {
+ return false;
+ }
+ }else if(this.objLayer[i].layer_style[k].name == guiLayerStyle){
+ legendUrl = this.objLayer[i].layer_style[k].legendurl;
+ if (this.gui_wms_sldurl !== "") {
+ legendUrl += "&SLD="+escape(this.gui_wms_sldurl);
+ }
+ if(legendUrl !=='' && legendUrl !== null && typeof(legendUrl) != 'undefined'){
+ return legendUrl;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return false;
+};
+
+/**
+ * get all querylayers
+ *
+ * @return array of layernames
+ * @type string[]
+ */
+wms_const.prototype.getQuerylayers = function(map){
+ var currentScale = map.getScale();
+ queryLayers = [];
+ for(var i=0; i< this.objLayer.length; i++){
+
+ var isVisible = this.objLayer[i].gui_layer_minscale <= currentScale &&
+ (this.objLayer[i].gui_layer_maxscale >= currentScale ||
+ this.objLayer[i].gui_layer_maxscale === 0);
+ if(this.objLayer[i].gui_layer_querylayer === 1 && !this.objLayer[i].has_childs && isVisible){
+ queryLayers.push(this.objLayer[i].layer_name);
+ }
+ }
+ if(queryLayers.length === 0){
+ return false;
+ }
+ return queryLayers;
+};
+
+/**
+ * get a layer Object by layer_pos
+ *
+ * @param int payer_pos layer_pos of layer you want to get
+ * @return object layer
+ */
+
+wms_const.prototype.getLayerByLayerPos = function(layer_pos){
+ for(var i=0;i<this.objLayer.length;i++){
+ if(this.objLayer[i].layer_pos == layer_pos) {
+ return this.objLayer[i];
+ }
+ }
+ return null;
+};
+
+wms_const.prototype.getLayerById = function(id){
+ for(var i=0;i<this.objLayer.length;i++){
+ if(parseInt(this.objLayer[i].layer_uid, 10) === parseInt(id,10)) {
+ return this.objLayer[i];
+ }
+ }
+ return null;
+};
+/**
+ * get the state of sublayers from a specified layer
+ *
+ * @param int layer_id of the parent layer
+ * @param String type "visible" or "querylayer"
+ * @return int -1 if state differs else the state
+ */
+
+wms_const.prototype.getSublayerState = function(layer_id, type){
+ var i;
+ var state=-1,value;
+ for(i = 0; i < this.objLayer.length; i++){
+ if(this.objLayer[i].layer_id==layer_id) {
+ break;
+ }
+ }
+
+ //go throught sublayers
+ for(var j = i+1; j < this.objLayer.length; j++){
+ if(this.objLayer[i].parent_layer == this.objLayer[j].parent_layer) {
+ break;
+ }
+ if(type == "visible") {
+ value = this.objLayer[j].gui_layer_visible;
+ }
+ else if(type == "querylayer") {
+ value = this.objLayer[j].gui_layer_querylayer;
+ }
+ if(state == -1) {
+ state = value;
+ }
+ if(state != value) {
+ return -1;
+ }
+ }
+
+ return state;
+};
+/**
+ * handle change of visibility / quaryability of a layer
+ *
+ * @param string layer_name of layer to handle
+ * @param string type of change ("visible" or "querylayer")
+ * @param int value of the change
+ */
+wms_const.prototype.handleLayer = function(layer_name, type, value){
+ var i;
+ var found = false;
+ for(i = 0; i < this.objLayer.length; i++){
+ if(this.objLayer[i].layer_name==layer_name) {
+ found = true;
+ break;
+ }
+ }
+ // layer not found
+ if (!found) {
+ return;
+ }
+
+ //Set visibility/queryability of Layer and Sublayers
+ for(var j = i; j < this.objLayer.length; j++){
+ if (i != j && this.objLayer[i].layer_parent >= this.objLayer[j].layer_parent) {
+ break;
+ }
+ if(type == "visible") {
+ this.objLayer[j].gui_layer_visible = parseInt(value, 10);
+ }
+ else if(type=="querylayer" && this.objLayer[j].gui_layer_queryable) {
+ this.objLayer[j].gui_layer_querylayer = parseInt(value, 10);
+ }
+ }
+
+ //Update visibility/queryability of parent layer
+ var parentLayer = this.getLayerByLayerPos(this.objLayer[i].layer_parent);
+ if(parentLayer){
+ var state = this.getSublayerState(parentLayer.layer_id, type);
+ if(state!=-1){
+ if(type == "visible") {
+ this.objLayer[j].gui_layer_visible = state;
+ }
+ else if(type=="querylayer" && this.objLayer[j].gui_layer_queryable) {
+ this.objLayer[j].gui_layer_querylayer = state;
+ }
+ }
+ }
+};
+
+
+/**
+ * move a layer (with his sublayers) up or down
+ *
+ * @param int layerId layer_id of layer to move
+ * @param boolean moveUp true to move up or false to move down
+ * @return boolean success
+ */
+
+wms_const.prototype.moveLayer = function(layerId, moveUp){
+ var iLayer=-1;
+ var i;
+
+ //find layer to move
+ for(i=0;i<this.objLayer.length;i++){
+ if(this.objLayer[i].layer_id==layerId){
+ iLayer=i;
+ break;
+ }
+ }
+ if(iLayer==-1) {
+ return false;
+ }
+
+ var upperLayer = -1;
+ var lowerLayer = -1;
+
+ //find layer to swap position with
+ var parentLayer = this.objLayer[iLayer].layer_parent;
+ if(moveUp){
+ lowerLayer = iLayer;
+
+ //find previous layer on same level
+ for(i=iLayer-1;i>0;i--){
+ if(parentLayer == this.objLayer[i].layer_parent){
+ upperLayer = i;
+ break;
+ }
+ }
+ if(upperLayer == -1){
+ //alert("The Layer you selected is already on top of parent Layer/WMS");
+ return false;
+ }
+ }
+ else{
+ upperLayer = iLayer;
+
+ //find next layer on same level
+ for(i=iLayer+1;i<this.objLayer.length;i++){
+ if(parentLayer == this.objLayer[i].layer_parent){
+ lowerLayer = i;
+ break;
+ }
+ }
+ if(lowerLayer == -1){
+ //alert("The Layer you selected is already on bottom of parent Layer/WMS");
+ return false;
+ }
+ }
+
+ //calc number of layers to move down
+ var layersDown = lowerLayer - upperLayer;
+
+ //get number of layers to move up
+ for(i=lowerLayer+1; i<this.objLayer.length; i++){
+ if(parentLayer == this.objLayer[i].layer_parent){
+ break;
+ }
+ }
+ var layersUp = i - lowerLayer;
+
+ //do moving
+ var temp = [];
+ for(i=0;i<layersDown+layersUp;i++){
+ temp[temp.length]=this.objLayer[upperLayer+i];
+ }
+ for(i=0;i<layersUp;i++){
+ this.objLayer[upperLayer+i]=temp[i+layersDown];
+ }
+ for(i=0;i<layersDown;i++){
+ this.objLayer[upperLayer+layersUp+i]=temp[i];
+ }
+
+ return true;
+};
+
+function wms_add_data_type_format(datatype,dataformat){
+ var insertDataFormat = true;
+ for (var i = 0 ; i < wms[wms.length-1].data_type.length ; i ++) {
+ if (wms[wms.length-1].data_type[i] == datatype && wms[wms.length-1].data_format[i] == dataformat) {
+ insertDataFormat = false;
+ }
+ }
+ if (insertDataFormat === true) {
+ wms[wms.length-1].data_type[wms[wms.length-1].data_type.length] = datatype;
+ wms[wms.length-1].data_format[wms[wms.length-1].data_format.length] = dataformat;
+ }
+}
+function wms_addSRS(epsg,minx,miny,maxx,maxy){
+ wms[wms.length-1].gui_epsg[wms[wms.length-1].gui_epsg.length] = epsg;
+ wms[wms.length-1].gui_epsg_supported[wms[wms.length-1].gui_epsg_supported.length] = true;
+ wms[wms.length-1].gui_minx[wms[wms.length-1].gui_minx.length] = minx;
+ wms[wms.length-1].gui_miny[wms[wms.length-1].gui_miny.length] = miny;
+ wms[wms.length-1].gui_maxx[wms[wms.length-1].gui_maxx.length] = maxx;
+ wms[wms.length-1].gui_maxy[wms[wms.length-1].gui_maxy.length] = maxy;
+}
+function wms_addLayerStyle(styleName, styleTitle, count, layerCount, styleLegendUrl, styleLegendUrlFormat){
+ var currentLayer = wms[wms.length-1].objLayer[layerCount];
+ if (currentLayer) {
+ currentLayer.layer_style[count] = {};
+ currentLayer.layer_style[count].name = styleName;
+ currentLayer.layer_style[count].title = styleTitle;
+ currentLayer.layer_style[count].legendurl = styleLegendUrl;
+ currentLayer.layer_style[count].legendurlformat = styleLegendUrlFormat;
+ }
+}
+//TODO: add layerstyle handling....
+//layer
+function wms_add_layer(
+ layer_parent,
+ layer_uid,
+ layer_name,
+ layer_title,
+ layer_dataurl_href,
+ layer_pos,
+ layer_queryable,
+ layer_minscale,
+ layer_maxscale,
+ layer_metadataurl,
+ gui_layer_wms_id,
+ gui_layer_status,
+ gui_layer_style,
+ gui_layer_selectable,
+ gui_layer_visible,
+ gui_layer_queryable,
+ gui_layer_querylayer,
+ gui_layer_minscale,
+ gui_layer_maxscale,
+ gui_layer_wfs_featuretype){
+
+ wms[wms.length-1].objLayer[wms[wms.length-1].objLayer.length] = new wms_layer(
+ layer_parent,
+ layer_uid,
+ layer_name,
+ layer_title,
+ layer_dataurl_href,
+ layer_pos,
+ layer_queryable,
+ layer_minscale,
+ layer_maxscale,
+ layer_metadataurl,
+ gui_layer_wms_id,
+ gui_layer_status,
+ gui_layer_style,
+ parseInt(gui_layer_selectable, 10),
+ parseInt(gui_layer_visible, 10),
+ parseInt(gui_layer_queryable, 10),
+ parseInt(gui_layer_querylayer, 10),
+ parseInt(gui_layer_minscale, 10),
+ parseInt(gui_layer_maxscale, 10),
+ gui_layer_wfs_featuretype );
+ var parentLayer = wms[wms.length-1].getLayerByLayerPos(parseInt(layer_parent, 10));
+ if(parentLayer) {
+ parentLayer.has_childs = true;
+ }
+}
+function layer_addEpsg(epsg,minx,miny,maxx,maxy){
+ var j = wms[wms.length-1].objLayer.length-1;
+ var k = wms[wms.length-1].objLayer[j].layer_epsg.length;
+ var currentLayer = wms[wms.length-1].objLayer[j];
+ currentLayer.layer_epsg[k]={};
+ currentLayer.layer_epsg[k].epsg = epsg;
+ currentLayer.layer_epsg[k].minx = minx;
+ currentLayer.layer_epsg[k].miny = miny;
+ currentLayer.layer_epsg[k].maxx = maxx;
+ currentLayer.layer_epsg[k].maxy = maxy;
+}
+function wms_layer(
+ layer_parent,
+ wms_layer_uid,
+ layer_name,
+ layer_title,
+ layer_dataurl_href,
+ layer_pos,
+ layer_queryable,
+ layer_minscale,
+ layer_maxscale,
+ layer_metadataurl,
+ gui_layer_wms_id,
+ gui_layer_status,
+ gui_layer_style,
+ gui_layer_selectable,
+ gui_layer_visible,
+ gui_layer_queryable,
+ gui_layer_querylayer,
+ gui_layer_minscale,
+ gui_layer_maxscale,
+ gui_layer_wfs_featuretype){
+ this.layer_id = wms_layer_count;
+ this.layer_uid = wms_layer_uid;
+ this.layer_parent = layer_parent;
+ this.layer_name = layer_name;
+ this.layer_title = layer_title;
+ this.layer_currentTitle = layer_title;
+ this.layer_dataurl_href = layer_dataurl_href;
+ this.layer_pos = layer_pos;
+ this.layer_queryable = layer_queryable;
+ this.layer_minscale = layer_minscale;
+ this.layer_maxscale = layer_maxscale;
+ this.layer_metadataurl = layer_metadataurl;
+ this.layer_epsg = [];
+ this.gui_layer_wms_id = gui_layer_wms_id;
+ this.gui_layer_status = gui_layer_status;
+ this.gui_layer_selectable = gui_layer_selectable;
+ this.gui_layer_visible = gui_layer_visible;
+ this.gui_layer_queryable = gui_layer_queryable;
+ this.gui_layer_querylayer = gui_layer_querylayer;
+ this.gui_layer_minscale = gui_layer_minscale;
+ this.gui_layer_maxscale = gui_layer_maxscale;
+ this.gui_layer_style = gui_layer_style;
+ this.gui_layer_wfs_featuretype = gui_layer_wfs_featuretype;
+ this.has_childs = false;
+ this.layer_style = [];
+ wms_layer_count++;
+}
+/**
+ * check the scale of the layer
+ *
+ * @param Object mapObj the mapbender mapObject of the layer
+ * @return boolean if the layer is in scale or not
+ * @type boolean
+ */
+wms_layer.prototype.checkScale = function(mapObj){
+ var currentScale = parseInt(mapObj.getScale(), 10);
+ if (arguments.length === 2 && arguments[1] !== null) {
+ currentScale = arguments[1];
+ }
+ var minScale = parseInt(this.gui_layer_minscale, 10);
+ var maxScale = parseInt(this.gui_layer_maxscale, 10);
+ if(minScale === 0 && maxScale === 0){
+ return true;
+ }
+ if(minScale > currentScale || (maxScale !== 0 && maxScale < currentScale)) {
+ return false;
+ }
+ return true;
+};
+/**
+ * set visibility of the layer
+ * @param boolean visible visibility on/off
+ */
+wms_layer.prototype.setVisible = function(visible){
+ this.gui_layer_visible = parseInt(visible, 10);
+};
+
+/**
+ * set queryability of the layer
+ * @param boolean queryable queryability on/off
+ */
+
+wms_layer.prototype.setQueryable = function(queryable){
+ this.gui_layer_querylayer = parseInt(queryable, 10);
+};
More information about the Mapbender_commits
mailing list