diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index 408e6335e4..f4094b2f1d 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -367,24 +367,21 @@ OpenLayers.Bounds.prototype = { }, /** - * @param {int} decimal How many significant digits in the bbox coords? - * Default is 6 - * - * @returns Simple String representation of OpenLayers.Bounds object. - * (ex. "5,42,10,45") - * @type String - */ - toBBOX:function(decimal) { - if (decimal== null) { - decimal = 6; - } - var mult = Math.pow(10, decimal); - var bbox = Math.round(this.left*mult)/mult + "," + - Math.round(this.bottom*mult)/mult + "," + - Math.round(this.right*mult)/mult + "," + - Math.round(this.top*mult)/mult; - - return bbox; + * @return Simple String representation of OpenLayers.Bounds object. + * (ex. "5,42,10,45") + * @type String + */ + toBBOX:function(power) { + var mult; + if (power) { + mult = Math.pow(10,power); + } else { + mult = Math.pow(10,6); + } + return (Math.round(this.left*mult)/mult + "," + + Math.round(this.bottom*mult)/mult + "," + + Math.round(this.right*mult)/mult + "," + + Math.round(this.top*mult)/mult); }, /** @@ -812,52 +809,6 @@ String.prototype.camelize = function() { }; - -/********************* - * * - * ARRAY * - * * - *********************/ - - - -/** Remove an object from an array. Iterates through the array -* to find the item, then removes it. -* -* @param {Object} item -* -* @returns A reference to the array -* @type Array -*/ -Array.prototype.remove = function(item) { - for(var i=0; i < this.length; i++) { - if(this[i] == item) { - this.splice(i,1); - //break;more than once?? - } - } - return this; -} - -/** -* @returns A fresh copy of the array -* @type Array -*/ -Array.prototype.clone = function() { - var clone = new Array(); - for (var i = 0; i < this.length; i++) { - clone[i] = this[i]; - } - return clone; -}; - -/** -*/ -Array.prototype.clear = function() { - this.length = 0; -}; - - /********************* * * * NUMBER * diff --git a/lib/OpenLayers/Layer/GeoRSS.js b/lib/OpenLayers/Layer/GeoRSS.js index 3570d2d8fb..00d969c071 100644 --- a/lib/OpenLayers/Layer/GeoRSS.js +++ b/lib/OpenLayers/Layer/GeoRSS.js @@ -148,7 +148,7 @@ OpenLayers.Layer.GeoRSS.prototype = if (this.features != null) { while(this.features.length > 0) { var feature = this.features[0]; - this.features.remove(feature); + OpenLayers.Util.removeItem(this.features, feature); feature.destroy(); } } diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 46b65d19b8..610ad5a200 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -324,7 +324,7 @@ OpenLayers.Layer.Grid.prototype = for(var iRow=0; iRow < this.grid.length; iRow++) { var row = this.grid[iRow]; for(var iCol=0; iCol < row.length; iCol++) { - row[iCol].clear(); + OpenLayers.Util.clearArray(row[iCol]); } } } diff --git a/lib/OpenLayers/Layer/Markers.js b/lib/OpenLayers/Layer/Markers.js index cbfd1925d3..cebbe55e38 100644 --- a/lib/OpenLayers/Layer/Markers.js +++ b/lib/OpenLayers/Layer/Markers.js @@ -70,7 +70,7 @@ OpenLayers.Layer.Markers.prototype = * @param {OpenLayers.Marker} marker */ removeMarker: function(marker) { - this.markers.remove(marker); + OpenLayers.Util.removeItem(this.markers, marker); if ((marker.icon != null) && (marker.icon.imageDiv != null) && (marker.icon.imageDiv.parentNode == this.div) ) { this.div.removeChild(marker.icon.imageDiv); diff --git a/lib/OpenLayers/Layer/Text.js b/lib/OpenLayers/Layer/Text.js index a8a171db97..02254a8ff9 100644 --- a/lib/OpenLayers/Layer/Text.js +++ b/lib/OpenLayers/Layer/Text.js @@ -155,7 +155,7 @@ OpenLayers.Layer.Text.prototype = if (this.features != null) { while(this.features.length > 0) { var feature = this.features[0]; - this.features.remove(feature); + OpenLayers.Util.removeItem(this.features, feature); feature.destroy(); } } diff --git a/lib/OpenLayers/Layer/WMS/Untiled.js b/lib/OpenLayers/Layer/WMS/Untiled.js index 9cf400172c..e2e6c9b8d7 100644 --- a/lib/OpenLayers/Layer/WMS/Untiled.js +++ b/lib/OpenLayers/Layer/WMS/Untiled.js @@ -124,7 +124,7 @@ OpenLayers.Layer.WMS.Untiled.prototype = //clear out the old tile if (this.tile) { - this.tile.clear(); + OpenLayers.Util.clearArray(this.tile); } //determine new tile bounds diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 08ed33e5de..936b613832 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -327,7 +327,7 @@ OpenLayers.Map.prototype = { this.layerContainerDiv.removeChild(layer.div); } layer.map = null; - this.layers.remove(layer); + OpenLayers.Util.removeItem(this.layers, layer); // if we removed the base layer, need to set a new one if (this.baseLayer == layer) { @@ -432,7 +432,7 @@ OpenLayers.Map.prototype = { * @param {OpenLayers.Popup} popup */ removePopup: function(popup) { - this.popups.remove(popup); + OpenLayers.Util.removeItem(this.popups, popup); if (popup.div) { try { this.layerContainerDiv.removeChild(popup.div); } catch (e) { } // Popups sometimes apparently get disconnected diff --git a/lib/OpenLayers/Popup/AnchoredBubble.js b/lib/OpenLayers/Popup/AnchoredBubble.js index 1dea84a142..8d7e2628c8 100644 --- a/lib/OpenLayers/Popup/AnchoredBubble.js +++ b/lib/OpenLayers/Popup/AnchoredBubble.js @@ -175,7 +175,7 @@ OpenLayers.Popup.AnchoredBubble.prototype = //we want to round all the corners _except_ the opposite one. var corner = OpenLayers.Bounds.oppositeQuadrant(this.relativePosition); - corners.remove(corner); + OpenLayers.Util.removeItem(corners, corner); return corners.join(" "); }, diff --git a/lib/OpenLayers/Tile.js b/lib/OpenLayers/Tile.js index 4305f533f8..eb9fc46eb9 100644 --- a/lib/OpenLayers/Tile.js +++ b/lib/OpenLayers/Tile.js @@ -84,7 +84,7 @@ OpenLayers.Tile.prototype = { redraw = true; } - this.clear(); + OpenLayers.Util.clearArray(this); this.bounds = bounds.clone(); this.position = position.clone(); if (redraw) { diff --git a/lib/OpenLayers/Tile/WFS.js b/lib/OpenLayers/Tile/WFS.js index 1524136c2f..26d8a40d22 100644 --- a/lib/OpenLayers/Tile/WFS.js +++ b/lib/OpenLayers/Tile/WFS.js @@ -60,7 +60,7 @@ OpenLayers.Tile.WFS.prototype = */ draw:function() { if (this.drawn) { - this.clear(); + OpenLayers.Util.clearArray(this); } OpenLayers.Tile.prototype.draw.apply(this, arguments); if (this.layer.displayOutsideMaxExtent || (this.layer.maxExtent && diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index ea3e346ca2..45e84050a9 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -35,6 +35,31 @@ OpenLayers.Util.extend = function(destination, source) { return destination; }; + +/** Remove an object from an array. Iterates through the array +* to find the item, then removes it. +* +* @param {Object} item +* +* @returns A reference to the array +* @type Array +*/ +OpenLayers.Util.removeItem = function(array, item) { + for(var i=0; i < array.length; i++) { + if(array[i] == item) { + array.splice(i,1); + //break;more than once?? + } + } + return array; +}; + +/** +*/ +OpenLayers.Util.clearArray = function(array) { + array.length = 0; +}; + /** * @param {String} id * @param {OpenLayers.Pixel} px diff --git a/tests/test_Util.html b/tests/test_Util.html index 46a3e859b9..f7a843e451 100644 --- a/tests/test_Util.html +++ b/tests/test_Util.html @@ -30,21 +30,15 @@ } function test_03_Util_Array(t) { - t.plan( 5 ); + t.plan( 2 ); var array = new Array(1,2,3,4,5); - array.remove(3); - t.eq( array.toString(), "1,2,4,5", "array.remove works"); + OpenLayers.Util.removeItem(array, 3); + t.eq( array.toString(), "1,2,4,5", "Util.removeItem works"); - copy = array.clone(); - t.eq( copy.toString(), "1,2,4,5", "array.clone() works"); - array.push(7); - t.eq( copy.toString(), "1,2,4,5", "changing a value in the copied array doesnt affect the new array"); - - - t.eq( copy.indexOf(5), 3, "indexOf function returns index of value in an array"); - t.eq( copy.indexOf(75), -1, "indexOf function returns -1 when element not found in array"); + OpenLayers.Util.clearArray(array); + t.eq( array.toString(), "", "Util.clearArray works"); }