diff --git a/platform/android/MapLibreAndroidTestApp/src/main/AndroidManifest.xml b/platform/android/MapLibreAndroidTestApp/src/main/AndroidManifest.xml index 171af89c8..85aaf0875 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapLibreAndroidTestApp/src/main/AndroidManifest.xml @@ -7,6 +7,7 @@ + + + + + android:label="@string/activity_observer_activity"> @@ -1259,13 +1271,11 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activity.FeatureOverviewActivity" /> - + android:exported="true" + android:label="@string/activity_map_options_xml"> @@ -1273,7 +1283,6 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activity.FeatureOverviewActivity" /> - diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/sources/VectorTileActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/sources/VectorTileActivity.kt new file mode 100644 index 000000000..c19e7e0c5 --- /dev/null +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/sources/VectorTileActivity.kt @@ -0,0 +1,85 @@ +package org.maplibre.android.testapp.activity.sources + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import org.maplibre.android.camera.CameraUpdateFactory +import org.maplibre.android.geometry.LatLngBounds +import org.maplibre.android.maps.MapView +import org.maplibre.android.style.layers.LineLayer +import org.maplibre.android.style.layers.PropertyFactory.lineColor +import org.maplibre.android.style.layers.PropertyFactory.lineWidth +import org.maplibre.android.style.sources.TileSet +import org.maplibre.android.style.sources.VectorSource +import org.maplibre.android.testapp.R +import org.maplibre.android.testapp.styles.TestStyles + + +class VectorTileActivity : AppCompatActivity() { + private lateinit var mapView: MapView + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_vector_tile) + mapView = findViewById(R.id.mapView) + + mapView.getMapAsync { + it.animateCamera( + CameraUpdateFactory.newLatLngBounds( + // z: 12, x: 2177, y: 1436 is one of the available tiles: + // https://github.com/maplibre/demotiles/tree/gh-pages/tiles-omt/12/2177 + LatLngBounds.from(12, 2177, 1436), + 0 + ) + ) + it.setStyle(TestStyles.PROTOMAPS_GRAYSCALE) { style -> + // --8<-- [start:addTileSet] + val tileset = TileSet( + "openmaptiles", + "https://demotiles.maplibre.org/tiles-omt/{z}/{x}/{y}.pbf" + ) + val openmaptiles = VectorSource("openmaptiles", tileset) + style.addSource(openmaptiles) + val roadLayer = LineLayer("road", "openmaptiles").apply { + setSourceLayer("transportation") + setProperties( + lineColor("red"), + lineWidth(2.0f) + ) + } + // --8<-- [end:addTileSet] + + style.addLayer(roadLayer) + } + } + } + + override fun onStart() { + super.onStart() + mapView.onStart() + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onStop() { + super.onStop() + mapView.onStop() + } + + override fun onLowMemory() { + super.onLowMemory() + mapView.onLowMemory() + } + + override fun onDestroy() { + super.onDestroy() + mapView.onDestroy() + } +} diff --git a/platform/android/MapLibreAndroidTestApp/src/main/res/layout/activity_vector_tile.xml b/platform/android/MapLibreAndroidTestApp/src/main/res/layout/activity_vector_tile.xml new file mode 100644 index 000000000..858b80c49 --- /dev/null +++ b/platform/android/MapLibreAndroidTestApp/src/main/res/layout/activity_vector_tile.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/platform/android/MapLibreAndroidTestApp/src/main/res/values/descriptions.xml b/platform/android/MapLibreAndroidTestApp/src/main/res/values/descriptions.xml index ac42003f1..fcfdcb842 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/res/values/descriptions.xml +++ b/platform/android/MapLibreAndroidTestApp/src/main/res/values/descriptions.xml @@ -80,6 +80,7 @@ Blend an overlay on a map Example Custom Geometry Source Load a map without providing a style URI or JSON + Load MVT data Suzhou using Droid Sans for Chinese glyphs Example raster-dem source and hillshade layer Use HeatmapLayer to visualise earthquakes diff --git a/platform/android/MapLibreAndroidTestApp/src/main/res/values/strings.xml b/platform/android/MapLibreAndroidTestApp/src/main/res/values/strings.xml index af6620dd9..75bf61e83 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapLibreAndroidTestApp/src/main/res/values/strings.xml @@ -8,4 +8,5 @@ World Tour Benchmark Writes out avg. fps and 1% fps after world tour with .flyTo() Search + Data Sources diff --git a/platform/android/MapLibreAndroidTestApp/src/main/res/values/titles.xml b/platform/android/MapLibreAndroidTestApp/src/main/res/values/titles.xml index dfe67710e..6a0953d43 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/res/values/titles.xml +++ b/platform/android/MapLibreAndroidTestApp/src/main/res/values/titles.xml @@ -76,6 +76,7 @@ Map overlay Grid Source No Style URI/JSON + Vector Tile source Local CJK glyph generation Hillshade Heatmap layer diff --git a/platform/android/docs/data/MVT.md b/platform/android/docs/data/MVT.md new file mode 100644 index 000000000..85d358f5c --- /dev/null +++ b/platform/android/docs/data/MVT.md @@ -0,0 +1,16 @@ +# Vector Tiles + +{{ activity_source_note("VectorTileActivity.kt") }} + +You can specify where to load MVTs (which sometimes have `.pbf` extension) by creating a `TileSet` object with template parameters (for example `{z}` which will be replaced with the zoom level). + +MapLibre has [a repo](https://github.com/maplibre/demotiles/tree/gh-pages/tiles-omt) with some example vector tiles with the OpenMapTiles schema around Innsbruck, Austria. In the example we load these MVTs and create a line layer for the road network. + +```kotlin +--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/sources/VectorTileActivity.kt:addTileSet" +``` + +
+ ![Screenshot of road overlay from vector tile source]({{ s3_url("vectortilesource.png") }}){ width="400" } + {{ openmaptiles_caption() }} +