In the event that you are using more than one service, the default extent will be the initial extent of the base map or first layer added.
Setting the Initial Extent
There are several options for setting the initial map extent through your code. The easiest way to do so is through the constructor for the map. The constructor for the Map object takes a required parameter which points to <div> element on your page, and an options parameter which can contain the initial extent of the map as well as other options such as the layer used to initialize the map, the inclusion of navigation controls, and others. Click here to see a full description of the available options that can be included in the constructor.
For instance, the following code snippet shows how you can accomplish setting the extent through the constructor. To set the initial extent of the map you will need to know the min and max x and y values of the extent.
You can also accomplish the same task but in a slightly different manner through the use of the setExtent method on Map as you see in the code example below.
You could also set each property of the extent separately.
Setting the Initial Extent when using Multiple Services
If you’re using multiple map services in your application, the default extent will be the initial extent of the base layer. If you know the extent you’d like to use ahead of time then you can include the extent in the map constructor as we’ve shown above. However, at times you will either not know the extent ahead of time or you may want to use the extent of a secondary layer. For instance, if you’re using a map service that shows the extent of the world as your base layer, and a second map service with your local data you’d probably want to set the extent of your application to that of your local data. The code example below from ESRI shows how this can be accomplished through the fullExtent property found on ArcGISMapServiceLayer.
Getting the Current Extent
You can obtain the current map extent through the read-only Map.extent property or through the use of events. The later method for returning the current map extent is through the use of Map events, and specifically the “onExtentChange” event. The topic of events requires a fair amount of explanation so I will save this for my next post, but for now here is an example which uses the “onExtentChange” event to return the current map extent which is then displayed in a <div> tag below the map.