Skip to content

Instantly share code, notes, and snippets.

@rdaly1490
Created February 9, 2016 21:09
Show Gist options
  • Save rdaly1490/eb98fc5ff5be253c5610 to your computer and use it in GitHub Desktop.
Save rdaly1490/eb98fc5ff5be253c5610 to your computer and use it in GitHub Desktop.
Custom control class for Leaflet. Helps avoid issue where double clicking on a control button causes the map to zoom
class customControl extends L.Control {
constructor(options) {
super(options);
this.options = {
position: 'topright',
};
L.Util.setOptions(this, options);
}
onAdd() {
const container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-custom');
container.style.backgroundColor = 'black';
container.style.backgroundImage = 'url(http://coenraets.org/present/react/img/react.png)';
container.style.marginTop = '10px';
container.style.backgroundSize = '30px 30px';
container.style.width = '30px';
container.style.height = '30px';
container.ondblclick = (e) => {
e.stopPropagation();
console.log('On Dbl Click');
};
container.onclick = this.options.onclickMethod;
return container;
}
}
map.addControl(new customControl({
position: 'bottomleft',
onclickMethod: function() {console.log('On Click'); },
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment