【10.2移动新特性】Android 10.2 API简化,同样的功能,更少的代码!

0
分享 2016-06-10
ArcGIS移动产品开发包Android和iOS 10.2版于前段时间正式发布,除了众所周知的强劲的离线支持,新版本中还有哪些激动人心的增强呢?请看“新特性系列博客”为您揭秘。

ArcGIS Runtime SDK for Android 10.2中有一个重大的新特性就是API的简化,让开发者能够使用更少的代码就能完成功能开发。比如,在10.2之前的版本中,加载底图需要使用ArcGISTiledMapServiceLayer的特殊方法来指定底图的初始化范围、缩放等级、加载的图层等,而在10.2新的编程模式中,通过新增的类MapOptions来预定义底图、缩放级别、居中位置等,让MapViews的创建过程大大简化。

新增的MapOptions类

使用MapOptions类可以简化创建MapView的方法,创建一个MapOptions的对象,并指定范围、等级、居中位置等各种值,并将该对象作为参数传入MapView的构造函数中。使用方法如下:
MapOptions topo = new MapOptions(MapType.TOPO, 23, -110, 9);
MapView mMapView = new MapView(this, topo);


同样的,现在可以使用MapOptions类的setMapOptions方法来轻松切换底图:
MapOptions streets = new MapOptions(MapType.STREETS);
mMapView.setMapOptions(streets);


上述方法可以将地图的底图切换到STREETS类型。为了定义各个底图的extent,开发者必须在切换底图之前获取地图的范围,并使用setOnStatusChangedListener方法来设定地图范围的变化:
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);
}
});


上面示例代码显示了MapOptions类在Java代码中的用法,实际上,MapOptions类也可以在XML中使用(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中如上定义之后,在Java代码中,只需要一句代码即可实例化MapView:
// Retrieve the MapView, Basemap, ZoomLevel, and Center from XML layout
MapView mMapView = (MapView) findViewById(R.id.map);

可使用示例向导加载名为Basemaps的例子来查看全部代码。

文章来源:http://blog.csdn.net/arcgis_all/article/details/17261519

0 个评论

要回复文章请先登录注册