Hi Everyone,
Over the past year or two I've been using an older script posted that copied popups between webmap layers. See the script below.
# This script assigns a pop up from one web map layer (source) to another web map layer (target).
# User to provide the following inputs:
# web map 32-character id for both the source and target web map. If the layers are in the same webmap the id will be the same.
# exact name of layer in source web map with existing popup to copy (source layer)
# exact name of layer in target web map to which the popup will be assigned to (target layer)
# ArcGIS Online credentials: url, username & password
### WARNING: THIS SCRIPT WILL COMPLETELY REMOVE THE EXISTING POPUP FROM THE TARGET LAYER AND ASSIGN IT WITH THE SOURCE LAYER POPUP ###
############## USER INPUTS ###################################################################
account = '' # AGOL/Portal url
username = '' # AGOL Username
password = '' # AGOL password
webmap_id_source = '' # 32-character id of web map with the source layer
webmap_id_target = '' # 32-character id of web map with the target layer
copy_popup_from_this_layer = '' # insert the exact layer name as it is in the source webmap
paste_popup_to_this_layer = '' # insert the exact layer name as it is in the target webmap
##############################################################################################
### EXECUTE ###
#Import
from arcgis.gis import GIS
from arcgis.mapping import WebMap
import sys
# 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)
source_webmap = gis.content.get(webmap_id_source)
target_webmap = gis.content.get(webmap_id_target)
# Get web map and all its layers if the source and target layers are in different web maps. Define source and target layers.
if webmap_id_source != webmap_id_target:
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
source_layer = [i for i in layers_sourceWM if i.title == copy_popup_from_this_layer]
target_layer = [i for i in layers_targetWM if i.title == paste_popup_to_this_layer]
# Get web map and all its layers if the source and target layers are in the same web map. Define source and target layers.
if webmap_id_source == webmap_id_target:
web_map_obj_target = WebMap(source_webmap)
layersWM = web_map_obj_target.layers
source_layer = [i for i in layersWM if i.title == copy_popup_from_this_layer]
target_layer = [i for i in layersWM if i.title == paste_popup_to_this_layer]
# Check there's one source or target layer with the same name in the map. If not, report and cancel script.
if len(source_layer) == 0:
sys.exit("Script cancelled: source layer name doesn't exist in web map")
if len(target_layer) == 0:
sys.exit("Script cancelled: target layer name doesn't exist in web map")
if len(source_layer) >1:
sys.exit("Script cancelled: more than one layer in the web map has the source name. Not sure which one you want to copy the pop-up from! Please make sure the layer has a unique name (you can change it back after you run the script)")
if len(target_layer) >1:
sys.exit("Script cancelled: more than one layer in the target web map has the target name. Not sure which one you want to copy the pop-up to! Please make sure the layer has a unique name (you can change it back after you run the script)")
# Paste the source popup to the target layer
target_layer[0].update({'popupInfo':source_layer[0].popupInfo})
# Update/save webmap
web_map_obj_target.update()
With the update from 2.3 to 2.4 it seems to have broken many parts of the code. I'm aware of the module and class change from arcgis.mapping/Webmap to arcgis.map/Map but I'm having issues with other parts of the code, such as the Webmap function and calling layers from these webmaps.
if webmap_id_source != webmap_id_target:
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
source_layer = [i for i in layers_sourceWM if i.title == copy_popup_from_this_layer]
target_layer = [i for i in layers_targetWM if i.title == paste_popup_to_this_layer]
I've spent a bit trying to fix the script myself but I'm still fairly new to coding and haven't been able to figure it out. This script saves a massive amount of time, if anyone could help me out I'd greatly appreciate it!!