Advanced Map Widget Useage

This guide covers more advanced uses for the map widget: see using the map widget for more information!

Property Updating

The map widget handles zoom, tilt, heading/rotation, basemap, center, extent, etc. features in an interesting and powerful way. Try running the below cells to gain insight into how these properties are updated:

In [18]:
from arcgis.gis import GIS

def print_map_info(map):
    print("Mode =\t\t{}".format(map.mode))
    if map.mode == "2D":
        print("Zoom =\t\t{}\n".format(map.zoom) + \
              "Rotation =\t{}".format(map.rotation))
    elif map.mode == "3D":
        print("Zoom =\t\t{}\n".format(map.zoom) + \
              "Tilt =\t\t{}\n".format(map.tilt) + \
              "Heading =\t{}".format(map.heading))
        raise Exception("Not supported argument")

usa_map = GIS().map("USA")
usa_map.mode = "3D"
In [3]:
Mode =		3D
Zoom =		1.3856049324356938
Tilt =		0.13085251425698102
Heading =	8.537736462515939e-07

Now, using your mouse, move the map to a new location, zoom in, modify the tilt and heading, etc. After you've move the camera, run the below cell to print out the current state of those properties:

In [4]:
Mode =		3D
Zoom =		4.057564184135124
Tilt =		8.446352685544214
Heading =	15.599097870716443

The values of those python variables have changed when you moved around in the widget! Experiment with printing out the values of center, extent, and any of the above properties. See the API reference for more information.

Then, try clicking on this icon on the upper left corner of the widget:

You'll notice that you've switched from 3D mode to 2D mode! All properties, including map.mode have been updated! Try running the below cell to see what your current values are:

In [5]:
Mode =		2D
Zoom =		4.0
Rotation =	344.40090214146767

You can always click the icon on the upper left corner to switch between 2D and 3D mode. The widget will do it's best to preserve your current view.


You can setup an asyncronous callback using the on_click() or on_draw_end() to create dynamic, interactive 'apps'. You need to create a callback function like function_name(map_inst, geometry), with map_inst being the MapView instance, and geometry being the geometry instance that the user clicked.

The below example takes a point a user clicks on the map, reverse geocodes from the geometry, and prints out the resultant location.

In [14]:
from arcgis.gis import GIS
import arcgis.geocoding as geocoding
gis = GIS()
callback_map ='San Diego convention center, San Diego, CA', 16)
def find_addr(callback_map, g):
        geocoded = geocoding.reverse_geocode(g)
        print("Couldn't match address. Try another place...")