[OpenLayers-Users] Change Layer Vis outside of LayerSwitcher
Stephen Woodbridge
woodbri at swoodbridge.com
Sun Apr 26 13:23:42 EDT 2009
Christopher Schmidt wrote:
> On Sun, Apr 26, 2009 at 01:13:47PM -0400, Stephen Woodbridge wrote:
>> Christopher Schmidt wrote:
>>> On Sun, Apr 26, 2009 at 11:43:24AM -0400, Stephen Woodbridge wrote:
>>>> Hi,
>>>>
>>>> If I change the visibility of a layer in JavaScript, How do I get that
>>>> reflected in LayerSwitcher? Or maybe the question should be: How do tell
>>>> LayerSwitcher in JavaScript that I want to change layers selected?
>>> If you need to, something is broken. Can you share the code that isn't
>>> working?
>>>
>>> Regards,
>> Christopher,
>>
>> http://imaptools.com:8080/maps/dd3.html?lat=34.5315&lon=69.1571&zoom=14&layers=B00TFTTTF&start=69.150255%2034.535834&stop=69.158273%2034.52821&method=STS&lang=eng
>>
>> It is likely that my hack job of code has broken something.
>> Overlays seem to update ok, but the base layer is not updating.
>>
>> I am trying to add the buttons instead of the LayerSwitcher and finally
>> got them to work, although there is probably a much easier way to do it.
>>
>> So to reproduce is click on the [Map][Satellite][Contour] or [Show
>> labels] checkbox and these work as they should. If you open the
>> layerswitcher, you will see that the "Overlay Streets" and "90M Contour
>> Lines" toggle on and off with the button clicks, but changing the
>> baselayer visibility with the [Map][Satellite] buttons does not update
>> the layerswitcher.
>
> When I open the above URL, it doesn't work in my browser, so I can't
> click anything to test it, but my guess is that you'r eusing
> setVisibility on the layer instead of setBaseLayer on th map to 'choose'
> a base layer. When changing base layers, you should always use
> setBaseLayer to pick the one you want to be the base.
> -- Chris
Yes, you are correct, I'm using setVisibility, I will change that. I
also just tried it in IE and its broken there, so I guess I have more
debugging to do.
Thank you,
-Steve
>> I also have not looked into trying to make the buttons update when
>> things are toggled in the layerswitcher. None of this is a real issue
>> because layerswitcher will probably be commented out totally in the
>> production system. But it seemed like a practical exercise to better
>> understand how things work.
>>
>> I am always open to suggestions on better ways to code these solutions.
>>
>> Thank you,
>> -Steve
>
More information about the Users
mailing list