MBTiles raster tile source (#708)

This commit is contained in:
Andrea Antonello
2019-04-05 09:53:33 +02:00
committed by Emux
parent db6be82ce2
commit 71f94f3f79
7 changed files with 417 additions and 1 deletions

View File

@@ -91,6 +91,9 @@
<activity
android:name=".MarkerOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MBTilesBitmapTileActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MultiMapViewActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />

View File

@@ -25,5 +25,8 @@
<string name="search_key">\'*\' or OSM key</string>
<string name="search_value">void or value</string>
<string name="now">Now</string>
<string name="warning">Warning</string>
<string name="startup_message_mbtiles">To run this sample activity, you need any MBTiles with filename test.mbtiles installed on storage.\n\nadb push file.mbtiles /sdcard/test.mbtiles</string>
<string name="exit">Exit</string>
</resources>

View File

@@ -0,0 +1,69 @@
/*
* Copyright 2019 Andrea Antonello
* Copyright 2019 devemux86
*
* 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.test;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import org.oscim.android.tiling.source.mbtiles.MBTilesBitmapTileSource;
import org.oscim.core.BoundingBox;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import java.io.File;
/**
* An example activity making use of MBTiles.
*/
public class MBTilesBitmapTileActivity extends BitmapTileActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File file = new File(Environment.getExternalStorageDirectory(), "test.mbtiles");
if (!file.exists()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(R.string.warning)
.setMessage(R.string.startup_message_mbtiles)
.setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.show();
return;
}
MBTilesBitmapTileSource tileSource = new MBTilesBitmapTileSource(file.getAbsolutePath(), 128, null);
BitmapTileLayer bitmapLayer = new BitmapTileLayer(mMap, tileSource);
mMap.layers().add(bitmapLayer);
/* set initial position on first run */
MapPosition pos = new MapPosition();
mMap.getMapPosition(pos);
if (pos.x == 0.5 && pos.y == 0.5) {
BoundingBox bbox = tileSource.getBounds();
if (bbox != null) {
pos.setByBoundingBox(bbox, Tile.SIZE * 4, Tile.SIZE * 4);
mMap.setMapPosition(pos);
}
}
}
}

View File

@@ -8,6 +8,7 @@
* Copyright 2017 nebular
* Copyright 2018 boldtrn
* Copyright 2018-2019 Gustl22
* Copyright 2019 Andrea Antonello
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@@ -115,6 +116,7 @@ public class Samples extends Activity {
linearLayout.addView(createLabel("Raster Maps"));
linearLayout.addView(createButton(BitmapTileActivity.class));
linearLayout.addView(createButton(MBTilesBitmapTileActivity.class));
linearLayout.addView(createLabel("Overlays"));
linearLayout.addView(createButton(MarkerOverlayActivity.class));