OpenLayers OpenLayers

Changeset 1590

Show
Ignore:
Timestamp:
10/05/06 11:18:02 (2 years ago)
Author:
sderle
Message:

Removed modifications to Array.prototype and moved them into OL.Util instead. All tests pass.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/BaseTypes.js

    r1588 r1590  
    368368 
    369369    /**  
    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); 
    388385    }, 
    389386     
     
    813810 
    814811 
    815  
    816 /********************* 
    817  *                   * 
    818  *      ARRAY        *  
    819  *                   *  
    820  *********************/ 
    821  
    822  
    823  
    824 /** Remove an object from an array. Iterates through the array 
    825 *    to find the item, then removes it. 
    826 * 
    827 * @param {Object} item 
    828 *  
    829 * @returns A reference to the array 
    830 * @type Array 
    831 */ 
    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 array 
    844 * @type Array 
    845 */ 
    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  
    861812/********************* 
    862813 *                   * 
  • trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js

    r1588 r1590  
    149149            while(this.features.length > 0) { 
    150150                var feature = this.features[0]; 
    151                 this.features.remove(feature); 
     151                OpenLayers.Util.removeItem(this.features, feature); 
    152152                feature.destroy(); 
    153153            } 
  • trunk/openlayers/lib/OpenLayers/Layer/Grid.js

    r1588 r1590  
    325325                var row = this.grid[iRow]; 
    326326                for(var iCol=0; iCol < row.length; iCol++) { 
    327                     row[iCol].clear(); 
     327                    OpenLayers.Util.clearArray(row[iCol]); 
    328328                } 
    329329            } 
  • trunk/openlayers/lib/OpenLayers/Layer/Markers.js

    r1588 r1590  
    7171     */ 
    7272    removeMarker: function(marker) { 
    73         this.markers.remove(marker); 
     73        OpenLayers.Util.removeItem(this.markers, marker); 
    7474        if ((marker.icon != null) && (marker.icon.imageDiv != null) && 
    7575            (marker.icon.imageDiv.parentNode == this.div) ) { 
  • trunk/openlayers/lib/OpenLayers/Layer/Text.js

    r1588 r1590  
    156156            while(this.features.length > 0) { 
    157157                var feature = this.features[0]; 
    158                 this.features.remove(feature); 
     158                OpenLayers.Util.removeItem(this.features, feature); 
    159159                feature.destroy(); 
    160160            } 
  • trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js

    r1588 r1590  
    125125            //clear out the old tile  
    126126            if (this.tile) { 
    127                 this.tile.clear(); 
     127                OpenLayers.Util.clearArray(this.tile); 
    128128            } 
    129129 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r1588 r1590  
    328328        } 
    329329        layer.map = null; 
    330         this.layers.remove(layer); 
     330        OpenLayers.Util.removeItem(this.layers, layer); 
    331331 
    332332        // if we removed the base layer, need to set a new one 
     
    433433    */ 
    434434    removePopup: function(popup) { 
    435         this.popups.remove(popup); 
     435        OpenLayers.Util.removeItem(this.popups, popup); 
    436436        if (popup.div) { 
    437437            try { this.layerContainerDiv.removeChild(popup.div); } 
  • trunk/openlayers/lib/OpenLayers/Popup/AnchoredBubble.js

    r1588 r1590  
    176176        //we want to round all the corners _except_ the opposite one.  
    177177        var corner = OpenLayers.Bounds.oppositeQuadrant(this.relativePosition); 
    178         corners.remove(corner); 
     178        OpenLayers.Util.removeItem(corners, corner); 
    179179 
    180180        return corners.join(" "); 
  • trunk/openlayers/lib/OpenLayers/Tile.js

    r1588 r1590  
    8585        } 
    8686 
    87         this.clear(); 
     87        OpenLayers.Util.clearArray(this); 
    8888        this.bounds = bounds.clone(); 
    8989        this.position = position.clone(); 
  • trunk/openlayers/lib/OpenLayers/Tile/WFS.js

    r1588 r1590  
    6161    draw:function() { 
    6262        if (this.drawn) { 
    63             this.clear(); 
     63            OpenLayers.Util.clearArray(this); 
    6464        } 
    6565        OpenLayers.Tile.prototype.draw.apply(this, arguments); 
  • trunk/openlayers/lib/OpenLayers/Util.js

    r1588 r1590  
    3434    } 
    3535    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*/ 
     47OpenLayers.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*/ 
     59OpenLayers.Util.clearArray = function(array) { 
     60    array.length = 0; 
    3661}; 
    3762 
  • trunk/openlayers/tests/test_Util.html

    r1550 r1590  
    3131 
    3232    function test_03_Util_Array(t) { 
    33         t.plan( 5 ); 
     33        t.plan( 2 ); 
    3434 
    3535        var array = new Array(1,2,3,4,5); 
    3636 
    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");     
    4842         
    4943    }