[OpenLayers-Users] Capture empty result from wfs protocol
Eric Lemoine
eric.lemoine at camptocamp.com
Fri Jun 11 15:25:03 EDT 2010
On Thu, Jun 10, 2010 at 11:26 PM, Zer <zer_matt at hotmail.com> wrote:
>
> Hi users,
>
> I have a vector layer that shows features fetched from Geoserver using fixed
> strategy and wfs protocol together with a filter. Works just fine!
>
> I then use wfsParcelLayer.events.on and a function on the featuresadded
> event to zoom in to the feature. That works fine too.
>
> However, sometimes the filter returns no hits, witch is ok. I would then
> like to show a message to inform the user that there where no hits. I tried
> to do that using the same event I use when zooming in to the feature, but
> since no features are added, the event never fires. I also tried the
> 'beforefeaturesadded' event, but the result is (of course) the same.
>
> How can I capture the result to check there are any features or not in the
> result? Is there a callback function that I can use in the wfs protocol?
>
> I've added some of my code here.
>
> Thanks,
>
> -ZM
>
>
> wfsLayer = new OpenLayers.Layer.Vector("Vector"), {
> strategies: [new OpenLayers.Strategy.Fixed({
> preload: false
> })],
> styleMap: vectorStyleMap,
> protocol: new OpenLayers.Protocol.WFS({
> version: "1.1.0",
> extractAttributes: true,
> filter: filter,
> ....
>
> wfsLayer.events.on({
> featuresadded: function(event) {
> map.zoomToExtent(wfsLayer.getDataExtent
> }
> });
Hi. How about
wfsLayer.events.on({
featuresadded: function(event) {
map.zoomToExtent(this.getDataExtent());
},
loadend: function() {
if(this.features.length === 0) {
alert("no features loaded");
}
}
});
?
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
More information about the Users
mailing list