[OpenLayers-Users] Changing style of feature parsed by GeoJSON

Christopher Schmidt crschmidt at metacarta.com
Mon May 4 09:28:51 EDT 2009


On Mon, May 04, 2009 at 01:00:59PM +0200, Stefan Lischke wrote:
> > On Mon, May 04, 2009 at 12:39:59PM +0200, Stefan Lischke wrote:
> > > > On Wed, Apr 29, 2009 at 05:16:50PM +0200, Stefan Lischke wrote:
> > > > > Hi,
> > > > > 
> > > > > I desperatly try to change the style of a 
> > > > > OpenLayers.Feature.Vector that i parsed with 
> > > > > OpenLayers.Format.GeoJSON. Since i
> > > > cannot not give
> > > > > the style in the Feature Constructor i'm searching for
> > > > another way to do it.
> > > > > Is it possible to include the style atrributes within 
> > the GeoJSON?
> > > > > 
> > > > > I tried to use the old style by set the style attribute and
> > > > redraw the
> > > > > feature [1,2] but it did not work. Any other Ideas?
> > > > 
> > > > http://docs.openlayers.org/library/feature_styling.html#stylemap
> > > 
> > > Unfortunatly your link did not help me. To create a 
> > style-Map and gove 
> > > it to the constructor of the vector is one solution that i 
> > cannot use 
> > > because i do not call the constructor, the GeoJSON Parser 
> > creates the objects.
> > 
> > The StyleMap is added to the constructor of the *layer*, not 
> > the features. It is specifcally designed to work when formats 
> > are being used to parse the data.
> 
> OK, so did i understand you right, i'm not able to display multiple features
> (polygons) parsed by GeoJSON on one Layer? 

Sure you can.

> So i have to create one layer per
> style/color of a polygon?

No, you use rules to filter based on properties of the feature.

See, for example, http://crschmidt.net/mapping/choropleth.html

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list