Here's a series of ways to set the map extent and how to get the map extent.
If you do not set the map extent when you initialize the map, the default settings information will be used, which will be the extent of the map displayed when you last saved the map document you are using. If you use multiple layers, or a service, the default map extent will be the extent information for the BASEMAP or the first layer.
To set the map extent, use the extent property or the extent class.
If you are using the Extent property, follow these steps: Add <esri:Extent> tag, and set the coordinate value for the range and the ID of the spatial reference as follows:
<esri:spatialreference id= "WGs" wkid= "4326"/><esri:extent id= "Extentofkansas" xmin= " -103" ymin= "xmax="- 94 "ymax=" " spatialreference=" {WGS} "/><esri:map id=" MyMap "extent=" {Extentofkansas} "> <esri : Arcgistiledmapservicelayer url= "http://server.arcgisonline.com/ArcGIS/rest/services/ esri_streetmap_ World_2d/mapserver "/> <esri:arcgisdynamicmapservicelayer id=" Mylayer " url="/http/ sampleserver1.arcgisonline.com/arcgis/rest/services/ Petroleum/kgs_oilgasfields_kansas/mapserver "/>< /esri:map>
If you are using the extent class, similar to the above, the approximate label structure is as follows:
<esri:spatialreference id= "WGs" wkid= "4326"/><esri:map id= "MyMap" > <esri:extent> < Esri:extent xmin= " -103" ymin= "xmax=" -94 "ymax=" "" Spatialreference= "{WGS}"/> </esri:extent> <esri:arcgistiledmapservicelayer url= "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ Streetmap_world_2d/mapserver "/> <esri:arcgisdynamicmapservicelayer id=" Mylayer " url="/http/ Sampleserver1.arcgisonline.com/arcgis/rest/services/petroleum/kgs_oilgasfields_kansas/mapserver "/></esri :map>
In some cases, the map extent that we want to set is not the Basemap or the first layer, but the coordinate range of the other layers or services added. You can set it by using the Load property: load= "mymap.extent = mykansaslayer.fullextent". The function of the load property is to execute the code inside the quotation marks when the map is created. Here is the code that executes the quotation marks inside this section to set the map extent to the specified layer range. The reference code is as follows:
<esri:map id= "MyMap" > <esri:arcgistiledmapservicelayer url= "http://server.arcgisonline.com/ arcgis/rest/services/ esri_streetmap_world_2d/mapserver "/> <esri:arcgisdynamicmapservicelayer load= "mymap.extent = mykansaslayer.fullextent" id= "Mykansaslayer" url= "/http/ sampleserver1.arcgisonline.com/arcgis/rest/services/ Petroleum/kgs_oilgasfields_kansas/mapserver "/>< /esri:map>
Events are monitored for changes in the map extent, using the Extentevent event, which is activated whenever the user pans or zooms the map. You can add the mxml tag by adding it, or you can add it through ActionScript code, as shown in the following example:
MXML Example:
<esri:map id= "MyMap" extentchange= "Displayextent ()" > <esri:arcgistiledmapservicelayer url= "http ://server.arcgisonline.com/arcgis/rest/services/ Esri_streetmap_world_2d/mapserver "/></esri:Map>
As Example:
Mymap.addeventlistener (Extentevent.extent_change, Extentchangehandler);
ArcGIS for Flex API version3.7 Tutorial: 9. Setting and use of map extent extent