ArcGIS Python API zoom_to_layer() attribute error

90
3
Jump to solution
08-10-2020 06:28 AM
Highlighted
New Contributor II

I am working with the ArcGIS API for Python mapping widget within the ArcGIS jupyter notebook environment. I've successfully connected to my organization's enterprise portal, grabbed content, mapped it, and set the zoom level manually (see code below). The problem is when I try to zoom to the added layer, at which point I receive the error:

AttributeError: 'MapView' object has no attribute 'zoom_to_layer'

According to the arcgis.widgets documentation page and all other Esri tutorials I've seen zoom_to_layer() exists and I'm using the correct syntax, of "map.zoom_to_layer(layer)".

The only thing I can think of is that since my installation of the API is what comes with ArcGIS 10.7.1 (API version 1.6.1) whereas all the online API documentation pages are for version 1.8.2. Is zoom_to_layer() functionality that has been implemented between those two versions? Or can anyone else think of reasons why this might be erroring?

gis = GIS("portal_url", username="my_username")

contentItem = gis.content.get('content_string')

contentLayer = contentItem.layers[0]

m = gis.map()

m.add_layer(contentLayer)

m.zoom_to_layer(contentLayer) #this errors

# m.zoom = 14 #this works fine

m

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Contributor

Hi Tracy Whelen‌,

I just checked the ArcGIS API for Python V1.6.1 in the following link:

Release v1.6.1 · Esri/arcgis-python-api · GitHub 

The file is downloadable, you can download and check it for yourself. The equivalent notebook file for this link (other Esri tutorials) isusing-the-map-widget.

It looks like  zoom_to_layer  is not available for this version.

I hope that helps.

View solution in original post

3 Replies
Highlighted
Esri Contributor

Hi Tracy Whelen‌,

I just checked the ArcGIS API for Python V1.6.1 in the following link:

Release v1.6.1 · Esri/arcgis-python-api · GitHub 

The file is downloadable, you can download and check it for yourself. The equivalent notebook file for this link (other Esri tutorials) isusing-the-map-widget.

It looks like  zoom_to_layer  is not available for this version.

I hope that helps.

View solution in original post

Highlighted
New Contributor II

Thanks Mehdi! That was helpful confirmation.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Tracy, it seems like your question has been answered.  Please mark a reply correct to close out this question.

Reply
0 Kudos