Hello,
I have developed a nice map on Map Viewer, where I carefully designed the coloring and labeling for each layer (coming from hosted feature layer on ArcGIS Online).
Now I would like to reuse that map, to represent an other country, without overwriting all the hosted feature layers I have previously done. I have managed to copy the MapViewer (with "save as") but I don't manage to change the source of each layer.
Is manually doing the same edition for each new map I create the only way to do that ?
Thanks in advance for your help and support,
Kilian
Solved! Go to Solution.
There's no out of the box tool to change the layer source in the web map.
You can use third-party tools to update the Web Map JSON directly. This directly modifies the underlying map code to change the source. Esri has such a tool known as the 'ArcGIS Assistant'.
https://assistant.esri-ps.com/
Third-party apps, including the ArcGIS Assistant, are not supported. Any issues that arise from using these tools are not supported by Esri. So make sure you make a copy of your map, or the map JSON, before using the tools to modify the URLs for services in web maps.
Of course your new service will need to align with your old one, to ensure any applied properties will persist.
There's no out of the box tool to change the layer source in the web map.
You can use third-party tools to update the Web Map JSON directly. This directly modifies the underlying map code to change the source. Esri has such a tool known as the 'ArcGIS Assistant'.
https://assistant.esri-ps.com/
Third-party apps, including the ArcGIS Assistant, are not supported. Any issues that arise from using these tools are not supported by Esri. So make sure you make a copy of your map, or the map JSON, before using the tools to modify the URLs for services in web maps.
Of course your new service will need to align with your old one, to ensure any applied properties will persist.
I use a couple of Python API functions to do this kind of thing. The first one downloads the map's source as a JSON file:
def download_data(gis: GIS, item_id: str, save_path: str):
"""
Opens the specified item's data and saves it to the specified path.
:param gis: The GIS connection.
:param item_id: The Item ID to open.
:param save_path: The location to save the item data.
:return: None.
"""
content_mgr = gis.content
item = content_mgr.get(item_id)
if item is None:
raise Exception(f"download_data: Could not open item.")
item_data = item.get_data()
with open(save_path, "w") as output_file:
json.dump(item_data, output_file)
The first thing I do is create a backup copy of this download in case I botch something. Next, I crack the JSON open in a text editor and do whatever I need to do; in your case this would probably be finding and replacing two layer properties:
Sometimes I'll do things like downloading multiple maps and copying symbology or pop-up settings from one and pasting it into another, or writing additional code to bulk update properties.
Then I use this function to push the definition back up:
def update_data(gis: GIS, item_id: str, file_path: str):
"""
Updates the specified item with the data in the specified file.
:param gis: The GIS connection.
:param item_id: The Item ID to update.
:param file_path: The file to update the item with.
:return: None.
"""
content_mgr = gis.content
item = content_mgr.get(item_id)
if item is None:
raise Exception(f"update_data: Could not open item.")
with open(file_path) as input_file:
input_file_data = input_file.read()
if not item.update(data=input_file_data):
raise Exception(f"update_data: update() returned failure code.")
I would definitely recommend trying this workflow out on a map you don't care about first!
Thank you very much for your help on this one. I figured out it wouldn't be as straightforward as I think it should be. I'll try both solutions you guys kindly provided and hope to find a solution.
I've tried @ChristopherCounsell 's solution and it worked great as quick patch. I'll implement @MobiusSnake 's solution in the future when I'll integrate the Python API in my workflow. Thank you !