Hi all,<br><br>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. <br><br> mVectorLayer = new OpenLayers.Layer.Vector("Overlay", {<br>
strategies: [new OpenLayers.Strategy.BBOX()],<br> protocol: new OpenLayers.Protocol.HTTP({<br> url: '<a href="http://localhost:56786/jlist.geojson">http://localhost:56786/jlist.geojson</a>',<br>
format: new OpenLayers.Format.GeoJSON({<br> 'read': myReadFunction,<br> 'internalProjection': map.baseLayer.projection,<br> 'externalProjection': new OpenLayers.Projection("EPSG:4326")<br>
})<br> }),<br> projection: new OpenLayers.Projection("EPSG:900913")<br> });<br><br>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.<br>
<br>{ "type": "FeatureCollection",<br> "features": [<br> { "type": "Feature",<br> "geometry": {"type": "Point", "coordinates": [29.0, 41.060]},<br>
"properties": {"name": "IST J1", "img": "img/marker.png"}<br> },<br> { "type": "Feature",<br> "geometry": {"type": "Point", "coordinates": [29.0, 41.100]},<br>
"properties": {"name": "IST J2", "img": "img/marker.png"}<br> },<br> { "type": "Feature",<br> "geometry": {"type": "Point", "coordinates": [59.0, 41.100]},<br>
"properties": {"name": "IST J3", "img": "img/marker.png"}<br> }<br> ]<br>}<br><br>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?<br>
<br> function myReadFunction(json, type, filter) {<br> alert("json: " + json);<br> <br> type = (type) ? type : "FeatureCollection";<br> var results = null;<br>
var obj = null;<br> if (typeof json == "string") {<br> obj = OpenLayers.Format.JSON.prototype.read.apply(this,<br> [json, filter]);<br>
} else {<br> obj = json;<br> }<br> if (!obj) {<br> OpenLayers.Console.error("Bad JSON: " + json);<br> } else if (typeof (obj.type) != "string") {<br>
OpenLayers.Console.error("Bad GeoJSON - no type: " + json);<br> } else if (this.isValidType(obj, type)) {<br> switch (type) {<br> case "Geometry":<br>
try {<br> results = this.parseGeometry(obj);<br> } catch (err) {<br> OpenLayers.Console.error(err);<br> }<br>
break;<br> case "Feature":<br> try {<br> results = this.parseFeature(obj);<br> results.type = "Feature";<br>
} catch (err) {<br> OpenLayers.Console.error(err);<br> }<br> break;<br> case "FeatureCollection":<br>
// for type FeatureCollection, we allow input to be any type<br> results = [];<br> switch (obj.type) {<br> case "Feature":<br>
try {<br> results.push(this.parseFeature(obj));<br> } catch (err) {<br> results = null;<br>
OpenLayers.Console.error(err);<br> }<br> break;<br> case "FeatureCollection":<br> for (var i = 0, len = obj.features.length; i < len; ++i) {<br>
try {<br> results.push(this.parseFeature(obj.features[i]));<br> } catch (err) {<br> results = null;<br>
OpenLayers.Console.error(err);<br> }<br> }<br> break;<br> default:<br>
try {<br> var geom = this.parseGeometry(obj);<br> results.push(new OpenLayers.Feature.Vector(geom));<br> } catch (err) {<br>
results = null;<br> OpenLayers.Console.error(err);<br> }<br> }<br> break;<br>
}<br> }<br> return results;<br>}<br><br>Thanks a lot for your helps and explanations,<br>Yasemin<br>