dbl-click event for feature layer not firing

6201
9
01-23-2015 05:01 PM
by Anonymous User
Not applicable

I am trying to zoom the map on a double-click even if I am double clicking a feature layer...but the map won't zoom. When I try to listen for 'dbl-click' on the feature layer, it doesn't even print to the console:

featureLayer.on("dbl-click", function(evt) {
     console.log("dbl-click");
});


  console.log('hi');


});

Can anyone replicate this? I have a label layer and if I double click over the text it zooms the map and seems the event is fired for the label layer...as soon as I double click on the graphic of a feature layer, no response.

Tags (1)
0 Kudos
9 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Sarah,

Would you be able to post more of you code?  I was unable to reproduce this.  Here is a JS Fiddle of the code I used.

0 Kudos
by Anonymous User
Not applicable

The code is a bit convoluted because I am using dojo classes to implement a dgrid table. I updated the JS Fiddle in a tiny way to confirm one thing: when the layer is double-clicked it captures that event, but also two 'click' events. Edit fiddle - JSFiddle

I have a feature layer 'click' event that calls my dgrid class and selects the row in the dgrid for the graphic that was clicked on the map. When I try to implement a double-click event with this in place, the double-click never registers. I have a feeling it is because the double-click is actually firing the click event first, which goes through a query to select the feature....and perhaps it is getting lost in the deferred query object?

I am able to replicate this issue in this sample in the sandbox: dgrid | ArcGIS API for JavaScript

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Not sure if this will help, but you could add an 'if' statement to see if the feature is already selected.  If it is, you could then zoom to it on a second click.  Or, if you were to double-click from the start, it will highlight and zoom to the feature all at once.  In the sample you referenced, you would update the 'selectGrid' function:

function selectGrid(e) {
    if(id){
      if(e.graphic.attributes.OBJECTID == id){
        map.setExtent(e.graphic.geometry.getExtent());
      }
    }
    id = e.graphic.attributes.OBJECTID;
    // select the feature that was clicked
    var query = new Query();
    query.objectIds = [id];
    var states = map.getLayer("states");
    states.selectFeatures(query, FeatureLayer.SELECTION_NEW);
    // select the corresponding row in the grid
    // and make sure it is in view
    grid.clearSelection();
    grid.select(id);
    grid.row(id).element.scrollIntoView();
}

Here is an updated JSFiddle.

0 Kudos
by Anonymous User
Not applicable

Thanks for the thought Jake...doesn't get to the heart of my problem. I want normal map zooming on dbl-click, and feature interactivity on single click, with the events completely isolated. There seems to be no way for me to capture the dbl-click event when it occurs on a feature layer-- checking if a feature is selected already does not get around the problem that a user may dbl-click elsewhere on the layer, not on the same feature. I also don't want to zoom to a feature, I want to zoom 1 map level...I could force that if I there was a way to know the user had double-clicked!

Seems like a serious issue to me.

0 Kudos
JoshHevenor
Occasional Contributor II

I worked through the esri's dgrid sample and the code in the selectGrid function dealing with the dgrid rows looks like it's causing your trouble. I can't see why off hand.

I wrote a work-around and posted it here: dgridclick.html

UPDATE:  Workout is using setTimeout as mentioned by Sarah Clark

by Anonymous User
Not applicable

I wrote a workaround using a setTimeout() function based on this JQuery example: README

Thanks everyone.

0 Kudos
by Anonymous User
Not applicable

Oh Josh, yours is cleaner This is what I came up with:

var click;    
layer.on('click', function(evt) {
        // !!!! Check first if it's a dbl-click using time-out !!!!
        click++;
        if (click == 1) {
            setTimeout(function() {
                if (click == 1) {
                    click = 0;                   
                 // proceed                               
                    dgrid.selectGrid(map, dgrid, evt, storeGraphics, symbols, exclude);
                }
            }, 300);
        } else {
            // dbl-click, clear the global
            click = 0;
        }
    });
by Anonymous User
Not applicable

FYI this bug is now logged with ESRI:

Defect ID: BUG-000084944

Synopsis: When double-clicking on a feature layer that has a callback function, the dbl-click event does not fire and the click event fires twice.

0 Kudos
MatúšVandák
New Contributor

Hello Sarah.

FYI, I came to the same issue. Now after clicking like a fool when trying to get the point, I realize that the graphic is triggering dbl-click event when you move mouse between two clicks of double click for a few pixels.

When you double click the same pixel without move, graphic catches 2 clicks, but after small move, it catches dbl-click.

And another specific behaviour for me on Linux. If I double click graphic in Chrome, the graphic triggers two click events, but map triggers dbl-click event. If I double click graphic in Firefox, the graphic triggers two click and the map also. In Firefox the lower layer will not get dbl-click event.

I know this will not help you, but IMHO it is good to know.

And maybe it's good to add this information into bug description so they will be able to find solution sooner.

0 Kudos