ArcGIS API for Flex(四) 地图的当前范围和规模
发布时间:2020-12-15 03:35:45 所属栏目:百科 来源:网络整理
导读:通过导航地图(平移/缩放)改变程度,或使用导航滑块来放大/缩
通过导航地图(平移/缩放)改变程度,或使用导航滑块来放大/缩小。并且显示地理坐标 效果如下: 代码:(主要是esri官方代码,稍作修改)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:esri="http://www.esri.com/2008/ags" pageTitle="Map Extent and Mouse Coordinates"> <fx:Script> <![CDATA[ import com.esri.ags.geometry.Extent; import com.esri.ags.geometry.MapPoint; import com.esri.ags.utils.WebMercatorUtil; // when mouse (cursor) is on the map ... private function loadHandler():void { myMap.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler); } // ... show coordinates of current (mouse) location private function mouseMoveHandler(event:MouseEvent):void { const mapPoint:MapPoint = myMap.toMapFromStage(event.stageX,event.stageY); const latlong:MapPoint = WebMercatorUtil.webMercatorToGeographic(mapPoint) as MapPoint; mousecoords.text = "x,y is " + mapPoint.x.toFixed(0) + "," + mapPoint.y.toFixed(0) + " and Lat/Long is: " + latlong.y.toFixed(6) + " / " + latlong.x.toFixed(6); } // convert current projected extent to geographic and show as such protected function showExtentInGeographic(extent:Extent):String { const geoExtent:Extent = WebMercatorUtil.webMercatorToGeographic(myMap.extent) as Extent; // return geoExtent.toString() + ".." ; return " " + geoExtent.xmin.toFixed(6) + "," + geoExtent.ymin.toFixed(6) + "," + geoExtent.xmax.toFixed(6) + "," + geoExtent.ymax.toFixed(6) + " (wkid: " + geoExtent.spatialReference.wkid + ")"; } ]]> </fx:Script> <s:controlBarLayout> <s:VerticalLayout gap="10" paddingBottom="7" paddingLeft="10" paddingRight="10" paddingTop="7"/> </s:controlBarLayout> <s:controlBarContent> <s:RichText width="100%" fontFamily="宋体" fontSize="16" fontWeight="bold" color="#006030"> 此示例演示如何使用的事件监听器 鼠标以显示鼠标所在位置的最新信息。 地图的当前范围和规模也显示为你 通过导航地图(平移/缩放)改变程度,或使用 导航滑块来放大/缩小。 </s:RichText> <s:HGroup> <s:Label fontWeight="bold" text="当前地图范围:" fontFamily="宋体" fontSize="16" color="#006030"/> <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}")' fontFamily="宋体" fontSize="16" fontWeight="bold" color="#006030"/> </s:HGroup> <s:HGroup> <s:Label text=" 当前地图范围(地理):" fontFamily="宋体" fontSize="16" fontWeight="bold" color="#006030"/> <s:RichEditableText editable="false" text="{showExtentInGeographic(myMap.extent)}" fontFamily="宋体" fontSize="16" fontWeight="bold" color="#006030"/> </s:HGroup> <s:HGroup> <s:Label fontFamily="宋体" fontSize="16" fontWeight="bold" color="#006030" text="目前的鼠标坐标:"/> <s:RichEditableText id="mousecoords" editable="false" text="将鼠标移动到地图上看到它的当前坐标..." fontFamily="宋体" fontSize="16" fontWeight="bold" color="#006030"/> </s:HGroup> <s:HGroup> <s:Label fontFamily="宋体" fontSize="16" fontWeight="bold" color="#006030" text=" 当前地图的比例尺是:"/> <s:RichEditableText editable="false" text="1:{myMap.scale.toFixed(0)} (level {myMap.level})" fontFamily="宋体" fontSize="16" fontWeight="bold" color="#006030"/> </s:HGroup> </s:controlBarContent> <esri:Map id="myMap" load="loadHandler()"> <esri:extent> <esri:Extent xmin="3035000" ymin="4305000" xmax="3475000" ymax="10125000"> <esri:SpatialReference wkid="102100"/> <!-- same as tiled map service below --> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> </esri:Map> </s:Application> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |