[Mapbender-commits] r1690 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Sep 26 09:38:29 EDT 2007
Author: nimix
Date: 2007-09-26 09:38:29 -0400 (Wed, 26 Sep 2007)
New Revision: 1690
Modified:
trunk/mapbender/http/javascripts/map.js
trunk/mapbender/http/javascripts/map_obj.js
Log:
a lot of prototype function for redesign
Modified: trunk/mapbender/http/javascripts/map.js
===================================================================
--- trunk/mapbender/http/javascripts/map.js 2007-09-26 09:49:10 UTC (rev 1689)
+++ trunk/mapbender/http/javascripts/map.js 2007-09-26 13:38:29 UTC (rev 1690)
@@ -215,26 +215,305 @@
this.epsg = wms[0].gui_wms_epsg;
this.extent = setExtent(this.width,this.height,this.epsg);
this.mapURL = [];
+
+ /**
+ * get the width of the mapObj
+ *
+ * @member mb_mapObj_const
+ * @return width of the mapObj
+ * @type integer
+ */
+ this.getWidth = function(){
+ return parseInt(this.width);
+ };
+
+ /**
+ * set the width of the mapObj
+ *
+ * @param {integer} widht the width of the mapObj
+ */
+ this.setWidth = function(width){
+ this.width = parseInt(width);
+ };
+
+ /**
+ * get the height of the mapObj
+ *
+ * @member mb_mapObj_const
+ * @return width of the mapObj
+ * @type integer
+ */
+ this.getHeight = function(){
+ return parseInt(this.height);
+ };
+
+ /**
+ * set the height of the mapObj
+ *
+ * @param {integer} height the height of the mapObj
+ */
+ this.setHeight = function(height){
+ this.height = parseInt(height);
+ };
+
+ /**
+ * get the extent of the mapObj
+ *
+ * @member mb_mapObj_const
+ * @return extent of the mapObj as commaseparated minx,minx,maxx,maxy
+ * @type string
+ */
+ this.getExtent = function(){
+ return this.extent;
+ };
+
+ /**
+ * get the extent as minx, maxx, miny, maxy
+ *
+ * @return extent and additional informations of the mapObj
+ * @type Object
+ */
+ this.getExtentInfos = function(){
+ var c = this.getExtent().split(",");
+ var ext = new Extent(c[0],c[1],c[2],c[3]);
+ return ext;
+ };
+
+ /**
+ * 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;
+ }
+ this.setExtent(ext.minx,ext.miny,ext.maxx,ext.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){
+ 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(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;
+ this.setExtent(minx,miny,maxx,maxy);
+ //Todo:
+ //setMapRequest!
+ }
+
+ /**
+ * set the extent of the wms
+ */
+ this.setExtent = function(minx,miny,maxx,maxy){
+ this.extent = String(minx)+","+String(miny)+","+String(maxx)+","+String(maxy);
+ }
+
+ /**
+ * 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;
+ };
+
+ /**
+ * get all MapRequests
+ *
+ * @return array of all 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;
+ };
+
+ /**
+ * get all featureInfoRequests
+ *
+ * @member mb_mapObj_const
+ * @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){
+ var allRequests = [];
+ //loop through all wms to get the FeatureInfoRequests
+ for(var i=0; i<this.wms.length; i++){
+ 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 mb_mapObj_const
+ * @return scale
+ * @type integer
+ */
+ this.getScale = function(){
+ var scale;
+ var bbox = this.extent.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 Math.round(scale);
+ };
+ /**
+ * 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;
+ }
+
for(var i=0; i<mb_MapObjectSubFunctions.length; i++){
eval(mb_MapObjectSubFunctions[i]);
}
}
-
+/*
+ * get the conjunction character of an URL
+ * @param {String} onlineresource
+ * @return the character & or ?
+ * @type String
+ */
function mb_getConjunctionCharacter(onlineresource){
+ var conChar;
if(onlineresource.indexOf("?") > -1){
if(onlineresource.charAt(onlineresource.length-1) == "?"){
- nextvalue = "";
+ conChar = "";
}else if(onlineresource.charAt(onlineresource.length-1) == "&"){
- nextvalue = "";
+ conChar = "";
}else{
- nextvalue = "&";
+ conChar = "&";
}
}
if(onlineresource.indexOf("?") == -1){
- nextvalue = "?";
+ conChar = "?";
}
- return nextvalue;
+ return conChar;
}
@@ -601,14 +880,14 @@
var styles = "";
var querylayers = "";
for(var ii=0; ii<mb_mapObj[ind].wms[i].objLayer.length; ii++){
- if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_visible == 1 && ii>0){
+ if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_visible == 1 && !mb_mapObj[ind].wms[i].objLayer[ii].has_childs){
if(cnt_layers > 0){layers += ","; styles += ","; }
layers += mb_mapObj[ind].wms[i].objLayer[ii].layer_name;
//alert(mb_mapObj[ind].wms[i].objLayer[ii].layer_name);
styles += "";
cnt_layers++;
}
- if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
+ if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_querylayer == 1 && !mb_mapObj[ind].wms[i].objLayer[ii].has_childs){
if(cnt_querylayers > 0){querylayers += ",";}
querylayers += mb_mapObj[ind].wms[i].objLayer[ii].layer_name;
cnt_querylayers++;
@@ -751,29 +1030,22 @@
document.getElementById(elName).innerHTML = tagSource;
}
}
+/*
+ * global function to zoom a mapobject
+ *
+ * use: mb_mapObj.zoom() {@link mb_mapObj_const#zoom}
+ * @deprecated
+ *
+ */
function zoom(frameName,in_, factor,x,y) {
- var x = parseFloat(x);
- var y = parseFloat(y);
- var ind = getMapObjIndexByName(frameName);
- var arrayBBox = mb_mapObj[ind].extent.split(",");
- var xtentx = parseFloat(arrayBBox[2]) - parseFloat(arrayBBox[0]);
- var xtenty = parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1]);
- var centerx = parseFloat(arrayBBox[0]) + xtentx/2;
- var centery = parseFloat(arrayBBox[1]) + xtenty/2;
- var factor = parseFloat(factor);
- if(x){
- centerx = x;
- centery = y;
- }
- if (!in_) {factor = 1 / factor;}
- var new_xtentx = xtentx / factor;
- var new_xtenty = xtenty / factor;
- var minx = centerx - new_xtentx / 2;
- var miny = centery - new_xtenty / 2;
- var maxx = centerx + new_xtentx / 2;
- var maxy = centery + new_xtenty / 2;
- mb_mapObj[ind].extent = minx + "," + miny + "," + maxx + "," + maxy;
- setMapRequest(frameName);
+ var obj = getMapObjByName(frameName);
+ if(x && y){
+ obj.zoom(in_, factor, x, y);
+ }
+ else{
+ obj.zoom(in_, factor, false, false);
+ }
+ setMapRequest(frameName);
}
function mb_panMap(frameName,dir){
var ind = getMapObjIndexByName(frameName);
@@ -997,6 +1269,14 @@
}
}
}
+function getMapObjByName(frameName){
+ for(var i=0; i<mb_mapObj.length; i++){
+ if(mb_mapObj[i].frameName == frameName){
+ return mb_mapObj[i];
+ }
+ }
+ return false;
+}
function mb_getLayerTitleByName(map_index, wms_index, myLayer_name){
for(var i=0; i<mb_mapObj[map_index].wms[wms_index].objLayer.length; i++){
if(mb_mapObj[map_index].wms[wms_index].objLayer[i].layer_name == myLayer_name){
@@ -1069,27 +1349,37 @@
mb_mapObj[ind].extent = minx + "," + miny + "," + maxx + "," + maxy;
setMapRequest(frameName);
}
+/*
+ * converts the extent of the mapobject so that the maximum extent will be displayed {@link mb_mapObj_const#calculateExtent}
+ * use: mb_mapObj.calculateExtent
+ * @deprecated
+ *
+ */
function mb_calculateExtent(frameName,minx,miny,maxx,maxy){
- var ind = getMapObjIndexByName(frameName);
-
- var extenty = parseFloat(maxy) - parseFloat(miny);
- var extentx = parseFloat(maxx) - parseFloat(minx);
-
- var relation_px_x = mb_mapObj[ind].width / mb_mapObj[ind].height;
- var relation_px_y = mb_mapObj[ind].height / mb_mapObj[ind].width;
- var relation_bbox_x = extentx / extenty;
- var centerx = parseFloat(minx) + (extentx/2);
- var centery = parseFloat(miny) + (extenty/2);
- if(relation_bbox_x <= relation_px_x){
- minx = centerx - relation_px_x * extenty / 2;
- maxx = centerx + relation_px_x * extenty / 2;
- }
- if(relation_bbox_x > relation_px_x){
- miny = centery - relation_px_y * extentx / 2;
- maxy = centery + relation_px_y * extentx / 2;
- }
- mb_mapObj[ind].extent = minx +","+ miny +","+ maxx +","+ maxy;
+ var map = getMapObjByName(frameName);
+ var extent = new Extent(minx,miny,maxx,maxy);
+ map.calculateExtent(extent);
}
+/*
+ * @class extent
+ * @param {float} minx
+ * @param {float} miny
+ * @param {float} maxx
+ * @param {float} maxy
+ * @return the extent as object
+ * @type Object
+ */
+function Extent(minx,miny,maxx,maxy){
+ this.minx = parseFloat(minx);
+ this.miny = parseFloat(miny);
+ this.maxx = parseFloat(maxx);
+ this.maxy = parseFloat(maxy);
+ this.extentx = this.maxx - this.minx;
+ this.extenty = this.maxy - this.miny;
+ this.centerx = this.minx + this.extentx/2;
+ this.centery = this.miny + this.extenty/2;
+ return this;
+}
function mb_showHighlight(frameName,x,y){
var pos = makeRealWorld2mapPos(frameName,x, y);
Modified: trunk/mapbender/http/javascripts/map_obj.js
===================================================================
--- trunk/mapbender/http/javascripts/map_obj.js 2007-09-26 09:49:10 UTC (rev 1689)
+++ trunk/mapbender/http/javascripts/map_obj.js 2007-09-26 13:38:29 UTC (rev 1690)
@@ -5,9 +5,27 @@
*/
//global variables
-var wms = new Array();
+var wms = [];
var wms_layer_count = 0;
-//list of all wms-objects
+
+/*
+ * 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 {String} gui_wms_sldurl url to an actual sld
+ */
function add_wms(
wms_id,
wms_version,
@@ -21,7 +39,8 @@
gui_wms_featureinfoformat,
gui_wms_exceptionformat,
gui_wms_epsg,
- gui_wms_visible){
+ gui_wms_visible,
+ gui_wms_sldurl){
wms[wms.length] = new wms_const(
wms_id,
wms_version,
@@ -35,10 +54,30 @@
gui_wms_featureinfoformat,
gui_wms_exceptionformat,
gui_wms_epsg,
- gui_wms_visible);
- wms_layer[wms.length - 1] = new Array();
+ parseInt(gui_wms_visible),
+ gui_wms_sldurl);
+ wms_layer[wms.length - 1] = [];
}
-//the wms constructor
+/**
+ * @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 {String} gui_wms_sldurl url to an actual sld
+ *
+ */
function wms_const(
wms_id,
wms_version,
@@ -52,7 +91,8 @@
gui_wms_featureinfoformat,
gui_wms_exceptionformat,
gui_wms_epsg,
- gui_wms_visible){
+ gui_wms_visible,
+ gui_wms_sldurl){
if (!wms_id) {
var id_ok = false;
@@ -73,23 +113,357 @@
this.wms_getfeatureinfo = wms_getfeatureinfo;
this.wms_getlegendurl = wms_getlegendurl;
this.wms_filter = wms_filter;
- this.data_type = new Array();
- this.data_format = new Array();
- this.objLayer = new Array();
+ 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 = new Array();
- this.gui_minx = new Array();
- this.gui_miny = new Array();
- this.gui_maxx = new Array();
- this.gui_maxy = new Array();
+ this.gui_epsg = [];
+ this.gui_minx = [];
+ this.gui_miny = [];
+ this.gui_maxx = [];
+ this.gui_maxy = [];
-// opacity version
- this.gui_wms_mapopacity = 1;
+ // opacity version
+ this.gui_wms_mapopacity = 1;
+ // sld version
+ this.gui_wms_sldurl = gui_wms_sldurl;
}
+
+/**
+ * rephrases the mapRequest
+ *
+ * @param {Object} mapObj the mapbender mapObject of the wms
+ * @return mapRequest, i.e. onlineresource + params
+ * @type String
+ */
+wms_const.prototype.getMapRequest = function(mapObj){
+ //console.log()
+ //check visible layers first
+ var layers = this.getLayers(mapObj);
+ if(!layers){
+ return false;
+ }
+
+ var rq = this.wms_getmap;
+ rq += mb_getConjunctionCharacter(this.wms_getmap);
+ if(this.wms_version === "1.0.0"){
+ rq += "WMTVER=" + this.wms_version + "&REQUEST=map";
+ }
+ else{
+ rq += "VERSION=" + this.wms_version + "&REQUEST=getMap&SERVICE=WMS";
+ }
+
+ rq += "&LAYERS=" + layers.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 += "&EXCEPTIONS=" + this.gui_wms_exceptionformat;
+ //Todo: error occurs:
+ //var throwNotice = new Mb_notice("getMapRequest: " + rq);
+ //window.console.log("getMapRequest: " + rq);
+ return rq;
+};
+
+
+/**
+ * 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;
+ //console.log(rq);
+ return rq;
+};
+
+/**
+ * get all visible layers
+ *
+ * @return array of layernames
+ * @type string[]
+ */
+wms_const.prototype.getLayers = function(mapObj){
+
+ //visibility of the wms
+ var wmsIsVisible = (this.gui_wms_visible > 0);
+ if(!wmsIsVisible){
+ return false;
+ }
+ visibleLayers = [];
+ for(var i=0; i< this.objLayer.length; i++){
+ if(this.objLayer[i].gui_layer_visible === 1 && ! this.objLayer[i].has_childs){
+ if(this.objLayer[i].checkScale(mapObj)){
+ //console.log("checkLayer: " + this.objLayer[i].layer_name);
+ visibleLayers.push(this.objLayer[i].layer_name);
+ }
+ }
+ }
+ if(visibleLayers.length === 0){
+ return false;
+ }
+ return visibleLayers;
+};
+
+/**
+ * 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.getStyleByLayerName(layers[i]);
+ if(!style){
+ style = '';
+ }
+ styles.push(style)
+ }
+ return styles;
+ }
+ return false;
+};
+
+/**
+ * get the style of the layer
+ *
+ * @param layername
+ * @return the stylename of the given layer
+ * @type string
+ */
+wms_const.prototype.getStyleByLayerName = function(layername){
+ return false;
+};
+
+/**
+ * get all querylayers
+ *
+ * @return array of layernames
+ * @type string[]
+ */
+wms_const.prototype.getQuerylayers = function(){
+ queryLayers = [];
+ for(var i=0; i< this.objLayer.length; i++){
+ if(this.objLayer[i].gui_layer_querylayer === 1 && ! this.objLayer[i].has_childs ){
+ 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;
+};
+/**
+ * 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;
+ for(i = 0; i < this.objLayer.length; i++){
+ if(this.objLayer[i].layer_name==layer_name)
+ break;
+ }
+
+ //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);
+ else if(type=="querylayer")
+ this.objLayer[j].gui_layer_querylayer = parseInt(value);
+ }
+
+ //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_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 ++) {
@@ -110,16 +484,16 @@
wms[wms.length-1].gui_maxy[wms[wms.length-1].gui_maxy.length] = maxy;
}
function wms_addLayerStyle(styleName, styleTitle, count, layerCount, styleLegendUrl, styleLegendUrlFormat){
- if (wms[wms.length-1].objLayer[layerCount]) {
- wms[wms.length-1].objLayer[layerCount].layer_style[count] = new Array();
- wms[wms.length-1].objLayer[layerCount].layer_style[count]["name"] = styleName;
- wms[wms.length-1].objLayer[layerCount].layer_style[count]["title"] = styleTitle;
- wms[wms.length-1].objLayer[layerCount].layer_style[count]["legendurl"] = styleLegendUrl;
- wms[wms.length-1].objLayer[layerCount].layer_style[count]["legendurlformat"] = 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,
@@ -155,23 +529,27 @@
layer_metadataurl,
gui_layer_wms_id,
gui_layer_status,
- gui_layer_selectable,
- gui_layer_visible,
- gui_layer_queryable,
- gui_layer_querylayer,
- gui_layer_minscale,
- gui_layer_maxscale,
+ parseInt(gui_layer_selectable),
+ parseInt(gui_layer_visible),
+ parseInt(gui_layer_queryable),
+ parseInt(gui_layer_querylayer),
+ parseInt(gui_layer_minscale),
+ parseInt(gui_layer_maxscale),
gui_layer_wfs_featuretype );
+ var parentLayer = wms[wms.length-1].getLayerByLayerPos(parseInt(layer_parent));
+ 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;
- wms[wms.length-1].objLayer[j].layer_epsg[k]=new Array();
- wms[wms.length-1].objLayer[j].layer_epsg[k]["epsg"]=epsg;
- wms[wms.length-1].objLayer[j].layer_epsg[k]["minx"]=minx;
- wms[wms.length-1].objLayer[j].layer_epsg[k]["miny"]=miny;
- wms[wms.length-1].objLayer[j].layer_epsg[k]["maxx"]=maxx;
- wms[wms.length-1].objLayer[j].layer_epsg[k]["maxy"]=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,
@@ -204,7 +582,7 @@
this.layer_minscale = layer_minscale;
this.layer_maxscale = layer_maxscale;
this.layer_metadataurl = layer_metadataurl;
- this.layer_epsg = new Array();
+ 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;
@@ -214,6 +592,45 @@
this.gui_layer_minscale = gui_layer_minscale;
this.gui_layer_maxscale = gui_layer_maxscale;
this.gui_layer_wfs_featuretype = gui_layer_wfs_featuretype;
- this.layer_style = new Array();
+ this.gui_layer_style;
+ this.has_childs = false;
+ this.layer_style = [];
wms_layer_count++;
-}
\ No newline at end of file
+}
+/**
+ * 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 minScale = this.gui_layer_minscale;
+ var maxScale = this.gui_layer_maxscale;
+ var currentScale = mapObj.getScale();
+ if(minScale === 0 && maxScale === 0){
+ return true;
+ }
+ if(minScale < currentScale || 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);
+ //console.log("setVisible(%i) for Layer %s",visible, this.layer_name);
+}
+
+/**
+ * set queryability of the layer
+ * @param boolean queryable queryability on/off
+ */
+
+wms_layer.prototype.setQueryable = function(queryable){
+ this.gui_layer_querylayer = parseInt(queryable);
+ //console.log("setQueryable(%i) for Layer %s",queryable, this.layer_name);
+};
\ No newline at end of file
More information about the Mapbender_commits
mailing list