Suspending Identify while using Draw Toolbar

682
7
Jump to solution
07-30-2012 01:04 PM
by Anonymous User
Not applicable
Is it possible to suspend the identifyTask initiated via: "dojo.connect(map,"onClick",executeIdentifyTask);" when the user clicks on a button from the Draw toolbar? That is without having to create a separate Identify button on the toolbar?

Thanks!

RGibson
0 Kudos
1 Solution

Accepted Solutions
danbecker
Occasional Contributor III
I attempted this but to no avail....and ideas?

<button data-dojo-type="dijit.form.Button" data-dojo-props="onClick:function(){toolbar.activate(esri.toolbars.Draw.POLYLINE);map.hideZoomSlider();dojo.disconnect(handler);}">Polyline</button>


I'd put the function up in the js and remove it from your html markup. i'm doing something very similar, disabling onClick listener, enabling onMouseOver listener when load, then the opposite when identify button is clicked. search for my thread "onMouseOver onMouseOut" and you can see my markup.

something like this

//globals var handler; //var to hold event listener var map; var toolbar;  function init(){     //define map here     //define toolbar here     handler = dojo.connect(map,"onClick",executeIdentifyTask); }  function initToolbar(){     dojo.disconnect(handler);     toolbar.activate(esri.toolbars.Draw.POLYLINE);     map.hideZoomSlider(); }  dojo.addonload(init);  <button data-dojo-type="dijit.form.Button" data-dojo-props="onClick:initToolbar()">Polyline</button>    

View solution in original post

0 Kudos
7 Replies
derekswingley1
Frequent Contributor
Yes, dojo.connect returns a handle that you can pass to dojo.disconnect to disconnect an event listener. In this case, pass the handle returned by dojo.connect to dojo.disconnect just before you call toolbar.activate. When you call toolbar.deactivate, re-connect your identify click event listener (and save a reference to the return value of dojo.connect).
0 Kudos
by Anonymous User
Not applicable
Thanks, Derek for the fast response.

I have attempted:

var handler = dojo.connect(map, "onClick", executeIdentifyTask);

How would I then utilize this variable? Maybe here somewhere?:

<button data-dojo-type="dijit.form.Button" data-dojo-props="onClick:function(){toolbar.activate(esri.toolbars.Draw.POLYGON);map.hideZoomSlider();}">Polygon</button>

Thanks again!

RGibson
0 Kudos
derekswingley1
Frequent Contributor
Yes, you'd use your handler variable. Since you need to reference it outside of the function where it's defined, handler needs to be global (or it need to be a property a global object).

I know we do it in some of our samples, but it's generally a bad idea to inline your JS with your markup. Changes (and down the road, maintenance) are much easier when your markup, CSS and JS are each in their places/files.
0 Kudos
by Anonymous User
Not applicable
I attempted this but to no avail....and ideas?

<button data-dojo-type="dijit.form.Button" data-dojo-props="onClick:function(){toolbar.activate(esri.toolbars.Draw.POLYLINE);map.hideZoomSlider();dojo.disconnect(handler);}">Polyline</button>
0 Kudos
danbecker
Occasional Contributor III
I attempted this but to no avail....and ideas?

<button data-dojo-type="dijit.form.Button" data-dojo-props="onClick:function(){toolbar.activate(esri.toolbars.Draw.POLYLINE);map.hideZoomSlider();dojo.disconnect(handler);}">Polyline</button>


I'd put the function up in the js and remove it from your html markup. i'm doing something very similar, disabling onClick listener, enabling onMouseOver listener when load, then the opposite when identify button is clicked. search for my thread "onMouseOver onMouseOut" and you can see my markup.

something like this

//globals var handler; //var to hold event listener var map; var toolbar;  function init(){     //define map here     //define toolbar here     handler = dojo.connect(map,"onClick",executeIdentifyTask); }  function initToolbar(){     dojo.disconnect(handler);     toolbar.activate(esri.toolbars.Draw.POLYLINE);     map.hideZoomSlider(); }  dojo.addonload(init);  <button data-dojo-type="dijit.form.Button" data-dojo-props="onClick:initToolbar()">Polyline</button>    
0 Kudos
by Anonymous User
Not applicable
Gave this a try but the "initToolbar" function is firing as the page loads and not when the button is clicked. And I did place the initToolbar function outside of the "init" function. Thanks.
0 Kudos
by Anonymous User
Not applicable
Okay, figured this out. Thanks to everyone. The code supplied by dbecker88 is essentially correct but with one revision:

<button data-dojo-type="dijit.form.Button" data-dojo-props="onClick:initToolbar()">Polyline</button>

SHOULD BE

<button data-dojo-type="dijit.form.Button" data-dojo-props="onClick:function(){initToolbar();}">Polyline</button>

Thanks again for the assistance.
0 Kudos