diff --git a/docs/Changelog.md b/docs/Changelog.md index 6e23bad0..84ea3e7e 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -5,6 +5,7 @@ - Render themes: tag transform [#420](https://github.com/mapsforge/vtm/issues/420) - Render themes: PNG scaling [#595](https://github.com/mapsforge/vtm/issues/595) - PathLayer(s) scaled width [#594](https://github.com/mapsforge/vtm/issues/594) +- Mapilion MVT vector tiles & Hillshading [#614](https://github.com/mapsforge/vtm/issues/614) - vtm-gdx-poi3d module [#600](https://github.com/mapsforge/vtm/pull/600) - vtm-models module [#580](https://github.com/mapsforge/vtm/issues/580) - Many other minor improvements and bug fixes diff --git a/vtm-android-example/AndroidManifest.xml b/vtm-android-example/AndroidManifest.xml index 4973e19d..8333e816 100644 --- a/vtm-android-example/AndroidManifest.xml +++ b/vtm-android-example/AndroidManifest.xml @@ -67,6 +67,9 @@ + diff --git a/vtm-android-example/src/org/oscim/android/test/MapilionMvtActivity.java b/vtm-android-example/src/org/oscim/android/test/MapilionMvtActivity.java new file mode 100644 index 00000000..51d04d74 --- /dev/null +++ b/vtm-android-example/src/org/oscim/android/test/MapilionMvtActivity.java @@ -0,0 +1,79 @@ +/* + * Copyright 2018 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 . + */ +package org.oscim.android.test; + +import android.os.Bundle; + +import org.oscim.android.cache.TileCache; +import org.oscim.layers.tile.bitmap.BitmapTileLayer; +import org.oscim.layers.tile.buildings.BuildingLayer; +import org.oscim.layers.tile.vector.VectorTileLayer; +import org.oscim.layers.tile.vector.labeling.LabelLayer; +import org.oscim.theme.VtmThemes; +import org.oscim.tiling.source.OkHttpEngine; +import org.oscim.tiling.source.UrlTileSource; +import org.oscim.tiling.source.bitmap.DefaultSources; +import org.oscim.tiling.source.mvt.MapilionMvtTileSource; + +public class MapilionMvtActivity extends MapActivity { + + // Metered API key for demonstration purposes + private static final String API_KEY = "3b3d8353-0fb8-4513-bfe0-d620b2d77c45"; + + private static final boolean USE_CACHE = false; + + private TileCache mCache; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + OkHttpEngine.OkHttpFactory factory = new OkHttpEngine.OkHttpFactory(); + + UrlTileSource tileSource = MapilionMvtTileSource.builder() + .apiKey(API_KEY) + .httpFactory(factory) + //.locale("en") + .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); + mMap.setTheme(VtmThemes.OPENMAPTILES); + + // Hillshading + UrlTileSource shadedTileSource = DefaultSources.MAPILION_HILLSHADE + .apiKey(API_KEY) + .httpFactory(factory) + .build(); + mMap.layers().add(new BitmapTileLayer(mMap, shadedTileSource)); + + mMap.layers().add(new BuildingLayer(mMap, l)); + mMap.layers().add(new LabelLayer(mMap, l)); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + if (mCache != null) + mCache.dispose(); + } +} diff --git a/vtm-android-example/src/org/oscim/android/test/Samples.java b/vtm-android-example/src/org/oscim/android/test/Samples.java index f3b77e02..4fa4abc0 100644 --- a/vtm-android-example/src/org/oscim/android/test/Samples.java +++ b/vtm-android-example/src/org/oscim/android/test/Samples.java @@ -83,6 +83,7 @@ public class Samples extends Activity { linearLayout.addView(createLabel(null)); linearLayout.addView(createButton(SimpleMapActivity.class)); linearLayout.addView(createButton(MapsforgeActivity.class)); + linearLayout.addView(createButton(MapilionMvtActivity.class)); /*linearLayout.addView(createButton(MapzenMvtActivity.class)); linearLayout.addView(createButton(MapzenGeojsonActivity.class));*/ linearLayout.addView(createButton(NextzenMvtActivity.class)); diff --git a/vtm-mvt/src/org/oscim/tiling/source/mvt/MapilionMvtTileSource.java b/vtm-mvt/src/org/oscim/tiling/source/mvt/MapilionMvtTileSource.java new file mode 100644 index 00000000..445760b4 --- /dev/null +++ b/vtm-mvt/src/org/oscim/tiling/source/mvt/MapilionMvtTileSource.java @@ -0,0 +1,69 @@ +/* + * Copyright 2018 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 . + */ +package org.oscim.tiling.source.mvt; + +import org.oscim.tiling.ITileDataSource; +import org.oscim.tiling.OverzoomTileDataSource; +import org.oscim.tiling.source.UrlTileDataSource; +import org.oscim.tiling.source.UrlTileSource; + +public class MapilionMvtTileSource extends UrlTileSource { + + private static final String DEFAULT_URL = "https://tiles.mapilion.com/data/v3"; + private static final String DEFAULT_PATH = "/{Z}/{X}/{Y}.pbf"; + + public static class Builder> extends UrlTileSource.Builder { + private String locale = ""; + + public Builder() { + super(DEFAULT_URL, DEFAULT_PATH); + overZoom(14); + } + + public T locale(String locale) { + this.locale = locale; + return self(); + } + + public MapilionMvtTileSource build() { + return new MapilionMvtTileSource(this); + } + } + + @SuppressWarnings("rawtypes") + public static Builder builder() { + return new Builder(); + } + + private final String locale; + + public MapilionMvtTileSource(Builder builder) { + super(builder); + this.locale = builder.locale; + } + + public MapilionMvtTileSource() { + this(builder()); + } + + public MapilionMvtTileSource(String urlString) { + this(builder().url(urlString)); + } + + @Override + public ITileDataSource getDataSource() { + return new OverzoomTileDataSource(new UrlTileDataSource(this, new MvtTileDecoder(locale), getHttpEngine()), mOverZoom); + } +} diff --git a/vtm-playground/src/org/oscim/test/MapilionMvtTest.java b/vtm-playground/src/org/oscim/test/MapilionMvtTest.java new file mode 100644 index 00000000..d8215487 --- /dev/null +++ b/vtm-playground/src/org/oscim/test/MapilionMvtTest.java @@ -0,0 +1,88 @@ +/* + * Copyright 2018 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 . + */ +package org.oscim.test; + +import org.oscim.core.MapPosition; +import org.oscim.gdx.GdxMapApp; +import org.oscim.layers.tile.bitmap.BitmapTileLayer; +import org.oscim.layers.tile.buildings.BuildingLayer; +import org.oscim.layers.tile.vector.VectorTileLayer; +import org.oscim.layers.tile.vector.labeling.LabelLayer; +import org.oscim.theme.VtmThemes; +import org.oscim.tiling.source.OkHttpEngine; +import org.oscim.tiling.source.UrlTileSource; +import org.oscim.tiling.source.bitmap.DefaultSources; +import org.oscim.tiling.source.mvt.MapilionMvtTileSource; + +import java.io.File; +import java.util.UUID; + +import okhttp3.Cache; +import okhttp3.OkHttpClient; + +public class MapilionMvtTest extends GdxMapApp { + + // Metered API key for demonstration purposes + private static final String API_KEY = "3b3d8353-0fb8-4513-bfe0-d620b2d77c45"; + + private static final boolean USE_CACHE = false; + + @Override + public void createLayers() { + OkHttpClient.Builder builder = new OkHttpClient.Builder(); + if (USE_CACHE) { + // Cache the tiles into file system + File cacheDirectory = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); + int cacheSize = 10 * 1024 * 1024; // 10 MB + Cache cache = new Cache(cacheDirectory, cacheSize); + builder.cache(cache); + } + OkHttpEngine.OkHttpFactory factory = new OkHttpEngine.OkHttpFactory(builder); + + UrlTileSource tileSource = MapilionMvtTileSource.builder() + .apiKey(API_KEY) + .httpFactory(factory) + //.locale("en") + .build(); + + VectorTileLayer l = mMap.setBaseMap(tileSource); + mMap.setTheme(VtmThemes.OPENMAPTILES); + + // Hillshading + UrlTileSource shadedTileSource = DefaultSources.MAPILION_HILLSHADE + .apiKey(API_KEY) + .httpFactory(factory) + .build(); + mMap.layers().add(new BitmapTileLayer(mMap, shadedTileSource)); + + mMap.layers().add(new BuildingLayer(mMap, l)); + mMap.layers().add(new LabelLayer(mMap, l)); + + MapPosition pos = MapPreferences.getMapPosition(); + if (pos != null) + mMap.setMapPosition(pos); + } + + @Override + public void dispose() { + MapPreferences.saveMapPosition(mMap.getMapPosition()); + super.dispose(); + } + + public static void main(String[] args) { + GdxMapApp.init(); + GdxMapApp.run(new MapilionMvtTest()); + } +} diff --git a/vtm/src/org/oscim/tiling/source/bitmap/DefaultSources.java b/vtm/src/org/oscim/tiling/source/bitmap/DefaultSources.java index 96d8eb85..35664206 100644 --- a/vtm/src/org/oscim/tiling/source/bitmap/DefaultSources.java +++ b/vtm/src/org/oscim/tiling/source/bitmap/DefaultSources.java @@ -61,4 +61,11 @@ public class DefaultSources { .url("https://tiles.wmflabs.org/hillshading") .tilePath("/{Z}/{X}/{Y}.png") .zoomMax(14); + + // Needs an API key + public static Builder MAPILION_HILLSHADE = BitmapTileSource.builder() + .url("https://tiles.mapilion.com/hillshades") + .tilePath("/{Z}/{X}/{Y}.png") + .zoomMin(1) + .zoomMax(12); }