[OpenLayers-Users] Making a change of style permanent

Christopher Schmidt crschmidt at metacarta.com
Sun Apr 15 08:35:42 EDT 2007


On Sun, Apr 15, 2007 at 11:21:28AM +0100, Nick Whitelegg wrote:
> On Friday 06 Apr 2007 04:37, you wrote:
> > On Thu, Apr 05, 2007 at 11:49:28PM +0100, Nick Whitelegg wrote:
> > > For example if you go to http://www.free-map.org.uk/vector/, choose the
> > > "select" button, click on a green line, choose the "change" button and
> > > type in "bridleway", it will change from green to brown, but then, when
> > > you select another line, it will go back to the original green.
> >
> > Your code says:
> >
> > vectorLayer.ways[selectedFeature].style=style;
> >
> > What you actually mean is:
> >
> > selectedFeature.style = style;
> 
> Bit of a late reply, but I've been working on other aspects of the editor the 
> past few days. Anyhow, that code I think was from an earlier version of 
> OpenLayers which used feature IDs, not features.
> 
> Anyhow I've corrected it, but the change of style is still not permanent. See
> 
> http://www.free-map.org.uk/vector_test/
> 
> and try changing the style of any feature. It will change temporarily, but 
> then when you select something else, it will go back to the old style. 

Ahhhh. Okay.

So the problem here is different than the one I was seeing before, where
the style would actually go away when the map zoomed. Now, it's when you
unselect it.

The problem is that when a feature is selected, the style attribute is
stashed away -- since the display has to change when the feature is
selected. If you change the style *while* the feature is selected, then
as soon as it's unselected, the old style is reset. 

What you want to change is *both* feature.style *and* feature.originalStyle:
The former will work while it's selected, and once it's unselected, the
latter will work.

I think this will help.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list