ArcGIS.Server.9.3和ArcGIS API for Flex的GeometryService和量算距离面积(十一)
2008-11-01 16:32
477 查看
目的:
1.ArcGIS API for Flex用GeometryService实现量算距离和面积,本例子主要包含GeometryService的project、simplify、lengths、areasAndLengths等实现。
准备工作:
1.在ArcGIS.Server.9.3发布一个叫USA的Map Service。
2.在ArcGIS.Server.9.3发布一个叫Geometry的Geometry Service,默认设置就可以了。
完成后的效果图:
<esri:Extent id="myExtent" xmin="-183.780014745329" ymin="16.2975638854873" xmax="-61.4068547410964" ymax="74.0304580085983" >
2 <esri:SpatialReference wkid="4269" />
3 </esri:Extent>
4 <mx:Canvas width="575" height="337" borderStyle="solid" borderThickness="3" left="10" verticalCenter="11">
5 <esri:Map id="myMap" extent="{myExtent}">
6 <esri:ArcGISDynamicMapServiceLayer url="http://jh-53a435fbc0e8/ArcGIS/rest/services/USA/MapServer" />
7 <esri:GraphicsLayer id="myGraphicsLayer" symbolFunction="mySymbolFunction"/>
8 </esri:Map>
9 </mx:Canvas>
10 <mx:Label verticalCenter="-176" left="98" id="minfo" fontSize="12"/>
3.这样当然还需要Draw、ToggleButtonBar等,相应代码:
1<esri:SimpleLineSymbol id="sls" style="solid" color="0x00FF00" width="2" alpha="0.7"/>
2 <esri:SimpleMarkerSymbol id="sms" style="diamond" color="0x00FF00" size="15" alpha="0.7"/>
3 <esri:SimpleFillSymbol id="sfs" color="0x00FF00" alpha="0.7">
4 <esri:SimpleLineSymbol color="0x000000"/>
5 </esri:SimpleFillSymbol>
6 <esri:Draw id="drawToolbar" map="{myMap}" graphicsLayer="{myGraphicsLayer}" drawEnd="drawEndHandler(event)" />
7 <mx:ToggleButtonBar verticalCenter="-174" itemClick="itemClickHandler(event)" toggleOnClick="true" left="10">
8 <mx:dataProvider>
9 <mx:Array>
10 <mx:Object icon="{polyline}" />
11 <mx:Object icon="{polygon}" />
12 </mx:Array>
13 </mx:dataProvider>
14 </mx:ToggleButtonBar>
4.最后还需要添加GeometryService,代码如下:
1<esri:GeometryService id="geometryService" url="http://jh-53a435fbc0e8/ArcGIS/rest/services/Geometry/GeometryServer" showBusyCursor="true" concurrency="last">
2 </esri:GeometryService>
5.这样界面以及控件都已经设置完毕了,开始编写代码首先是GraphicsLayer控件的symbolFunction,就设置GraphicsLayer控件中绘图的显示样式,这个前面几个例子已经用到过多次了就不做详细说明了,代码如下:
1private function mySymbolFunction(graphic:Graphic):Symbol
2//ToggleButtonBar的按钮点击事件用设置drawToolbar操作类型
2 private function itemClickHandler(event:ItemClickEvent):void
3 //画图操作完成后执行的事件
2 private function drawEndHandler(event:DrawEvent):void
3private function projectCompleteHandler(event:GeometryServiceEvent):void
2//simplify完成后执行的事件调用areasAndLengths方法
2 private function simplifyCompleteHandler(event : GeometryServiceEvent):void
3 //areasAndLengths完成后执行的事件显示把面积显示在Label上
2 private function areaslengthsCompleteHandler(event : GeometryServiceEvent ) : void
3//lengths完成后执行的事件显示把线距离显示在Label上
2 private function lengthsCompleteHandler(event : GeometryServiceEvent):void
3 {
4 geometryService.removeEventListener(GeometryServiceEvent.LENGTHS_COMPLETE,lengthsCompleteHandler);
5 minfo.text="距离:"+event.lengths[0]/1000+"km";
6 }
12.这样就完成了距离和面积的量算功能,这样要特别地图数据等情况进行project、simplify操作否则会得到不正确的结果。
1.ArcGIS API for Flex用GeometryService实现量算距离和面积,本例子主要包含GeometryService的project、simplify、lengths、areasAndLengths等实现。
准备工作:
1.在ArcGIS.Server.9.3发布一个叫USA的Map Service。
2.在ArcGIS.Server.9.3发布一个叫Geometry的Geometry Service,默认设置就可以了。
完成后的效果图:
<esri:Extent id="myExtent" xmin="-183.780014745329" ymin="16.2975638854873" xmax="-61.4068547410964" ymax="74.0304580085983" >
2 <esri:SpatialReference wkid="4269" />
3 </esri:Extent>
4 <mx:Canvas width="575" height="337" borderStyle="solid" borderThickness="3" left="10" verticalCenter="11">
5 <esri:Map id="myMap" extent="{myExtent}">
6 <esri:ArcGISDynamicMapServiceLayer url="http://jh-53a435fbc0e8/ArcGIS/rest/services/USA/MapServer" />
7 <esri:GraphicsLayer id="myGraphicsLayer" symbolFunction="mySymbolFunction"/>
8 </esri:Map>
9 </mx:Canvas>
10 <mx:Label verticalCenter="-176" left="98" id="minfo" fontSize="12"/>
3.这样当然还需要Draw、ToggleButtonBar等,相应代码:
1<esri:SimpleLineSymbol id="sls" style="solid" color="0x00FF00" width="2" alpha="0.7"/>
2 <esri:SimpleMarkerSymbol id="sms" style="diamond" color="0x00FF00" size="15" alpha="0.7"/>
3 <esri:SimpleFillSymbol id="sfs" color="0x00FF00" alpha="0.7">
4 <esri:SimpleLineSymbol color="0x000000"/>
5 </esri:SimpleFillSymbol>
6 <esri:Draw id="drawToolbar" map="{myMap}" graphicsLayer="{myGraphicsLayer}" drawEnd="drawEndHandler(event)" />
7 <mx:ToggleButtonBar verticalCenter="-174" itemClick="itemClickHandler(event)" toggleOnClick="true" left="10">
8 <mx:dataProvider>
9 <mx:Array>
10 <mx:Object icon="{polyline}" />
11 <mx:Object icon="{polygon}" />
12 </mx:Array>
13 </mx:dataProvider>
14 </mx:ToggleButtonBar>
4.最后还需要添加GeometryService,代码如下:
1<esri:GeometryService id="geometryService" url="http://jh-53a435fbc0e8/ArcGIS/rest/services/Geometry/GeometryServer" showBusyCursor="true" concurrency="last">
2 </esri:GeometryService>
5.这样界面以及控件都已经设置完毕了,开始编写代码首先是GraphicsLayer控件的symbolFunction,就设置GraphicsLayer控件中绘图的显示样式,这个前面几个例子已经用到过多次了就不做详细说明了,代码如下:
1private function mySymbolFunction(graphic:Graphic):Symbol
2//ToggleButtonBar的按钮点击事件用设置drawToolbar操作类型
2 private function itemClickHandler(event:ItemClickEvent):void
3 //画图操作完成后执行的事件
2 private function drawEndHandler(event:DrawEvent):void
3private function projectCompleteHandler(event:GeometryServiceEvent):void
2//simplify完成后执行的事件调用areasAndLengths方法
2 private function simplifyCompleteHandler(event : GeometryServiceEvent):void
3 //areasAndLengths完成后执行的事件显示把面积显示在Label上
2 private function areaslengthsCompleteHandler(event : GeometryServiceEvent ) : void
3//lengths完成后执行的事件显示把线距离显示在Label上
2 private function lengthsCompleteHandler(event : GeometryServiceEvent):void
3 {
4 geometryService.removeEventListener(GeometryServiceEvent.LENGTHS_COMPLETE,lengthsCompleteHandler);
5 minfo.text="距离:"+event.lengths[0]/1000+"km";
6 }
12.这样就完成了距离和面积的量算功能,这样要特别地图数据等情况进行project、simplify操作否则会得到不正确的结果。
相关文章推荐
- ArcGIS.Server.9.3和ArcGIS API for Flex的GeometryService和量算距离面积(十一)
- [转]ArcGIS.Server.9.3和ArcGIS API for Flex的GeometryService和量算距离面积(十)
- [转]ArcGIS.Server.9.3和ArcGIS API for Flex的GeometryService和buffer分析(十一)
- ArcGIS.Server.9.3和ArcGIS API for JavaScript实现距离量算和面积量算(九)
- ArcGIS.Server.9.3和ArcGIS API for JavaScript实现距离量算和面积量算(九)
- ArcGIS.Server.9.3和ArcGIS API for JavaScript实现距离量算和面积量算(九)
- ArcGIS.Server.9.3和ArcGIS API for Flex的GeometryService和buffer分析(十)
- ArcGIS.Server.9.3和ArcGIS API for Flex的GeometryService和buffer分析(十)
- ArcGIS.Server.9.3和ArcGIS API for Flex实现动态图层和瓦片图层叠加显示(二)
- ArcGIS.Server.9.3和ArcGIS API for Flex实现Toolbar功能(四)
- ArcGIS.Server.9.3和ArcGIS API for Flex实现Query查询定位中心功能(七)
- [转]ArcGIS.Server.9.3和ArcGIS API for Flex实现Toolbar功能(四)
- ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和服务区分析(十二)
- ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和最短路径分析(十三)
- ArcGIS.Server.9.3和ArcGIS API for Flex实现GraphicsLayer上画点、线、面(五)
- [转]ArcGIS.Server.9.3和ArcGIS API for Flex实现GraphicsLayer上画点、线、面(五)
- ArcGIS.Server.9.3和ArcGIS API for Flex在MapTips显示饼图数据统计(九)
- ArcGIS.Server.9.3和ArcGIS API for Flex的GeoprocessingServices和最短路径分析(十三)
- ArcGIS.Server.9.3和ArcGIS API for Flex实现基本的地图浏览(一)
- ArcGIS.Server.9.3和ArcGIS API for Flex实现Identify的功能图查属性(六)