[Mapbender-commits] r1850 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Nov 26 05:25:58 EST 2007


Author: christoph
Date: 2007-11-26 05:25:57 -0500 (Mon, 26 Nov 2007)
New Revision: 1850

Modified:
   trunk/mapbender/http/javascripts/map.js
Log:
code optimization

Modified: trunk/mapbender/http/javascripts/map.js
===================================================================
--- trunk/mapbender/http/javascripts/map.js	2007-11-26 08:57:00 UTC (rev 1849)
+++ trunk/mapbender/http/javascripts/map.js	2007-11-26 10:25:57 UTC (rev 1850)
@@ -1269,20 +1269,16 @@
 	posY = Math.round(posY * roundy)/roundy;
 	return new Array(posX, posY);
 }
+
 function makeRealWorld2mapPos(frameName,rw_posx, rw_posy){
    var ind = getMapObjIndexByName(frameName);
-   var arrayBBox = mb_mapObj[ind].extent.split(",");
+   var mpObj = mb_mapObj[ind]; 
+   var arrayBBox = mpObj.extent.split(",");
    var minX = parseFloat(arrayBBox[0]);
    var minY = parseFloat(arrayBBox[1]);
    var maxX = parseFloat(arrayBBox[2]);
    var maxY = parseFloat(arrayBBox[3]);
-   var xtentx = parseFloat(arrayBBox[2]) - parseFloat(arrayBBox[0]);
-   var xtenty =  parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1]);
-   var width = mb_mapObj[ind].width;
-   var height = mb_mapObj[ind].height;
-   pixPos_x = Math.round(parseFloat(((rw_posx - minX)/xtentx)*width));
-   pixPos_y = Math.round(parseFloat(((maxY - rw_posy)/xtenty)*height));
-   return new Array(pixPos_x, pixPos_y);
+   return [Math.round((rw_posx - minX)*mpObj.width/(maxX - minX)), Math.round((maxY - rw_posy)*mpObj.height/(maxY - minY))];
 }
 
 function mb_arrangeElement(frameName, elName, left, top) {
@@ -2007,10 +2003,14 @@
 	 */
 	this.del = function(i){
 		i = this.getIndex(i);
-		for(var z = i; z < this.count() - 1; z++){
-			this.list[z] = this.list[z+1];
+		if (i !== false) {
+			for(var z = i; z < this.count() - 1; z++){
+				this.list[z] = this.list[z+1];
+			}
+			this.list.length -= 1;
+			return true;
 		}
-		this.list.length -= 1;
+		return false;
 	};
 
 	/**
@@ -2038,7 +2038,8 @@
 	 * @param {Object} item an object
 	 */
 	this.add = function(item) {
-		this.list.push(item);
+		var i = this.list.length;
+		this.list[i] = item;
 	};
 	/**
 	 * adds a copy of item to this {@link List}.
@@ -2046,7 +2047,7 @@
 	 * @param {Object} item an object
 	 */
 	this.addCopy = function(item) {
-		this.list.push(cloneObject(item));
+		this.add(cloneObject(item));
 	};
 	/**
 	 * attaches the {@link List} aList to this {@link List}
@@ -2064,13 +2065,15 @@
 	 * @type Integer
 	 */
 	this.getIndex = function(i){ 
-		if ((i >= 0 && i < this.list.length) || (i*(-1)>0 && i*(-1) <= this.list.length)){
-			if (i >= 0) {return i;} else {return this.list.length+i;}
+		var len = this.list.length;
+		if (i<0 && len + i > -1) {
+			return len + i;			
 		}
-		else {
-			var e = new Mb_exception("class List: function getIndex: member index " + i + " is not valid");
-			return false;
+		else if (i > -1 && i < len){
+			return i;
 		}
+		var e = new Mb_exception("class List: function getIndex: member index " + i + " is not valid");
+		return false;
 	};
 	/**
 	 * @returns a {String} representation of this List



More information about the Mapbender_commits mailing list