Changeset 1590
- Timestamp:
- 10/05/06 11:18:02 (2 years ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/BaseTypes.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Layer/Grid.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Layer/Markers.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Layer/Text.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Map.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Popup/AnchoredBubble.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Tile.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Tile/WFS.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Util.js (modified) (1 diff)
- trunk/openlayers/tests/test_Util.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/BaseTypes.js
r1588 r1590 368 368 369 369 /** 370 * @param {int} decimal How many significant digits in the bbox coords? 371 * Default is 6 372 * 373 * @returns Simple String representation of OpenLayers.Bounds object. 374 * (ex. <i>"5,42,10,45"</i>) 375 * @type String 376 */ 377 toBBOX:function(decimal) { 378 if (decimal== null) { 379 decimal = 6; 380 } 381 var mult = Math.pow(10, decimal); 382 var bbox = Math.round(this.left*mult)/mult + "," + 383 Math.round(this.bottom*mult)/mult + "," + 384 Math.round(this.right*mult)/mult + "," + 385 Math.round(this.top*mult)/mult; 386 387 return bbox; 370 * @return Simple String representation of OpenLayers.Bounds object. 371 * (ex. <i>"5,42,10,45"</i>) 372 * @type String 373 */ 374 toBBOX:function(power) { 375 var mult; 376 if (power) { 377 mult = Math.pow(10,power); 378 } else { 379 mult = Math.pow(10,6); 380 } 381 return (Math.round(this.left*mult)/mult + "," + 382 Math.round(this.bottom*mult)/mult + "," + 383 Math.round(this.right*mult)/mult + "," + 384 Math.round(this.top*mult)/mult); 388 385 }, 389 386 … … 813 810 814 811 815 816 /*********************817 * *818 * ARRAY *819 * *820 *********************/821 822 823 824 /** Remove an object from an array. Iterates through the array825 * to find the item, then removes it.826 *827 * @param {Object} item828 *829 * @returns A reference to the array830 * @type Array831 */832 Array.prototype.remove = function(item) {833 for(var i=0; i < this.length; i++) {834 if(this[i] == item) {835 this.splice(i,1);836 //break;more than once??837 }838 }839 return this;840 }841 842 /**843 * @returns A fresh copy of the array844 * @type Array845 */846 Array.prototype.clone = function() {847 var clone = new Array();848 for (var i = 0; i < this.length; i++) {849 clone[i] = this[i];850 }851 return clone;852 };853 854 /**855 */856 Array.prototype.clear = function() {857 this.length = 0;858 };859 860 861 812 /********************* 862 813 * * trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js
r1588 r1590 149 149 while(this.features.length > 0) { 150 150 var feature = this.features[0]; 151 this.features.remove(feature);151 OpenLayers.Util.removeItem(this.features, feature); 152 152 feature.destroy(); 153 153 } trunk/openlayers/lib/OpenLayers/Layer/Grid.js
r1588 r1590 325 325 var row = this.grid[iRow]; 326 326 for(var iCol=0; iCol < row.length; iCol++) { 327 row[iCol].clear();327 OpenLayers.Util.clearArray(row[iCol]); 328 328 } 329 329 } trunk/openlayers/lib/OpenLayers/Layer/Markers.js
r1588 r1590 71 71 */ 72 72 removeMarker: function(marker) { 73 this.markers.remove(marker);73 OpenLayers.Util.removeItem(this.markers, marker); 74 74 if ((marker.icon != null) && (marker.icon.imageDiv != null) && 75 75 (marker.icon.imageDiv.parentNode == this.div) ) { trunk/openlayers/lib/OpenLayers/Layer/Text.js
r1588 r1590 156 156 while(this.features.length > 0) { 157 157 var feature = this.features[0]; 158 this.features.remove(feature);158 OpenLayers.Util.removeItem(this.features, feature); 159 159 feature.destroy(); 160 160 } trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js
r1588 r1590 125 125 //clear out the old tile 126 126 if (this.tile) { 127 this.tile.clear();127 OpenLayers.Util.clearArray(this.tile); 128 128 } 129 129 trunk/openlayers/lib/OpenLayers/Map.js
r1588 r1590 328 328 } 329 329 layer.map = null; 330 this.layers.remove(layer);330 OpenLayers.Util.removeItem(this.layers, layer); 331 331 332 332 // if we removed the base layer, need to set a new one … … 433 433 */ 434 434 removePopup: function(popup) { 435 this.popups.remove(popup);435 OpenLayers.Util.removeItem(this.popups, popup); 436 436 if (popup.div) { 437 437 try { this.layerContainerDiv.removeChild(popup.div); } trunk/openlayers/lib/OpenLayers/Popup/AnchoredBubble.js
r1588 r1590 176 176 //we want to round all the corners _except_ the opposite one. 177 177 var corner = OpenLayers.Bounds.oppositeQuadrant(this.relativePosition); 178 corners.remove(corner);178 OpenLayers.Util.removeItem(corners, corner); 179 179 180 180 return corners.join(" "); trunk/openlayers/lib/OpenLayers/Tile.js
r1588 r1590 85 85 } 86 86 87 this.clear();87 OpenLayers.Util.clearArray(this); 88 88 this.bounds = bounds.clone(); 89 89 this.position = position.clone(); trunk/openlayers/lib/OpenLayers/Tile/WFS.js
r1588 r1590 61 61 draw:function() { 62 62 if (this.drawn) { 63 this.clear();63 OpenLayers.Util.clearArray(this); 64 64 } 65 65 OpenLayers.Tile.prototype.draw.apply(this, arguments); trunk/openlayers/lib/OpenLayers/Util.js
r1588 r1590 34 34 } 35 35 return destination; 36 }; 37 38 39 /** Remove an object from an array. Iterates through the array 40 * to find the item, then removes it. 41 * 42 * @param {Object} item 43 * 44 * @returns A reference to the array 45 * @type Array 46 */ 47 OpenLayers.Util.removeItem = function(array, item) { 48 for(var i=0; i < array.length; i++) { 49 if(array[i] == item) { 50 array.splice(i,1); 51 //break;more than once?? 52 } 53 } 54 return array; 55 }; 56 57 /** 58 */ 59 OpenLayers.Util.clearArray = function(array) { 60 array.length = 0; 36 61 }; 37 62 trunk/openlayers/tests/test_Util.html
r1550 r1590 31 31 32 32 function test_03_Util_Array(t) { 33 t.plan( 5);33 t.plan( 2 ); 34 34 35 35 var array = new Array(1,2,3,4,5); 36 36 37 array.remove(3); 38 t.eq( array.toString(), "1,2,4,5", "array.remove works"); 39 40 copy = array.clone(); 41 t.eq( copy.toString(), "1,2,4,5", "array.clone() works"); 42 array.push(7); 43 t.eq( copy.toString(), "1,2,4,5", "changing a value in the copied array doesnt affect the new array"); 44 45 46 t.eq( copy.indexOf(5), 3, "indexOf function returns index of value in an array"); 47 t.eq( copy.indexOf(75), -1, "indexOf function returns -1 when element not found in array"); 37 OpenLayers.Util.removeItem(array, 3); 38 t.eq( array.toString(), "1,2,4,5", "Util.removeItem works"); 39 40 OpenLayers.Util.clearArray(array); 41 t.eq( array.toString(), "", "Util.clearArray works"); 48 42 49 43 }
