【移动GIS】MBTiles离线地图设置

使用Osmdroid,利用MBTiles格式存储离线瓦片,下面为加载方式:

/**
 * 离线地图
 * 来自离线文件 mbtiles_db.mbtiles
 * 
 * 
 */
public class OfflineMBTilesDemo extends Activity {
	private MapView mapView;
	public  RelativeLayout rl;
	public  MapTileProviderArray mProvider;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setOfflineForMBTiles();// 离线数据
		
		ScaleBarOverlay scaleBar = new ScaleBarOverlay(getApplicationContext());//比例尺
		mapView.getOverlays().add(scaleBar);
	}
	public void setOfflineForMBTiles() {
		{//离线数据设置
		DefaultResourceProxyImpl mResourceProxy = new DefaultResourceProxyImpl(
				this.getApplicationContext());
		SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(
				this.getApplicationContext());
		
		File f = new File("SD/map/MBTiles" , "mbtiles_db.mbtiles");
		IArchiveFile[] files = { MBTilesFileArchive.getDatabaseFileArchive(f) };
		OfflineTileSource offlineSource = new OfflineTileSource("ehl_mbtiles_db", ResourceProxy.string.offline_mode, 7, 15, 256, ".png");

		MapTileModuleProviderBase moduleProvider = new MapTileFileArchiveProvider( simpleReceiver, offlineSource, files);
		MapTileProviderArray mProvider = new MapTileProviderArray( offlineSource, null, new MapTileModuleProviderBase[] { moduleProvider });
		this.mapView = new MapView(this, 256, mResourceProxy, mProvider);
		}
		
		{//地图初始化设置
		this.mapView.setBuiltInZoomControls(true);// 最下方出现放大缩小按钮
		this.mapView.setMultiTouchControls(true);// 触控放大缩小
		this.mapView.setUseDataConnection(false);
		mapView.getController().setCenter(
				new GeoPoint(29.35, 106.33));// 设置中心点
		mapView.getController().setZoom(9);
		}
		
		{//布局
		final RelativeLayout rl = new RelativeLayout(this);
		rl.addView(this.mapView, new RelativeLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
				this.setContentView(rl);
		}
	}
}


 

你可能感兴趣的:(GIS)