Strategies that request data (fixed and bbox currently) should transform geometries when the layer projection is different than the map projection. This adds reprojection support to the Fixed and BBOX strategies. Given more strategies that request data, we will likely want to extract out the common parts. r=elemoine (closes #1841)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8804 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -19,7 +19,8 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
|
||||
/**
|
||||
* Property: bounds
|
||||
* {<OpenLayers.Bounds>} The current data bounds.
|
||||
* {<OpenLayers.Bounds>} The current data bounds (in the same projection
|
||||
* as the layer - not always the same projection as the map).
|
||||
*/
|
||||
bounds: null,
|
||||
|
||||
@@ -103,12 +104,29 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
* must be incondtionally read.
|
||||
*/
|
||||
update: function(options) {
|
||||
var mapBounds = this.layer.map.getExtent();
|
||||
var mapBounds = this.getMapBounds();
|
||||
if ((options && options.force) || this.invalidBounds(mapBounds)) {
|
||||
this.calculateBounds(mapBounds);
|
||||
this.triggerRead();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getMapBounds
|
||||
* Get the map bounds expressed in the same projection as this layer.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Bounds>} Map bounds in the projection of the layer.
|
||||
*/
|
||||
getMapBounds: function() {
|
||||
var bounds = this.layer.map.getExtent();
|
||||
if(!this.layer.projection.equals(this.layer.map.getProjectionObject())) {
|
||||
bounds = bounds.clone().transform(
|
||||
this.layer.map.getProjectionObject(), this.layer.projection
|
||||
);
|
||||
}
|
||||
return bounds;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: invalidBounds
|
||||
@@ -122,7 +140,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
*/
|
||||
invalidBounds: function(mapBounds) {
|
||||
if(!mapBounds) {
|
||||
mapBounds = this.layer.map.getExtent();
|
||||
mapBounds = this.getMapBounds();
|
||||
}
|
||||
return !this.bounds || !this.bounds.containsBounds(mapBounds);
|
||||
},
|
||||
@@ -136,7 +154,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
*/
|
||||
calculateBounds: function(mapBounds) {
|
||||
if(!mapBounds) {
|
||||
mapBounds = this.layer.map.getExtent();
|
||||
mapBounds = this.getMapBounds();
|
||||
}
|
||||
var center = mapBounds.getCenterLonLat();
|
||||
var dataWidth = mapBounds.getWidth() * this.ratio;
|
||||
@@ -189,6 +207,8 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
/**
|
||||
* Method: merge
|
||||
* Given a list of features, determine which ones to add to the layer.
|
||||
* If the layer projection differs from the map projection, features
|
||||
* will be transformed from the layer projection to the map projection.
|
||||
*
|
||||
* Parameters:
|
||||
* resp - {<OpenLayers.Protocol.Response>} The response object passed
|
||||
@@ -198,6 +218,17 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
this.layer.destroyFeatures();
|
||||
var features = resp.features;
|
||||
if(features && features.length > 0) {
|
||||
var remote = this.layer.projection;
|
||||
var local = this.layer.map.getProjectionObject();
|
||||
if(!local.equals(remote)) {
|
||||
var geom;
|
||||
for(var i=0, len=features.length; i<len; ++i) {
|
||||
geom = features[i].geometry;
|
||||
if(geom) {
|
||||
geom.transform(remote, local);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.layer.addFeatures(features);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -88,6 +88,17 @@ OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
merge: function(resp) {
|
||||
var features = resp.features;
|
||||
if (features && features.length > 0) {
|
||||
var remote = this.layer.projection;
|
||||
var local = this.layer.map.getProjectionObject();
|
||||
if(!local.equals(remote)) {
|
||||
var geom;
|
||||
for(var i=0, len=features.length; i<len; ++i) {
|
||||
geom = features[i].geometry;
|
||||
if(geom) {
|
||||
geom.transform(remote, local);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.layer.addFeatures(features);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user