Turn Popups On/Off in ArcGIS Online Webmap via Javascript API Web Application
Think you almost have it. It may be that you need to reset the handle on connect...
clickHandle = dojo.connect(map, "onClick", clickListener);
The following is working for me...
var agolPopupClickHandle,
agolPopupclickEventListener;
//get the response
.then {
agolPopupClickHandle = response.clickEventHandle;
agolPopupclickEventListener = response.clickEventListener;
}
//connect editor
if (agolPopupClickHandle) {
dojo.disconnect(agolPopupClickHandle);
agolPopupClickHandle = null;
}
//disconnect editor
if (!agolPopupClickHandle) {
agolPopupClickHandle = dojo.connect(theMap, "onClick", agolPopupclickEventListener);
}
So with further trial and error, I discovered the issue. I was unaware of how dojo.disconnect
and dojo.connect
work.
If I turn off the ignorePopups
option when calling esri.arcgis.utils.createMap
I will get the standard popup. Then, in the mapDeferred.then
call, I set global variables
clickHandle = response.clickEventHandle
clickListener = response.clickEventListener
Later in my initEditor
function, if bool == true
then I disconnect clickHandle
dojo.disconnect(clickHandle)
In the else
clause:
dojo.disconnect(clickHandle) // This will disconnect the original clickHandle if it is still connected
clickHandle = dojo.connect(map, "onClick", clickListener) // This will reconnect clickListener and return a new clickHandle that can be disconnected next time the editor is enabled
The issue was that I had multiple handles connected to the onClick
event and I was only disconnecting one or the other and not both.