How to add custom tile source to VTM?

119 views
Skip to first unread message

Ali Mahdian

unread,
May 12, 2021, 3:11:27 AM5/12/21
to Mapsforge & VTM
Hi,
I am using VTM 0.15.0 and want to add a custom tile server(like a.tile.openstreetmap.fr) to map. This is my code but not working:

BitmapTileSource mTileSource = BitmapTileSource.builder()
.url("https://a.tile.openstreetmap.fr/hot")
.tilePath("/{Z}/{X}/{Y}.jpg").build();

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.setHttpEngine(new OkHttpEngine.OkHttpFactory(builder));
mTileSource.setHttpRequestHeaders(Collections.singletonMap("User-Agent", "vtm-android-example"));

mBitmapLayer = new BitmapTileLayer(mMap, mTileSource);
mMap.layers().add(mBitmapLayer);

Emux

unread,
May 12, 2021, 3:40:56 AM5/12/21
to mapsfo...@googlegroups.com
See DefaultSources for how to create custom tile sources.

And BitmapTileActivity for how to use a bitmap tile source.

--
Emux
Reply all
Reply to author
Forward
0 new messages