lizardtechblog / Leaflet.OpacityControls

Simple Leaflet controls to adjust the opacity of a map.
BSD 3-Clause "New" or "Revised" License
30 stars 18 forks source link

Slider uses a fixed default of 60% opacity #9

Open barryhunter opened 6 years ago

barryhunter commented 6 years ago

Seems the slider has a fixed default of 60% which may not match the actual application.

For the moment, have just changed my copy of Control.Opacity.js to set the initial value (in my case to 80%), but seems it could be dynamic

The onAdd function should be able to compute it from the layer,

var opacity_value = opacity_layer.options.opacity; var value = opacity_value * 100;

sort of thing. But I guess the main issue, is the opacity_layer, may not be known when the control is created, ie setOpacityLayer not called, (or it might not have its opacity set yet!) - as the slider is 'internal' application code cant easily call 'setValue' on it, to initialize it to match an actual layer.

Easiest perhap would be to have a function 'setOpacity' methon on the control, that sets both the opacity of the actual layer, and sets the value on the slider.