arcgis.mapping module contains classes and functions to represent and interact with web maps, scenes, and certain layer types such as map image and vector tiles. In this page we will observe how to visualize maps, scenes and layers using the map widget in Jupyter notebook environment.
Using the map widget¶
GIS object includes a map widget for displaying geographic locations, visualizing GIS content, as well as the results of your analysis. To use the map widget, call
gis.map() and assign it to a variable, that you can then query to bring up the widget in the notebook:
import arcgis from arcgis.gis import GIS # Create a GIS object, as an anonymous user for this example gis = GIS()
# Create a map widget map1 = gis.map('Paris') # Passing a place name to the constructor # will initialize the extent of the map. map1
The map widget has several properties that you can query and set, such as its zoom level, basemap, height, etc:
Assigning a value to the
zoom property will update the widget.
map1.zoom = 10
Let us query the basemap property of the widget
Your notebook can have as many of these widgets as you wish. Let us create another map widget and modify some of its properties.
map2 = gis.map() # creating a map object with default parameters map2
Assigning a basemap of your choice to the
basemap property will update the widget.
map2.basemap = 'streets' # more about this in the next section of the sample
You can make the widget bigger or smaller by modifying the height property.
map2.height = '200px'
center property reveals the coordinates of the center of the map.
If you know the latitude and longitude of your place of interest, you can assign it to the center property.
map2.center = [34,-118] # here we are setting the map's center to Los Angeles
You can use geocoding to get the coordinates of place names and drive the widget. Geocoding convert place names to coordinates and can be used using
Let us geocode
Times Square, NY and set the map's extent to the geocoded location's extent.
location = arcgis.geocoding.geocode('Times Square, NY', max_locations=1) map2.extent = location['extent']
ArcGIS Online includes several basemaps from Esri that you can use in your maps. Let us list them.
from IPython.display import display #basemaps are of type Web Map basemaps = gis.content.search("tags:esri_basemap AND owner:esri", item_type = "web map") for basemap in basemaps: display(basemap)
When a map widget is created as seen in the samples above, a number of Esri basemaps are included with widget. You can list them using the
# Let us create another map widget for this part of the sample map3 = gis.map('New York')
['streets', 'satellite', 'hybrid', 'topo', 'gray', 'dark-gray', 'oceans', 'national-geographic', 'terrain', 'osm']
Let us animate our widget by cycling through basemaps and assigning it to the
basemap property of the map widget.
import time for basemap in map3.basemaps: map3.basemap = basemap time.sleep(3)
Some Esri partners and other users have also shared their basemaps for everyone to use. Let us search for them, but this time using
tags property of the items:
stamenbasemaps = gis.content.search("tags:partner_basemap owner:dkensok stamen", item_type="web map", max_items=3) for basemap in stamenbasemaps: display(basemap)
Feedback on this topic?