Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dblclick fires click-[-click]-dblclick all browsers #233

Closed
ghost opened this issue Apr 4, 2014 · 3 comments
Closed

dblclick fires click-[-click]-dblclick all browsers #233

ghost opened this issue Apr 4, 2014 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 4, 2014

leaflet 0.8dev/esri-leaflet 0.0.1-beta.4
dbl-click fires click-dbl-click or click-click-dbl-click depending on browser.
http://www.portlandmaps.com/arcmaps/fix/leaflet.dbl-click.htm
http://www.portlandmaps.com/arcmaps/fix/leaflet.dbl-click.fixed.htm (hacky fix with set|clearTimeout)

@patrickarlt
Copy link
Contributor

This behavior is by design as a part of Leaflet so this isn't and Esri Leaflet issues. If you want to have a click-to-identify/double-click-to-zoom experience its easy to filter the showing/hiding of the popup with some simple flags like so.

// Create Map, Basemap and Dynamic Map Layer
var map = L.map('map').setView([42, -74], 5);

L.esri.basemapLayer("Oceans").addTo(map);

var hurricanes = L.esri.dynamicMapLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/", {
  opacity : 1,
  layers: [0,1]
}).addTo(map);

// create variables to track if we should render the popup
var shouldRenderPopup = true;
var lastClick;

// when the map is clicked start the identify call and set the last clicked latlng and allow the popup to be shown
map.on('click', function(e){
  hurricanes.identify(e.latlng, function(data) {
    // if shouldRenderPopup is false (from a doubleclick) or this latlng doesn't equal the last clicked latlng dont render the popup
    if(!shouldRenderPopup || !lastClick.equals(e.latlng)){
      return false;
    }

    //add the popup to the map where the mouse was clicked at
    var popup = L.popup()
      .setLatLng(e.latlng)
      .setContent("Popup")
      .openOn(map);
  });

  // set the flags to show the popup
  shouldRenderPopup = true;
  lastClick = e.latlng;
});

// when the map is double clicked dont show popups
map.on('dblclick', function(e){
  shouldRenderPopup = false;
});

This is some thing I'll look at implementing this behavior as part of #28

@ghost
Copy link
Author

ghost commented Apr 7, 2014

this does not work for me. you can see the popup on the first click and then it disappears if it was a double-click, because a dblclick is firing click-dblclick. not sure why it disappears. maybe because leaflet hides popups on zoom. but the point is if you see a popup at all when double-clicking you've fired a click as well, after the bailout param check. http://www.portlandmaps.com/arcmaps/fix/leaflet.dbl-click2.htm using chrome 33.0.1750.154 m

@patrickarlt
Copy link
Contributor

Looks like there is a relation between the time your identify task takes and the double click event delay implemented by the browser so if you identify job returns BEFORE the second click this wont work.

After some more digging online the only way to really work around this is with a timer as shown below.

// Create Map, Basemap and Dynamic Map Layer
var map = L.map('map').setView([42, -74], 5);

L.esri.basemapLayer("Oceans").addTo(map);

var hurricanes = L.esri.dynamicMapLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/", {
  opacity : 1,
  layers: [0,1]
}).addTo(map);

// create variables to track if we should render the popup
var shouldRenderPopup = false;
var lastClick;
var popup = L.popup();
// when the map is clicked start the identify call and set the last clicked latlng and allow the popup to be shown
map.on('click', function(e){
  console.log("click");
  hurricanes.identify(e.latlng, {}, function(data) {
    console.log("check state");
    // if shouldRenderPopup is false (from a doubleclick) or this latlng doesn't equal the last clicked latlng dont render the popup
    setTimeout(function(){
      if(shouldRenderPopup && lastClick.equals(e.latlng)){
        //add the popup to the map where the mouse was clicked at
        popup.setLatLng(e.latlng).setContent("Popup").openOn(map);
      } else {
        map.closePopup(popup);
      }
    }, 200);
  });

  // set the flags to show the popup
  shouldRenderPopup = true;
  lastClick = e.latlng;
});

// when the map is double clicked dont show popups
map.on('dblclick', function(e){
  console.log("dblclick");
  shouldRenderPopup = false;
  lastClick = e.latlng;
});

map.on('zoomstart', function(e){
  console.log('zoomstart');
});

I'm still all for putting this in as a part of #28 since it only will add a click delay for the one listener and you could pass the delay as an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant