diff --git a/examples/wfs-spatial-filter.html b/examples/wfs-spatial-filter.html new file mode 100644 index 0000000000..d6acead436 --- /dev/null +++ b/examples/wfs-spatial-filter.html @@ -0,0 +1,37 @@ + + + + + + + OpenLayers WFS Protocol with Filter + + + + + +

WFS Protocol and Filter

+
+ filter, wfs, spatial +
+

+ Demonstrates the use of a spatial filter in making GetFeature requests using the WFS protocol. +

+
+
+

+ If a vector layer has a filter and the protocol supports server-side filtering, + the filter will be serialized in requests for features. The WFS protocol can be + used with a vector layer to serialize a filter using OGC Filter Encoding. +

+ This example has a draw control that is always active. When you draw a polygon + on the map, the filter for the main vector layer will be updated, and features + that intersect your drawn polygon will be requested. +

+ See the source + for details on how this is done. +

+
+ + + diff --git a/examples/wfs-spatial-filter.js b/examples/wfs-spatial-filter.js new file mode 100644 index 0000000000..d39b0bea85 --- /dev/null +++ b/examples/wfs-spatial-filter.js @@ -0,0 +1,36 @@ +OpenLayers.ProxyHost= "/proxy?url="; +var map = new OpenLayers.Map('map'); +var wms = new OpenLayers.Layer.WMS( + "OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0", + {layers: "basic"} +); + +var layer = new OpenLayers.Layer.Vector("WFS", { + strategies: [new OpenLayers.Strategy.BBOX()], + protocol: new OpenLayers.Protocol.WFS({ + url: "http://demo.opengeo.org/geoserver/wfs", + featureType: "tasmania_roads", + featureNS: "http://www.openplans.org/topp" + }) +}); + +map.addLayers([wms, layer]); +map.setCenter(new OpenLayers.LonLat(146.7, -41.8), 6); + +var drawings = new OpenLayers.Layer.Vector(); +map.addLayer(drawings); +var draw = new OpenLayers.Control.DrawFeature(drawings, OpenLayers.Handler.Polygon); +map.addControl(draw); +draw.activate(); + +drawings.events.on({ + beforefeatureadded: function(event) { + var geometry = event.feature.geometry; + layer.filter = new OpenLayers.Filter.Spatial({ + type: OpenLayers.Filter.Spatial.INTERSECTS, + value: event.feature.geometry + }); + layer.refresh({force: true}); + return false; + } +});