OpenLayers OpenLayers

Ticket #750: getDataExtent.patch

File getDataExtent.patch, 3.0 kB (added by euzuro, 1 year ago)

renamed and added empty stub to Layer.js so others can follow suit

  • tests/Layer/test_Markers.html

    old new  
    4949        layer.destroy(); 
    5050        t.eq( layer.map, null, "layer.map is null after destroy" ); 
    5151    } 
     52 
     53    function test_03_Layer_Markers_getDataExtent(t) { 
     54        t.plan( 4 ); 
     55 
     56        var layer = {}; 
     57        var ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []); 
     58        t.eq(ret, null, "does not crash, returns null on layer with null 'this.markers'"); 
     59 
     60        layer.markers = []; 
     61        ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []); 
     62        t.eq(ret, null, "returns null on layer with empty 'this.markers'"); 
     63         
     64        layer.markers.push({ 
     65            'lonlat': new OpenLayers.LonLat(4,5) 
     66        }); 
     67        var expectedBounds = new OpenLayers.Bounds(4,5,4,5); 
     68        ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []); 
     69        t.ok(ret.equals(expectedBounds), "returns expected bounds with only one marker"); 
     70 
     71        layer.markers.push({ 
     72            'lonlat': new OpenLayers.LonLat(1,2) 
     73        }); 
     74        var expectedBounds = new OpenLayers.Bounds(1,2,4,5); 
     75        ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []); 
     76        t.ok(ret.equals(expectedBounds), "returns expected bounds with multiple markers"); 
     77 
     78    } 
     79 
    5280  // --> 
    5381  </script> 
    5482</head> 
  • lib/OpenLayers/Layer.js

    old new  
    723723        return this.getZoomForResolution(idealResolution); 
    724724    }, 
    725725     
     726    /**  
     727     * Method: getDataExtent 
     728     * Calculates the max extent which includes all of the data for the layer. 
     729     *     This function is to be implemented by subclasses. 
     730     *  
     731     * Returns: 
     732     * {<OpenLayers.Bounds>} 
     733     */ 
     734    getDataExtent: function () { 
     735        //to be implemented by subclasses 
     736    }, 
     737 
    726738    /** 
    727739     * APIMethod: getZoomForResolution 
    728740     *  
  • lib/OpenLayers/Layer/Markers.js

    old new  
    139139            } 
    140140        } 
    141141    }, 
     142     
     143    /**  
     144     * Method: getDataExtent 
     145     * Calculates the max extent which includes all of the markers. 
     146     *  
     147     * Returns: 
     148     * {<OpenLayers.Bounds>} 
     149     */ 
     150    getDataExtent: function () { 
     151        var maxExtent = null; 
     152         
     153        if ( this.markers && (this.markers.length > 0)) { 
     154            var maxExtent = new OpenLayers.Bounds(); 
     155            for(var i=0; i < this.markers.length; i++) { 
     156                var marker = this.markers[i]; 
     157                maxExtent.extend(marker.lonlat); 
     158            } 
     159        } 
    142160 
     161        return maxExtent; 
     162    }, 
     163 
    143164    CLASS_NAME: "OpenLayers.Layer.Markers" 
    144165});