In my OpenLayers map I allow users to draw an ad-hoc polygon vector. Then I need to get all the features from a WFS vector layer that fall within the ad-hoc polygon.
Here is the code I have that allows the user to draw the ad-hoc polygon in the map. This code works fine:
function buildIt() {
//CREATE THE NEW VECTOR
var polygonLayer = new OpenLayers.Layer.Vector("Poly Layer");
//ADD IT TO THE MAP
map.addLayer(polygonLayer);
//CREATE A DRAWFEATURE CONTROL
var polyedit = new OpenLayers.Control.DrawFeature(
polygonLayer,//POINT IT AT THE USER DEFINED POLYGON LAYER
OpenLayers.Handler.Polygon
);
// 'point' is one of the named callbacks specified by OpenLayers.Handler.Polygon
// and is called every time a point is added to the feature being drawn
polyedit.handler.callbacks.point = function (pt) {
console.log(pt)
}
map.addControl(polyedit);//ADD THE DRAWFEATURE CONTROL TO THE MAP
polyedit.activate();//ACTIVATE THE DRAWFEATURE CONTROL
}
After this I am clueless. How can I get all the features that fall within the user defined polygon? Specifically, I need to get the attributes from each WFS feature (sometimes points, sometimes polygons) that fall within the user drawn ad-hoc polygon.
Any suggestions would be appreciated! Thanks.
Best Answer
After some research I was able to find a solution. This function allows a user to draw an ad-hoc polygon and then interates through another WFS layer to locate any polygons that intersect the ad-hoc polygon. In my case I used this with WFS layers served from my GeoServer.