6

I am attempting to set up an Identify button that will only allow the identify functionality to be performed when the button is pressed. I have gotten to the point that the identify only works when the button has been pushed the first time but I can't seem to turn the button off. I have pasted a few bits of code below or you can follow the link to see the entire thing.

http://geoville.org/viewers/PopUp/

Funtion to activate Identify

function activateIdentify(){
    if (dijit.byId("tool_identify").checked) {
        dojo.connect(map, "onClick", executeIdentifyTask);
    }
  }

Button to Activate function

<div dojoType="dijit.form.ToggleButton" id="tool_identify" iconClass="dijitCheckBoxIcon" onClick="activateIdentify();" >Identify</div>

Function to toggle buttons

function toggleButtonIcon(tool) {

    //only the tools in the toolbar are dijit togglebuttons so can iterate thru them
    dijit.registry.byClass("dijit.form.ToggleButton").forEach(function(togbtn) {
      if (togbtn == tool) {
        togbtn.attr("checked", true);
      }
      else {
        togbtn.attr("checked", false);
      }
    });
  }  //end toggleButtonIcon

Thanks for your help.

-Mike

6

Mike,

Set a global variable to hold the "onClick" listener, then disable the listener when the button is disabled.

var identifyListener;

function activateIdentify(){
  if (dijit.byId("tool_identify").checked) {
    identifyListener = dojo.connect(map, "onClick", executeIdentifyTask);
  } else {
    dojo.disconnect(identifyListener);
  }
}
  • Thanks @Stephen Lead, your code solved exactly what I asked for. In the long run I am attempting to integrate an "Identify" button into the Esri Navtoolbar sample by using multiple toggle buttons. Most of the code samples I find just seem overly complex. Any suggestions on how to integrate the added block of code with your previous suggestion. I have also updated the sample at the link. geoville.org/viewers/PopUp – Mike Long Jun 27 '11 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.