Optionally include SRS id in serialized BBOX by constructing a HTTP protocol with srsInBBOX true. r=elemoine (closes #3006).
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11015 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -79,6 +79,15 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
*/
|
*/
|
||||||
wildcarded: false,
|
wildcarded: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: srsInBBOX
|
||||||
|
* {Boolean} Include the SRS identifier in BBOX query string parameter.
|
||||||
|
* Default is false. If true and the layer has a projection object set,
|
||||||
|
* any BBOX filter will be serialized with a fifth item identifying the
|
||||||
|
* projection. E.g. bbox=-1000,-1000,1000,1000,EPSG:900913
|
||||||
|
*/
|
||||||
|
srsInBBOX: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Protocol.HTTP
|
* Constructor: OpenLayers.Protocol.HTTP
|
||||||
* A class for giving layers generic HTTP protocol.
|
* A class for giving layers generic HTTP protocol.
|
||||||
@@ -200,6 +209,9 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
switch(filter.type) {
|
switch(filter.type) {
|
||||||
case OpenLayers.Filter.Spatial.BBOX:
|
case OpenLayers.Filter.Spatial.BBOX:
|
||||||
params.bbox = filter.value.toArray();
|
params.bbox = filter.value.toArray();
|
||||||
|
if (this.srsInBBOX && filter.projection) {
|
||||||
|
params.bbox.push(filter.projection.getCode());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OpenLayers.Filter.Spatial.DWITHIN:
|
case OpenLayers.Filter.Spatial.DWITHIN:
|
||||||
params.tolerance = filter.distance;
|
params.tolerance = filter.distance;
|
||||||
|
|||||||
+24
-10
@@ -199,11 +199,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_read_bbox(t) {
|
function test_read_bbox(t) {
|
||||||
t.plan(1);
|
t.plan(6);
|
||||||
var protocol = new OpenLayers.Protocol.HTTP();
|
|
||||||
|
|
||||||
// fake XHR request object
|
|
||||||
var request = {'status': 200};
|
|
||||||
|
|
||||||
var _get = OpenLayers.Request.GET;
|
var _get = OpenLayers.Request.GET;
|
||||||
|
|
||||||
@@ -211,16 +207,34 @@
|
|||||||
var filter = new OpenLayers.Filter.Spatial({
|
var filter = new OpenLayers.Filter.Spatial({
|
||||||
type: OpenLayers.Filter.Spatial.BBOX,
|
type: OpenLayers.Filter.Spatial.BBOX,
|
||||||
value: bounds,
|
value: bounds,
|
||||||
projection: "foo"
|
projection: new OpenLayers.Projection("foo")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// log requests
|
||||||
|
var log, exp;
|
||||||
OpenLayers.Request.GET = function(options) {
|
OpenLayers.Request.GET = function(options) {
|
||||||
t.eq(options.params['bbox'].toString(), bounds.toArray().toString(),
|
log.push(options.params.bbox);
|
||||||
'GET called with bbox filter in params');
|
return {status: 200};
|
||||||
return request;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var resp = protocol.read({filter: filter});
|
// 1) issue request with default protocol
|
||||||
|
log = [];
|
||||||
|
new OpenLayers.Protocol.HTTP().read({filter: filter});
|
||||||
|
|
||||||
|
t.eq(log.length, 1, "1) GET called once");
|
||||||
|
t.ok(log[0] instanceof Array, "1) bbox param is array");
|
||||||
|
exp = bounds.toArray();
|
||||||
|
t.eq(log[0], exp, "1) bbox param doesn't include SRS id by default");
|
||||||
|
|
||||||
|
// 2) issue request with default protocol
|
||||||
|
log = [];
|
||||||
|
new OpenLayers.Protocol.HTTP({srsInBBOX: true}).read({filter: filter});
|
||||||
|
|
||||||
|
t.eq(log.length, 1, "2) GET called once");
|
||||||
|
t.ok(log[0] instanceof Array, "2) bbox param is array");
|
||||||
|
exp = bounds.toArray();
|
||||||
|
exp.push("foo");
|
||||||
|
t.eq(log[0], exp, "2) bbox param includes SRS id if srsInBBOX is true");
|
||||||
|
|
||||||
OpenLayers.Request.GET = _get;
|
OpenLayers.Request.GET = _get;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user