[GIS] How to select WFS features by polygon in OpenLayers

openlayers-2polygon

I need to be able to select features on a wfs layer using a polygon instead of a box. I was hoping this would be a standard option in the SelectFeature class. Too bad this isn't the case.

Any implementation suggestions?

Best Answer

You can use the layer.filter property on the vector layer then refresh the layer.

layer.filter = new OpenLayers.Filter.Spatial({
    type: OpenLayers.Filter.Spatial.INTERSECTS,
    value: event.feature.geometry
});
layer.refresh({force: true});

Here's the Example

Granted this will make all the non-selected layers disappear, but you can possibly do this just to collect the array of features (without refreshing the layer) then use the SelectFeature class to select only the ones the filter returned.