[OpenLayers-Users] Get WFS features geometry data

Christopher Schmidt crschmidt at metacarta.com
Thu May 24 07:42:11 EDT 2007


On Thu, May 24, 2007 at 12:58:44PM +0200, bkausbk at web.de wrote:
> var map = new OpenLayers.Map("map");
> 
> var baselayer = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://someurl/map", {layers: "mapname"});
> var wfslayer =  new OpenLayers.Layer.WFS(
>     "Some Name",
>     "http://someurl/wfs",
>     {},
>     {featureClass: OpenLayers.Feature.WFS}
> );
> 
> map.addLayers([baselayer, wfslayer]);
> 
> So but how do I get access to the features of WFS?

Don't use a 'featureClass' -- this makes it a markers layer, rather than
a vectors layer, and a markerslayer doesn't provide you access to the
geographic data in the fashion you want. 

> I found an example somewhere showing to access it by "map.layers[1].features" ... but corresponding the current source code there is NO "features" variable within OpenLayers.Layer class as it should be.

The 'featureClass' changes the behavior -- remove it and you will have a
features property.

> Another problem is, I only want features of the current view, is this possible?

That's how WFS works, though it uses a buffer around the current view -
that buffer can be dropped to 1.0 via a 'ratio: 1.0' option to the
layer.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list