How can I keep my Map click handler from responding to the Draw Toolbar?

3803
2
Jump to solution
04-09-2015 12:39 PM
DavidElies
New Contributor III

I just recently realized that my Map.graphics click handler has been interfering with the Draw Toolbar.  When I draw polylines and I click to start a new line in the same poly, the click (which always falls on the line) causes errors because my handler only expects to handle the graphics that I have added, not those from the draw toolbar.  My first instinct is to use a distinct graphics layer for the draw toolbar.  This would cause the least changes in my code.  If not possible, the only other solution I see is to use a distinct graphics layer for my graphics.  This would take a lot more work on my part. Is it possible to use a different graphics layer than the map's default graphics layer for the draw (and edit) toolbar? If not, is there maybe another solution I'm not considering?  My click handler code could be changed, but I don't know what would always distinguish my graphics from those created by the draw toolbar.

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

In my app, I created a pauasble event for the map click (this requires "dojo/on").

mapClickEvent = on.pausable(map, "click", function (evt) { mapClickHandler(evt); });

When the user draws a feature with the Draw toolbar, I pause that event and restart it when the drawing is complete.

toolbar = new Draw(map);
toolbar.on('draw-end', performQuery);
registry.byId('btnPoint').on('click', function () {
    mapClickEvent.pause();
    toolbar.activate(this.drawtype);

function performQuery(evt) {
    mapClickEvent.resume();

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

In my app, I created a pauasble event for the map click (this requires "dojo/on").

mapClickEvent = on.pausable(map, "click", function (evt) { mapClickHandler(evt); });

When the user draws a feature with the Draw toolbar, I pause that event and restart it when the drawing is complete.

toolbar = new Draw(map);
toolbar.on('draw-end', performQuery);
registry.byId('btnPoint').on('click', function () {
    mapClickEvent.pause();
    toolbar.activate(this.drawtype);

function performQuery(evt) {
    mapClickEvent.resume();
DavidElies
New Contributor III

Thanks Ken Buja,

I had to refactor a bit so that my drawtoolbar code could see the click handler, but it works a treat!

0 Kudos