Shashwat Tripathi
Shashwat Tripathi

Reputation: 582

Leaflet layer control open only on click

Is there any way to open leaflet layer control only when clicked?

By default, it expands/collapse when on mouseover/mouseout. I want to open only on click.

Upvotes: 1

Views: 3221

Answers (2)

Shashwat Tripathi
Shashwat Tripathi

Reputation: 582

Stop propagation on mouse over solved it. I am using d3 here but It can be easily handled by plain javascript or by jQuery.

d3.select(".leaflet-control-layers-toggle").on("mouseover", function () {
        //this will make sure that layer popup menu
        //not opens when mouseover
        d3.event.stopPropagation();
    });

Upvotes: 0

treecon
treecon

Reputation: 2835

You can use a bit of jQuery to get this done.

Set the 'collapsed' option to false and instead, create a button to show/hide the layer control.

btn.onclick = function() {
  $('.leaflet-control-layers').toggle();
}

jsFiddle:https://jsfiddle.net/jht7u28L/1/ (a basic example)

Upvotes: 1

Related Questions