实现效果如下图所示;
-
做第一个评论者吧!
抢沙发>>
(1)更简单的调用云GIS(ArcGIS Online)上的数据
以前我们调用ArcGIS Online上的地图,需要知道底图的URL地址:
<string name="WORLD_STREET_MAP">http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer</string>
<string name="WORLD_TOPO_MAP">http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer</string>
<string name="WORLD_NATGEO_MAP">http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer</string>
<string name="OCEAN_BASEMAP">http://services.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer</string>
同时在代码中调用该服务地址:
//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文档中我们可以简单的配置下:
<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"/>
然后在代码中简单的一句:
MapView mMapView = (MapView) findViewById(R.id.map);
当然我们可以很简单就修改底图和范围:
MapOptions streets = new MapOptions(MapType.STREETS);
mMapView.setMapOptions(streets);
(2)简单的标签
然后在项目中就可以看到引用的库文件了
第二步,写入代码,引用库文件的MapViewHelper 类,如下所示:
// Using MapOptions
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"); }
}
});
实现效果如下图所示;