Creating new module vtm-android-mvt
This commit is contained in:
parent
bd8cea37ad
commit
1647dd989e
@ -3,6 +3,7 @@ include ':vtm'
|
|||||||
include ':vtm-android'
|
include ':vtm-android'
|
||||||
include ':vtm-android-example'
|
include ':vtm-android-example'
|
||||||
include ':vtm-android-gdx'
|
include ':vtm-android-gdx'
|
||||||
|
include ':vtm-android-mvt'
|
||||||
include ':vtm-app'
|
include ':vtm-app'
|
||||||
include ':vtm-desktop'
|
include ':vtm-desktop'
|
||||||
include ':vtm-desktop-lwjgl'
|
include ':vtm-desktop-lwjgl'
|
||||||
|
@ -9,6 +9,7 @@ configurations.all {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':vtm-android')
|
implementation project(':vtm-android')
|
||||||
|
implementation project(':vtm-android-mvt')
|
||||||
implementation project(':vtm-extras')
|
implementation project(':vtm-extras')
|
||||||
implementation project(':vtm-http')
|
implementation project(':vtm-http')
|
||||||
implementation project(':vtm-jeo')
|
implementation project(':vtm-jeo')
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
<string name="now">Now</string>
|
<string name="now">Now</string>
|
||||||
<string name="warning">Warning</string>
|
<string name="warning">Warning</string>
|
||||||
<string name="startup_message_mbtiles">To run this sample activity, you need an MBTiles Database installed on storage.\n\nadb push %s %s</string>
|
<string name="startup_message_mbtiles">To run this sample activity, you need an MBTiles Database installed on storage.\n\nadb push %s %s</string>
|
||||||
<string name="unknown_format_mbtiles">Unknown format \'%s\' found in MBTiles database \'%s\' in field \'metadata.format\'. Supported format(s) are: \'%s\'</string>
|
|
||||||
<string name="exit">Exit</string>
|
<string name="exit">Exit</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -19,10 +19,8 @@ package org.oscim.android.test;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import org.oscim.android.tiling.source.mbtiles.MBTilesBitmapTileDataSourceWorker;
|
import org.oscim.android.tiling.source.mbtiles.MBTilesBitmapTileSource;
|
||||||
import org.oscim.android.tiling.source.mbtiles.MBTilesMvtTileDataSourceWorker;
|
|
||||||
import org.oscim.android.tiling.source.mbtiles.MBTilesTileSource;
|
import org.oscim.android.tiling.source.mbtiles.MBTilesTileSource;
|
||||||
import org.oscim.core.BoundingBox;
|
import org.oscim.core.BoundingBox;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
@ -55,29 +53,7 @@ public class MBTilesBitmapTileActivity extends BitmapTileActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MBTilesTileSource tileSource = new MBTilesTileSource(file.getAbsolutePath(), null, 128, null);
|
MBTilesTileSource tileSource = new MBTilesBitmapTileSource(file.getAbsolutePath(), 128, null);
|
||||||
|
|
||||||
if (!MBTilesBitmapTileDataSourceWorker.SUPPORTED_FORMATS.contains(tileSource.getMetadataFormat())) {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
||||||
.setTitle(R.string.warning)
|
|
||||||
.setMessage(
|
|
||||||
getResources().getString(
|
|
||||||
R.string.unknown_format_mbtiles,
|
|
||||||
tileSource.getMetadataFormat(),
|
|
||||||
file.getAbsolutePath(),
|
|
||||||
TextUtils.join(", ", MBTilesMvtTileDataSourceWorker.SUPPORTED_FORMATS)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.show();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BitmapTileLayer bitmapLayer = new BitmapTileLayer(mMap, tileSource);
|
BitmapTileLayer bitmapLayer = new BitmapTileLayer(mMap, tileSource);
|
||||||
mMap.layers().add(bitmapLayer);
|
mMap.layers().add(bitmapLayer);
|
||||||
|
@ -19,23 +19,17 @@ package org.oscim.android.test;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import org.oscim.android.cache.TileCache;
|
import org.oscim.android.mvt.tiling.source.mbtiles.MBTilesMvtTileSource;
|
||||||
import org.oscim.android.tiling.source.mbtiles.MBTilesMvtTileDataSourceWorker;
|
|
||||||
import org.oscim.android.tiling.source.mbtiles.MBTilesTileSource;
|
import org.oscim.android.tiling.source.mbtiles.MBTilesTileSource;
|
||||||
|
import org.oscim.android.tiling.source.mbtiles.UnsupportedMBTilesDatabaseException;
|
||||||
import org.oscim.core.BoundingBox;
|
import org.oscim.core.BoundingBox;
|
||||||
import org.oscim.core.GeoPoint;
|
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.Tile;
|
import org.oscim.core.Tile;
|
||||||
import org.oscim.layers.tile.buildings.BuildingLayer;
|
import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||||
import org.oscim.theme.VtmThemes;
|
import org.oscim.theme.VtmThemes;
|
||||||
import org.oscim.tiling.TileSource;
|
|
||||||
import org.oscim.tiling.source.OkHttpEngine;
|
|
||||||
import org.oscim.tiling.source.UrlTileSource;
|
|
||||||
import org.oscim.tiling.source.mvt.OpenMapTilesMvtTileSource;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -60,19 +54,13 @@ public class MBTilesMvtTileActivity extends MapActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MBTilesTileSource tileSource = new MBTilesTileSource(file.getAbsolutePath(), "en");
|
MBTilesTileSource tileSource;
|
||||||
|
try {
|
||||||
if (!MBTilesMvtTileDataSourceWorker.SUPPORTED_FORMATS.contains(tileSource.getMetadataFormat())) {
|
tileSource = new MBTilesMvtTileSource(file.getAbsolutePath(), "en");
|
||||||
|
} catch (UnsupportedMBTilesDatabaseException e) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||||
.setTitle(R.string.warning)
|
.setTitle(R.string.warning)
|
||||||
.setMessage(
|
.setMessage(e.getMessage())
|
||||||
getResources().getString(
|
|
||||||
R.string.unknown_format_mbtiles,
|
|
||||||
tileSource.getMetadataFormat(),
|
|
||||||
file.getAbsolutePath(),
|
|
||||||
TextUtils.join(", ", MBTilesMvtTileDataSourceWorker.SUPPORTED_FORMATS)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
2
vtm-android-mvt/AndroidManifest.xml
Normal file
2
vtm-android-mvt/AndroidManifest.xml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<manifest package="org.oscim.android.mvt" />
|
62
vtm-android-mvt/build.gradle
Normal file
62
vtm-android-mvt/build.gradle
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
apply plugin: 'com.android.library'
|
||||||
|
apply plugin: 'com.github.dcendents.android-maven'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api project(':vtm-android')
|
||||||
|
api project(':vtm-mvt')
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion androidCompileSdk()
|
||||||
|
buildToolsVersion "$androidBuildVersionTools"
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_7
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_7
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
versionCode project.versionCode()
|
||||||
|
versionName project.versionName()
|
||||||
|
minSdkVersion androidMinSdk()
|
||||||
|
targetSdkVersion androidTargetSdk()
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
manifest.srcFile 'AndroidManifest.xml'
|
||||||
|
java.srcDirs = ['src']
|
||||||
|
}
|
||||||
|
debug.setRoot('build-types/debug')
|
||||||
|
release.setRoot('build-types/release')
|
||||||
|
}
|
||||||
|
|
||||||
|
lintOptions { abortOnError false }
|
||||||
|
}
|
||||||
|
|
||||||
|
android.libraryVariants.all { variant ->
|
||||||
|
def name = variant.buildType.name
|
||||||
|
if (name == "debug")
|
||||||
|
return
|
||||||
|
|
||||||
|
def jar = project.tasks.create "jar${name.capitalize()}", Jar
|
||||||
|
jar.dependsOn variant.javaCompileProvider
|
||||||
|
jar.exclude '**/BuildConfig.class'
|
||||||
|
jar.exclude '**/R.class'
|
||||||
|
jar.exclude '**/R$*.class'
|
||||||
|
jar.from variant.javaCompileProvider.get().destinationDir
|
||||||
|
artifacts.add('archives', jar)
|
||||||
|
|
||||||
|
file('natives').eachDir() { dir ->
|
||||||
|
def nativesJar = project.tasks.create "nativesJar${name.capitalize()}-${dir.name}", Jar
|
||||||
|
nativesJar.classifier = "natives-${dir.name}"
|
||||||
|
nativesJar.from(dir.path)
|
||||||
|
artifacts.add('archives', nativesJar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (project.hasProperty("SONATYPE_USERNAME")) {
|
||||||
|
afterEvaluate {
|
||||||
|
project.apply from: "${rootProject.projectDir}/deploy.gradle"
|
||||||
|
}
|
||||||
|
}
|
@ -12,17 +12,14 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.oscim.android.tiling.source.mbtiles;
|
package org.oscim.android.mvt.tiling.source.mbtiles;
|
||||||
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
|
|
||||||
import org.oscim.core.BoundingBox;
|
import org.oscim.android.tiling.source.mbtiles.MBTilesTileDataSource;
|
||||||
import org.oscim.core.MercatorProjection;
|
import org.oscim.core.MercatorProjection;
|
||||||
import org.oscim.layers.tile.MapTile;
|
import org.oscim.layers.tile.MapTile;
|
||||||
import org.oscim.map.Viewport;
|
|
||||||
import org.oscim.tiling.ITileDataSink;
|
import org.oscim.tiling.ITileDataSink;
|
||||||
import org.oscim.tiling.ITileDataSource;
|
|
||||||
import org.oscim.tiling.OverzoomDataSink;
|
import org.oscim.tiling.OverzoomDataSink;
|
||||||
import org.oscim.tiling.QueryResult;
|
import org.oscim.tiling.QueryResult;
|
||||||
import org.oscim.tiling.source.mvt.MvtTileDecoder;
|
import org.oscim.tiling.source.mvt.MvtTileDecoder;
|
||||||
@ -30,26 +27,16 @@ import org.oscim.tiling.source.mvt.MvtTileDecoder;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
public class MBTilesMvtTileDataSourceWorker implements ITileDataSource {
|
public class MBTilesMvtTileDataSource extends MBTilesTileDataSource {
|
||||||
public final static List<String> SUPPORTED_FORMATS = Arrays.asList("pbf");
|
private final static List<String> SUPPORTED_FORMATS = Arrays.asList("pbf");
|
||||||
|
|
||||||
private static final String SELECT_TILES_FORMAT =
|
public static final String WHERE_FORMAT = "zoom_level=%d AND tile_column=%d AND tile_row=%d";
|
||||||
"SELECT zoom_level, tile_column, tile_row, tile_data " +
|
|
||||||
"FROM tiles " +
|
|
||||||
"WHERE %s " +
|
|
||||||
"ORDER BY zoom_level DESC " +
|
|
||||||
"LIMIT 1";
|
|
||||||
|
|
||||||
private static final String WHERE_FORMAT = "zoom_level=%d AND tile_column=%d AND tile_row=%d";
|
|
||||||
|
|
||||||
private final String mLocale;
|
private final String mLocale;
|
||||||
private final SQLiteDatabase mDatabase;
|
|
||||||
|
|
||||||
private final ThreadLocal<MvtTileDecoder> mThreadLocalMvtTileDecoders = new ThreadLocal<MvtTileDecoder>() {
|
private final ThreadLocal<MvtTileDecoder> mThreadLocalMvtTileDecoders = new ThreadLocal<MvtTileDecoder>() {
|
||||||
@Override
|
@Override
|
||||||
@ -58,9 +45,17 @@ public class MBTilesMvtTileDataSourceWorker implements ITileDataSource {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public MBTilesMvtTileDataSourceWorker(SQLiteDatabase database, String locale) {
|
public MBTilesMvtTileDataSource(String databasePath, String locale) {
|
||||||
|
super(databasePath);
|
||||||
|
|
||||||
|
assertDatabaseFormat();
|
||||||
|
|
||||||
mLocale = locale != null ? locale : "en";
|
mLocale = locale != null ? locale : "en";
|
||||||
mDatabase = database;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getSupportedFormats() {
|
||||||
|
return SUPPORTED_FORMATS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Kostas Tzounopoulos
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
|
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.oscim.android.mvt.tiling.source.mbtiles;
|
||||||
|
|
||||||
|
import org.oscim.android.tiling.source.mbtiles.MBTilesTileSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a Vector MBTiles tile source (OpenMapTiles MVT with gzipped-pbf tiles)
|
||||||
|
*/
|
||||||
|
public class MBTilesMvtTileSource extends MBTilesTileSource {
|
||||||
|
public MBTilesMvtTileSource(String databasePath) {
|
||||||
|
this(databasePath, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a MBTiles tile data source for Raster databases
|
||||||
|
*
|
||||||
|
* @param databasePath the MBTiles database path
|
||||||
|
* @param locale the locale to use when rendering the MBTiles
|
||||||
|
*/
|
||||||
|
public MBTilesMvtTileSource(String databasePath, String locale) {
|
||||||
|
super(new MBTilesMvtTileDataSource(databasePath, locale));
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,6 @@ apply plugin: 'com.github.dcendents.android-maven'
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api project(':vtm')
|
api project(':vtm')
|
||||||
api project(':vtm-mvt')
|
|
||||||
api 'com.caverock:androidsvg:1.3'
|
api 'com.caverock:androidsvg:1.3'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,19 +17,16 @@
|
|||||||
package org.oscim.android.tiling.source.mbtiles;
|
package org.oscim.android.tiling.source.mbtiles;
|
||||||
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
|
||||||
import org.oscim.backend.CanvasAdapter;
|
import org.oscim.backend.CanvasAdapter;
|
||||||
import org.oscim.backend.canvas.Bitmap;
|
import org.oscim.backend.canvas.Bitmap;
|
||||||
import org.oscim.core.BoundingBox;
|
|
||||||
import org.oscim.core.MercatorProjection;
|
import org.oscim.core.MercatorProjection;
|
||||||
import org.oscim.layers.tile.MapTile;
|
import org.oscim.layers.tile.MapTile;
|
||||||
import org.oscim.map.Viewport;
|
|
||||||
import org.oscim.tiling.ITileDataSink;
|
import org.oscim.tiling.ITileDataSink;
|
||||||
import org.oscim.tiling.ITileDataSource;
|
|
||||||
import org.oscim.tiling.QueryResult;
|
import org.oscim.tiling.QueryResult;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -37,34 +34,43 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A tile data source for MBTiles Raster databases.
|
* A tile data source for MBTiles Raster databases.
|
||||||
*/
|
*/
|
||||||
public class MBTilesBitmapTileDataSourceWorker implements ITileDataSource {
|
public class MBTilesBitmapTileDataSource extends MBTilesTileDataSource {
|
||||||
public final static List<String> SUPPORTED_FORMATS = Arrays.asList("png", "jpg", "jpeg");
|
private final static List<String> SUPPORTED_FORMATS = Arrays.asList("png", "jpg", "jpeg");
|
||||||
protected static final Logger log = LoggerFactory.getLogger(MBTilesBitmapTileDataSourceWorker.class);
|
protected static final Logger log = LoggerFactory.getLogger(MBTilesBitmapTileDataSource.class);
|
||||||
|
|
||||||
private final Integer mAlpha;
|
private final Integer mAlpha;
|
||||||
private final Integer mTransparentColor;
|
private final Integer mTransparentColor;
|
||||||
private final SQLiteDatabase mDatabase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a MBTiles tile data source.
|
* Create a MBTiles tile data source for Raster databases
|
||||||
*
|
*
|
||||||
* @param database the MBTiles database
|
* @param path the MBTiles database path
|
||||||
* @param alpha an optional alpha value [0-255] to make the tiles transparent.
|
* @param alpha an optional alpha value [0-255] to make the tiles transparent.
|
||||||
* @param transparentColor an optional color that will be made transparent in the bitmap.
|
* @param transparentColor an optional color that will be made transparent in the bitmap.
|
||||||
*/
|
*/
|
||||||
MBTilesBitmapTileDataSourceWorker(SQLiteDatabase database, Integer alpha, Integer transparentColor) {
|
public MBTilesBitmapTileDataSource(String path, Integer alpha, Integer transparentColor) {
|
||||||
mDatabase = database;
|
super(path);
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertDatabaseFormat();
|
||||||
|
} catch (UnsupportedMBTilesDatabaseException e) {
|
||||||
|
log.error("Invalid MBTiles database", e);
|
||||||
|
}
|
||||||
|
|
||||||
mAlpha = alpha;
|
mAlpha = alpha;
|
||||||
mTransparentColor = transparentColor;
|
mTransparentColor = transparentColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getSupportedFormats() {
|
||||||
|
return SUPPORTED_FORMATS;
|
||||||
|
}
|
||||||
|
|
||||||
private static android.graphics.Bitmap processAlpha(android.graphics.Bitmap bitmap, int alpha) {
|
private static android.graphics.Bitmap processAlpha(android.graphics.Bitmap bitmap, int alpha) {
|
||||||
android.graphics.Bitmap newBitmap = android.graphics.Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), android.graphics.Bitmap.Config.ARGB_8888);
|
android.graphics.Bitmap newBitmap = android.graphics.Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), android.graphics.Bitmap.Config.ARGB_8888);
|
||||||
Canvas canvas = new Canvas(newBitmap);
|
Canvas canvas = new Canvas(newBitmap);
|
||||||
@ -136,16 +142,17 @@ public class MBTilesBitmapTileDataSourceWorker implements ITileDataSource {
|
|||||||
* @return the tile image bytes.
|
* @return the tile image bytes.
|
||||||
*/
|
*/
|
||||||
private byte[] readTile(int tileX, int tileY, byte zoomLevel) {
|
private byte[] readTile(int tileX, int tileY, byte zoomLevel) {
|
||||||
|
long tmsTileY = MercatorProjection.tileYToTMS(tileY, zoomLevel);
|
||||||
|
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
long tmsTileY = MercatorProjection.tileYToTMS(tileY, zoomLevel);
|
|
||||||
cursor = mDatabase.rawQuery(
|
cursor = mDatabase.rawQuery(
|
||||||
MBTilesTileDataSource.SELECT_TILES,
|
String.format(MBTilesTileDataSource.SELECT_TILES_FORMAT, MBTilesTileDataSource.WHERE_FORMAT),
|
||||||
new String[]{String.valueOf(zoomLevel), String.valueOf(tileX), String.valueOf(tmsTileY)}
|
new String[]{String.valueOf(zoomLevel), String.valueOf(tileX), String.valueOf(tmsTileY)}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
return cursor.getBlob(0);
|
return cursor.getBlob(cursor.getColumnIndexOrThrow("tile_data"));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Andrea Antonello
|
||||||
|
* Copyright 2019 devemux86
|
||||||
|
* Copyright 2019 Kostas Tzounopoulos
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
|
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.oscim.android.tiling.source.mbtiles;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a Raster MBTiles tile source
|
||||||
|
*/
|
||||||
|
public class MBTilesBitmapTileSource extends MBTilesTileSource {
|
||||||
|
public MBTilesBitmapTileSource(String databasePath) {
|
||||||
|
this(databasePath, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a MBTiles tile data source for Raster databases
|
||||||
|
*
|
||||||
|
* @param databasePath the MBTiles database path
|
||||||
|
* @param alpha an optional alpha value [0-255] to make the tiles transparent.
|
||||||
|
* @param transparentColor an optional color that will be made transparent in the bitmap.
|
||||||
|
*/
|
||||||
|
public MBTilesBitmapTileSource(String databasePath, Integer alpha, Integer transparentColor) {
|
||||||
|
super(new MBTilesBitmapTileDataSource(databasePath, alpha, transparentColor));
|
||||||
|
}
|
||||||
|
}
|
@ -20,106 +20,60 @@ import android.database.Cursor;
|
|||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.locationtech.jts.geom.Point;
|
|
||||||
import org.oscim.core.BoundingBox;
|
import org.oscim.core.BoundingBox;
|
||||||
import org.oscim.core.GeoPoint;
|
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.layers.tile.MapTile;
|
|
||||||
import org.oscim.map.Viewport;
|
import org.oscim.map.Viewport;
|
||||||
import org.oscim.tiling.ITileDataSink;
|
|
||||||
import org.oscim.tiling.ITileDataSource;
|
import org.oscim.tiling.ITileDataSource;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MBTilesTileDataSource implements ITileDataSource {
|
abstract public class MBTilesTileDataSource implements ITileDataSource {
|
||||||
private static final String TABLE_TILES = "tiles";
|
public static final String SELECT_TILES_FORMAT =
|
||||||
private static final String COL_TILES_ZOOM_LEVEL = "zoom_level";
|
"SELECT zoom_level, tile_column, tile_row, tile_data " +
|
||||||
private static final String COL_TILES_TILE_COLUMN = "tile_column";
|
"FROM tiles " +
|
||||||
private static final String COL_TILES_TILE_ROW = "tile_row";
|
"WHERE %s " +
|
||||||
private static final String COL_TILES_TILE_DATA = "tile_data";
|
"ORDER BY zoom_level DESC " +
|
||||||
private static final String TABLE_METADATA = "metadata";
|
"LIMIT 1";
|
||||||
private static final String COL_METADATA_NAME = "name";
|
|
||||||
private static final String COL_METADATA_VALUE = "value";
|
|
||||||
|
|
||||||
public static final String SELECT_TILES = "SELECT " + COL_TILES_TILE_DATA + " from " + TABLE_TILES + " where "
|
public static final String WHERE_FORMAT = "zoom_level=? AND tile_column=? AND tile_row=?";
|
||||||
+ COL_TILES_ZOOM_LEVEL + "=? AND " + COL_TILES_TILE_COLUMN + "=? AND " + COL_TILES_TILE_ROW + "=?";
|
public static final String SELECT_METADATA = "SELECT name, value FROM metadata";
|
||||||
public static final String SELECT_METADATA = "select " + COL_METADATA_NAME + "," + COL_METADATA_VALUE + " from "
|
|
||||||
+ TABLE_METADATA;
|
|
||||||
|
|
||||||
private final SQLiteDatabase mDatabase;
|
protected final SQLiteDatabase mDatabase;
|
||||||
private final String mLocale;
|
protected Map<String, String> mMetadata;
|
||||||
private final Integer mAlpha;
|
|
||||||
private final Integer mTransparentColor;
|
|
||||||
private Map<String, String> mMetadata;
|
|
||||||
private ITileDataSource mTileDataSource;
|
|
||||||
|
|
||||||
public MBTilesTileDataSource(String path, String locale, Integer alpha, Integer transparentColor) {
|
public MBTilesTileDataSource(String path) {
|
||||||
mDatabase = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
|
mDatabase = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
|
||||||
mLocale = locale;
|
|
||||||
mAlpha = alpha;
|
|
||||||
mTransparentColor = transparentColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
abstract public List<String> getSupportedFormats();
|
||||||
public void cancel() {
|
|
||||||
findWorker().cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
findWorker().cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void query(MapTile requestTile, ITileDataSink requestDataSink) {
|
|
||||||
findWorker().query(requestTile, requestDataSink);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ITileDataSource findWorker() {
|
|
||||||
if (mTileDataSource != null) {
|
|
||||||
return mTileDataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected void assertDatabaseFormat() {
|
||||||
String mbTilesFormat = getFormat();
|
String mbTilesFormat = getFormat();
|
||||||
|
|
||||||
if (mbTilesFormat == null) {
|
if (mbTilesFormat == null) {
|
||||||
throw new RuntimeException("Unable to read the '" + TABLE_METADATA + ".format' field of the database.");
|
throw new RuntimeException("'metadata.format' field was not found. Is this an MBTiles database?");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MBTilesBitmapTileDataSourceWorker.SUPPORTED_FORMATS.contains(mbTilesFormat)) {
|
List<String> supportedFormats = getSupportedFormats();
|
||||||
mTileDataSource = new MBTilesBitmapTileDataSourceWorker(mDatabase, mAlpha, mTransparentColor);
|
|
||||||
|
|
||||||
return mTileDataSource;
|
if (!supportedFormats.contains(mbTilesFormat)) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
String.format(
|
||||||
|
"Unsupported MBTiles 'metadata.format: %s'. Supported format(s) are: %s",
|
||||||
|
mbTilesFormat,
|
||||||
|
TextUtils.join(", ", supportedFormats)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MBTilesMvtTileDataSourceWorker.SUPPORTED_FORMATS.contains(mbTilesFormat)) {
|
|
||||||
mTileDataSource = new MBTilesMvtTileDataSourceWorker(mDatabase, mLocale);
|
|
||||||
|
|
||||||
return mTileDataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> supportedFormats = new ArrayList<>();
|
|
||||||
supportedFormats.addAll(MBTilesBitmapTileDataSourceWorker.SUPPORTED_FORMATS);
|
|
||||||
supportedFormats.addAll(MBTilesMvtTileDataSourceWorker.SUPPORTED_FORMATS);
|
|
||||||
|
|
||||||
throw new RuntimeException(
|
|
||||||
String.format(
|
|
||||||
"Unknown MBtiles database format '%s' found in the 'metadata.format' field of the database. "
|
|
||||||
+ "Expected one of: '%s'",
|
|
||||||
mbTilesFormat,
|
|
||||||
TextUtils.join(", ", supportedFormats)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getAttribution() {
|
public String getAttribution() {
|
||||||
return getMetadata().get("attribution");
|
return getMetadata().get("attribution");
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBox getBounds() {
|
public BoundingBox getBounds() {
|
||||||
String bounds = getMetadata().get("bounds");
|
String bounds = getMetadata().get("bounds");
|
||||||
|
|
||||||
if (bounds == null) {
|
if (bounds == null) {
|
||||||
@ -135,7 +89,7 @@ public class MBTilesTileDataSource implements ITileDataSource {
|
|||||||
return new BoundingBox(s, w, n, e);
|
return new BoundingBox(s, w, n, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapPosition getCenter() {
|
public MapPosition getCenter() {
|
||||||
String center = getMetadata().get("center");
|
String center = getMetadata().get("center");
|
||||||
|
|
||||||
if (center == null) {
|
if (center == null) {
|
||||||
@ -154,51 +108,51 @@ public class MBTilesTileDataSource implements ITileDataSource {
|
|||||||
return centerMapPosition;
|
return centerMapPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getDescription() {
|
public String getDescription() {
|
||||||
return getMetadata().get("description");
|
return getMetadata().get("description");
|
||||||
}
|
}
|
||||||
|
|
||||||
String getFormat() {
|
public String getFormat() {
|
||||||
return getMetadata().get("format");
|
return getMetadata().get("format");
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer getPixelScale() {
|
public Integer getPixelScale() {
|
||||||
String pixelScale = getMetadata().get("pixel_scale");
|
String pixelScale = getMetadata().get("pixel_scale");
|
||||||
|
|
||||||
return pixelScale != null ? Integer.parseInt(pixelScale) : null;
|
return pixelScale != null ? Integer.parseInt(pixelScale) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getMaxZoom() {
|
public int getMaxZoom() {
|
||||||
String maxZoom = getMetadata().get("maxzoom");
|
String maxZoom = getMetadata().get("maxzoom");
|
||||||
|
|
||||||
return maxZoom != null ? Integer.parseInt(maxZoom) : Viewport.MAX_ZOOM_LEVEL;
|
return maxZoom != null ? Integer.parseInt(maxZoom) : Viewport.MAX_ZOOM_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getMinZoom() {
|
public int getMinZoom() {
|
||||||
String minZoom = getMetadata().get("minzoom");
|
String minZoom = getMetadata().get("minzoom");
|
||||||
|
|
||||||
return minZoom != null ? Integer.parseInt(minZoom) : Viewport.MIN_ZOOM_LEVEL;
|
return minZoom != null ? Integer.parseInt(minZoom) : Viewport.MIN_ZOOM_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getName() {
|
public String getName() {
|
||||||
return getMetadata().get("name");
|
return getMetadata().get("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
String getVersion() {
|
public String getVersion() {
|
||||||
return getMetadata().get("version");
|
return getMetadata().get("version");
|
||||||
}
|
}
|
||||||
|
|
||||||
String getId() {
|
public String getId() {
|
||||||
return getMetadata().get("id");
|
return getMetadata().get("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
Long getMTime() {
|
public Long getMTime() {
|
||||||
String mTime = getMetadata().get("mtime");
|
String mTime = getMetadata().get("mtime");
|
||||||
|
|
||||||
return mTime != null ? Long.parseLong(mTime) : null;
|
return mTime != null ? Long.parseLong(mTime) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getJson() {
|
public String getJson() {
|
||||||
return getMetadata().get("json");
|
return getMetadata().get("json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,46 +17,17 @@
|
|||||||
package org.oscim.android.tiling.source.mbtiles;
|
package org.oscim.android.tiling.source.mbtiles;
|
||||||
|
|
||||||
import org.oscim.core.BoundingBox;
|
import org.oscim.core.BoundingBox;
|
||||||
import org.oscim.core.GeoPoint;
|
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.map.Viewport;
|
|
||||||
import org.oscim.tiling.TileSource;
|
import org.oscim.tiling.TileSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A tile source for MBTiles Raster and Vector databases.
|
* A tile source for MBTiles databases.
|
||||||
* Supports the OpenMapTiles MVT pbf-gzip MBTiles format
|
|
||||||
*/
|
*/
|
||||||
public class MBTilesTileSource extends TileSource {
|
abstract public class MBTilesTileSource extends TileSource {
|
||||||
private final MBTilesTileDataSource mTileDataSource;
|
protected final MBTilesTileDataSource mTileDataSource;
|
||||||
|
|
||||||
/**
|
public MBTilesTileSource(MBTilesTileDataSource tileDataSource) {
|
||||||
* Create a MBTiles tile source (Raster/Vector)
|
mTileDataSource = tileDataSource;
|
||||||
*
|
|
||||||
* @param path the path to the MBTiles database.
|
|
||||||
*/
|
|
||||||
public MBTilesTileSource(String path) {
|
|
||||||
this(path, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an MBTiles tile source with additional parameters
|
|
||||||
*
|
|
||||||
* @param path the path to the MBTiles database. (Raster & Vector)
|
|
||||||
* @param locale the database locale to use, e.g. "en", "de" (Vector only)
|
|
||||||
* @param alpha an optional alpha value [0-255] to make the tiles transparent. (Raster only)
|
|
||||||
* @param transparentColor an optional color that will be made transparent in the bitmap. (Raster only)
|
|
||||||
*/
|
|
||||||
public MBTilesTileSource(String path, String locale, Integer alpha, Integer transparentColor) {
|
|
||||||
mTileDataSource = new MBTilesTileDataSource(path, locale, alpha, transparentColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a MBTiles tile source (Vector only)
|
|
||||||
*
|
|
||||||
* @param path the path to the MBTiles database.
|
|
||||||
*/
|
|
||||||
public MBTilesTileSource(String path, String locale) {
|
|
||||||
this(path, locale, null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package org.oscim.android.tiling.source.mbtiles;
|
||||||
|
|
||||||
|
public class UnsupportedMBTilesDatabaseException extends RuntimeException {
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user