Wednesday 20 September 2017

Turn Popups On/Off in ArcGIS Online Webmap via Javascript API Web Application


I am writing my first ArcGIS Javascript API web map application and consuming a web map authored in ArcGIS Online. The ArcGIS Online web map apparently does most of the work for me in terms of symbology, editing templates, and even popups.


For my application, I am trying to allow the user to edit features, but not all the time. I am able to toggle the editor on and off with the click of a button. The problem is that I have not been able to toggle the default popups on and off so that the user can edit attributes. Even when editing is enabled, the default non-editable popup appears when you click on a feature. The only way to avoid this is to use the ignorePopups option when calling esri.arcgis.utils.createMap. However, this means that when editing is disabled nothing happens when you click on a feature.



Here is my code. This has all been adapted from several samples provided in the ArcGIS Javascript API documentation.


    
















This pane could contain tools or additional content



















I realize that I could recreate a custom InfoWindow and AttributeInspector, but since this is already done automatically by the API, it would be nice if I didn't have to.


I tried to get the clickEventHandle and clickEventListener from the response given by mapDeffered.then() and then connect and disconnect when the editor is disabled and enabled, but the default popups remained even after I called dojo.disconnect(clickEventHandle).


Any help would be greatly appreciated.




Answer



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

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...