Thursday, 2 March 2017

arcgis server - Toggle Identify with Button


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


Identify


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



Answer




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);
}

}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...