Leaflet.Control.Custom icon indicating copy to clipboard operation
Leaflet.Control.Custom copied to clipboard

Events on child controls of the leaflet custom control

Open qannoufoualid opened this issue 6 years ago • 1 comments

First of all thank you for the job you did, but it's gonna be better to offer a way to create events on controls inside the parent leaflet control. Because if i got it well, your api allow only events on the global container. I can make a pull request for that.

qannoufoualid avatar Jul 01 '19 13:07 qannoufoualid

I faced the same problem as you and was wondering how to solve it. But in the end I just added a click event function on my child as this:

L.control.custom({
    position: 'topright',
    content : '<div class="form-check">' + 
	      '<input class="form-check-input" type="radio" name="PM" id="PM1" checked>' +
	      '<label class="form-check-label">PM1</label>' +
	      '</div>'+
	      '<div class="form-check">' +
	      '<input class="form-check-input" type="radio" name="PM" id="PM2">' +
	      '<label class="form-check-label">PM2</label>' +
	      '</div>' +
	      '</div>',
     style   :
     {
	margin: '10px',
	padding: '2px 0px 0px 0px',
     },
})
.addTo(map);

document.getElementById("PM1").addEventListener( "click", function() {...} );
document.getElementById("PM2").addEventListener( "click", function() {...} );

ochrin avatar Mar 27 '20 16:03 ochrin