博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2010年8月19日周四_insideTheAPI_Using Extent_6.4

Posted on 2010-08-20 07:05  星尘的天空  阅读(319)  评论(0编辑  收藏  举报

/*******************************************************************************/

//insideTheAPI

//Using Extent

//2010年8月19日_周四

/******************************************************************************/

 

NOTE: The following discussion assumes that you are familiar with the basic concepts of Flex.

This tutorial describes several ways to set a map's extent as well as how to retrieve the extent for use in other operations.

If you do not include extent information when you initialize a map, the default extent is used, which is the extent of the map as it was last saved in the map document. If you use multiple layers, or services, the default extent is the initial extent of the basemap or first layer added.

下面的教程假设你对Flex的基本的概念有一定的了解。

这个教程展示来若干种方法来设置一个地图的显示范围,以及如何在其他的操作中重新获取Extent使用。

如果你在地图初始化的时候没有包含extent信息,那么将会使用默认的范围,这个范围就是地图文档最后一次保存的时候显示的范围。如果你使用multiple layers,或者服务,默认的范围是基础地图开始的范围或者添加的第一个图层。

 

How to set an extent

To set an initial extent that is different from the default extent, use the extent property or Extent class.

Set the map extent using the extent property.

Add your map.

Insert the <esri:Extent> tag and specify the ID and coordinates.

Add the <esri:ArcGISDynamicMapServiceLayer> tag.

Your code should look similar to below.

如何设置一个Extent

设置一个开始的范围内和默认的范围是不相同的,使用extent属性或者Extent类。

使用Extent 属性设置地图显示范围

插入<esri:Extent>标签并定义ID和坐标系。

添加<esri:ArcGISDynamicMapServiceLayer>标签。

你的代码应该和下面的类似。

<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>

//

View another sample map extent set using the extent property.

Set the initial map extent using the Extent class.

Add your map.

Add the <esri:SpatialReference> tag and specify the desired projection and well-known ID.

Insert the <esri:extent> tag and specify the ID and coordinates.

Add the <ArcGISTiledMapServiceLayer> tag.

Your code should look similar to below.

观看另外一个例子,使用EXTENT属性设置地图范围

使用Extent类设置地图开始时的显示范围。

添加你的地图。

添加<esri:SpatialReference> 标签,指定要求的映射和ID。

插入<esri:extent>标签,指定ID和坐标系

添加<ArcGISTiledMapServiceLayer>标签。

你的代码应该和下面的类似。

<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>

View another sample map extent set using the Extent class.

How to set an extent when using multiple services

In some cases, you may want to use the extent of a layer that is not the initial layer or basemap. To do this, set the map extent to the extent of the desired layer.

In the following example, two layers are used: the base layer—ArcGIS Online world extent—and a second layer—the state of Kansas.

To set Kansas as the extent, add a load property that sets the extent of the map.

load="{myMap.extent=myKansasLayer.fullExtent}"

The load property creates the map and, when loaded, sets the full extent to the Kansas layer.

The code below sets the map extent to myKansasLayer using fullExtent.

查看另外一个使用EXTENT类设置地图范围的例子。

如何使用multiple services设置一个范围。

在一些情况下,你可能想使用一个图层的显示范围,这个范围不是图层开始的范围也不是基础地图的范围。 为了达到这个目的,设置地图的范围为所要求的图层的范围。

在随后的例子中,有两个图层被使用:基础图层-ArcGIS在线地世界地图范围,另外的一个图层:Kansas州。

为了设置Kansas作为范围,添加load属性设置地图的范围。

load="{myMap.extent=myKansasLayer.fullExtent}"

load属性创建了地图,当加载完成后,设置Kansas图层完全显示。

下面的代码使用FullExtent设置地图的范围为myKansasLayer

 

<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>

NOTE: If you want to set the initial extent instead of the full extent, use myKansasLayer.initialExtent.

How to get the current extent

Retrieve the current map extent using the extent property.

How to listen to extent changes

The map will fire off an ExtentEvent every time the user pan or zooms the map. You can add an event listener using either mxml or ActionScript to be notified of extent changes. See for example the Event sample

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>

ActionScript example:

myMap.addEventListener(ExtentEvent.EXTENT_CHANGE, extentChangeHandler);

注意:如何你想设置开始的范围而不是全幅显示,使用myKansasLayer.initialExtent.

如果获取当前地图范围。

使用extent 属性返回当前地图的范围。

如何侦听范围改变事件。

每次用户平移或者缩放地图,都会触发一个EXTENTEvent事件。你可以使用MXML或者脚本添加一个事件侦听,然后通知范围改变事件。查看例子Event sample

MXML实例

<esri:Map id="myMap" extentChange="displayExtent()">

    <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />

</esri:Map>

脚本示例

myMap.addEventListener(ExtentEvent.EXTENT_CHANGE, extentChangeHandler);