Add Multiple WMTS Layers Simultaneously to AGOL/Enterprise Web Map

385
2
10-24-2023 09:10 AM
Status: Open
LarryJahn
Occasional Contributor

Currently, when adding WMTS layers to a web map, there is no way to add multiple WMTS layers at a time.  For example, if I have 40 individual county layers of imagery,  I have to go through the process to add imagery 40 times in the web map.  It would be helpful if you could check/select multiple layers to be added simultaneously, similar to the process of adding WMS layers to a web map.

2 Comments
ArchitSrivastava

Hello @LarryJahn ,

This probably is not available through GUI but sure is a good enhancement for future. However, for the time being, I would suggest using python to accomplish this task. 

Here is a sample script which can help (will try to explain which step does what, so you can replace things accordingly for your scenario):

#Import the Modules
from arcgis.gis import GIS
from arcgis.mapping import WebMap
from arcgis.mapping.ogc import WMTSLayer

# Define your ArcGIS Online credentials
username = "your_username"
password = "your_password"
gis = GIS("https://webadaptor.domain.com/webadaptorname", "username", "password")

web_map_id = "your_web_map_id"

# Load the existing web map
web_map = WebMap(gis.content.get(web_map_id))

# List of county WMTS layers you want to add
county_layers = [
{
"name": "Layer_name",
"url": "URL",
},
{
"name": "Layer_name",
"url": "URL",
},
# Add the rest of your county layers here
]

# Loop through the county_layers list and add each layer to the web map
for county in county_layers:
wmts_layer = WMTSLayer(url=county["url"])
web_map.add_layer(wmts_layer, options={"title": county["name"]})

# Update the web map with the added layers
web_map.update()

print("County layers added to the web map.")

Give it a try and let me know if it helps!

-Archit

 

DougBrowning

@ArchitSrivastava Is there a way to query the WMTS for a layer list then loop and add all the layers?  With your code I would have to manually list them all but there are a lot.  That is why I wanted a script.

I can multiselect in Pro if maybe there is a way to add from there?  Trying to add them to an existing map makes it harder.

Also note you can just use gis = GIS('pro')  and it grabs your credentials from Pro.  That way no storing UN and Pass and it works for all users.  Plus works for multifactor and all that.

Edit in the end I just added the service in Pro, did a shift-select on all the layers, added, then published a web map with all of them.  Super fast and easy.  I could even make nested groups then.  Still looking for a way to add to existing maps but it could help someone.

Another edit having all those WMS and WTMS layers in a web map is slowing the map to a halt.  Also out of memory issues.  Pro is just fine.  Bummer really wish the tools could handle more.  Too much backend queries.

Thanks a lot