[GIS] Getting event object from Draw Toolbar onDrawEnd using ArcGIS API for JavaScript

arcgis-javascript-apidojoeventsmap-drawing

I am using the Draw Toolbar in the Esri Javascript API v3.4 and connecting to the onDrawEnd event using aspect.after(drawingToolbar, "onDrawEnd", drawEndHandleFunction, true);

I am using the Draw Toolbar with the EXTENT tool to allow my user to select features by drawing a box around them. So far it is working fine. However, I want the user to be able to add and subtract features from the selection using the CTRL and SHIFT keys while drawing.

I was able to do this in Chrome using the event.ctrlKey and event.shiftKey properties of the event global variable. Firefox does not appear to have an event global variable like this and so my function doesn't work. Firefox apparently passes an event as a parameter in the function, but that is not available because I used dojo/aspect.

Is there a better way to handle this? Otherwise is there a way to get a map mouse event that triggers the onDrawEnd event in the Draw Toolbar?

Best Answer

Attach to the keydown and keyup events. When the "draw-end" event fires use the "IsShiftDown" to see if the shift was being held down.

require(["dojo/on", "dojo/domReady!"], function(on) {

    var IsShiftDown = false;

    on(document, "keydown", function(event) {
        if(event.keyCode == 16)
           IsShiftDown = true;
    });

    on(document, "keyup", function(event) {
        if(event.keyCode == 16)
           IsShiftDown = false;
    });

});
Related Question