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載入時就被建立。