1.布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!--
mapoptions.MapType 指定地图类型
mapoptions.ZoomLevel 指定缩放级别
mapoptions.center 把坐标放在地图中心
设置默认显示的地图类型为topo
-->
<com.esri.android.map.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapoptions.MapType="topo"
mapoptions.ZoomLevel="13"
mapoptions.center="33.666354, -117.903557" />
</LinearLayout>
2.strings.xml
<resources>
<string name="app_name">ArcGISStudy</string>
<string name="StreetMapMenu">Streets</string>
<string name="TopoMenu">Topographic</string>
<string name="GrayMenu">Gray</string>
<string name="OceanMenu">Oceans</string>
</resources>
3.菜单布局
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/World_Street_Map"
app:showAsAction="never"
android:title="@string/StreetMapMenu"/>
<item
android:id="@+id/World_Topo"
app:showAsAction="never"
android:title="@string/TopoMenu"/>
<item
android:id="@+id/Gray"
app:showAsAction="never"
android:title="@string/GrayMenu"/>
<item
android:id="@+id/Ocean_Basemap"
app:showAsAction="never"
android:title="@string/OceanMenu"/>
</group>
</menu>
4.活动
package aystudio.nopi.arcgisstudy;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.esri.android.map.MapOptions;
import com.esri.android.map.MapView;
public class MainActivity extends AppCompatActivity {
private MapView mMapView;
// The basemap switching menu items.
// 谷歌翻译
// 底图切换菜单项
MenuItem mStreetsMenuItem = null;
MenuItem mTopoMenuItem = null;
MenuItem mGrayMenuItem = null;
MenuItem mOceansMenuItem = null;
// Create MapOptions for each type of basemap.
// 谷歌翻译
// 为每种底图类型创建MapOptions
final MapOptions mTopoBasemap = new MapOptions(MapOptions.MapType.TOPO);
final MapOptions mStreetsBasemap = new MapOptions(MapOptions.MapType.STREETS);
final MapOptions mGrayBasemap = new MapOptions(MapOptions.MapType.GRAY);
final MapOptions mOceansBasemap = new MapOptions(MapOptions.MapType.OCEANS);
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMapView = findViewById(R.id.mapview);
// Enable map to wrap around date line.
// 谷歌翻译
// 启用地图环绕日期变更线。
// 启用地图环绕日期行。
mMapView.enableWrapAround(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main,menu);
// Get the basemap switching menu items.
// 谷歌翻译
// 获取底图切换菜单项。
mStreetsMenuItem = menu.getItem(0);
mTopoMenuItem = menu.getItem(1);
mGrayMenuItem = menu.getItem(2);
mOceansMenuItem = menu.getItem(3);
// Also set the topo basemap menu item to be checked, as this is the default.
// 谷歌翻译
// 也被设定为检查地形底图菜单项,因为这是默认的。
// 还要设置要检查的topo底图菜单项,因为这是默认设置。
// 说明:当您的初始地图显示Topo地图时,将其设置为选中状态。
mTopoMenuItem.setChecked(true);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle menu item selection.
// 谷歌翻译
// 处理菜单项选择。
switch (item.getItemId()) {
case R.id.World_Street_Map:
mMapView.setMapOptions(mStreetsBasemap);
mStreetsMenuItem.setChecked(true);
return true;
case R.id.World_Topo:
mMapView.setMapOptions(mTopoBasemap);
mTopoMenuItem.setChecked(true);
return true;
case R.id.Gray:
mMapView.setMapOptions(mGrayBasemap);
mGrayMenuItem.setChecked(true);
return true;
case R.id.Ocean_Basemap:
mMapView.setMapOptions(mOceansBasemap);
mOceansMenuItem.setChecked(true);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//暂停渲染
@Override
protected void onPause() {
super.onPause();
if (mMapView != null) {
mMapView.pause();
}
}
//恢复渲染
@Override
protected void onResume() {
super.onResume();
if (mMapView != null) {
mMapView.unpause();
}
}
}
5.效果