Last active
August 29, 2015 14:21
-
-
Save raykendo/16e8e4ce959d871423d5 to your computer and use it in GitHub Desktop.
ArcGIS-JSAPI: DrawingToolbar hack for onDrawBegin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Making up for a missing "draw-begin" or "draw-start" event for the ArcGIS JavaScript API Drawing toolbar | |
* | |
* Problem: While the drawing toolbar in the ArcGIS JavaScript API has a "draw-end" and a "draw-complete" | |
* event, it doesn't have a "draw-start" or "draw-begin" event. | |
* | |
* Solution: Use a dojo/on pausable event that is only unpaused after the draw-end event. | |
*/ | |
require(["esri/map", "dojo/on", "esri/toolbars/draw"], function (Map, dojoOn, Draw) { | |
var map = new Map("mapdiv", {}); | |
var drawtoolbar = new Draw(map, {}); | |
//do stuff... | |
// set up event listener to trigger the "draw-begin" event | |
var onDrawBegin = dojoOn.pausable(map, "mouse-down", function () { | |
drawtoolbar.emit("draw-begin"); | |
// test if you can pause the onDrawBegin after the event is called. | |
if (onDrawBegin && typeof onDrawBegin.pause === "function") { | |
onDrawBegin.pause(); | |
} | |
}); | |
// pause it for now | |
onDrawBegin.pause(); | |
// set up the draw-end event to reactivate onDrawBegin | |
dojoOn(drawtoolbar, "draw-end, activate", function (evt) { | |
// resume the onDrawBegin when you touch the map to draw again. | |
onDrawBegin.resume(); | |
}); | |
dojoOn(drawtoolbar, "deactivate", function (evt) { | |
// pause draw event if the drawtoolbar is deactivated | |
onDrawBegin.pause(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment