question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The first click will not trigger the mouse down event in chrome

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

0reactions
mingiocommented, Apr 4, 2020

Your support is greatly appreciated.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found