Created
February 9, 2016 21:09
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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