Ticket #1830: resFactor.patch
| File resFactor.patch, 3.6 KB (added by tschaub, 22 months ago) |
|---|
-
tests/Strategy/BBOX.html
58 58 map: { 59 59 getExtent: function() { 60 60 return bounds; 61 }, 62 getResolution: function() { 63 return 1; 61 64 } 62 65 } 63 66 }); … … 157 160 // 2 tests 158 161 s.merge({features: features}); 159 162 } 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 } 160 180 161 181 </script> 162 182 </head> -
lib/OpenLayers/Strategy/BBOX.js
24 24 bounds: null, 25 25 26 26 /** 27 * Property: resolution 28 * {Float} The current data resolution. 29 */ 30 resolution: null, 31 32 /** 27 33 * Property: ratio 28 34 * {Float} The ratio of the data bounds to the viewport bounds (in each 29 35 * dimension). 30 36 */ 31 37 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, 32 53 33 54 /** 34 55 * Property: response … … 106 127 var mapBounds = this.layer.map.getExtent(); 107 128 if ((options && options.force) || this.invalidBounds(mapBounds)) { 108 129 this.calculateBounds(mapBounds); 130 this.resolution = this.layer.map.getResolution(); 109 131 this.triggerRead(); 110 132 } 111 133 }, 112 134 113 135 /** 114 136 * 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. 115 141 * 116 142 * Parameters: 117 143 * mapBounds - {<OpenLayers.Bounds>} the current map extent, will be … … 124 150 if(!mapBounds) { 125 151 mapBounds = this.layer.map.getExtent(); 126 152 } 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; 128 159 }, 129 160 130 161 /**
