关于离线地图mapsforge 几个重要代码记录

1.github地址: https://github.com/mapsforge/mapsforge

1.添加离线地图.map代码。

TileCache tileCache = AndroidUtil.createTileCache(getContext(), "mapcache",
                    getModel().displayModel.getTileSize(), 1f,
                    getModel().frameBufferModel.getOverdrawFactor());
            //加载map地图
MapDataStore mapDataStore = new MapFile(mapPath);
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
                    getModel().mapViewPosition, AndroidGraphicFactory.INSTANCE);
tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.DEFAULT);
Layers layers = getLayers();
layers.add(tileRendererLayer, LayerGroups.TileRendererLayer.getId());

2.图形在地图上居中显示。

BoundingBox boundingBox = new BoundingBox(latLongList);
int tileSize = mMapView.getModel().displayModel.getTileSize();
byte zoomLevel = LatLongUtils.zoomForBounds(new Dimension(tileSize, tileSize), boundingBox,             
                 tileSize);
mMapView.setCenter(boundingBox.getCenterPoint());
mMapView.setZoomLevel(zoomLevel);

 

你可能感兴趣的:(java,Android)