[Mapbender-commits] r4079 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Jun 23 04:37:37 EDT 2009
Author: christoph
Date: 2009-06-23 04:37:37 -0400 (Tue, 23 Jun 2009)
New Revision: 4079
Modified:
trunk/mapbender/http/javascripts/map_obj.js
Log:
Mapbender API
Modified: trunk/mapbender/http/javascripts/map_obj.js
===================================================================
--- trunk/mapbender/http/javascripts/map_obj.js 2009-06-23 08:27:23 UTC (rev 4078)
+++ trunk/mapbender/http/javascripts/map_obj.js 2009-06-23 08:37:37 UTC (rev 4079)
@@ -1,11 +1,11 @@
-/*
+/*
* $Id: map_obj.js 2517 2008-06-19 16:40:00Z 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.
+* License (>=v2). Read the file gpl.txt that comes with Mapbender for details.
*/
var mb_mapObj = [];
-function mb_mapObj_const(frameName, elementName, width, height, wms_index){
+function Map (frameName, elementName, width, height, wms_index){
/**
* set the extent of the wms
@@ -14,21 +14,22 @@
this.extent = String(minx) + "," + String(miny) + "," + String(maxx) + "," + String(maxy);
};
+/*
this.restrictedExtent = function (extent) {
this.restrictedExtent = extent;
};
-
+*/
/**
* get the width of the mapObj
*
- * @member mb_mapObj_const
+ * @member Map
* @return width of the mapObj
* @type integer
*/
this.getWidth = function(){
return parseInt(this.width, 10);
};
-
+
/**
* set the width of the mapObj
*
@@ -44,25 +45,25 @@
var domElement = this.getDomElement();
domElement.style.width = this.width;
};
-
+
/**
* get the height of the mapObj
*
- * @member mb_mapObj_const
+ * @member Map
* @return width of the mapObj
* @type integer
*/
this.getHeight = function(){
return parseInt(this.height, 10);
};
-
+
this.getDomElement = function(){
if(this.frameName){
return window.frames[this.frameName].document.getElementById(this.elementName);
}
return document.getElementById(this.elementName);
}
-
+
/**
* set the height of the mapObj
*
@@ -77,7 +78,7 @@
var domElement = this.getDomElement();
domElement.style.height = this.height;
};
-
+
this.getMousePosition = function (e) {
var clickX, clickY;
@@ -100,24 +101,24 @@
if (this.type == "DIV") {
var mapDomElement = this.getDomElement();
currentPos = new Point(
- clickX - parseInt(mapDomElement.style.left),
+ clickX - parseInt(mapDomElement.style.left),
clickY - parseInt(mapDomElement.style.top)
);
// if the mouse position is not on top of the map, return null
- if (currentPos.x < 0 || currentPos.x > this.width ||
+ if (currentPos.x < 0 || currentPos.x > this.width ||
currentPos.y < 0 || currentPos.y > this.height) {
return null;
}
}
else {
currentPos = new Point(
- clickX,
+ clickX,
clickY
);
}
return currentPos;
}
-
+
/**
* converts the extent of the mapobject so that the maximum extent will be displayed
*/
@@ -133,13 +134,13 @@
ext.miny = ext.centery - relation_px_y * ext.extentx / 2;
ext.maxy = ext.centery + relation_px_y * ext.extentx / 2;
}
-
+
// Check if ext is within restricted extent
// If not, calculate a new extent according
// to restricted extent.
/*
if ( this.restrictedExtent ) {
- if ( ext.minx < this.restrictedExtent.minx ) {
+ if ( ext.minx < this.restrictedExtent.minx ) {
ext.minx = this.restrictedExtent.minx;
ext.maxx = ext.minx + (relation_px_x * ext.extenty);
}
@@ -188,9 +189,9 @@
index++;
}
}
-
+
//
- // set list of visible layers, active querylayers
+ // set list of visible layers, active querylayers
// and styles for each WMS in this map
//
var cnt_layers;
@@ -204,7 +205,7 @@
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) {
@@ -229,10 +230,10 @@
this.styles[i] = styles;
this.querylayers[i] = querylayers;
}
-
+
this.epsg = wms[0].gui_wms_epsg;
var bbox_minx, bbox_miny, bbox_maxx, bbox_maxy;
-
+
for (var i = 0; i < wms[0].gui_epsg.length; i++) {
if (this.epsg == wms[0].gui_epsg[i]) {
bbox_minx = parseFloat(wms[0].gui_minx[i]);
@@ -242,27 +243,27 @@
}
}
var wmsExtent = new Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy);
-
+
this.calculateExtent(wmsExtent);
this.mapURL = [];
var domElement = this.getDomElement();
domElement.style.width = this.width;
- domElement.style.height = this.height;
-
+ domElement.style.height = this.height;
+
this.afterMapRequest = new MapbenderEvent();
-
+
/**
* get the extent of the mapObj
*
- * @member mb_mapObj_const
+ * @member Map
* @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
*
@@ -274,7 +275,7 @@
var ext = new Extent(c[0], c[1], c[2], c[3]);
return ext;
};
-
+
/**
* Sets the list of layers, styles and querylayers for a specified WMS
*/
@@ -313,9 +314,9 @@
}
// this.setExtent(ext.minx,ext.miny,ext.maxx,ext.maxy);
};
-
+
/**
- *
+ *
* @param {Object} direction
*/
this.pan = function (direction) {
@@ -327,83 +328,79 @@
var xtentx = maxx - minx;
var xtenty = maxy - miny;
var factor = 0.5;
-
+
switch (direction) {
case "NW" :
- minx -= (xtentx * factor);
- maxx -= (xtentx * factor);
- miny += (xtenty * factor);
+ minx -= (xtentx * factor);
+ maxx -= (xtentx * factor);
+ miny += (xtenty * factor);
maxy += (xtenty * factor);
break;
case "N" :
- miny += (xtenty * factor);
+ miny += (xtenty * factor);
maxy += (xtenty * factor);
break;
case "NE" :
- minx += (xtentx * factor);
- maxx += (xtentx * factor);
- miny += (xtenty * factor);
+ minx += (xtentx * factor);
+ maxx += (xtentx * factor);
+ miny += (xtenty * factor);
maxy += (xtenty * factor);
break;
case "E" :
- minx += (xtentx * factor);
+ minx += (xtentx * factor);
maxx += (xtentx * factor);
break;
case "SE" :
- minx += (xtentx * factor);
- maxx += (xtentx * factor);
- miny -= (xtenty * factor);
- maxy -= (xtenty * factor);
+ minx += (xtentx * factor);
+ maxx += (xtentx * factor);
+ miny -= (xtenty * factor);
+ maxy -= (xtenty * factor);
break;
case "S" :
- miny -= (xtenty * factor);
+ miny -= (xtenty * factor);
maxy -= (xtenty * factor);
break;
case "SW" :
- minx -= (xtentx * factor);
- maxx -= (xtentx * factor);
- miny -= (xtenty * factor);
+ minx -= (xtentx * factor);
+ maxx -= (xtentx * factor);
+ miny -= (xtenty * factor);
maxy -= (xtenty * factor);
break;
case "W" :
- minx -= (xtentx * factor);
+ minx -= (xtentx * factor);
maxx -= (xtentx * factor);
break;
}
this.extent = minx + "," + miny + "," + maxx + "," + maxy;
-
+
this.restrictedExtent;
this.setMapRequest();
-
+
};
-
+
this.zoomFull = function () {
-
-
-/*
-** not in use until now and commented out because of error in zoomFull module (Bolsena 23.6.09)
+
if (this.restrictedExtent) {
var newExtent = this.calculateExtent(this.restrictedExtent);
this.repaint(new Point(newExtent.minx, newExtent.miny), new Point(newExtent.maxx, newExtent.maxy));
}
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 Extent(bbox_minx, bbox_miny, bbox_maxx, bbox_maxy);
var newExtent = this.calculateExtent(wmsExtent);
this.repaint(new Point(newExtent.minx, newExtent.miny), new Point(newExtent.maxx, newExtent.maxy));
break;
}
}
-// }
+ }
};
-
+
/**
* zoom the map with a zoomfactor and optional to x,y coords
*
@@ -417,11 +414,11 @@
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);
@@ -430,7 +427,7 @@
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;
@@ -444,7 +441,7 @@
var relation_px_x = this.getWidth() / this.getHeight();
var relation_px_y = this.getHeight() / this.getWidth();
if ( this.restrictedExtent ) {
- if ( minx < this.restrictedExtent.minx ) {
+ if ( minx < this.restrictedExtent.minx ) {
minx = this.restrictedExtent.minx;
maxx = minx + (relation_px_x * new_disty);
}
@@ -462,12 +459,12 @@
}
}
*/
-
+
this.setExtent(minx, miny, maxx, maxy);
this.setMapRequest();
};
-
+
var performUnknownCalculation = function (value) {
return Math.pow(10,(
Math.round(
@@ -476,7 +473,7 @@
)
));
};
-
+
this.convertPixelToReal = function (aPoint) {
var arrayBBox = this.extent.split(",");
var minX = parseFloat(arrayBBox[0]);
@@ -500,14 +497,14 @@
}
else{
roundy = performUnknownCalculation(deltaY);
- }
+ }
var posX = parseFloat(minX + (aPoint.x / this.width) * xtentx);
var posY = parseFloat(maxY - (aPoint.y / this.height) * xtenty);
posX = Math.round(posX * roundx) / roundx;
posY = Math.round(posY * roundy) / roundy;
return new Point(posX, posY);
};
-
+
/**
* Convert real world coordinates to pixel coordinates
*/
@@ -518,11 +515,11 @@
var maxX = parseFloat(arrayBBox[2]);
var maxY = parseFloat(arrayBBox[3]);
return new Point(
- Math.round((aPoint.x - minX) * this.width /(maxX - minX)),
+ Math.round((aPoint.x - minX) * this.width /(maxX - minX)),
Math.round((maxY - aPoint.y) * this.height/(maxY - minY))
);
};
-
+
/**
* get the srs of the mapObj
*
@@ -532,7 +529,7 @@
this.getSRS = function(){
return this.epsg;
};
-
+
/**
* get all mapRequests
*
@@ -553,7 +550,7 @@
}
return false;
};
-
+
/**
* Return the map URL of the WMS at index i
* @param {Object} currentWmsIndex
@@ -565,17 +562,17 @@
return false;
}
var layerNames = validLayers.join(",");
-
+
url = currentWms.wms_getmap;
url += mb_getConjunctionCharacter(currentWms.wms_getmap);
-
+
if (currentWms.wms_version == "1.0.0") {
url += "WMTVER=" + currentWms.wms_version + "&REQUEST=map&";
}
else {
url += "VERSION=" + currentWms.wms_version + "&REQUEST=GetMap&SERVICE=WMS&";
}
-
+
url += "LAYERS=" + layerNames + "&";
url += "STYLES=";
var layer = layerNames.split(",");
@@ -594,14 +591,14 @@
url += "HEIGHT=" + this.height + "&";
url += "FORMAT=" + currentWms.gui_wms_mapformat + "&";
url += "BGCOLOR=0xffffff&";
-
+
if (currentWms.gui_wms_mapformat.search(/gif/i) > -1 ||
currentWms.gui_wms_mapformat.search(/png/i) > -1) {
url += "TRANSPARENT=TRUE&";
}
-
+
url += "EXCEPTIONS=" + currentWms.gui_wms_exceptionformat + "&";
-
+
// add vendor-specific
for (var v = 0; v < mb_vendorSpecific.length; v++) {
var functionName = 'setMapRequest';
@@ -609,7 +606,7 @@
// 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)
+ // scope (see mod_addSLD.php)
if (typeof(vendorSpecificString) != "undefined") {
url += vendorSpecificString + "&";
}
@@ -624,11 +621,11 @@
}
return url;
}
-
+
/**
* get all featureInfoRequests
*
- * @member mb_mapObj_const
+ * @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
@@ -659,11 +656,11 @@
}
return false;
};
-
+
/**
* calculation of the mapscale
*
- * @member mb_mapObj_const
+ * @member Map
* @return scale
* @type integer
*/
@@ -687,7 +684,7 @@
}
return parseInt(Math.round(scale));
};
-
+
/**
*
*/
@@ -699,10 +696,10 @@
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) {
@@ -722,9 +719,9 @@
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.split(",");
@@ -741,18 +738,18 @@
var maxy = parseFloat(y) + (this.height / (mb_resolution * 100 * 2) * scale);
this.repaint(new Point(minx, miny), new Point(maxx, maxy));
};
-
+
this.repaint = function(min, max){
this.extent = min.x + "," + min.y + "," + max.x + "," + max.y;
this.setMapRequest();
};
-
+
this.setSingleMapRequest = function (wms_id) {
eventBeforeMapRequest.trigger({map:this});
-
- var ts = mb_timestamp();
-
- for (var ii = 0; ii < this.wms.length; ii++){
+
+ var ts = mb_timestamp();
+
+ for (var ii = 0; ii < this.wms.length; ii++){
var currentWms = this.wms[ii];
if (currentWms.wms_id != wms_id) {
continue;
@@ -762,16 +759,16 @@
if (mb_log) {
var tmp = eval(mb_log + "('" + newMapURL + "','" + ts + "')");
}
- var myDivId = this.elementName + "_div_" + ii;
+ var myDivId = this.elementName + "_div_" + ii;
writeTag(this.frameName, myDivId, newMapRequest);
var myMapId = this.elementName + "_map_" + ii;
eventAfterMapRequest.trigger({"map":this, "myMapId":myMapId});
return true;
- }
- return false;
-
+ }
+ return false;
+
};
-
+
this.mb_setFutureObj = function(mod_back_cnt){
var cnt = this.mb_MapFutureObj.length;
this.mb_MapFutureObj[cnt] = {};
@@ -781,7 +778,7 @@
this.mb_MapFutureObj[cnt].epsg = this.epsg;
this.mb_MapFutureObj[cnt].extent = this.extent;
this.mb_MapFutureObj[cnt].layers = [];
-
+
for(var i=0; i<this.layers.length;i++){
this.mb_MapFutureObj[cnt].layers[i] = this.layers[i];
}
@@ -798,7 +795,7 @@
this.mb_MapFutureObj[cnt].querylayers[i] = this.querylayers[i];
}
}
-
+
this.setMapRequest = function(){
var ret = eventBeforeMapRequest.trigger({
map: this
@@ -808,19 +805,19 @@
}
var ts = mb_timestamp();
var myMapId = [];
-
+
var newMapRequest = "";
-
+
for (var ii = 0; ii < this.wms.length; ii++) {
var currentWms = this.wms[ii];
-
+
if (!(currentWms.gui_wms_visible > 0)) {
continue;
}
myMapId.push(this.elementName + "_map_" + ii);
-
+
newMapRequest += getLayerHtmlCode(ii);
-
+
}
writeTag(this.frameName, this.elementName+"_maps", newMapRequest);
@@ -835,21 +832,21 @@
var getLayerHtmlCode = function (ii) {
var currentWms = that.wms[ii];
-
- var myDivId = that.elementName + "_div_" + ii;
+
+ var myDivId = that.elementName + "_div_" + ii;
var myMapId = that.elementName + "_map_" + ii;
//disable Layer which are out of scale
var validLayers = that.checkScale(ii);
var layerNames = validLayers.toString();
-
+
var newMapURL = false;
var opacityString = "";
-
+
if (that.layers[ii] !== "" && layerNames !== ''){
// get map URL
newMapURL = that.getMapUrl(ii);
-
+
var currentOpacity = currentWms.gui_wms_mapopacity;
if (currentOpacity != 1) {
opacityString += "opacity:" + currentOpacity + "; ";
@@ -858,32 +855,32 @@
opacityString += "-khtml-opacity:" + currentOpacity;
}
}
-
+
var imageString = "";
if (newMapURL) {
imageString = "<img id='"+myMapId+"' name='mapimage' ";
imageString += "src='" + newMapURL + "' ";
imageString += "width='"+that.width+"' ";
imageString += "height='"+that.height+"' ";
- imageString += "border='0'>";
+ imageString += "border='0'>";
}
-
+
var newMapRequest = "<div id='"+myDivId+"' ";
newMapRequest += "style=\"position:absolute; top:0px; left:0px; ";
newMapRequest += "z-index:" + ii + ";" + opacityString + "\">";
newMapRequest += imageString;
- newMapRequest += "</div>";
-
- that.mapURL[ii]= newMapURL;
+ newMapRequest += "</div>";
+
+ that.mapURL[ii]= newMapURL;
currentWms.mapURL = newMapURL;
-
+
if (mb_log && currentWms.mapURL) {
var tmp = eval(mb_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) {
@@ -910,7 +907,7 @@
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]);
@@ -923,24 +920,24 @@
wms_ID = this.wms[i].wms_id;
}
}
- this.wms = new_wmsarray;
- this.layers = new_layerarray;
- this.querylayers = new_querylayerarray;
- this.styles = new_stylesarray;
+ 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]);
+ another_new_wmsarray.push(window.wms[i]);
}
}
- window.wms = another_new_wmsarray;
+ window.wms = another_new_wmsarray;
};
-
+
/**
- * move a wms or layer
+ * move a wms or layer
*
* @param int wms_id id of wms to move
* @param int layer_id id of layer to move
@@ -954,18 +951,18 @@
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;
@@ -978,10 +975,10 @@
this.layers[j] = upperLayers;
this.styles[j] = upperStyles;
this.querylayers[j] = upperQuerylayers;
-
+
return true;
};
-
+
this.getMousePos = function(e){
if(ie){
if(this.frameName){
@@ -997,18 +994,18 @@
clickX = e.pageX;
clickY = e.pageY;
}
-
+
//remove divtag offset
clickX -= parseInt(this.getDomElement().style.left);
clickY -= parseInt(this.getDomElement().style.top);
-
+
return new Point(clickX, clickY);
}
eventAfterMapObjectConstruction.trigger();
}
-mb_mapObj_const.prototype.getWfsConfIds = function (wfs_config) {
+Map.prototype.getWfsConfIds = function (wfs_config) {
var db_wfs_conf_id = [];
var js_wfs_conf_id = [];
More information about the Mapbender_commits
mailing list