googlearchive / js-marker-clusterer

A marker clustering library for the Google Maps JavaScript API v3.
https://googlemaps.github.io/js-marker-clusterer/docs/reference.html
Apache License 2.0
1.28k stars 775 forks source link

Only perform click event when not preceded by a drag #78

Closed fritz-c closed 8 years ago

fritz-c commented 8 years ago

When markers are occupying a large portion of the clickable area of the map, it can be frustrating to try to pan about the map and accidentally trigger unwanted click events.

The default behavior for Google Maps markers, presumably in response to this issue, appears to be as follows: When a drag event occurs between the mousedown and mouseup of a click, the click event is not called.

Here's with the InfoWindow sample code for example: marker-behavior

js-marker-clusterer, before

However, js-marker-clusterer, by changing the markers to an overlay, loses this behavior: cluster-behavior-before

js-marker-clusterer, after

This pull request restores the behavior of the markers, as in: cluster-behavior-after

broady commented 8 years ago

LGTM. Have you signed the CLA?

fritz-c commented 8 years ago

Yes, I have. The email (gmail) is a secondary email on this account, however. Would that be an issue?

broady commented 8 years ago

Nope, that's OK.

cwellsx commented 7 years ago

This breaks (i.e. it disables) zoomOnClick functionality on Chrome, possibly due to a Chrome bug which inserts a mousemove after mousedown before click -- https://bugs.chromium.org/p/chromium/issues/detail?id=161464

I'm currently using Chrome version 57.0.2987.133 on Windows 10 version 1607 (64-bit).

IMO you can fix this by changing the new mousemove handler to ...

google.maps.event.addDomListener(this.div_, 'mousemove', function(event) {
    if (event.movementX || event.movementY) {
        isDragging = true;
    }
});

... so that it doesn't set isDragging if the movementX and movementY of the mousemove event are both zero.