Ticket #1830: resFactor.patch

File resFactor.patch, 3.6 KB (added by tschaub, 22 months ago)

add a resFactor option to make strategy more agressive

  • tests/Strategy/BBOX.html

     
    5858            map: { 
    5959                getExtent: function() { 
    6060                    return bounds; 
     61                }, 
     62                getResolution: function() { 
     63                    return 1; 
    6164                } 
    6265            } 
    6366        }); 
     
    157160        // 2 tests 
    158161        s.merge({features: features}); 
    159162    } 
     163     
     164    function test_resFactor(t) { 
     165        t.plan(0); 
     166         
     167        var map = new OpenLayers.Map("map"); 
     168        var bbox = new OpenLayers.Strategy.BBOX(); 
     169        var layer = new OpenLayers.Layer.Vector("test", { 
     170            strategies: [bbox], 
     171            isBaseLayer: true 
     172        }); 
     173        map.addLayer(layer); 
     174        map.setCenter(new OpenLayers.LonLat(0, 0), 0); 
     175         
     176        // This test needs to be finished.  Stopping here because it looks 
     177        // like this reveals a bug with the "moveend" event. 
     178         
     179    } 
    160180 
    161181  </script> 
    162182</head> 
  • lib/OpenLayers/Strategy/BBOX.js

     
    2424    bounds: null, 
    2525     
    2626    /** 
     27     * Property: resolution 
     28     * {Float} The current data resolution. 
     29     */ 
     30    resolution: null, 
     31     
     32    /** 
    2733     * Property: ratio 
    2834     * {Float} The ratio of the data bounds to the viewport bounds (in each 
    2935     *     dimension). 
    3036     */ 
    3137    ratio: 2, 
     38     
     39    /** 
     40     * Property: resFactor 
     41     * {Float} Optional factor used to determine when previously requested 
     42     *     features are invalid.  If set, the resFactor will be compared to 
     43     *     the resolution of the previous request to the current map resolution. 
     44     *     If resFactor > (old / new) and 1/resFactor < (old / new).  If you 
     45     *     set a resFactor of 1, data will be requested every time the 
     46     *     resolution changes.  If you set a resFactor of 3, data will be 
     47     *     requested if the old resolution is 3 times the new, or if the new 
     48     *     is 3 times the old.  If the old bounds do not contain the new bounds 
     49     *     new data will always be requested (with or without considering 
     50     *     resFactor). 
     51     */ 
     52    resFactor: null, 
    3253 
    3354    /** 
    3455     * Property: response 
     
    106127        var mapBounds = this.layer.map.getExtent(); 
    107128        if ((options && options.force) || this.invalidBounds(mapBounds)) { 
    108129            this.calculateBounds(mapBounds); 
     130            this.resolution = this.layer.map.getResolution(); 
    109131            this.triggerRead(); 
    110132        } 
    111133    }, 
    112134 
    113135    /** 
    114136     * Method: invalidBounds 
     137     * Determine whether the previously requested set of features is invalid. 
     138     *     This occurs when the new map bounds do not contain the previously 
     139     *     requested bounds.  In addition, if <resFactor> is set, it will be 
     140     *     considered. 
    115141     * 
    116142     * Parameters: 
    117143     * mapBounds - {<OpenLayers.Bounds>} the current map extent, will be 
     
    124150        if(!mapBounds) { 
    125151            mapBounds = this.layer.map.getExtent(); 
    126152        } 
    127         return !this.bounds || !this.bounds.containsBounds(mapBounds); 
     153        var invalid = !this.bounds || !this.bounds.containsBounds(mapBounds); 
     154        if(!invalid && this.resFactor) { 
     155            var ratio = this.resolution / this.layer.map.getResolution(); 
     156            invalid = (ratio >= this.resFactor || ratio <= (1 / this.resFactor)); 
     157        } 
     158        return invalid; 
    128159    }, 
    129160  
    130161    /**