1) 地图如何设置初始级别或比例尺? 在config.xml中设置map节点。 center必须有,否则level和scale则无效。 如果level和scale同时有值,则会取scale。 center格式为: "x y",必须用空格隔开。
可查看MapManager.mxml文件的configMapAttributes()函数。具体见331行。 else if (id == "center") { map.addEventListener(MapEvent.LOAD, map_loadHandler); } 这行添加事件监听map_loadHandler。
map_loadHandler方法设置中心点代码: map.centerAt(centerPt); if (scale > 0) { map.scale = scale; } else if (level >= 0) { map.level = level; }
总结如下: 在config.xml的map节点中设置center属性和(level、scale任选一个)属性。
2)是谁发布MapEvent.LOAD事件的呢? public static const LOAD:String = "load";
com.esri.ags.Map对象方法: creationCompleteHandler方法会执行如下代码: private function creationCompleteHandler(event:FlexEvent) : void { this.m_creationComplete = true; this.checkIfCompleteAndHasWidthAndHeightAndBaseLayerLoaded(); return; }
在checkIfCompleteAndHasWidthAndHeightAndBaseLayerLoaded中发布这个事件: private function checkIfCompleteAndHasWidthAndHeightAndBaseLayerLoaded() : void { if (this.m_creationComplete) { } if (this.m_widthAndHeightNotZero) { } if (this.m_baseLayerLoaded) { this.m_mouseHandler.enable(); if (this.m_keyboardNavigationEnabled) { this.m_keyboardHandler.enable(); } var _loc_1:* = this.reaspect(this.m_extent); this.m_oldExtent = this.reaspect(this.m_extent); this.extent = _loc_1; this.m_loaded = true; this.m_layerContainer.setMapOnLoadedLayers(); if (!this.m_mapLoadEventWasDispatched) { this.m_mapLoadEventWasDispatched = true; dispatchEvent(new MapEvent(MapEvent.LOAD, this)); //发布地图加载事件 } } return; }
总结如下:Map类创建完成后发布地图加载事件。
3)Map控件是在何时被创建? Map类定义如下: public class Map extends UIComponent { ... }
MapManager.mxml文件中标签: <s:SkinnableContainer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" creationComplete="this_creationCompleteHandler()" skinClass="com.esri.viewer.skins.MapManagerSkin">
其中skinClass标签,指向MapManagerSkin.mxml文件。 在这个里面有如下代码 <s:Group id="managerView" width="100%" height="100%"> <!-- Start map at size 0 so that only one extentChange is fired after it's been sized and had its extent set. --> <esri:Map id="map" width="0" height="0" left.resized="{hostComponent.mapLeft}" right.resized="{hostComponent.mapRight}" top.resized="{hostComponent.mapTop}" bottom.resized="{hostComponent.mapBottom}" zoomSliderVisible="false"/> </s:Group>
总结如下: Map对象在index.mxml加载时就被创建。
转载:http://www.cnblogs.com/janehlp/archive/2012/09/18/2689989.html
转载于:https://www.cnblogs.com/x38160/p/3173059.html
相关资源:ArcGIS Server开发框架——FlexViewer