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.

Let us search and access a few web maps:

In [ ]:
import os
import json
from IPython.display import display
import arcgis
from arcgis.gis import GIS

# connect to your GIS
gis = GIS("portalurl","username","password")

Searching for web maps

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

In [ ]:
webmap_search = gis.content.search("", item_type="Web Map")
webmap_search
Out[ ]:
[<Item title:"India" type:Web Map owner:demo_deldev>,
 <Item title:"WM2_public_items" type:Web Map owner:demo_deldev>,
 <Item title:"WM1_private_items" type:Web Map owner:demo_deldev>,
 <Item title:"USA Gun Ownership" type:Web Map owner:deldev>,
 <Item title:"LA County Infrastructure at Risk" type:Web Map owner:demo_deldev>,
 <Item title:"Mass shootings" type:Web Map owner:deldev>,
 <Item title:"Chennai_Lakes_Map" type:Web Map owner:demo_deldev>,
 <Item title:"Ebola treatment locations" type:Web Map owner:demo_deldev>]

Let us take a look at the 'Ebola web map'

In [ ]:
ebola_map_item = webmap_search[-1]
ebola_map_item
Out[ ]:
Ebola treatment locations
This map shows locations of Ebola treatment centers in AfricaWeb Map by demo_deldev
Last Modified: December 15, 2016
0 comments, 0 views

Creating a WebMap object

You can create a WebMap object using the constructor and passing the web map item as the parameter:

In [ ]:
from arcgis.mapping import WebMap
ebola_map = WebMap(ebola_map_item)

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

In [ ]:
ebola_map['operationalLayers']
Out[ ]:
[{'id': 'layer1',
  'itemId': 'a24ae8550ea34a449699479b7e35217d',
  'layerType': 'ArcGISFeatureLayer',
  'opacity': 1,
  'title': 'Ebola_Treatment_Units - Ebola_Treatment_Units_Classed',
  'url': 'http://services6.arcgis.com/SMX5BErCXLM7eDtY/arcgis/rest/services/Ebola_Treatment_Units/FeatureServer/1',
  'visibility': True}]

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

In [ ]:
ebola_map['baseMap']
Out[ ]:
{'baseMapLayers': [{'id': 'World_Topo_Map_9991',
   'layerType': 'ArcGISTiledMapServiceLayer',
   'opacity': 1,
   'title': 'World Topographic Map',
   'url': 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer',
   'visibility': True}],
 'title': 'Topographic'}

You can find the list of all keys that you can query for by calling the keys() function:

In [ ]:
ebola_map.keys()
Out[ ]:
odict_keys(['version', 'baseMap', 'spatialReference', 'operationalLayers'])

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:

In [ ]:
ebola_map

ebola map

Updating a web map

The WebMap object provides an update() method that allows you to modify a web map and save those changes back. To update a web map, 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 map for an example.

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

In [ ]:
webscene_search = gis.content.search("", item_type="Web Scene")
webscene_search
Out[ ]:
[<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.

In [ ]:
webscene_item = webscene_search[0]
webscene_item
Out[ ]:
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:

In [ ]:
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.

In [ ]:
webscene_obj['operationalLayers']
Out[ ]:
[{'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:

In [ ]:
webscene_obj.keys()
Out[ ]:
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:

In [ ]:
webscene_obj

tropical cyclones web scene

Updating a web scene

The WebScene object provides an update() method that allows you to modify a web map 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.


Feedback on this topic?