Working with web maps and web scenes

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 and overview, visit the product documentation for web maps and web scenes.

Web maps and scenes are stored as items on your portal and their content is in JavaScript Object Notation (JSON), a text format that can easily be transferred, stored, and edited. In this guide we will observe how to work maps and scenes using the arcgis.mapping module.

Working with web maps

2D maps in your GIS are stored as web map items. A web map contains a JSON defining the bookmarks, layers, their symbology, order and other cartographic information. If you are interested in learning more about this specification, refer to this documentation. In the mapping module, web maps are represented using a WebMap class. At version 1.3 of the Python API, the WebMap class has been enhanced with the ability to easily add, remove layers and a few other basic operations.

from IPython.display import display
import arcgis
from arcgis.gis import GIS

# connect to your GIS
gis = GIS('home')

Searching for web maps

We can search for web maps just like any other item:

webmap_search = gis.content.search("Ebola maps", item_type="Web Map")
webmap_search
[<Item title:"Ebola treatment locations - badlayer-original" type:Web Map owner:arcgis_python>,
 <Item title:"Ebola treatment locations" type:Web Map owner:arcgis_python>,
 <Item title:"Ebola treatment locations" type:Web Map owner:arcgis_python>,
 <Item title:"Ebola treatment locations - badlayer" type:Web Map owner:arcgis_python>,
 <Item title:"better ebola map" type:Web Map owner:arcgis_python>]

Let us take a look at one of the web maps

ebola_map_item = webmap_search[1]
ebola_map_item
Ebola treatment locations
This map shows locations of Ebola treatment centers in AfricaWeb Map by arcgis_python
Last Modified: December 06, 2017
0 comments, 2 views

Creating a WebMap object

You can create an empty web map with a default basemap and no operational layers from the WebMap class:

from arcgis.mapping import WebMap
empty_webmap = WebMap()
empty_webmap.layers
[]

You can also create a WebMap object from an existing web map item by passing the web map item as the parameter to the constructor:

ebola_map = WebMap(ebola_map_item)

A typical web map consists of a few operational layers and one or more basemap layers. To view the operational layers, call the layers property:

for layer in ebola_map.layers:
    print(layer.title)
Ebola_Treatment_Units - Ebola_Treatment_Units_Unclassed
Ebola_Treatment_Units - Ebola_Treatment_Units_Classed

Similarly, you can find what basemap is used in this web map by querying the baseMap property:

ebola_map.basemap
{
  "baseMapLayers": [
    {
      "id": "World_Topo_Map_9991",
      "layerType": "ArcGISTiledMapServiceLayer",
      "url": "https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",
      "visibility": true,
      "opacity": 1,
      "title": "World Topographic Map"
    }
  ],
  "title": "Topographic"
}

At any time, you can get the full definition of the web map by calling the definition property:

ebola_map.definition.spatialReference
{
  "wkid": 102100,
  "latestWkid": 3857
}

You can also cast the definition into a Python dictionary and print out the keys:

dict(ebola_map.definition).keys()
dict_keys(['operationalLayers', 'baseMap', 'spatialReference', 'authoringApp', 'authoringAppVersion', 'version'])

Displaying the web map

When using the Jupyter notebook environment, a WebMap object can be easily visualized by simply querying it. A map widget loads up and the map is rendered:

ebola_map

img: ebola webmap

Removing layers from a web map

You can update a web map by adding or removing layers. For instance, the cell below removes one of the layers from the web map and adds a different layer.

# remove the first - unclassed layer from the map
ebola_map.remove_layer(ebola_map.layers[0])

Adding layers to a web map

To add new layers, call the add_layer() method. You can layer objects such as FeatureLayer, ImageryLayer, FeatureCollection objects and also Item objects. When adding a layer to the web map you can specify options such as title, custom symbols, visibility, opaticy etc. The code below adds a feature layer collection item to the web map.

liberia_item = gis.content.get('49161527a2bc4f4782b50d2c14e38f4a')
ebola_map.add_layer(liberia_item, options={'title':'Liberia facilities and hospitals'})
True

Saving or Updating a web map

To save a web map, simply call the save() method. Similarly, if you created the WebMap object from an existing web map item, then you can call the update() method to update it.

Note, save() method always creates a new item with updated web map definition, so if you want to create a copy of an existing web map, this is a great way. For instance, the cell below calls the save() method and creates a new web map item with the new set of layers without disturbing the original Ebola web map item.

