底圖圖磚
底圖圖磚
提供底圖圖磚切換功能,手持裝置提供之底圖圖磚包括:通用版電子地圖、混合地圖及福衛二號衛星影像,底圖圖磚切換程式範例說明如下:
public class MainActivity extends Activity implements OnItemSelectedListener{
TGOnlineMap _MapView = null;
RelativeLayout AddMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AddMapView = (RelativeLayout)findViewById(R.id.AddMapView);
try {
_MapView = new TGOnlineMap(this);
AddMapView.addView(_MapView);
_MapView.setBackgroundColor(Color.rgb(165,191,221));
Spinner spinner = (Spinner) findViewById(R.id.MapType_spinner);
//取得畫面上的底圖類型下拉選單
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.MapType_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
//當選擇下拉選單內的項目, 執行切換底圖圖磚的程式
} catch (TGRuntimeRemoteException e) {
e.printStackTrace();
}
}
/*圖磚代碼:名稱說明
TGOSMAP:台灣通用電子地圖
NLSCMAP:台灣通用電子地圖
ROADMAP:混合地圖
F2IMAGE:福衛二號衛星影像*/
private void setLayer(String layerName) {
if (layerName.equals(getString(R.string.TGOSMAP))) {
_MapView.setMapType(MapType.TGOSMAP); //使用setMapType()進行底圖切換
} else if (layerName.equals(getString(R.string.NLSCMAP))) {
_MapView.setMapType(MapType.NLSCMAP);
} else if (layerName.equals(getString(R.string.ROADMAP))) {
_MapView.setMapType(MapType.ROADMAP);
} else if (layerName.equals(getString(R.string.F2IMAGE))) {
_MapView.setMapType(MapType.F2IMAGE);
} else {
Log.i("LDA", "Error setting layer with name " + layerName);
}
_MapView.invalidate(true);
}
@Override
public void onItemSelected(AdapterView<?> parent, View arg1, int position,
long arg3) {
setLayer((String) parent.getItemAtPosition(position));
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
}