我正在使用带有离线 MBTiles 的 OSMdroid。我需要能够添加用户以从ListView
. ListView
窗户很容易。但是,我需要帮助根据从中选择的 MBtiles 加载不同的 MBtiles ListView
。我的 MBTiles 是从 SDCard 加载的。
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RelativeLayout;
public class OfflineMapDemoActivity extends Activity {
private String MapName;
public String getMapName(){
return MapName;
}
public void setMapName(String s){
MapName = s;
}
// layout
private RelativeLayout mapLayout;
// MapView
private MapView mapView;
private MapController mapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// init Layout
setContentView(R.layout.main);
this.mapLayout = (RelativeLayout) findViewById(R.id.mapLayout);
// init Offline Map
MapName="World.sqlitedb";
this.mapView = new OfflineMapView(this, MapName);
this.mapController = mapView.getController();
// set Zoom Countrol
this.mapView.setBuiltInZoomControls(true);
// set Touch Control
this.mapView.setMultiTouchControls(true);
// zoom to 15
this.mapController.setZoom(15);
//add mapview
this.mapLayout.addView(this.mapView, new RelativeLayout.LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.FILL_PARENT));
// scroll to 24082456, 120558472
GeoPoint geoPoint = new GeoPoint(24082456, 120558472);
this.mapController.setCenter(geoPoint);
}
}
我创建了一个全局字符串变量来保存类可以通过公共方法设置的MapName
位置。Listview
setMapName()
顺便说一句,有没有一种方法可以自动读取 MBTiles 中心而不是像这样的硬编码?
// scroll to 24082456, 120558472
GeoPoint geoPoint = new GeoPoint(24082456, 120558472);
this.mapController.setCenter(geoPoint);
每次用户切换到OSMdroid
地图ListView
以从列表视图加载选定的离线 MBtiles 地图时,我应该使用哪种方法?上面的 Create 方法只在第一次加载时加载一次 MBTiles 地图?这是列表视图代码。
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;
public class MyTwoListItemsActivity extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<Map<String, String>> list = buildData();
String[] from = { "mapname", "selected" };
int[] to = { android.R.id.text1, android.R.id.text2 };
SimpleAdapter adapter = new SimpleAdapter(this, list,
android.R.layout.simple_list_item_2, from, to);
setListAdapter(adapter);
}
private ArrayList<Map<String, String>> buildData() {
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.add(putData("Map1", "Map1"));
list.add(putData("Map2", "Map2"));
list.add(putData("Map3", "Map3"));
return list;
}
private HashMap<String, String> putData(String name, String purpose) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("mapname", mapname);
item.put("selected", selected);
return item;
}
}
如何集成 和 之间MyTwoListItemsActivity
的切换OfflineMapDemoActivity
?