[OpenLayers-Users] How to know if a WFS layer has no features?
Tim Schaub
tschaub at openplans.org
Fri Nov 30 13:13:30 EST 2007
Guido_bs wrote:
> Hello, I'm not so good in using OL, so I have a question for you experts.
> In my application I build a WFS layer and this layer can have some WFS
> features (shown as markers) or not, it depends from a query to Mapserver:
>
> layer_wfs = new OpenLayers.Layer.WFS( "My Markers", MAPSERVER_URL,
> {map:MAPFILE_DIR+filtercode+".map", typename: "filter"},{ featureClass:
> OpenLayers.Feature.WFS});
>
> If there are not features for the layer, Mapserver gives me this answer:
>
> <?xml version='1.0' encoding="ISO-8859-1" ?>
>
> <wfs:FeatureCollection
>
> xmlns:MYSQL="http://ogc.dmsolutions.ca/gml/2.1.2/feature.xsd"
>
> xmlns:wfs="http://www.opengis.net/wfs"
>
> xmlns:gml="http://www.opengis.net/gml"
>
> xmlns:ogc="http://www.opengis.net/ogc"
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:schemaLocation="http://www.opengis.net/wfs
> http://schemas.opengeospatial.net/wfs/1.0.0/WFS-basic.xsd
>
> http://ogc.dmsolutions.ca/gml/2.1.2/feature.xsd
> http://foo.foo.org/cgi-bin/mapserv
>
> ?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=filter&OUTPUTFORMAT=XMLSCHEMA">
>
> <gml:boundedBy>
>
> <gml:null>missing</gml:null>
>
> </gml:boundedBy>
>
> </wfs:FeatureCollection>
>
> I'd like to know if after its creation, layer_wfs has no WFS features. Is
> there a function in OL to do it? I thought to read the "missing" string in
> Mapserver answer but I don't know how to do it and I don't understand where
> Mapserver answer is read by OL.
> My OL version is 2.5.
> Thanks a lot,
> Guido
If your layer has no features, then:
layer_wfs.features.length == 0;
Since your data is loaded asynchronously, you'd have to listen for the
"loadend" event on your layer:
layer_wfs.events.register("loadend", layer_wfs, function() {
if(this.features.length == 0) {
// do something about no features
}
});
or something like that.
Tim
More information about the Users
mailing list