Android samples: use OkHttp cache
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
* Copyright 2016-2018 devemux86
|
* Copyright 2016-2020 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@@ -20,8 +20,8 @@ package org.oscim.android.test;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import okhttp3.Cache;
|
||||||
import org.oscim.android.cache.TileCache;
|
import okhttp3.OkHttpClient;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.layers.TileGridLayer;
|
import org.oscim.layers.TileGridLayer;
|
||||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||||
@@ -29,11 +29,10 @@ import org.oscim.theme.VtmThemes;
|
|||||||
import org.oscim.tiling.TileSource;
|
import org.oscim.tiling.TileSource;
|
||||||
import org.oscim.tiling.source.OkHttpEngine;
|
import org.oscim.tiling.source.OkHttpEngine;
|
||||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import java.io.File;
|
||||||
|
|
||||||
public class BaseMapActivity extends MapActivity {
|
public class BaseMapActivity extends MapActivity {
|
||||||
static final Logger log = LoggerFactory.getLogger(BaseMapActivity.class);
|
|
||||||
|
|
||||||
static final boolean USE_CACHE = false;
|
static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
@@ -41,8 +40,6 @@ public class BaseMapActivity extends MapActivity {
|
|||||||
TileSource mTileSource;
|
TileSource mTileSource;
|
||||||
TileGridLayer mGridLayer;
|
TileGridLayer mGridLayer;
|
||||||
|
|
||||||
private TileCache mCache;
|
|
||||||
|
|
||||||
public BaseMapActivity(int contentView) {
|
public BaseMapActivity(int contentView) {
|
||||||
super(contentView);
|
super(contentView);
|
||||||
}
|
}
|
||||||
@@ -54,15 +51,19 @@ public class BaseMapActivity extends MapActivity {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
if (USE_CACHE) {
|
||||||
|
// Cache the tiles into file system
|
||||||
|
File cacheDirectory = new File(getExternalCacheDir(), "tiles");
|
||||||
|
int cacheSize = 10 * 1024 * 1024; // 10 MB
|
||||||
|
Cache cache = new Cache(cacheDirectory, cacheSize);
|
||||||
|
builder.cache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
mTileSource = OSciMap4TileSource.builder()
|
mTileSource = OSciMap4TileSource.builder()
|
||||||
.httpFactory(new OkHttpEngine.OkHttpFactory())
|
.httpFactory(new OkHttpEngine.OkHttpFactory(builder))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (USE_CACHE) {
|
|
||||||
mCache = new TileCache(this, null, "tile.db");
|
|
||||||
mCache.setCacheSize(512 * (1 << 10));
|
|
||||||
mTileSource.setCache(mCache);
|
|
||||||
}
|
|
||||||
mBaseLayer = mMap.setBaseMap(mTileSource);
|
mBaseLayer = mMap.setBaseMap(mTileSource);
|
||||||
|
|
||||||
/* set initial position on first run */
|
/* set initial position on first run */
|
||||||
@@ -72,14 +73,6 @@ public class BaseMapActivity extends MapActivity {
|
|||||||
mMap.setMapPosition(53.08, 8.83, Math.pow(2, 16));
|
mMap.setMapPosition(53.08, 8.83, Math.pow(2, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
if (mCache != null)
|
|
||||||
mCache.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
|
||||||
|
|||||||
@@ -16,22 +16,21 @@
|
|||||||
package org.oscim.android.test;
|
package org.oscim.android.test;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import org.oscim.android.cache.TileCache;
|
import okhttp3.Cache;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.MercatorProjection;
|
import org.oscim.core.MercatorProjection;
|
||||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||||
import org.oscim.renderer.MapRenderer;
|
import org.oscim.renderer.MapRenderer;
|
||||||
|
import org.oscim.tiling.source.OkHttpEngine;
|
||||||
import org.oscim.tiling.source.bitmap.BitmapTileSource;
|
import org.oscim.tiling.source.bitmap.BitmapTileSource;
|
||||||
import org.oscim.tiling.source.bitmap.DefaultSources;
|
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class BitmapTileActivity extends MapActivity {
|
public class BitmapTileActivity extends MapActivity {
|
||||||
|
|
||||||
static final Logger log = LoggerFactory.getLogger(BitmapTileActivity.class);
|
|
||||||
|
|
||||||
private static final boolean USE_CACHE = false;
|
private static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
private final BitmapTileSource mTileSource;
|
private final BitmapTileSource mTileSource;
|
||||||
@@ -43,12 +42,9 @@ public class BitmapTileActivity extends MapActivity {
|
|||||||
|
|
||||||
public BitmapTileActivity(BitmapTileSource tileSource) {
|
public BitmapTileActivity(BitmapTileSource tileSource) {
|
||||||
super(R.layout.activity_map);
|
super(R.layout.activity_map);
|
||||||
tileSource.setHttpRequestHeaders(Collections.singletonMap("User-Agent", "vtm-android-example"));
|
|
||||||
mTileSource = tileSource;
|
mTileSource = tileSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TileCache mCache;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -58,31 +54,24 @@ public class BitmapTileActivity extends MapActivity {
|
|||||||
if (mTileSource == null)
|
if (mTileSource == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
if (USE_CACHE) {
|
if (USE_CACHE) {
|
||||||
String cacheFile = mTileSource.getUrl()
|
// Cache the tiles into file system
|
||||||
.toString()
|
File cacheDirectory = new File(getExternalCacheDir(), "tiles");
|
||||||
.replaceFirst("https?://", "")
|
int cacheSize = 10 * 1024 * 1024; // 10 MB
|
||||||
.replaceAll("/", "-");
|
Cache cache = new Cache(cacheDirectory, cacheSize);
|
||||||
|
builder.cache(cache);
|
||||||
log.debug("use bitmap cache {}", cacheFile);
|
|
||||||
mCache = new TileCache(this, null, cacheFile);
|
|
||||||
mCache.setCacheSize(512 * (1 << 10));
|
|
||||||
mTileSource.setCache(mCache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mTileSource.setHttpEngine(new OkHttpEngine.OkHttpFactory(builder));
|
||||||
|
mTileSource.setHttpRequestHeaders(Collections.singletonMap("User-Agent", "vtm-android-example"));
|
||||||
|
|
||||||
mBitmapLayer = new BitmapTileLayer(mMap, mTileSource);
|
mBitmapLayer = new BitmapTileLayer(mMap, mTileSource);
|
||||||
mMap.layers().add(mBitmapLayer);
|
mMap.layers().add(mBitmapLayer);
|
||||||
|
|
||||||
//loooop(1);
|
//loooop(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
if (mCache != null)
|
|
||||||
mCache.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stress testing
|
// Stress testing
|
||||||
void loooop(final int i) {
|
void loooop(final int i) {
|
||||||
final long time = (long) (500 + Math.random() * 1000);
|
final long time = (long) (500 + Math.random() * 1000);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 devemux86
|
* Copyright 2018-2020 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* 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
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@@ -16,10 +16,10 @@ package org.oscim.android.test;
|
|||||||
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import okhttp3.Cache;
|
||||||
import okhttp3.CipherSuite;
|
import okhttp3.CipherSuite;
|
||||||
import okhttp3.ConnectionSpec;
|
import okhttp3.ConnectionSpec;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import org.oscim.android.cache.TileCache;
|
|
||||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||||
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;
|
||||||
@@ -30,6 +30,7 @@ import org.oscim.tiling.source.UrlTileSource;
|
|||||||
import org.oscim.tiling.source.bitmap.DefaultSources;
|
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||||
import org.oscim.tiling.source.mvt.MapilionMvtTileSource;
|
import org.oscim.tiling.source.mvt.MapilionMvtTileSource;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -41,13 +42,18 @@ public class MapilionMvtActivity extends MapActivity {
|
|||||||
|
|
||||||
private static final boolean USE_CACHE = false;
|
private static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
private TileCache mCache;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
if (USE_CACHE) {
|
||||||
|
// Cache the tiles into file system
|
||||||
|
File cacheDirectory = new File(getExternalCacheDir(), "tiles");
|
||||||
|
int cacheSize = 10 * 1024 * 1024; // 10 MB
|
||||||
|
Cache cache = new Cache(cacheDirectory, cacheSize);
|
||||||
|
builder.cache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/square/okhttp/issues/4053
|
// https://github.com/square/okhttp/issues/4053
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
||||||
@@ -71,13 +77,6 @@ public class MapilionMvtActivity extends MapActivity {
|
|||||||
//.locale("en")
|
//.locale("en")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (USE_CACHE) {
|
|
||||||
// Cache the tiles into a local SQLite database
|
|
||||||
mCache = new TileCache(this, null, "tile.db");
|
|
||||||
mCache.setCacheSize(512 * (1 << 10));
|
|
||||||
tileSource.setCache(mCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
||||||
mMap.setTheme(VtmThemes.OPENMAPTILES);
|
mMap.setTheme(VtmThemes.OPENMAPTILES);
|
||||||
|
|
||||||
@@ -91,12 +90,4 @@ public class MapilionMvtActivity extends MapActivity {
|
|||||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||||
mMap.layers().add(new LabelLayer(mMap, l));
|
mMap.layers().add(new LabelLayer(mMap, l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
if (mCache != null)
|
|
||||||
mCache.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2018 devemux86
|
* Copyright 2017-2020 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* 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
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
package org.oscim.android.test;
|
package org.oscim.android.test;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import okhttp3.Cache;
|
||||||
import org.oscim.android.cache.TileCache;
|
import okhttp3.OkHttpClient;
|
||||||
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;
|
||||||
@@ -25,41 +25,35 @@ import org.oscim.tiling.source.OkHttpEngine;
|
|||||||
import org.oscim.tiling.source.UrlTileSource;
|
import org.oscim.tiling.source.UrlTileSource;
|
||||||
import org.oscim.tiling.source.geojson.MapzenGeojsonTileSource;
|
import org.oscim.tiling.source.geojson.MapzenGeojsonTileSource;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class MapzenGeojsonActivity extends MapActivity {
|
public class MapzenGeojsonActivity extends MapActivity {
|
||||||
|
|
||||||
private static final boolean USE_CACHE = false;
|
private static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
private TileCache mCache;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
if (USE_CACHE) {
|
||||||
|
// Cache the tiles into file system
|
||||||
|
File cacheDirectory = new File(getExternalCacheDir(), "tiles");
|
||||||
|
int cacheSize = 10 * 1024 * 1024; // 10 MB
|
||||||
|
Cache cache = new Cache(cacheDirectory, cacheSize);
|
||||||
|
builder.cache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
UrlTileSource tileSource = MapzenGeojsonTileSource.builder()
|
UrlTileSource tileSource = MapzenGeojsonTileSource.builder()
|
||||||
.apiKey("xxxxxxx") // Put a proper API key
|
.apiKey("xxxxxxx") // Put a proper API key
|
||||||
.httpFactory(new OkHttpEngine.OkHttpFactory())
|
.httpFactory(new OkHttpEngine.OkHttpFactory(builder))
|
||||||
//.locale("en")
|
//.locale("en")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (USE_CACHE) {
|
|
||||||
// Cache the tiles into a local SQLite database
|
|
||||||
mCache = new TileCache(this, null, "tile.db");
|
|
||||||
mCache.setCacheSize(512 * (1 << 10));
|
|
||||||
tileSource.setCache(mCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
||||||
mMap.setTheme(VtmThemes.MAPZEN);
|
mMap.setTheme(VtmThemes.MAPZEN);
|
||||||
|
|
||||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||||
mMap.layers().add(new LabelLayer(mMap, l));
|
mMap.layers().add(new LabelLayer(mMap, l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
if (mCache != null)
|
|
||||||
mCache.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2018 devemux86
|
* Copyright 2016-2020 devemux86
|
||||||
* Copyright 2017 Mathieu De Brito
|
* Copyright 2017 Mathieu De Brito
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
package org.oscim.android.test;
|
package org.oscim.android.test;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import okhttp3.Cache;
|
||||||
import org.oscim.android.cache.TileCache;
|
import okhttp3.OkHttpClient;
|
||||||
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;
|
||||||
@@ -26,41 +26,35 @@ import org.oscim.tiling.source.OkHttpEngine;
|
|||||||
import org.oscim.tiling.source.UrlTileSource;
|
import org.oscim.tiling.source.UrlTileSource;
|
||||||
import org.oscim.tiling.source.mvt.MapzenMvtTileSource;
|
import org.oscim.tiling.source.mvt.MapzenMvtTileSource;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class MapzenMvtActivity extends MapActivity {
|
public class MapzenMvtActivity extends MapActivity {
|
||||||
|
|
||||||
private static final boolean USE_CACHE = false;
|
private static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
private TileCache mCache;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
if (USE_CACHE) {
|
||||||
|
// Cache the tiles into file system
|
||||||
|
File cacheDirectory = new File(getExternalCacheDir(), "tiles");
|
||||||
|
int cacheSize = 10 * 1024 * 1024; // 10 MB
|
||||||
|
Cache cache = new Cache(cacheDirectory, cacheSize);
|
||||||
|
builder.cache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
UrlTileSource tileSource = MapzenMvtTileSource.builder()
|
UrlTileSource tileSource = MapzenMvtTileSource.builder()
|
||||||
.apiKey("xxxxxxx") // Put a proper API key
|
.apiKey("xxxxxxx") // Put a proper API key
|
||||||
.httpFactory(new OkHttpEngine.OkHttpFactory())
|
.httpFactory(new OkHttpEngine.OkHttpFactory(builder))
|
||||||
//.locale("en")
|
//.locale("en")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (USE_CACHE) {
|
|
||||||
// Cache the tiles into a local SQLite database
|
|
||||||
mCache = new TileCache(this, null, "tile.db");
|
|
||||||
mCache.setCacheSize(512 * (1 << 10));
|
|
||||||
tileSource.setCache(mCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
||||||
mMap.setTheme(VtmThemes.MAPZEN);
|
mMap.setTheme(VtmThemes.MAPZEN);
|
||||||
|
|
||||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||||
mMap.layers().add(new LabelLayer(mMap, l));
|
mMap.layers().add(new LabelLayer(mMap, l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
if (mCache != null)
|
|
||||||
mCache.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 devemux86
|
* Copyright 2018-2020 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* 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
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
package org.oscim.android.test;
|
package org.oscim.android.test;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import okhttp3.Cache;
|
||||||
import org.oscim.android.cache.TileCache;
|
import okhttp3.OkHttpClient;
|
||||||
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;
|
||||||
@@ -25,41 +25,35 @@ import org.oscim.tiling.source.OkHttpEngine;
|
|||||||
import org.oscim.tiling.source.UrlTileSource;
|
import org.oscim.tiling.source.UrlTileSource;
|
||||||
import org.oscim.tiling.source.geojson.NextzenGeojsonTileSource;
|
import org.oscim.tiling.source.geojson.NextzenGeojsonTileSource;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class NextzenGeojsonActivity extends MapActivity {
|
public class NextzenGeojsonActivity extends MapActivity {
|
||||||
|
|
||||||
private static final boolean USE_CACHE = false;
|
private static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
private TileCache mCache;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
if (USE_CACHE) {
|
||||||
|
// Cache the tiles into file system
|
||||||
|
File cacheDirectory = new File(getExternalCacheDir(), "tiles");
|
||||||
|
int cacheSize = 10 * 1024 * 1024; // 10 MB
|
||||||
|
Cache cache = new Cache(cacheDirectory, cacheSize);
|
||||||
|
builder.cache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
UrlTileSource tileSource = NextzenGeojsonTileSource.builder()
|
UrlTileSource tileSource = NextzenGeojsonTileSource.builder()
|
||||||
.apiKey("xxxxxxx") // Put a proper API key
|
.apiKey("xxxxxxx") // Put a proper API key
|
||||||
.httpFactory(new OkHttpEngine.OkHttpFactory())
|
.httpFactory(new OkHttpEngine.OkHttpFactory(builder))
|
||||||
//.locale("en")
|
//.locale("en")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (USE_CACHE) {
|
|
||||||
// Cache the tiles into a local SQLite database
|
|
||||||
mCache = new TileCache(this, null, "tile.db");
|
|
||||||
mCache.setCacheSize(512 * (1 << 10));
|
|
||||||
tileSource.setCache(mCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
||||||
mMap.setTheme(VtmThemes.MAPZEN);
|
mMap.setTheme(VtmThemes.MAPZEN);
|
||||||
|
|
||||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||||
mMap.layers().add(new LabelLayer(mMap, l));
|
mMap.layers().add(new LabelLayer(mMap, l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
if (mCache != null)
|
|
||||||
mCache.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 devemux86
|
* Copyright 2018-2020 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* 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
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
package org.oscim.android.test;
|
package org.oscim.android.test;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import okhttp3.Cache;
|
||||||
import org.oscim.android.cache.TileCache;
|
import okhttp3.OkHttpClient;
|
||||||
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;
|
||||||
@@ -25,41 +25,35 @@ import org.oscim.tiling.source.OkHttpEngine;
|
|||||||
import org.oscim.tiling.source.UrlTileSource;
|
import org.oscim.tiling.source.UrlTileSource;
|
||||||
import org.oscim.tiling.source.mvt.NextzenMvtTileSource;
|
import org.oscim.tiling.source.mvt.NextzenMvtTileSource;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class NextzenMvtActivity extends MapActivity {
|
public class NextzenMvtActivity extends MapActivity {
|
||||||
|
|
||||||
private static final boolean USE_CACHE = false;
|
private static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
private TileCache mCache;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
if (USE_CACHE) {
|
||||||
|
// Cache the tiles into file system
|
||||||
|
File cacheDirectory = new File(getExternalCacheDir(), "tiles");
|
||||||
|
int cacheSize = 10 * 1024 * 1024; // 10 MB
|
||||||
|
Cache cache = new Cache(cacheDirectory, cacheSize);
|
||||||
|
builder.cache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
UrlTileSource tileSource = NextzenMvtTileSource.builder()
|
UrlTileSource tileSource = NextzenMvtTileSource.builder()
|
||||||
.apiKey("xxxxxxx") // Put a proper API key
|
.apiKey("xxxxxxx") // Put a proper API key
|
||||||
.httpFactory(new OkHttpEngine.OkHttpFactory())
|
.httpFactory(new OkHttpEngine.OkHttpFactory(builder))
|
||||||
//.locale("en")
|
//.locale("en")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (USE_CACHE) {
|
|
||||||
// Cache the tiles into a local SQLite database
|
|
||||||
mCache = new TileCache(this, null, "tile.db");
|
|
||||||
mCache.setCacheSize(512 * (1 << 10));
|
|
||||||
tileSource.setCache(mCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
||||||
mMap.setTheme(VtmThemes.MAPZEN);
|
mMap.setTheme(VtmThemes.MAPZEN);
|
||||||
|
|
||||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||||
mMap.layers().add(new LabelLayer(mMap, l));
|
mMap.layers().add(new LabelLayer(mMap, l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
if (mCache != null)
|
|
||||||
mCache.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2018 devemux86
|
* Copyright 2016-2020 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* 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
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
package org.oscim.android.test;
|
package org.oscim.android.test;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import okhttp3.Cache;
|
||||||
import org.oscim.android.cache.TileCache;
|
import okhttp3.OkHttpClient;
|
||||||
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;
|
||||||
@@ -25,41 +25,35 @@ import org.oscim.tiling.source.OkHttpEngine;
|
|||||||
import org.oscim.tiling.source.UrlTileSource;
|
import org.oscim.tiling.source.UrlTileSource;
|
||||||
import org.oscim.tiling.source.mvt.OpenMapTilesMvtTileSource;
|
import org.oscim.tiling.source.mvt.OpenMapTilesMvtTileSource;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class OpenMapTilesMvtActivity extends MapActivity {
|
public class OpenMapTilesMvtActivity extends MapActivity {
|
||||||
|
|
||||||
private static final boolean USE_CACHE = false;
|
private static final boolean USE_CACHE = false;
|
||||||
|
|
||||||
private TileCache mCache;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
if (USE_CACHE) {
|
||||||
|
// Cache the tiles into file system
|
||||||
|
File cacheDirectory = new File(getExternalCacheDir(), "tiles");
|
||||||
|
int cacheSize = 10 * 1024 * 1024; // 10 MB
|
||||||
|
Cache cache = new Cache(cacheDirectory, cacheSize);
|
||||||
|
builder.cache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
UrlTileSource tileSource = OpenMapTilesMvtTileSource.builder()
|
UrlTileSource tileSource = OpenMapTilesMvtTileSource.builder()
|
||||||
.apiKey("xxxxxxx") // Put a proper API key
|
.apiKey("xxxxxxx") // Put a proper API key
|
||||||
.httpFactory(new OkHttpEngine.OkHttpFactory())
|
.httpFactory(new OkHttpEngine.OkHttpFactory(builder))
|
||||||
//.locale("en")
|
//.locale("en")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (USE_CACHE) {
|
|
||||||
// Cache the tiles into a local SQLite database
|
|
||||||
mCache = new TileCache(this, null, "tile.db");
|
|
||||||
mCache.setCacheSize(512 * (1 << 10));
|
|
||||||
tileSource.setCache(mCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
||||||
mMap.setTheme(VtmThemes.OPENMAPTILES);
|
mMap.setTheme(VtmThemes.OPENMAPTILES);
|
||||||
|
|
||||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||||
mMap.layers().add(new LabelLayer(mMap, l));
|
mMap.layers().add(new LabelLayer(mMap, l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
if (mCache != null)
|
|
||||||
mCache.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user