[OpenLayers-Users] Inducing LayerSwitcher to Update Through Programming

Christopher Schmidt crschmidt at metacarta.com
Tue Feb 24 13:27:36 EST 2009


On Tue, Feb 24, 2009 at 11:07:19AM -0700, Bill Thoen wrote:
> Christopher Schmidt wrote:
> >On Tue, Feb 24, 2009 at 09:51:03AM -0700, Bill Thoen wrote:
> >  
> >>Christopher Schmidt wrote:
> >>    
> >>>map.setBaseLayer(map.layers[1])
> >>>on http://openlayers.org/dev/examples/controls.html  cause the
> >>>ayerSwitcher to redraw for me. Does it not do that for you? It should;
> >>>if it doesn't, that's a bug.
> >>> 
> >>>      
> >>Here's an example where a layer is switched under the LayerSwitcher's 
> >>nose, and it doesn't react to it even if you call setBaseLayer() after 
> >>the change: http://206.168.217.244/gallery/ToggleBaseLayer.html
> >>    
> >
> >setBaseLayer after the layer is *already* visible won't do anything,
> >that is correct. That's not how setBaseLayer is designed to be used.  
> >Though this exposes a behavior in the LayerSwitcher, I don't think it's
> >a bug, because this demonstration seems a bit like an anti-use of the
> >library.
> >
> >  
> >>I realize that if I had called setBaseLayer() first I wouldn't have to 
> >>go through all that bit to change layer visibilities, but this "bug" 
> >>appeared as a result of originally wanting to change overlay layers.
> >>    
> >
> >Overlay layers should react to setVisibility -- something that base
> >layers do differently. Can you find an overlay layer whiwch doesn't do
> >the right thing if you setVisiblity on it (via the method, rather than
> >via layer.visibility and layer.redraw() or somethign like that)?  
> >  
> No, setVisibility works as advertised on all overlay layers. This was 
> what I was focused on to begin with, and I was updating the property 
> because I didn't know any better (I'm still on the steep part of the 
> learning curve with this library.)  It was only after I had done it that 
> I realized that the base layers were not being handled. So I tinkered 
> with the LayerSwitcher innards even more, but finally decided I was 
> going about this all wrong and hence my original question about what's 
> the right way. One problem for beginner JavaScript programmers like me 
> is that since everything is exposed, you're tempted to grab at the first 
> thing that looks good. Its sort of like giving a monkey the keys to the 
> banana plantation. I agree with you that calling setBaseLayer after I've 
> set visibility is a mistake,  but because setBaseLayer didn't work as 
> expected in this case, I wondered if I should call attention to it anyway.

Yep. I would say that this is perhaps worth documenting, but is
definitely a rare case.

For teh record, the difference between:

  http://dev.openlayers.org/apidocs/

and

  http://dev.openlayers.org/docs/

Sort of acts a set of "Here's what you can monkey with safely". (It's
not perfect, because the actual intention is "This won't change", but
the result is pretty similar.)

Best Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list