[OpenLayers-Users] simultaneous parse and display of WFS data?
Stephen Woodbridge
woodbri at swoodbridge.com
Mon Mar 22 11:39:04 EDT 2010
Chris Green wrote:
> Hi all
>
>
>
> Apologies for re-posting but I am hoping someone can guide me on my
> problem over simultaneously parsing and displaying features obtained by
> WFS on a vector layer:
>
>
>
>
>
> I have defined a vector layer which successfully makes a WFS call and
> displays features captured by my filter, as below:
>
>
>
> var wfs = new OpenLayers.Layer.Vector("WFS", {
>
> styleMap: WFSstyle,
>
> strategies: [new OpenLayers.Strategy.Fixed()],
>
> protocol: new OpenLayers.Protocol.WFS.v1_1_0({
>
> url:
> "http://localhost/cgi-bin/mapserv.exe?map=c:/ms4w/apps/NewStart/htdocs/my.map",
>
> featureType: "cities",
>
> info_format: 'text',
>
> maxFeatures: 100,
>
> filter: myFilter,
>
> featureNS: "http://mapserver.gis.umn.edu/mapserver"
>
> })
>
> });
>
>
>
> Since I also want a list of the captured features in text form I can
> get this by adding to the above protocol definition:
>
>
>
> parseFeatures: function(request) {
>
> …code to present features as a list….
>
> }
>
>
>
> My problem is that when I add parseFeatures to the WFS protocol the
> vector layer no longer displays the features. It seems that I can either
> have the features displayed on the layer or parse them into a list, but
> not both.
>
>
>
> Does anyone know of a way of getting both things at the same time?
Chris,
I think you want to add an event listener to the layer for
"featuresadded" something like:
wfs.events.register('featuresadded', null, function(features) {
for(var i=0, len=features.length; i<len; i++) {
// do something with each features[i] feature
}
});
http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Layer/Vector-js.html
These will already be parsed into OL features so you do not need to
parse them just, if you juat want the attributes then:
features[i].attributes is a hash array of the attributes
http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Feature/Vector-js.html
-Steve
More information about the Users
mailing list