[OpenLayers-Users] Toggling vector layers?

Jeff Dege jdege at korterra.com
Mon Aug 13 14:25:17 EDT 2007


OK, it's me, again.

As is often the case, I figured out what I was doing wrong on my own.

First, don't mess with the Layer.visibility flag, call the
Layer.setVisibility() method.

Second, if you want to hide the layer from the layer switcher, set the
Layer.displayInLayerSwitcher flag before you call Layer.setVisibility().
Layer.setVisibility() will throw a changelayer event, which will cause
the layer switcher to update it's layer list. 
 

> -----Original Message-----
> From: users-bounces at openlayers.org 
> [mailto:users-bounces at openlayers.org] On Behalf Of Jeff Dege
> Sent: Monday, August 13, 2007 12:18 PM
> To: users at openlayers.org
> Subject: [OpenLayers-Users] Toggling vector layers?
> 
> I've a problem where I need to be able to toggle a vector layer on and
> off.
> 
> I'd originally thought about adding and removing a vector 
> layer, but the
> panel edit controls need to have the layer existing when they are
> constructed, and there's no method for removing controls from a panel,
> so I thought I'd try just hiding the vector layer, using 
> 
> First issue was that I didn't want the vector layer to display in the
> layer switcher when it was hidden, I needed to set
> layer.displayInLayerSwitcher = false.  But if I later made the layer
> visible and set layer.displayInLayerSwitcher = true, the layer would
> still not display in the layer switcher.  Tracing through the code
> resulted in my adding calling a changelayer event after setting
> layer.displayInLayerSwitcher = true, after which the layer switcher
> displayed the layer.
> 
> But drawing didn't work.  If I clicked on the polygon control, I could
> draw a polygon, but when I double-clicked on the last point 
> to close it
> out, the scratch polygon would disappear, and the vector 
> layer would be
> blank.
> 
> The problem seems to be that Vector.drawn is false - it's only set to
> true when moveTo() has been called, and because its visibility was
> false, moveTo() has never been called on it.
> 
> Which leads me to conclude that there's more to toggling a 
> layer on and
> off than just changing its visibility flag.
> 
> How should I be approaching this?
> 
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 



More information about the Users mailing list