Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9982ce1
commit 2c14dda
Showing
14 changed files
with
669 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Geopackage support for osmdroid | ||
|
||
https://github.com/ngageoint/geopackage-android | ||
|
||
|
||
# License | ||
This library: ASF 2.0 | ||
Dependencies: NGA code is MIT | ||
|
||
|
||
# How to use | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
description = 'Geopackage support for osmdroid' | ||
|
||
apply plugin: 'com.android.application' | ||
apply from: "https://raw.githubusercontent.com/gradle-fury/gradle-fury/v1.1.3/gradle/android-support.gradle" | ||
|
||
android { | ||
|
||
defaultConfig { | ||
applicationId "org.osmdroid.gpkg" | ||
minSdkVersion 14 | ||
targetSdkVersion 22 | ||
} | ||
} | ||
|
||
dependencies { | ||
//crash logging | ||
//compile 'ch.acra:acra:4.7.0' | ||
|
||
testCompile 'junit:junit:4.12' | ||
compile project(':osmdroid-android') | ||
|
||
compile "mil.nga.geopackage:geopackage-android:1.3.0" | ||
|
||
compile 'com.google.android.gms:play-services:8.4.0' | ||
compile 'com.google.maps.android:android-maps-utils:0.4.3' | ||
compile 'com.j256.ormlite:ormlite-android:4.48' | ||
compile 'mil.nga.geopackage:geopackage-core:1.2.0' | ||
compile 'ar.com.hjg:pngj:2.1.0' | ||
compile 'mil.nga:tiff:1.0.0' | ||
|
||
//compile 'com.j256.ormlite:ormlite-android:4.48' | ||
//compile 'mil.nga.geopackage:geopackage-core:1.2.0' | ||
//compile 'mil.nga.geopackage:geopackage:1.2.0' | ||
|
||
//compile 'org.sqldroid:sqldroid:1.1.0-SNAPSHOT' | ||
//compile 'org.xerial:sqlite-jdbc:3.7.2' | ||
//compile 'mil.nga.geopackage:geopackage-core:1.1.0' | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
osmdroid-geopackage/src/androidTest/java/org/osmdroid/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.osmdroid; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.osmdroid.gpkg" > | ||
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" /> | ||
|
||
<!-- PROTECTION_NORMAL permissions, automatically granted --> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<!-- DANGEROUS PERMISSIONS, must request --> | ||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
|
||
<application | ||
|
||
android:largeHeap="true" | ||
android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" > | ||
<activity android:name="MainActivity" android:icon="@drawable/icon" android:label="OSM Gpgk"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"></action> | ||
<category android:name="android.intent.category.LAUNCHER"></category> | ||
</intent-filter> | ||
</activity> | ||
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> | ||
</application> | ||
|
||
</manifest> |
236 changes: 236 additions & 0 deletions
236
osmdroid-geopackage/src/main/java/org/osmdroid/gpkg/GeoPackageMapTileModuleProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
package org.osmdroid.gpkg; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.drawable.BitmapDrawable; | ||
import android.graphics.drawable.Drawable; | ||
import android.util.Log; | ||
|
||
import org.osmdroid.api.IMapView; | ||
import org.osmdroid.config.Configuration; | ||
import org.osmdroid.tileprovider.MapTile; | ||
import org.osmdroid.tileprovider.MapTileRequestState; | ||
import org.osmdroid.tileprovider.modules.IFilesystemCache; | ||
import org.osmdroid.tileprovider.modules.MapTileModuleProviderBase; | ||
import org.osmdroid.tileprovider.tilesource.ITileSource; | ||
import org.osmdroid.tileprovider.tilesource.XYTileSource; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import mil.nga.geopackage.GeoPackage; | ||
import mil.nga.geopackage.GeoPackageManager; | ||
import mil.nga.geopackage.factory.GeoPackageFactory; | ||
import mil.nga.geopackage.tiles.retriever.GeoPackageTile; | ||
import mil.nga.geopackage.tiles.retriever.GeoPackageTileRetriever; | ||
import mil.nga.geopackage.tiles.user.TileDao; | ||
|
||
/** | ||
* This is called the GeoPackage Slowmo because it's damn slow. | ||
* Created by alex on 10/29/15. | ||
*/ | ||
public class GeoPackageMapTileModuleProvider extends MapTileModuleProviderBase { | ||
|
||
//TileRetriever retriever; | ||
IFilesystemCache tileWriter = null; | ||
GeoPackageManager manager; | ||
|
||
//GeoPackage geoPackage; | ||
List<String> tiles; | ||
ITileSource currentTileSource; | ||
Set<GeoPackage> tileSources = new HashSet<>(); | ||
/** | ||
* Compress format | ||
*/ | ||
private static final Bitmap.CompressFormat COMPRESS_FORMAT = Bitmap.CompressFormat.PNG; | ||
|
||
|
||
|
||
|
||
public GeoPackageMapTileModuleProvider(File[] pFile, | ||
final Context context, IFilesystemCache cache) { | ||
//int pThreadPoolSize, final int pPendingQueueSize | ||
super(Configuration.getInstance().getTileFileSystemThreads(), Configuration.getInstance().getTileFileSystemMaxQueueSize()); | ||
|
||
tileWriter = cache; | ||
// Get a manager | ||
manager = GeoPackageFactory.getManager(context); | ||
// Available databases | ||
|
||
|
||
// Import database | ||
for (int i = 0; i < pFile.length; i++) { | ||
try { | ||
boolean imported = manager.importGeoPackage((pFile[i])); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
// Available databases | ||
List<String> databases = manager.databases(); | ||
// Open database | ||
for (int i = 0; i < databases.size(); i++) { | ||
tileSources.add(manager.open(databases.get(i))); | ||
} | ||
|
||
} | ||
|
||
|
||
public Drawable getMapTile(MapTile pTile) { | ||
|
||
|
||
Drawable tile = null; | ||
|
||
|
||
String src = currentTileSource.name(); //table name | ||
//String database = currentTileSource.getBaseUrls()[0]; //database name | ||
|
||
GeoPackage next = null; | ||
boolean found = false; | ||
//find out db connection | ||
Iterator<GeoPackage> iterator = tileSources.iterator(); | ||
while (iterator.hasNext()) { | ||
next = iterator.next(); | ||
if (next.getTileTables().contains(src)) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
|
||
if (found) { | ||
TileDao tileDao = next.getTileDao(src); | ||
GeoPackageTileRetriever retriever = new GeoPackageTileRetriever(tileDao); | ||
|
||
int zoom = pTile.getZoomLevel(); | ||
int x = pTile.getX(); | ||
int y = pTile.getY(); | ||
|
||
|
||
GeoPackageTile geoPackageTile = retriever.getTile(x, y, zoom); | ||
if (geoPackageTile != null && geoPackageTile.data != null) { | ||
byte[] image = geoPackageTile.data; | ||
if (image != null) { | ||
BitmapFactory.Options opt = new BitmapFactory.Options(); | ||
opt.outHeight = 256; //360 | ||
opt.outWidth = 256;//248 | ||
Bitmap imageBitmap = BitmapFactory.decodeByteArray(image, 0, image.length, opt); | ||
tile = new BitmapDrawable(imageBitmap); | ||
/*Date dateExpires; | ||
Long override=Configuration.getInstance().getExpirationOverrideDuration(); | ||
if (override!=null) { | ||
dateExpires= new Date(System.currentTimeMillis() + override); | ||
} else { | ||
dateExpires = new Date(System.currentTimeMillis() + OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE + Configuration.getInstance().getExpirationExtendedDuration()); | ||
} | ||
pTile.setExpires(dateExpires); | ||
tileWriter.saveFile(src, pTile, new ByteArrayInputStream(image)); | ||
*/ | ||
} | ||
} | ||
} | ||
|
||
return tile; | ||
|
||
} | ||
|
||
public static class Container { | ||
String database; | ||
List<String> tiles; | ||
List<String> features; | ||
} | ||
|
||
|
||
public List<Container> getTileSources() { | ||
List<Container> srcs = new ArrayList<>(); | ||
List<String> databases = manager.databases(); | ||
for (int i = 0; i < databases.size(); i++) { | ||
GeoPackage handle = manager.open(databases.get(i)); | ||
Container c = new Container(); | ||
c.database = databases.get(i); | ||
c.tiles = new ArrayList<>(); | ||
c.tiles.addAll(handle.getTileTables()); | ||
c.features = new ArrayList<>(); | ||
c.features.addAll(handle.getFeatureTables()); | ||
srcs.add(c); | ||
} | ||
|
||
return srcs; | ||
} | ||
|
||
@Override | ||
public void detach() { | ||
|
||
|
||
Iterator<GeoPackage> iterator = tileSources.iterator(); | ||
while (iterator.hasNext()){ | ||
iterator.next().close(); | ||
} | ||
tileSources.clear(); | ||
|
||
manager = null; | ||
} | ||
|
||
|
||
protected class TileLoader extends MapTileModuleProviderBase.TileLoader { | ||
|
||
@Override | ||
public Drawable loadTile(final MapTileRequestState pState) { | ||
|
||
final MapTile pTile = pState.getMapTile(); | ||
|
||
try { | ||
Drawable mapTile = getMapTile(pTile); | ||
return mapTile; | ||
} catch (final Throwable e) { | ||
Log.e(IMapView.LOGTAG, "Error loading tile", e); | ||
} finally { | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
protected String getName() { | ||
return "Geopackage"; | ||
} | ||
|
||
@Override | ||
protected String getThreadGroupName() { | ||
return getName(); | ||
} | ||
|
||
@Override | ||
protected Runnable getTileLoader() { | ||
return new TileLoader(); | ||
} | ||
|
||
@Override | ||
public boolean getUsesDataConnection() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getMinimumZoomLevel() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getMaximumZoomLevel() { | ||
return 22; | ||
} | ||
|
||
@Override | ||
public void setTileSource(ITileSource tileSource) { | ||
currentTileSource = tileSource; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.