Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a custom onClick handler for my map that is meant to add a point wherever the map is clicked. I'm finding that this function is triggered even when I click the map to pan. Is it possible to somehow ignore the onClick event if the map is panning?

Update:

Here is the code for my onClick handler.

this.mapClickHandle = dojo.connect(this.map, "onClick", lang.hitch(this, function(evt) {

    this.layers.forEach(function(layer) {

        layer.layerObject.clearSelection();

    });

    console.log(evt.screenPoint)

    var toleranceInPixels = 10;
    var pnt = evt.mapPoint;

    var pixelWidth = this.map.extent.getWidth() / this.map.width;
    var toleranceInMapCoords = toleranceInPixels * pixelWidth;
    var ext = new esri.geometry.Extent(pnt.x - toleranceInMapCoords, pnt.y - toleranceInMapCoords, pnt.x + toleranceInMapCoords, pnt.y + toleranceInMapCoords, this.map.spatialReference);

    var q = new esri.tasks.Query();
    q.geometry = ext;

    var deferreds = this.layers.map(function(layer) {

        return layer.layerObject.selectFeatures(q);

    });

    all(deferreds).then(lang.hitch(this, function(results) {

        if (results.some(
            function(result) {
            return result.length > 0;
        })) {
            dijit.byId(this.mapPage).performTransition(this.attributePage, 1, "fade", null);
        } else {
            if (this._editing) {
                this._newGeom = evt.mapPoint;
                dijit.byId(this.mapPage).performTransition(this.templatePage, 1, "fade", null);
            }
        }

    }));

}));

This is for a mobile web application using the JS API v3.4. The behavior I am seeing is still in my desktop web browser though. Basically, what the code above does is transition to the attribute view if an existing feature is clicked on (or nearby) or it transitions to the editor template page if the map is clicked and not existing features are nearby.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

This sample would suggest that the API already separates a single click from drag events quite well (as well as double clicks).

http://developers.arcgis.com/en/javascript/samples/map_infowindow/

Would you mind posting some code or at least explaining what you're doing with your custom onclick handler?

share|improve this answer
    
Well, I can't explain it. I refreshed the page over an over and it didn't make a difference. When I stopped debugging and restarted debugging. Everything works. –  Brian Apr 8 '13 at 23:08
1  
I've found oftentimes that when making changes like this it's a good idea to clear the browser cache when refreshing. It's yet another reason I love Firebug, which lets you disable the browser cache for whatever site you're testing. –  Kevin R Dyke Apr 9 '13 at 13:36
    
Do you know if that is possible with Chrome DevTools? –  Brian Apr 9 '13 at 15:48
    
Yup, if you click the gear in the bottom right of the DevTools, you should see a Disable cache checkbox close to the top. –  Kevin R Dyke Apr 9 '13 at 18:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.