ArcGIS For Flex学习之Mapping---Map Extent and Mouse Coordinates

本文介绍了一个使用Adobe Flex和Esri API实现的地图应用示例。该示例展示了如何实时显示鼠标在地图上的位置坐标及地理坐标,并更新地图当前范围和比例尺。

效果图如下:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
 3                xmlns:s="library://ns.adobe.com/flex/spark"
 4                xmlns:esri="http://www.esri.com/2008/ags"
 5                pageTitle="Map Extent and Mouse Coordinates">
 6 
 7     <fx:Script>
 8         <![CDATA[
 9             import com.esri.ags.geometry.Extent;
10             import com.esri.ags.geometry.MapPoint;
11             import com.esri.ags.utils.WebMercatorUtil;
12 
13             // when mouse (cursor) is on the map ...
14             private function loadHandler():void
15             {
16                 myMap.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
17             }
18 
19             // ... show coordinates of current (mouse) location
20             private function mouseMoveHandler(event:MouseEvent):void
21             {
22                 const mapPoint:MapPoint = myMap.toMapFromStage(event.stageX, event.stageY);
23                 const latlong:MapPoint = WebMercatorUtil.webMercatorToGeographic(mapPoint) as MapPoint;
24                 mousecoords.text =
25                     "x,y is " + mapPoint.x.toFixed(0) + "," + mapPoint.y.toFixed(0)
26                     + " and Lat/Long is: " + latlong.y.toFixed(6)
27                     + " / " + latlong.x.toFixed(6);
28             }
29 
30             // convert current projected extent to geographic and show as such
31             protected function showExtentInGeographic(extent:Extent):String
32             {
33                 const geoExtent:Extent = WebMercatorUtil.webMercatorToGeographic(myMap.extent) as Extent;
34                 // return geoExtent.toString() + ".." ;
35                 return " " + geoExtent.xmin.toFixed(6)
36                     + ", " + geoExtent.ymin.toFixed(6)
37                     + ", " + geoExtent.xmax.toFixed(6)
38                     + ", " + geoExtent.ymax.toFixed(6)
39                     + "   (wkid: " + geoExtent.spatialReference.wkid + ")";
40             }
41         ]]>
42     </fx:Script>
43 
44     <s:controlBarLayout>
45         <s:VerticalLayout gap="10"
46                           paddingBottom="7"
47                           paddingLeft="10"
48                           paddingRight="10"
49                           paddingTop="7"/>
50     </s:controlBarLayout>
51     <s:controlBarContent>
52         <s:RichText width="100%">
53             This sample demonstrates how to use event listeners on the
54             mouse to display current information about the mouse location.
55             The map's current extent and scale is also displayed as you
56             change the extent by navigating the map (pan/zoom) or use the
57             navigation slider to zoom in/out.
58         </s:RichText>
59         <s:HGroup>
60             <s:Label fontWeight="bold" text="Current map extent:"/>
61             <s:RichEditableText editable="false" text='xmin="{myMap.extent.xmin.toFixed(0)}" ymin="{myMap.extent.ymin.toFixed(0)}" xmax="{myMap.extent.xmax.toFixed(0)}" ymax="{myMap.extent.ymax.toFixed(0)}"   (wkid="{myMap.spatialReference.wkid}")'/>
62         </s:HGroup>
63         <s:HGroup>
64             <s:Label fontWeight="bold" text="Current map extent (in geographic):"/>
65             <s:RichEditableText editable="false" text="{showExtentInGeographic(myMap.extent)}"/>
66         </s:HGroup>
67         <s:HGroup>
68             <s:Label fontWeight="bold" text="Current Mouse Coordinates:"/>
69             <s:RichEditableText id="mousecoords"
70                                 editable="false"
71                                 text="Move the mouse over the map to see its current coordinates..."/>
72         </s:HGroup>
73         <s:HGroup>
74             <s:Label fontWeight="bold" text="Current map scale is"/>
75             <s:RichEditableText editable="false" text="1:{myMap.scale.toFixed(0)} (level {myMap.level})"/>
76         </s:HGroup>
77     </s:controlBarContent>
78 
79     <esri:Map id="myMap" load="loadHandler()">
80         <esri:extent>
81             <esri:Extent xmin="3035000" ymin="4305000" xmax="3475000" ymax="10125000">
82                 <esri:SpatialReference wkid="102100"/>
83                 <!-- same as tiled map service below -->
84             </esri:Extent>
85         </esri:extent>
86         <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
87     </esri:Map>
88 
89 </s:Application>
View Code

 

转载于:https://www.cnblogs.com/wicked-fly/p/4040284.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值