New Features for ArcGIS Android API v10.2

在 10.2 的版本我們建立了一個新的程式編輯模式以簡化對 MapView 的設定,如底圖、縮放比例、及中心位置。之前的版本我們在使用 ArcGISTiledMapServiceLayer 時我們必須另外呼叫副程式去設定範圍 (Extent) 或是縮放比例,最後再把這個圖層加到地圖 (Map)。10.2 版的 API 中大大地簡化了這整個流程。

 

《MapOptions》

當您在實作 MapView 及定義底圖、縮放比例及中心時,最簡單的方法是使用「MapOptions」,最典型的使用方法如下:

 

MapOptions topo = new MapOptions(MapType.TOPO, 23, -110, 9); 
MapView mMapView = new MapView(this, topo);

 

 

您可以利用MapOptions Class中的setMapOptions方法簡單的切換底圖

 

MapOptions streets = new MapOptions(MapType.STREETS);
mMapView.setMapOptions(streets);

 

 

以下的作法將會在切換底圖為 MapType.STREET 的同時將地圖範圍 (Extent) 也切到 STREET 底圖。為了實現底圖地圖範圍的切換,您必須在切換底圖的同時取得地圖的範圍且利用 thesetOnStatusChangedListener 方法定義到地圖上,如下範例:

 

Polygon extent = mMapView.getExtent();
mMapView.setMapOptions(streets);

// honor the extent when switching basemaps
mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
    private static final long serialVersionUID = 1L;

    @Override
    public void onStatusChanged(Object source, STATUS status) {
      mMapView.setExtent(extent);
    }
});

 

 

以上的範別是介紹如何在 Java 的程式碼中使用 MapOptions,然而您也可以在 XML Layout 中利用 MapOptions 為 MapView 定義 mapoptions 屬性。

 

<!-- MapView with MapOptions settings for Topo basemap, zoom level, 
and centered in Costa Mesa, CA. --> 
<com.esri.android.map.MapView 
android:id="@+id/map"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
mapoptions.MapType="topo" 
mapoptions.ZoomLevel="13" 
mapoptions.center="33.666354, -117.903557"/>

 

 

在 XML Layout 定義好 mapoptions 後,現在您可以在 Java 的程式中,只用到一行程式碼就可以實作 MapView

 

// Retrieve the MapView, Basemap, ZoomLevel, and Center from XML layout
MapView mMapView = (MapView) findViewById(R.id.map);

 

 


 

Dan O'Neill 撰寫,於 November 7, 2013

翻譯:互動國際數位.技術服務處.鄒國信

詳細原文請參考:

http://blogs.esri.com/esri/arcgis/2013/11/07/simplifed-api-part-1-new-features-for-arcgis-android-api-v10-2/