[OpenLayers-Users] simultaneous parse and display of WFS data?

Chris Green chris.green at ibstv.co.uk
Mon Mar 22 12:36:44 EDT 2010


Hi Steve


Great, that's the answer I was looking for!

Thanks


Chris

-----Original Message-----
From: Stephen Woodbridge [mailto:woodbri at swoodbridge.com] 
Sent: 22 March 2010 15:39
To: chris.green at ibstv.co.uk
Cc: users at openlayers.org
Subject: Re: [OpenLayers-Users] simultaneous parse and display of WFS data?

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.ma
p",
> 
>                 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/OpenLaye
rs/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/OpenLaye
rs/Feature/Vector-js.html


-Steve






More information about the Users mailing list