【移动GIS】离线地图ZIP格式设置

在OSMdroid中,使用ZIP格式离线文件来加载地图瓦片。

设置方式如下:

/**
 * 离线地图
 * 来自ZIP压缩文件
 * 
 * @author fazhen.zheng
 * 
 */
public class OfflineZipTilesDemo extends Activity {
	private MapView mapView;
	public  RelativeLayout rl;
	public  MapTileProviderArray mProvider;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setOfflineForZip();// 离线数据
		
		ScaleBarOverlay scaleBar = new ScaleBarOverlay(getApplicationContext());//比例尺
		mapView.getOverlays().add(scaleBar);
	}
	public void setOfflineForZip() {
		{//离线数据设置
		DefaultResourceProxyImpl mResourceProxy = new DefaultResourceProxyImpl(
				this.getApplicationContext());
		SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(
				this.getApplicationContext());
		
		File f = new File(TileProviderConstants.EHLMAP_PATH+"/zip" , "china.zip");
		IArchiveFile[] files = { ArchiveFileFactory.getArchiveFile(f) };
		
		OfflineTileSource offlineSource = new OfflineTileSource("china", ResourceProxy.string.offline_mode, 6, 13, 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(36.5447278702, 104.1347919517));// 设置中心点
		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);
		}
	}
}


 

你可能感兴趣的:(osmdroid,离线地图,Zip格式)