Hello everyone,
I'm creating customs webmaps with points and markers using Python.
I'd like to have Google Maps' satellite imagery (https://mt1.google.com/vt/lyrs=y&x={col}&y={row}&z={level}) as a basemap. In the online MapViewer it's easy to add a tile layer from an url but I don't see how to do it through Python.
The guide to use the widget (https://developers.arcgis.com/python/latest/guide/using-the-map-widget/) doesn't mention how to add a layer from an url as basemap, and I didn't find any solution in the documentation or in this questions board.
I've also tried manually creating a layer in the My Content folder of my Arcgis Location Platform but the add tile and add layer features are different from that in the online MapViewer.
Any help appreciated.
Thank you
You can use the `addDataFromPath` method of a `Map`:
import arcpy
prj = arcpy.mp.ArcGISProject('CURRENT')
m = prj.listMaps('MapName')[0]
lay: arcpy.mp.Layer = m.addDataFromPath(r'https://mt1.google.com/vt/lyrs=y&x={col}&y={row}&z={level}', 'AUTOMATIC')
lay.name = 'Google Hybrid'
prj.save()
Thank you Hayden, unfortunately Cursor tells me arcpy can only be imported when using Arcgis Pro, which I do not have as I use a simple Arcgis online account.
In that case you'll have to use the Arcgis API for Python. Arcpy is mostly for managing a Pro instance and wrangling tools/data.
The general flow should be the same though.
This works for me, but it's not google maps.
import arcpy
import os
# Get project and map
prj = arcpy.mp.ArcGISProject('CURRENT')
m = prj.listMaps()[0] # Gets the first map
# Path to connection file
conn_path = os.path.join(os.environ['USERPROFILE'], 'Documents', 'ArcGIS', 'Connections', 'GoogleMaps.wmts')
try:
# Add the connection
lyr = m.addDataFromPath(conn_path)
lyr.name = "Google Satellite"
# Refresh view
aprx = arcpy.mp.ArcGISProject('CURRENT')
#aprx.save()
print("Successfully added Esri World Imagery")
except Exception as e:
print(f"Error: {str(e)}")
# Alternative legal basemap if Google fails
world_imagery = m.addDataFromPath(r"https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer")
world_imagery.name = "Esri World Imagery"
Thank you Tony, unfortunately Cursor tells me arcpy can only be imported when using Arcgis Pro, which I do not have as I use a simple Arcgis online account.