[OpenLayers-Users] How to validate whether the BBOX strategy works successfully?
Yasemin YILMAZ
yasemin.yilmaz.embedded at gmail.com
Thu Aug 23 04:27:33 PDT 2012
Hi all,
I want to send requests to our feature server that asks only data within
the viewable map extent. So I've used BBOX strategy and HTTP Protocol as
following code.
mVectorLayer = new OpenLayers.Layer.Vector("Overlay", {
strategies: [new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.HTTP({
url: 'http://localhost:56786/jlist.geojson',
format: new OpenLayers.Format.GeoJSON({
'read': myReadFunction,
'internalProjection': map.baseLayer.projection,
'externalProjection': new
OpenLayers.Projection("EPSG:4326")
})
}),
projection: new OpenLayers.Projection("EPSG:900913")
});
I want to validate that our feature server receives the requests for only
data within the viewable map. So I've added a feature outside the viewable
map to the geojson file shown at below.
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [29.0, 41.060]},
"properties": {"name": "IST J1", "img": "img/marker.png"}
},
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [29.0, 41.100]},
"properties": {"name": "IST J2", "img": "img/marker.png"}
},
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [59.0, 41.100]},
"properties": {"name": "IST J3", "img": "img/marker.png"}
}
]
}
To validate, I've added an alert to the function myReadFunction which shows
the json string. But the alert shows all features in geojson file. I
suppose our feature server sends all geojson content instead of viewable
features? Do I comment it as right? How can I validate or observe whether
the BBOX strategy works successfully?
function myReadFunction(json, type, filter) {
alert("json: " + json);
type = (type) ? type : "FeatureCollection";
var results = null;
var obj = null;
if (typeof json == "string") {
obj = OpenLayers.Format.JSON.prototype.read.apply(this,
[json,
filter]);
} else {
obj = json;
}
if (!obj) {
OpenLayers.Console.error("Bad JSON: " + json);
} else if (typeof (obj.type) != "string") {
OpenLayers.Console.error("Bad GeoJSON - no type: " + json);
} else if (this.isValidType(obj, type)) {
switch (type) {
case "Geometry":
try {
results = this.parseGeometry(obj);
} catch (err) {
OpenLayers.Console.error(err);
}
break;
case "Feature":
try {
results = this.parseFeature(obj);
results.type = "Feature";
} catch (err) {
OpenLayers.Console.error(err);
}
break;
case "FeatureCollection":
// for type FeatureCollection, we allow input to be
any type
results = [];
switch (obj.type) {
case "Feature":
try {
results.push(this.parseFeature(obj));
} catch (err) {
results = null;
OpenLayers.Console.error(err);
}
break;
case "FeatureCollection":
for (var i = 0, len = obj.features.length;
i < len; ++i) {
try {
results.push(this.parseFeature(obj.features[i]));
} catch (err) {
results = null;
OpenLayers.Console.error(err);
}
}
break;
default:
try {
var geom = this.parseGeometry(obj);
results.push(new
OpenLayers.Feature.Vector(geom));
} catch (err) {
results = null;
OpenLayers.Console.error(err);
}
}
break;
}
}
return results;
}
Thanks a lot for your helps and explanations,
Yasemin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120823/60840b17/attachment.html>
More information about the Users
mailing list