/** * Reads and opens a MBTiles file given by url and loads its tiles into this layer. */ private void initialize(String url, final Context context) { initialize(getFile(url, context)); }
/** * Initialize a new tile layer, represented by a Database file. * * @param db a database used as the MBTiles source */ public MBTilesLayer(final SQLiteDatabase db) { super(getFileName(db.getPath()), db.getPath()); initialize(db); }
private void selectMBTilesBasemap(String mbtilesPath) { File mbtilesFile = new File(mbtilesPath); if(!mbtilesFile.exists()) { AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); builder.setTitle("Offline Basemap Not Found"); builder.setMessage("Please check out a deployment or add MBTiles files to " + ExternalStorage.getMBTilesDir()); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //placeholder } }); AlertDialog dialog = builder.create(); dialog.show(); return; } //add mbtiles to map MBTilesLayer mbTilesLayer = new MBTilesLayer(mbtilesFile); mapView.setTileSource(mbTilesLayer); setSelectedBasemap(mbtilesPath); // if we set an MBTiles from a DeploymentDetails, the map may not start panned to the bounds if (needsBoundsChecking) { BoundingBox bbox = mbTilesLayer.getBoundingBox(); mapView.zoomToBoundingBox(bbox); needsBoundsChecking = false; } }
/** * Initialize a new tile layer, represented by a MBTiles file. * * @param file a MBTiles file */ public MBTilesLayer(final File file) { super(file.getName(), file.getAbsolutePath()); initialize(file); }
private File getFile(String url, final Context context) { if (context != null) { //we assume asset here AssetManager am = context.getAssets(); InputStream inputStream; try { inputStream = am.open(url); final File mbTilesDir; if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || (!Environment.isExternalStorageRemovable())) { mbTilesDir = new File(context.getExternalFilesDir(null), url); } else { mbTilesDir = new File(context.getFilesDir(), url); } return createFileFromInputStream(inputStream, mbTilesDir.getPath()); } catch (IOException e) { Log.e(TAG, "MBTiles file not found in assets: " + e.toString()); return null; } } try { return new File(url); } catch (Exception e) { Log.e(TAG, "can't load MBTiles: " + e.toString()); return null; } }
/** * Initialize a new tile layer, represented by a MBTiles file. * * @param url path to a MBTiles file * @param context the graphics drawing context */ public MBTilesLayer(final Context context, final String url) { super(url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.')), url); initialize(url, context); }