The first click will not trigger the mouse down event in chrome
See original GitHub issueI make a little modified on the example: crs-simple.
I add a rectangle on a map. And there is a mousedown event listening on the rectangle. I add the options to map: renderer: L.canvas() and preferCanvas: true.
After I drag and drop the map, when I first click the Rectangle nothing happens. When I click the rectangle second time, the mousedown event is fired. But the first click should fire mousedown event also.
After I comment out the following lines, the program works.
renderer: L.canvas()
preferCanvas: true
Chrome 73.0.3683.86 x64 Leaflet: 1.6
Here is the code:
<script>
var map = L.map('map', {
crs: L.CRS.Simple,
renderer: L.canvas(),
preferCanvas: true,
});
var bounds = [[0,0], [1000,1000]];
var image = L.imageOverlay('https://leafletjs.com/examples/crs-simple/uqm_map_full.png', bounds).addTo(map);
map.fitBounds(bounds);
// define rectangle geographical bounds
var bounds = [[500, 500], [750, 750]];
// create an orange rectangle
var device = L.rectangle(bounds, {color: "#ff7800", weight: 1, fillOpacity:1}).addTo(map);
function onDeviceMouseDown(e) {
alert("You clicked the map at " + e.latlng);
}
device.on('mousedown', onDeviceMouseDown);
</script>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6
Top Results From Across the Web
Why don't click events trigger in Chrome when :active shifts ...
I have a container div called button_box that gets used with .mousedown() and .mouseup() . These set two flags, which then calls .trigger(...
Read more >mouseup does not trigger a click event on the current item
Hover over the grey box. Press and hold the left mouse button. 2. Release the left mouse button. Expected output: Mousedown event Mouseup...
Read more >Button click event not fired when dragging mouse ... - Monorail
This seems to be causing some mouse clicks to not be triggered. The reason being is that the mouse is often moving when...
Read more >Events | Maps JavaScript API - Google Developers
User events (such as "click" mouse events) are propagated from the DOM to the ... the Maps JavaScript API will fire an event...
Read more >Mouse events - The Modern JavaScript Tutorial
mousedown /mouseup: Mouse button is clicked/released over an element. ... it triggers in that case also, so it's not exactly the mouse event....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Click handled here: https://github.com/Leaflet/Leaflet/blob/d843c3b88486713827d7e860b58bdba75bfbd5a2/src/layer/vector/Canvas.js#L351
And on first click after drag
this._map._draggableMoved(layer)
istrue
, that’s why we miss first click.Inside of
_draggableMoved
there is check ofmap.dragging.moved()
: https://github.com/Leaflet/Leaflet/blob/d843c3b88486713827d7e860b58bdba75bfbd5a2/src/map/handler/Map.Drag.js#L89-L91Todo: inspect https://github.com/Leaflet/Leaflet/blob/master/src/dom/Draggable.js
Your support is greatly appreciated.