I'm not convinced you have anything that would cause the
beforefeatureadded to be triggered? I would have to say that while I
dont know your application strategy, it seems counterintuitive to me.
Maybe my way of doing lacks elegance, but here is my strategy for doing
what I think you want to do:
1/ Create a general purpose vector layer.
selectedLayer = new OpenLayers.Layer.Vector("Selected Layer", {
wrapDateLine: true,
displayOutsideMaxExtent: true,
displayInLayerSwitcher: false,
attribution: "<a href='http://www.gns.cri.nz'
target='metadata'><img src='images/GNS_logo_mini.png'></a>"
});
map.addLayer(selectedLayer);
2/ Add in my other layers.
3/ create wfsprotocols for WFS query layers
lay.wfsProtocol = new OpenLayers.Protocol.WFS.v1_1_0({
url: spatialQueryNode.url,
featurePrefix: spatialQueryNode.featurePrefix,
featureType: spatialQueryNode.featureType,
srsName: "EPSG:900913"
});
4/ Now set up query strategies. To query by polygon, I do
polySelCtrl = new
OpenLayers.Control.DrawFeature(selectedLayer, OpenLayers.Handler.Polygon, {
geodesic: true,
handlerOptions: {
citeCompliant: false
}
});
(the citecompliant stuff is about crossing 180 line). It draws onto the
general purpose vector layer.
Actually do the query with this.
polySelCtrl.events.register("featureadded", this, function
(e) {
clearData(); // clean up popups etc, clear the
selectLayer of features
wrapDateline(e.feature.geometry,map.baseLayer.maxExtent); // deals with
dateline issues
var pfilter = new OpenLayers.Filter.Spatial({
type: OpenLayers.Filter.Spatial.INTERSECTS,
value: e.feature.geometry
});
map.div.style.cursor = 'wait';
loadingPanel.maximizeControl();
wfsProtocol.read({
filter: pfilter,
propertyNames:propNames,
callback: processSpatialQuery,
scope: strategy
});
});
processSpatialQuery deals with the returned values.
I do something very similar for mouse-click event creating a BBOX or
DWithin filter
( ptSelCtrl = new
OpenLayers.Control.DrawFeature(selectedLayer, OpenLayers.Handler.Point,{
handlerOptions: {
citeCompliant: true
}
});
) but you can use getFeature or similar instead.
If you want query based on filter of feature values, then you create the
filter (eg
var filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.LIKE,
matchCase:false,
property: fld.name,
value: "*" + searchText + "*"
});
)
and action it with:
wfsProtocol.read({
filter: new OpenLayers.Filter.Logical({
type: OpenLayers.Filter.Logical.OR,
filters: filter
}),
callback: processSpatialQuery,
scope: strategy
});
(Same callback!)
processSpatialQuery can be rather complex, but in skeleton:
selectedLayer.destroyFeatures();
map.div.style.cursor = 'default';
loadingPanel.minimizeControl();
....
and
selectedLayer.addFeatures(request.features)
In summary have a general purpose selectedLayer for drawing and
highlighting; centralised request handlers (processSpatialQuery) used
for point, polygon and text queries, and used the wfsprotocol handler
throughout.
Not shown, but I actually add the wfsprotocol and point/poly controls to
the layer object.
I hope that might help.
Notice: This email and any attachments are confidential.
If received in error please destroy and immediately notify us.
Do not copy or disclose the contents.
_______________________________________________
Users mailing list
us...@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users