Your SlideShare is downloading. ×
iShare 技术 ArcGIS Flex Map Resize
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

iShare 技术 ArcGIS Flex Map Resize

732
views

Published on

如何在改变地图大小后, 要让地图的中心点也要跟着改变(即将地图移动到容器新的中心位置)

如何在改变地图大小后, 要让地图的中心点也要跟着改变(即将地图移动到容器新的中心位置)

Published in: Technology, Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
732
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 需求<br />在改变地图大小后, 要让地图的中心点也要跟着改变(即将地图移动到容器新的中心位置)<br />默认行为<br />ArcGIS Flex API Map在改变地图大小后不会移动地图, 还是待在原处, 地图容器大小确实变化了(由比例尺和logo的位置看出)<br />解决思路<br />我试过改变地图大小后重新绘制(refresh)每个图层, 似乎能够达到目的, 但只是暂时的, 地图好像无法包容住图层, 又反弹回去了(resize前的位置), hold不住啊!<br />只好边想边在网上找资料, 终于发现了可行的解决方案<br />Zooming to extent not working properly after resizing the map<br />It waits until a extentChange happens after a resize since the Map's own resize handler is changing the map's extent.<br />The need to wait a frame by using callLater() is a bug.<br />原来resize之后会改变Map的extent, 因此resize之后马上刷新图层只能暂时将地图移动到中心位置, 但extent改变后, 又会还原回去.<br />实现步骤<br />监听地图resize事件, 记录地图resize之前extent的中心点, 并监听extentChange<br />在extentChange事件中通过callLater设置地图的中心点为resize之前的中心点<br />完整代码<br /><?xml version="1.0" encoding="utf-8"?><br /><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"<br /> xmlns:esri="http://www.esri.com/2008/ags"<br /> layout="absolute"><br /> <mx:Script><br /> <![CDATA[<br /> import com.esri.ags.events.ExtentEvent;<br /> import com.esri.ags.geometry.MapPoint;<br /> private var center:MapPoint;<br /> private function buttonClickHandler():void {<br /> if (toggleButton.selected) {<br /> map.percentWidth = 100;<br /> } else {<br /> map.percentWidth = 50;<br /> }<br /> }<br /> private function mapResizeHandler():void {<br /> // 地图初始化加载时会触发一次resize事件, 但地图还未load完成<br /> // 初始地图会自动调整中心点到地图容器中心位置, 因此不需要手动调整<br /> if (map.loaded) {<br /> trace("这里还是地图resize之前的extent", map.extent);<br /> trace("我们想要地图定位到该中心点", map.extent.center);<br /> center = map.extent.center;<br /> map.addEventListener(ExtentEvent.EXTENT_CHANGE, mapExtentChangeHandler);<br /> }<br /> }<br /> private function mapExtentChangeHandler(event:ExtentEvent):void {<br /> map.removeEventListener(ExtentEvent.EXTENT_CHANGE, mapExtentChangeHandler);<br /> // 如果不callLater, 会有bug(地图缩放时中心点偏移)<br /> callLater(function(center:MapPoint):void {<br /> trace("地图resize之后会改变地图的extent", map.extent);<br /> trace("地图resize之后extent的中心点", map.extent.center);<br /> map.centerAt(center);<br /> }, [center]);<br /> }<br /> ]]><br /> </mx:Script><br /> <esri:Map id="map" resize="mapResizeHandler()"<br /> width="50%" height="100%" borderColor="0xfff" borderStyle="solid"><br /> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" /><br /> </esri:Map><br /> <mx:Button id="toggleButton" label="100%" click="buttonClickHandler()" toggle="true" /><br /></mx:Application><br />最终效果<br />