From a5f0b300f856c3b3aaa6a729c3f5789d9d2578b1 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 15 Jun 2011 20:55:08 +0000 Subject: [PATCH] Adding example demonstrating the use of a spatial filter with the WFS protocol. git-svn-id: http://svn.openlayers.org/trunk/openlayers@12087 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/wfs-spatial-filter.html | 37 ++++++++++++++++++++++++++++++++ examples/wfs-spatial-filter.js | 36 +++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 examples/wfs-spatial-filter.html create mode 100644 examples/wfs-spatial-filter.js 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; + } +});