【10.2移动新特性】Android 10.2 API简化,同样的功能,更少的代码!
分享
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
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 个评论
推荐内容
相关问题
- 在Visual studio 2015 中使用 Arcgis API for JavaScript v3.16 如何实现代码智能提示?
- Arcgis runtime for android初学者该如何系统的学习?
- Android端对于离线的支持
- ArcGIS Runtime SDK for Android 离线数据是否支持地方自定义坐标系
- 关于ArcGIS Runtime SDK for Android离线数据投影的问题
- 请问如何使用ArcEngine实现(在右击图例中)Convert To Gtaphics这一功能?
- CityEngine做的三维环境可以在移动端显示吗?
- portal for arcgis 1031使用管理员角色创建的3d场景怎么没有发布功能?
- 按照Engine+开发手册ArcEngine_10.0_C#二次开发编写的鹰眼的代码,运行时鹰眼不显示!
- arcgis请问如何把复杂的道路交叉处简化?
- ArcGIS Runtime SDK for Android加载本地影像时,如何对RGB波段进行调整?