Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
    
I have asked a new question here. gis.stackexchange.com/questions/11527/… –  Mike Long Jun 30 '11 at 15:50
add comment

1 Answer

up vote 3 down vote accepted

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);
  }
}
share|improve this answer
    
+1 this is how you should do it. –  Derek Swingley Jun 23 '11 at 2:59
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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