Using Leaflet JS, I would like to open a marker popup after the user has finished dragging the marker. However, disabling the ability to drag once the "dragend" event is fired prevents the popup to show. The "popupopen" event is fired properly.
The code below does not work on desktop. However, the popup opens just fine after dragging on touch devices.
Removing the ".openPopup();" fixes the problem on desktop browsers, but the issue is then present on touch devices.
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© OpenStreetMap'
}).addTo(map);
var marker = L.marker([51.5, -0.09]);
marker.on('dragstart', function() {
console.log('dragstart');
});
marker.on('drag', function() {
console.log('drag');
});
marker.on('dragend', function() {
console.log('dragend');
this.dragging.disable(); // Uncommenting this line allows the popup to show, but the user is still able to drag the marker.
this.options.draggable = false;
var content_string = '<div id="test_div">It works!</div>';
this.bindPopup(content_string, {
minWidth: 350,
closeButton: false
}).on('popupopen', function(e) {
console.log('popupopen')
}).openPopup();
});
map.addLayer(marker);
marker.dragging.enable();
marker.options.draggable = true;
JSFiddle showing how the popup does not open after dragging the marker: https://jsfiddle.net/fnllc/e15mg3b8/19/