FlexViewer架構地圖控制項三問

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.