Select to view content in your preferred language

Zooming 2 Layers in WebMap with ArcGIS using Python?

3121
5
Jump to solution
07-30-2019 07:18 PM
VitorRibeiro
New Contributor

I am using the ArcGIS library in Python.

I was able to create a WebMap with the command

WebMap ()

I added some Layers on it with the command

add_layer ()

I added property on Web Map

and saved my changes.

But I didn't have Extent (Zoom to layer) in my filtered Layers

I would like to get the extent of the filtered layer to pass the extent in the webmap, does anyone know any way?

Library - https://esri.github.io/arcgis-python-api/apidoc/html/index.html

0 Kudos
1 Solution

Accepted Solutions
DerrickWong
Esri Contributor

Hi Vitor Ribeiro‌,

If you know the extent, you can call

.update(item_properties={'extent': extent})

https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.toc.html#item


					
				
			
			
				
			
			
				
			
			
				

View solution in original post

5 Replies
DerrickWong
Esri Contributor

Hi Vitor Ribeiro‌,

You should be able to grab the extent from the layer object that is returned from a search:

Here's a sample code:

from arcgis.gis import GIS
gis = GIS("https://ABC.maps.arcgis.com", "USERNAME", "PASSWORD")
search_result = gis.content.search('title:LayerOfInterest', item_type = 'Feature Service')

if len(search_result) > 0:
   layer = search_result[0] #assuming we want the first layer.
   print(layer.extent)

Attached is a screenshot of the code running on my AGOL with the results displayed in the output.

Hope that helps.

VitorRibeiro
New Contributor

This form works, but returns something empty.

These steps I followed to child Web Map with my desired information. The biggest problem is zooming to the extent of Filtered Layers.

- I created WebMap ()

- Add 2 layers to wb

- I gave a definitionExpression on my layers (as shown in print)

- Set up webmap_item_properties with title

- snippet and tags

- I finally saved the Web Map

Unfortunately the extent of the Map is too far away, showing the entire globe of the basemap. I would like to know if it is possible to zoom the moment you filter in definitionExpression?

Here's a screenshot of my Jupyter Notebook

In the empty line was my sql, but I had personal information and could not publish, but it was working

0 Kudos
DerrickWong
Esri Contributor

Hi Vitor Ribeiro‌,

If you know the extent, you can call

.update(item_properties={'extent': extent})

https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.toc.html#item


					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
Carlode_Stefano
New Contributor

 @DerrickWong i'm calling the extent of the feature im interested, but when i publish the webmap the zoom is still at global level. How could i fix it? 

0 Kudos
DerrickWong
Esri Contributor

Hi @Carlode_Stefano 

How are you publishing the web map and where are you viewing it from?

If using the map widget from Jupyter Notebook, you can configure the desired zoom level via the attribute zoomlevel

If you are using Publish Item, you can specify the extent in the layerInfo object.

Alternatively, you can always open up the web map in Portal/AGOL and change the extent/zoom and save the changes manually.

 

Hope that helps.

 

Derrick

 

0 Kudos