An ArcGIS web map is an interactive display of geographic information through a composition of web layers, basemap and much more. A web scene is analogous to a web map but in the 3D space. To get an overview, visit the product documentation for web maps and web scenes.
This sample demonstrates how to create and publish simple examples of web maps and scenes using the Python API. If you are interested in learning more about the specification to author and publish complex and more illustrative maps, refer to this documentation.
import json
from arcgis.gis import GIS
from arcgis.map import Map, Scene
# connect to your GIS
# Create a connection to ArcGIS Online to search for contents
gis = GIS(profile="your_online_profile")
Publish a web map
The ArcGIS API for Python extends the WebMap
class with the capability to author new web maps and edit existing ones. You can perform basic operations such as adding, and removing layers.
# Create an empty web map with a default basemap
wm = Map()
The above creates a simple web map. This web map consists of a basemap web layer and an array of operational web layers. The opertaional layer is empty without any web layer urls. We will search for a public web layer titled USA 2020 Census Housing Characteristics - Legislative Geographies published by esri_demographics account and apply that as an operational layer for this web map.
search_result = gis.content.search("title:USA 2020 Census Housing Characteristics - Legislative Geographies and owner:esri_demographics", outside_org = True)
display(search_result)
[<Item title:"USA 2020 Census Housing Characteristics - Legislative Geographies" type:Feature Layer Collection owner:esri_demographics>, <Item title:"USA 2020 Census Race and Ethnicity Characteristics - Legislative Geographies" type:Feature Layer Collection owner:esri_demographics>, <Item title:"USA 2020 Census Age and Sex Characteristics - Legislative Geographies" type:Feature Layer Collection owner:esri_demographics>, <Item title:"USA 2020 Census Household Characteristics - Legislative Geographies" type:Feature Layer Collection owner:esri_demographics>, <Item title:"USA 2020 Census Population Characteristics - Legislative Geographies" type:Feature Layer Collection owner:esri_demographics>, <Item title:"USA 2020 Census Household Population Characteristics - Legislative Geographies" type:Feature Layer Collection owner:esri_demographics>, <Item title:"USA 2020 Census Group Quarters Population Characteristics - Legislative Geographies" type:Feature Layer Collection owner:esri_demographics>]
housing_census_legislative_item = search_result[0]
display(housing_census_legislative_item)
Add an operational layer to the web map
To add 'USA Demographic and Housing Characteristic' web layer as an operational layer, you can call the add()
method found on the MapContent
class and pass the FeatureLayer
object.
#query the layers in the item
housing_census_legislative_item.layers
[<FeatureLayer url:"https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Census_2020_DHC_Housing_Units_Legislative/FeatureServer/0">, <FeatureLayer url:"https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Census_2020_DHC_Housing_Units_Legislative/FeatureServer/1">, <FeatureLayer url:"https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Census_2020_DHC_Housing_Units_Legislative/FeatureServer/2">, <FeatureLayer url:"https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Census_2020_DHC_Housing_Units_Legislative/FeatureServer/3">]
# access the Map Content class
wm.content
Map Content
# add each layer individually
for lyr in housing_census_legislative_item.layers:
wm.content.add(lyr)
for lyr in wm.content.layers:
print(lyr.properties.name)
Nation Congressional District State Legislative Districts Upper State Legislative Districts Lower
Publish the web map as an item to the portal
Now that the web map content is ready, we will use the save()
method to save the WebMap
object as a web map item in the GIS. As parameters to the save()
method, you need to specify some essential properties for the new web map item.
web_map_properties = {'title':'USA 2020 Census Housing Characteristics - Legislative Geographies',
'snippet':'This map service shows Demographic and Housing Characteristics information' +\
'in the United States as of 2020 census.',
'tags':'ArcGIS Python API'}
# Call the save() with web map item's properties.
web_map_item = wm.save(item_properties=web_map_properties)
web_map_item
Display the web map
We have successfully published a web map with consisting of a basemap and desired web layer as the operational layer. We will read the published map as a WebMap
object and interact with it.
web_map_obj = Map(item=web_map_item)
# display the web map in an interactive widget
web_map_obj
Publish a web scene
So far, we have seen how to publish a web map. In this section, we will observe how to publish a web scene.
# get layers to add to a Scene
search_result = gis.content.search("title:Buildings_Montreal AND owner:esri_3d",
item_type="scene service", outside_org = True)
display(search_result)
[<Item title:"Buildings_Montreal_2016" type:Scene Layer owner:esri_3d>, <Item title:"Buildings_Montreal" type:Scene Layer owner:esri_3d>, <Item title:"Montreal, Canada Buildings" type:Scene Layer owner:esri_3d>]
buildings_layer = search_result[1]
display(buildings_layer)
ws = Scene()
ws.content
Scene Content
ws.content.add(buildings_layer)
ws.content.layers
[<Object3DLayer url:"https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Building_Montreal/SceneServer/layers/0">]
Publish the web scene as an item to the portal
We will use similar workflow through the Scene class.
web_scene_item_properties = {'title':'Web scene with photo realistic buildings',
'snippet':'This scene highlights buildings of Montreal, Canada',
'tags':'ArcGIS Python API'}
# Use the add() method to publish a new web scene
web_scene_item = ws.save(web_scene_item_properties)
web_scene_item.sharing.sharing_level="EVERYONE"
display(web_scene_item)
Display the web scene
We have successfully published a web scene with consisting of a basemap, elevation layer and desired web layer as the operational layer. We will read the published scene as a WebScene
object and interact with it.
web_scene_obj = Scene(item=web_scene_item)
# display the interactive web scene in the notebook
web_scene_obj
