Arcgis for flex api version3.7 Tutorial: 9. Setting and using map range extent, arcgisversion3.7
The following describes how to set a map range and how to obtain a map range.
If you do not set the MAP range when initializing a map, the default setting information is used, which is the display range of the map that was last saved in the map document. If you use multiple layers or services, the default map range will be the range information of the basemap or the first layer.
To set the MAP range, you must use the extent attribute or the Extent class.
To use the extent attribute, add the <esri: Extent> label and set the coordinates of the range and the ID of the Space reference. The Code is as follows:
<esri:SpatialReference id="wgs" wkid="4326"/><esri:Extent id="extentOfKansas" xmin="-103" ymin="36" xmax="-94" ymax="41" 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 use the Extent class, similar to the above, the approximate tag structure is as follows:
<esri:SpatialReference id="wgs" wkid="4326"/><esri:Map id="myMap"> <esri:extent> <esri:Extent xmin="-103" ymin="36" xmax="-94" ymax="41" 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 range we want to set is not the basemap or the first layer, but the coordinate range of other layers or services that we want to add. You can use the load attribute to set: load = "myMap. extent = myKansasLayer. fullExtent ". The load attribute function is to execute the code in quotation marks when creating a map. Here is the code that sets the MAP range to the specified layer range in the execution quotation marks. 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>
Listens for events that change the MAP range. When you use an ExtentEvent event, the event is activated whenever you pan or scale the map. You can add the MXML tag by adding the MXML tag, or using the ActionScript code, for 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);