Last active
December 11, 2015 04:09
-
-
Save odoe/4542944 to your computer and use it in GitHub Desktop.
Example of how you might use dojo/on with esri/map to handle multiple click events on the map with ArcGIS JavaScript API 3.3.
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
// Purely sample | |
// Just demonstrates how you may use the dojo/on method | |
// with the map click and other click events | |
define('identifyHandler', ['dojo/on', 'esri/tasks/identify'], function(on) { | |
var _idhandler = function(map) { | |
var task = new esri.tasks.IdentifyTask('url'); | |
var idparams = new esri.tasks.IdentifyParameters(); | |
idparams.tolerance = 3; | |
idparams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL; | |
// callback train, yeah yeah, it's a sample, jeez | |
this.handler = on.pausable(map, 'click', function(e) { | |
// blah blah, set up your Identify Parameters | |
var deferred = task.execute(idparams); | |
deferred.then(function(){ | |
// blah blah, do something | |
}); | |
}); | |
}; | |
return _idhandler; | |
}); | |
define('mapView', ['dojo/connect', 'identifyHandler', 'esri/map', 'esri/toolbars/draw'], function(connect, IdHandler) { | |
var _mapview = function() { | |
var self = this; | |
this.start = function() { | |
self.map = new esri.Map('map'); | |
/** | |
do a bunch of map stuff | |
**/ | |
connect.connect(self.map, 'onLoad', function() { | |
// initialize my little identify helper module | |
var identify = new IdHandler(self.map); | |
/** | |
Now, let's say you have a drawtool that will add points | |
to your map for some reason. A common problem is you can add the point, | |
but the map click to add a point also triggers the identify. | |
Easy way to handle this now... | |
**/ | |
var drawTool = new esri.toolbars.Draw(map); | |
/** draw nonsense stuff here somewhere **/ | |
connect.connect(someButton, 'click', function() { | |
drawTool.activate(esri.toolbars.Draw.POINT); | |
// now pause the identify map click | |
identify.handler.pause(); | |
}); | |
connect.connect(drawTool, 'onDrawEnd', function(geom) { | |
drawTool.deactivate(); | |
// turn the identify back on | |
identify.handler.resume(); | |
}); | |
}); | |
}; | |
}; | |
return _mapview; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment