arcgis api for flex 开发入门(二)map 的创建
bO
?,icjo0mE%?0在flex 中创建一个esri 的map ,你只需要使用<esri:Map>标签就可以轻松完成
。
UcqJAtbn-m0在<esri:Map>标签中可以添加属性和响应事件的消息。3sNews.Net——3S社区&资讯平台(Zy]P-SX L~
如下:
*io2e+j;U2KAS
b.B#@Z:w0<esri:Map width="100%" height="50%" id="EsriMap"
creationComplete="EsriMapCreateComplete()" resize="EsriMapResize
(event);" extentChange="ESRIMapExtentChange(event);"
mouseMove="OnDrawMouseMove(event)" />3sNews.Net——3S社区&资讯平台.KEwNAW]7Rf
width和 height定义的map 的大小,id="EsriMap" 唯一标识了这个map。3sNews.Net——3S社区&资讯平台 m;[E'} yj
针对map 的消息也有很多,最常用的就是creationComplete,resize和鼠标消息
了。
,u#^(c4Qlx8Tts;W$g:j0现在我们map有了,那么我们如何让她显示数据呢,这就需要给 <esri:Map>标签
添加一个layer 子标签 。
]SS#B0EX&h0在ags flex api 中有以下几种类型的layer。
'T V)F(o
UrJ;C6r0 ArcGISDynamicMapServiceLayer :Allows you to work with a dynamic map
service resource exposed by the ArcGIS Server REST API.3sNews.Net——3S社区&资讯平台3T'L`*w'E,cZ;q
ArcGISImageServiceLayer: Allows you to work with an image service
resource exposed by the ArcGIS Server REST API.
{y3pK.pf*g7^c9{O.k0 ArcGISMapServiceLayer :The base class for ArcGIS Server map
services.
3w sb4K
X)^T2qbx0 ArcGISTiledMapServiceLayer :Allows you to work with a cached map
service resource exposed by the ArcGIS Server REST API.3sNews.Net——3S社区&资讯平台
P%p^TE5E
ArcIMSMapServiceLayer :Allows you to work with an ArcIMS image
service.
GPResultImageLayer :Allows you to view a geoprocessing task result
identified by jobId and parameterName.3sNews.Net——3S社区&资讯平台6yf&_zQHL:x
GraphicsLayer: A layer that contains one or more Graphic features.
4~L6N.Qn2vqS#k0其中GraphicsLayer是支持客户端添加Graphic features的图层,需要在客户端表
现的,或者交互操作中产生的要素都要加到这个layer 上。
`g`Eb0下面,我们就添加一个ArcGISTiledMapServiceLayer和GraphicsLayer到map 上。
3sNews.Net——3S社区&资讯平台_+joM-h\R0u!oJ
<esri:Map width="100%" height="50%" id="EsriMap"
creationComplete="EsriMapCreateComplete()" resize="EsriMapResize
(event);" extentChange="ESRIMapExtentChange(event);"
mouseMove="OnDrawMouseMove(event)" >3sNews.Net——3S社区&资讯平台!X'L#P%oqd%z
<esri:ArcGISTiledMapServiceLayer
url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap
_World_2D/MapServer" />
)A/C6];p5X-x,y0<esri:GraphicsLayer id="myGraphicsLayer" spatialReference="{sr}"/>3sNews.Net——3S社区&资讯平台+U3R&^h.?g
</esri:Map>
[*Xp5c%Piqh m0@0其中<esri:ArcGISTiledMapServiceLayer>标签中的url 属性为提供该服务的地址
。<esri:GraphicsLayer>标签其中的spatialReference属性定义了该图层的空间
参考系。3sNews.Net——3S社区&资讯平台!O+cR9L$k4Z5{2@&Z
创建一个空间参考系,只需要使用<esri:SpatialReference>标签就可以了,其中
wkid 是esri已经定义好的空间草考系的ID,具体ID对应的空间参考可以在
http://resources.esri.com/help/9.3/arcgisserver/apis/REST/index.html?
gcs.html中查找。如下为创建一个kid="4326"的空间参考系。
#t"Hmi.HR6j0<esri:SpatialReference id="sr" wkid="4326"/>
那么,我们如何定义我们想显示的范围呢?
s9EGt} dKP,^0很简单,在<esri:Map>下面添加<esri:extent>子标签,我们就可以来控制当前的
显示范围了。
oX\g.j0 <esri:extent>3sNews.Net——3S社区&资讯平台9D
p;y
]v/_kzf c
<esri:Extent id = "esriMapExtent" xmin="116"
ymin="39.5" xmax="116.5" ymax="40.5"/>
E7F8yx0y]#K
O9r0 </esri:extent>3sNews.Net——3S社区&资讯平台s rqW|.c.E
其中x是经度,y 是纬度。
这样一个北京地区的map 就可以显示到我们面前了。
完整代码如下
<?xml version="1.0" encoding="utf-8"?>3sNews.Net——3S社区&资讯平台8}
~9l|O/a
<mx:Application
s6u"Kvto lm0 xmlns:mx="http://www.adobe.com/2006/mxml"
9Nz*A.o6d["m0 xmlns:esri="http://www.esri.com/2008/ags"
P9?h7^k f+g9~m0 pageTitle="Using ArcGIS API for Flex to connect to a cached ArcGIS Online service"
J2d)@QXB!u]0 styleName="plain">3sNews.Net——3S社区&资讯平台K~^#{2oF@CD"]K
<esri:SpatialReference id="sr" wkid="4326"/>3sNews.Net——3S社区&资讯平台8u,TZpDv~
<esri:Map crosshairVisible="true">
RQQ#x@;N1h*f[f0 <esri:extent>3sNews.Net——3S社区&资讯平台6W*Q3jv4H
<esri:Extent id = "esriMapExtent" xmin="116" ymin="39.5" xmax="116.5" ymax="40.5"/>
:tF
V/o)hU3g4q7o*dW0 </esri:extent>3sNews.Net——3S社区&资讯平台r a5G(k.T$l
<esri:ArcGISTiledMapServiceLayer3sNews.Net——3S社区&资讯平台.thCT9BH:^e
url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />3sNews.Net——3S社区&资讯平台/mG7YeX8tvi
<esri:GraphicsLayer id="myGraphicsLayer" spatialReference="{sr}"/>
aXX0k_ X0 </esri:Map>
1_3z}V(qb+n:}PIwK_z0</mx:Application>
b5NIU9FZ*D*O/Y0Flash:最后效果
H"nE|LA!J5@0