-
Notifications
You must be signed in to change notification settings - Fork 75
Offline map tiles
Nutiteq SDK core has a few offline map data source options built-in. DataSource describes from where map image tiles are loaded and it is given as constructor parameter to RasterLayer.
PackagedMapLayer is a raster layer that reads map tiles bundled in the app project /res/raw/ folder. It is very easy to use: just copy the map tiles to /res/raw of your application project, and add the layer like this:
RasterDataSource dataSource = new PackagedRasterDataSource(new EPSG3857(), 0, 3, "t{zoom}_{x}_{y}", getApplicationContext());
RasterLayer packagedMapLayer = new RasterLayer(dataSource, 16);
mapView.getLayers().setBaseLayer(packagedMapLayer);
The tile files must follow specific naming, and there are no subfolders, see details in PackagedMapLayer javadoc.
- Maximum size of map tiles is limited by maximum APK file size limit, which is 50MB. This enables to include a few general world zoom levels (about 4 or 5). However, many lower end devices have very limited total space for apps, these users would not be happy with bigger than say 10MB APK files. This limits how much maps you can bundle.
- Here is a basic online tool to create tile packages. It creates zip file what you need to uncompress and put *.png files to /res/raw
- Sample data is also included in AdvancedMap3D project.
Following layers are as source code in separate AdvancedLayers project. Include this to your project to use them - see readme in the project.
MBTiles support is included as source code in the AdvancedLayers project. MBTiles uses SQLite database format, so you have just one file to be downloaded and managed. Some tools to create MBTiles packages:
- Use MOBAC to download from free sources
- MBUtil enables to create mbtiles from/to TMS-style tile folders
- TileMill is wonderful open source generator of very nice map packages, in MBTiles format. It enables to add interaction with UTFGrid tooltips.
- MapTiler is nice utility for Mac, well worth a couple of bucks to support the developer
- Portable Basemap Server - free utility for Windows, loads data not only from various commercial servers and custom sources, but also from ESRI formats. Works mainly as WMTS server, but can create MBTiles as extra feature.
Following code assumes that you already have MBTiles file in your external storage. There are several ways to get it there:
- Download it from your own online server as per user request or automatically with app start, perhaps using Download Manager.
- Use Application Expansion File, so the file is hosted by by Play Store. See official info. You get free hosting, but less flexibility compared to plain http server or CDN.
- Add the file to APK assets folder. You cannot open MBTiles (sqlite file) from APK directly, so you must copy it with first application start. See code sample . The limit is max size of APK (50 MB).
try {
MBTilesRasterDataSource dataSource = new MBTilesRasterDataSource(new EPSG3857(), 0, 19, "/sdcard/mymaps.mbtiles", false, this);
RasterLayer mbLayer = new RasterLayer(dataSource, file.hashCode());
mapView.getLayers().addLayer(mbLayer);
} catch (IOException e) {
// means usually that given .mbtiles file is not found or cannot be opened as sqlite database
Log.error(e.getLocalizedMessage());
e.printStackTrace();
}
See MBTilesMapActivity.java in AdvancedMap3D project to see how interaction using UTFGrid can be created.
Following data sources can be also used as offline data sources:
- GDAL layer reads many different GIS file formats, like GeoTIFF etc