(1)更简单的调用云GIS(ArcGIS Online)上的数据
以前我们调用ArcGIS Online上的地图,需要知道底图的URL地址:
name="WORLD_STREET_MAP">http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer
name="WORLD_TOPO_MAP">http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer
name="WORLD_NATGEO_MAP">http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer
name="OCEAN_BASEMAP">http://services.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer
同时在代码中调用该服务地址:
//create an initial basemap
basemapStreet = new
ArcGISTiledMapServiceLayer(this.getResources()
.getString(R.string.WORLD_STREET_MAP));
// Add basemap to MapView
mMapView.addLayer(basemapStreet);
// set visibility
basemapStreet.setVisible(true);
如果需要更改底图,我们需要以下代码:
basemapTopo = new
ArcGISTiledMapServiceLayer(this.getResources()
.getString(R.string.WORLD_TOPO_MAP));
mMapView.addLayer(basemapTopo);
basemapStreet.setVisible(false);
basemapTopo.setVisible(true);
如果采用ArcGIS runtime for Android 10.2,这一切就更简单了。
首先,你不一定要记得arcgis online上的服务地址了,用MapOptions就能轻松搞定。
在xml文档中我们可以简单的配置下:
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"/>
然后在代码中简单的一句:
MapView mMapView = (MapView) findViewById(R.id.map);
当然我们可以很简单就修改底图和范围:
MapOptions streets = new MapOptions(MapType.STREETS);
mMapView.setMapOptions(streets);
(2)简单的标签
之前我们实现graphic的标签和气泡功能,需要PopupInfo和PictureMarkerSymbol,整个过程还是比较复杂,但是我们用了arcgis
runtime for android 10.2的ArcGIS Android Application
Framework,就能轻松实现。
第一步引用ArcGIS Android
Application Framework,右键项目,选择“ArcGIS Tools”,然后选择“add Application
Framework to project”,如下图所示:
然后在项目中就可以看到引用的库文件了
第二步,写入代码,如下所示:
mMapView = (MapView) findViewById(R.id.map);
// Create a MapView Helper
mvHelper = new MapViewHelper(mMapView);
// Create drawable icon
icon =
getResources().getDrawable(R.drawable.route_destination);
// Make sure map has loaded before adding geometries
mMapView.setOnStatusChangedListener(new OnStatusChangedListener()
{
private static final long serialVersionUID =
1L;
public void onStatusChanged(Object source,
STATUS status) {
// Add a
graphic to represent ESRI Headquarters
int loaded =
mvHelper.addMarkerGraphic(34.056695, -117.195693,
"ESRI", "World Headquarters", null, icon, false, 0);
if (loaded
< 0) {
Log.d("TAG", "Marker Graphic not added to MapView");
}
}
});
实现效果如下图所示;