I'm facing an issue with adding buttons to a Leaflet popup that appears when clicking on the map.
My goal is to have the popup display 2 buttons:
- Start from Here
- Go to this Location
The desired outcome looks like this sketch:
________________________________________________
|You clicked the map at LatLng(XXXXX,XXXXX) |
| --------------- ------------------- |
| |Start from here| |Go to this location| |
| --------------- ------------------- |
|___________________ ___________________________|
\/
However, my current popup displays: "You clicked the map at LatLng(XXXXX,XXXX) [object HTMLButtonElement]."
I am attempting to create the buttons using L.domUtil.
defineYourWaypointOnClick(e: any) {
var choicePopUp = L.popup();
var container = L.DomUtil.create('div'),
startBtn = this.createButton('Start from this location', container),
destBtn = this.createButton('Go to this location', container);
choicePopUp
.setLatLng(e.latlng)
.setContent('You clicked the map at ' + e.latlng.toString() + '<br>' + startBtn)
.openOn(this.map);
L.DomEvent.on(startBtn, 'click', () => {
alert("toto");
});
L.DomEvent.on(destBtn, 'click', () => {
alert("tata");
});
}
createButton(label: string, container: any) {
var btn = L.DomUtil.create('button', '', container);
btn.setAttribute('type', 'button');
btn.innerHTML = label;
return btn;
}
I trigger my method from here:
this.map.on('click', (e: any) => {
this.defineYourWaypointOnClick(e);
});
Your assistance with this matter would be greatly appreciated. Thank you :)