What are other consutant's best practices when cloning Field Maps maps?

484
2
11-06-2021 04:57 PM
David_Brooks
MVP Regular Contributor

I'm interested to hear what other people's workflows are for cloning Field Maps maps.

I routinely make a new map for tree surveyors, which contains different reference data for each site they visit (topo data and a basemap). However, the editable layer is currently the same across all the maps and contains the data from every site they've ever surveyed. 

I have this, as the field maps form contains a lot of configuration (expressions, groups, default values), that I don't want to apply to each and every field maps map that i create. This way, all I have to do is duplicate the map in the desktop Field Maps App and then substitute in the reference and base data.

HOWEVER, this does pose challenges for data security and risk of data mismanagement. Seeing as a single feature layer is being consumed across multiple projects, for multiple clients. (access and visibility currently managed by filters). In addition, I have recently had the need to make one of the fields nullable, which can't be reliably achieved through the admin console on a feature service that already contains data.

SO, I'm interested in hearing how others duplicate their configured field maps apps? Im thinking of creating fresh editable services for each map, and using AGOL Assistant to replace the service via the JSON of the Map. Have others done it this way successfully? Are there other ways of substituting feature services into a configured field maps map without losing the configuration?


David
..Maps with no limits..
0 Kudos
2 Replies
DougBrowning
MVP Esteemed Contributor

I have had some luck with AGOL Assistant.  We use it mostly to clone dashboards between states.

I also created a script that copies all the popups and labels from one map to the other.  Arcade came though also.  Note it is NOT tested much yet.  It did work.  It requires the maps to have the same layer names.  For me these are diff feature services - one for each state.  I start with a base map and set that up.  Then create a new map add the state service, run script, done.  I can then do 12 states pretty easy.  I have 30+ arcades, custom popup, etc and it is all done for me. 

*This was written for the Classic Map viewer so not sure how it will handle the New Map Viewer.  

Hope it helps some.  Note if you are logged into Pro it will just work no need to hardcode a password.

# CopyAllPopupsFromMaptoMapAGOL.py
# This script copies the popup from any layers in the source that are found in the target
#   Matching is done by layer name
# User to provide the following inputs:
    # web map 32-character id for both the source and target web map.

### WARNING: THIS SCRIPT WILL COMPLETELY REMOVE THE EXISTING POPUP FROM THE TARGET LAYER AND ASSIGN IT WITH THE SOURCE LAYER POPUP ###

# Created 6/28/2021
# Modified 6/28/2021
# Modifed to copy all layers that match names from one web map to another

############## USER INPUTS ###################################################################

account = 'https://www.arcgis.com' # AGOL/Portal url
# using Pro instead
##username = 'yourusername' # AGOL Username
##password = 'yourpassword' # AGOL password
webmap_id_source = '13a143333333333333339bc68' #  32-character id of web map with the source layer
webmap_id_target = '9f5d499333333333333574af2' #  32-character id of web map with the target laye

##############################################################################################

### EXECUTE ###

#Import
from arcgis.gis import GIS
from arcgis.mapping import WebMap
import sys

print("Starting")

# Check layers names and web maps are not identical
if webmap_id_source == webmap_id_target and copy_popup_from_this_layer == paste_popup_to_this_layer:
    sys.exit("Script cancelled: Source and Target layers have the same name and are within the same web map. Please rename one layer before continuing")

#Connect to GIS
#gis = GIS(account,username, password)
gis = GIS('pro')
source_webmap = gis.content.get(webmap_id_source)
target_webmap = gis.content.get(webmap_id_target)

# Get a list of layers in both web maps
web_map_obj_source = WebMap(source_webmap)
web_map_obj_target = WebMap(target_webmap)
layers_sourceWM = web_map_obj_source.layers
layers_targetWM = web_map_obj_target.layers

# Loop through all the source layers and copy to the matching targets
for sourceLayer in layers_sourceWM:
    found = 0
    for targetLayer in layers_targetWM:
        if targetLayer.title == sourceLayer.title:
            targetLayer.update({'popupInfo':sourceLayer.popupInfo})
            targetLayer.update({'showLabels':sourceLayer.showLabels})
            #targetLayer.update({'labelingInfo':sourceLayer.labelingInfo})
            found += 1

    if found == 0:
        print("Warning did not find layer " + sourceLayer.title + " in the target map")
    elif found > 1:
        print("Warning found the source layer " + sourceLayer.title + " " + str(found) + " times in the target map")
    else:
        print("Copied " + sourceLayer.title)

# Update/save webmap
web_map_obj_target.update()

print("Finished")

   

David_Brooks
MVP Regular Contributor

That's a good approach. I'm gad to see others using AGOL Assistant to good effect and your script gives me inspiration to tackle this task via Python. Good idea 👍


David
..Maps with no limits..