Is there a way to set the initial extent in a web map created in a program?

2324
4
Jump to solution
04-20-2017 01:50 PM
CharlieWare
New Contributor II

I have a python API script that creates a web map from a feature service. I would like to set the initial extent of the map to zoom into the features in the feature service. I can set the initial extent in the Settings tab of the ArcGIS Online UI but cannot find the setting in the web map specification for setting the initial extent through code. 

1 Solution

Accepted Solutions
AtmaMani
Esri Contributor

The extent is preserved as a property of the web map item and not in the web map definition, hence you may not find it in the web map spec. To set the extent using Python API, after publishing the web map, try to update the web map item using

update_parameters = {'extent':bottom_left_X, bottom_left_Y, top_right_X, top_right_Y}
#example - set NY as extent
#update_parameters = {'extent':'-74.227,40.537,-73.601,40.862'}
my_web_map_item.update(update_parameters)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The next time you open the web map, it should load this extent.

View solution in original post

4 Replies
AtmaMani
Esri Contributor

The extent is preserved as a property of the web map item and not in the web map definition, hence you may not find it in the web map spec. To set the extent using Python API, after publishing the web map, try to update the web map item using

update_parameters = {'extent':bottom_left_X, bottom_left_Y, top_right_X, top_right_Y}
#example - set NY as extent
#update_parameters = {'extent':'-74.227,40.537,-73.601,40.862'}
my_web_map_item.update(update_parameters)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The next time you open the web map, it should load this extent.

MaxSquires
Occasional Contributor

like this

bottom_left_X = "-141.108"
bottom_left_Y = "22.055"
top_right_X = "-56.821"
top_right_Y = "52.476"
update_parameters = {'extent': "{}, {}, {}, {}".format(bottom_left_X, bottom_left_Y, top_right_X, top_right_Y)}‍‍‍‍‍
0 Kudos
CharlieWare
New Contributor II

Thanks! That worked. I did have to enclose the string of coordinates in quotes. 

Is this in the documentation somewhere? I can't seem to find it. 

0 Kudos
AtmaMani
Esri Contributor

Thanks, yes, you would have to send it as a string, I updated the answer to reflect this. This part of the Python API is built on top of the ArcGIS REST API so I would recommend looking at a page like this Item Common Properties. That being said, we would like to make every effort to make the Python API doc adequate and suggest the REST API doc as reference to advanced users.