webmap_item_properties = {'title':'Ebola incidents and facilities',
                         'snippet':'Map created using Python API showing locations of Ebola treatment centers',
                         'tags':['automation', 'ebola', 'world health', 'python']}

ebola_map.save(webmap_item_properties, thumbnail='./webmap_thumbnail.png')
Ebola incidents and facilities
Map created using Python API showing locations of Ebola treatment centersWeb Map by arcgis_python
Last Modified: December 06, 2017
0 comments, 0 views

Working with web scenes

In your GIS, 3D maps are stored as web scene items. Similar to web maps, web scenes contain the definition of the layers, their cartography in JSON. In the mapping module, a web scene is represented using a WebScene object.

You can search for a web scene similar to any other item:

Searching for web scene items

webscene_search = gis.content.search("", item_type="Web Scene")
webscene_search
[<Item title:"Toprical Cyclones - Summer" type:Web Scene owner:demo_deldev>,
 <Item title:"Toprical Cyclones - Summer" type:Web Scene owner:demo_deldev>,
 <Item title:"Toprical Cyclones - Summer" type:Web Scene owner:demo_deldev>,
 <Item title:"Toprical Cyclones - Summer" type:Web Scene owner:demo_deldev>,
 <Item title:"Toprical Cyclones - Summer" type:Web Scene owner:demo_deldev>]

Let us access the first web scene from this list.

webscene_item = webscene_search[0]
webscene_item
Toprical Cyclones - Summer
Subset of Western Pacific Typhoons (2005) published by esri_3dWeb Scene by demo_deldev
Last Modified: December 15, 2016
0 comments, 1 views

Creating a WebScene object

You can create a WebScene object using the constructor and passing the web scene item as the parameter:

from arcgis.mapping import WebScene
webscene_obj = WebScene(webscene_item)

The WebScene object provides a dictionary representation of the information contained in the web scene. For instance, you can view the list of layers in this web map by querying the operationalLayers key.

webscene_obj['operationalLayers']
[{'id': '14a37c397dc-layer17',
  'layerType': 'GroupLayer',
  'layers': [{'id': '56803f3d64184140950f0ef1256a0603',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Pushpin 1',
        'styleName': 'EsriIconsStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'all',
         'minSize': 25,
         'type': 'sizeInfo',
         'valueUnit': 'unknown'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'showLabels': True,
    'title': 'Labels Q2',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/5',
    'visibility': False},
   {'id': '72668fcc8a904bd6a1444bef2e72f420',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Standing Cylinder',
        'styleName': 'EsriThematicShapesStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'height',
         'field': 'windspeed',
         'minDataValue': 0.0001,
         'minSize': 1,
         'type': 'sizeInfo'},
        {'axis': 'widthAndDepth',
         'minSize': 100000,
         'type': 'sizeInfo',
         'valueUnit': 'meters'},
        {'field': 'airpressure',
         'stops': [{'color': [245, 0, 0], 'value': 920},
          {'color': [245, 245, 0], 'value': 1014}],
         'type': 'colorInfo'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'popupInfo': {'mediaInfos': [{'caption': "<div><p><span style='font-weight:bold;'>Pressure: </span><span>{airpressure} hPa</span></p><p><span style='font-weight:bold;'>Wind speed: </span><span>{wind_mph} mph / {wind_kph} kph</span></p><p><p><span style='font-weight:bold;'>Date: </span><span>{timedescription}</span></p></div></p>",
       'title': "<div><p style='font-weight:bold;'><span>{typhoonclass} {typhoon}</span></p></div>",
       'type': 'image',
       'value': {'sourceURL': '{image}'}}],
     'title': '{typhoon}'},
    'title': 'Typhoons Q2',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/4',
    'visibility': False}],
  'listMode': 'hide-children',
  'opacity': 1,
  'title': 'April - June',
  'visibility': True,
  'visibilityMode': 'inherited'}]

Similar to a WebMap seen earlier, you can find the list of all keys that you can query for by calling the keys() function:

webscene_obj.keys()
odict_keys(['authoringApp', 'baseMap', 'initialState', 'version', 'operationalLayers', 'presentation', 'authoringAppVersion'])

Displaying the web scene

When using the Jupyter notebook environment, a WebScene object can be easily visualized by simply querying it. A map widget loads up and the scene is rendered:

webscene_obj

tropical cyclones web scene

Updating a web scene

The WebScene object provides an update() method that allows you to modify a web scene and save those changes back. To update a web scene, you modify its definition by changing the adding, removing or changing the values of its keys and then call the update() method. Refer to the sample notebook on using and updating a web scene for an example.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.