[OpenLayers-Users] set layer state

Richard Greenwood richard.greenwood at gmail.com
Sun Dec 2 22:36:38 EST 2007


On Dec 2, 2007 7:13 PM, Christopher Schmidt <crschmidt at metacarta.com> wrote:
> On Sun, Dec 02, 2007 at 06:54:00PM -0700, Richard Greenwood wrote:
> > On Dec 2, 2007 6:25 PM, Gregor Mosheh <gregor at hostgis.com> wrote:
> > > Richard Greenwood wrote:
> > > > How do you set a layer's state (turn it on/off) programmatically in JavaScript?
> > >
> > > http://dev.openlayers.org/docs/files/OpenLayers/Layer-js.html
> > >
> > > layer.setVisibility(true);
> > > layer.setVisibility(false);
> >
> > Thanks, now I'm off in search of how to update the  LayerSwitcher to
> > reflect the state change...
>
> This should happen automatically. (When I say 'should' in this case, I
> mean "I just tested it, and it did.") Can you share a minimal example
> that causes this to not be the case?

This probably isn't the best example, but in notile.html, old_ol_wms
is the default selected base layer. So if I put the following two
lines in, I expect to see the new_ol_wms radio button selected.

   old_ol_wms.setVisibility(false);
   new_ol_wms.setVisibility(true);

I tried the above lines as the last two lines in init(), and also
tried them in a script tag in the <body>

I am obviously missing the boat here.

Thanks for your help.

Rich

-- 
Richard Greenwood
richard.greenwood at gmail.com
www.greenwoodmap.com



More information about the Users mailing list