From e9afa1f461bc73e97bf92422422f7fdcb2cbc3c7 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Thu, 14 Nov 2024 23:46:58 +0100 Subject: [PATCH] Improve Android Example Documentation, Animation Types (#3019) --- .../workflows/gh-pages-android-examples.yml | 4 +- .github/workflows/gh-pages-mdbook.yml | 12 ++-- docs/mdbook/src/SUMMARY.md | 6 -- .../camera/CameraAnimationTypeActivity.kt | 13 ++++- .../activity/camera/CameraPositionActivity.kt | 8 +++ .../activity/camera/ManualZoomActivity.kt | 10 ++++ .../activity/camera/MaxMinZoomActivity.kt | 23 ++++---- .../activity/camera/ScrollByActivity.kt | 2 + .../activity_camera_animation_types.xml | 3 + platform/android/docs/assets/extra.css | 9 ++- .../android/docs/camera/animation-types.md | 57 ++++++++++++++++++- .../android/docs/camera/cameraposition.md | 34 ++++++++++- .../android/docs/camera/lat-lng-bounds.md | 9 +-- platform/android/docs/camera/min-max-zoom.md | 28 +++++++++ .../android/docs/camera/move-map-pixels.md | 15 +++++ platform/android/docs/camera/zoom-methods.md | 46 +++++++++++++++ platform/android/mkdocs.yaml | 4 +- 17 files changed, 244 insertions(+), 39 deletions(-) create mode 100644 platform/android/docs/camera/min-max-zoom.md create mode 100644 platform/android/docs/camera/move-map-pixels.md create mode 100644 platform/android/docs/camera/zoom-methods.md diff --git a/.github/workflows/gh-pages-android-examples.yml b/.github/workflows/gh-pages-android-examples.yml index 303b41776e7..5ebde8efcd0 100644 --- a/.github/workflows/gh-pages-android-examples.yml +++ b/.github/workflows/gh-pages-android-examples.yml @@ -23,8 +23,8 @@ jobs: run: make mkdocs-build - name: Deploy ๐Ÿš€ - uses: JamesIves/github-pages-deploy-action@v4.6.8 + uses: JamesIves/github-pages-deploy-action@v4.6.9 with: branch: gh-pages folder: platform/android/site - target-folder: maplibre-native/android/examples/ + target-folder: android/examples/ diff --git a/.github/workflows/gh-pages-mdbook.yml b/.github/workflows/gh-pages-mdbook.yml index 0696aa357fe..cb76f166427 100644 --- a/.github/workflows/gh-pages-mdbook.yml +++ b/.github/workflows/gh-pages-mdbook.yml @@ -5,11 +5,13 @@ on: push: branches: - main + paths: + - 'docs/mdbook/**' jobs: - build-docs: + gh-pages-mdbook-build: name: Build - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: extractions/setup-just@v2 @@ -27,10 +29,10 @@ jobs: name: book path: docs/mdbook/book/ - deploy-docs: - needs: build-docs + gh-pages-mdbook-deploy: + needs: gh-pages-mdbook-build name: Deploy - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Download book diff --git a/docs/mdbook/src/SUMMARY.md b/docs/mdbook/src/SUMMARY.md index dd8a871a845..ce37391c1c4 100644 --- a/docs/mdbook/src/SUMMARY.md +++ b/docs/mdbook/src/SUMMARY.md @@ -10,11 +10,5 @@ - [Android Map Rendering Data Flow](design/android-map-rendering-data-flow.md) - [Geometry Tile Worker](design/geometry-tile-worker.md) -- [MapLibre Native for Android](./android/README.md) - - [Quickstart](./android/getting-started-guide.md) - - [Annotation: Marker](./android/annotation-guide.md) - - [Location Component](./android/location-component-guide.md) - - [MapOptions Guide](./android/map-options-guide.md) - - [Profiling applications that use MapLibre Native](./profiling/README.md) - [Tracy profiling](./profiling/tracy-profiling.md) diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraAnimationTypeActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraAnimationTypeActivity.kt index 739eeafc61a..dd7b882e578 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraAnimationTypeActivity.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraAnimationTypeActivity.kt @@ -24,12 +24,13 @@ import timber.log.Timber * Shows how to use animate, ease and move camera update factory methods. */ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { + // # --8<-- [start:callback] private val callback: CancelableCallback = object : CancelableCallback { override fun onCancel() { Timber.i("Duration onCancel Callback called.") Toast.makeText( - this@CameraAnimationTypeActivity.applicationContext, + applicationContext, "Ease onCancel Callback called.", Toast.LENGTH_LONG ) @@ -39,13 +40,15 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { override fun onFinish() { Timber.i("Duration onFinish Callback called.") Toast.makeText( - this@CameraAnimationTypeActivity.applicationContext, + applicationContext, "Ease onFinish Callback called.", Toast.LENGTH_LONG ) .show() } } + // # --8<-- [end:callback] + private lateinit var maplibreMap: MapLibreMap private lateinit var mapView: MapView private var cameraState = false @@ -73,6 +76,7 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { // handle move button clicks val moveButton = findViewById(R.id.cameraMoveButton) moveButton?.setOnClickListener { view: View? -> + // # --8<-- [start:moveCamera] val cameraPosition = CameraPosition.Builder() .target(nextLatLng) @@ -81,11 +85,13 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { .tilt(0.0) .build() maplibreMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)) + // # --8<-- [end:moveCamera] } // handle ease button clicks val easeButton = findViewById(R.id.cameraEaseButton) easeButton?.setOnClickListener { view: View? -> + // # --8<-- [start:easeCamera] val cameraPosition = CameraPosition.Builder() .target(nextLatLng) @@ -98,11 +104,13 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { 7500, callback ) + // # --8<-- [end:easeCamera] } // handle animate button clicks val animateButton = findViewById(R.id.cameraAnimateButton) animateButton?.setOnClickListener { view: View? -> + // # --8<-- [start:animateCamera] val cameraPosition = CameraPosition.Builder().target(nextLatLng).bearing(270.0).tilt(20.0).build() maplibreMap.animateCamera( @@ -110,6 +118,7 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { 7500, callback ) + // # --8<-- [end:animateCamera] } } diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraPositionActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraPositionActivity.kt index 827343bbe8b..bd4305c5822 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraPositionActivity.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraPositionActivity.kt @@ -83,7 +83,9 @@ class CameraPositionActivity : FragmentActivity(), OnMapReadyCallback, View.OnCl if (logCameraChanges) { maplibreMap.addOnCameraIdleListener(idleListener) maplibreMap.addOnCameraMoveCancelListener(moveCanceledListener) + // # --8<-- [start:addOnCameraMoveListener] maplibreMap.addOnCameraMoveListener(moveListener) + // # --8<-- [end:addOnCameraMoveListener] maplibreMap.addOnCameraMoveStartedListener(moveStartedListener) } else { maplibreMap.removeOnCameraIdleListener(idleListener) @@ -151,12 +153,16 @@ class CameraPositionActivity : FragmentActivity(), OnMapReadyCallback, View.OnCl ContextCompat.getColor(this@CameraPositionActivity, android.R.color.holo_green_dark) ) } + + // # --8<-- [start:moveListener] private val moveListener = OnCameraMoveListener { Timber.e("OnCameraMove") fab.setColorFilter( ContextCompat.getColor(this@CameraPositionActivity, android.R.color.holo_orange_dark) ) } + // # --8<-- [end:moveListener] + private val moveCanceledListener = OnCameraMoveCanceledListener { Timber.e("OnCameraMoveCanceled") } @@ -203,6 +209,7 @@ class CameraPositionActivity : FragmentActivity(), OnMapReadyCallback, View.OnCl return } + // # --8<-- [start:cameraPosition] val cameraPosition = CameraPosition.Builder().target(LatLng(latitude, longitude)).zoom(zoom).bearing(bearing).tilt(tilt).build() maplibreMap?.animateCamera( @@ -218,6 +225,7 @@ class CameraPositionActivity : FragmentActivity(), OnMapReadyCallback, View.OnCl } } ) + // # --8<-- [end:cameraPosition] Timber.v(cameraPosition.toString()) } } diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ManualZoomActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ManualZoomActivity.kt index 6d57e6c9415..99592683cb9 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ManualZoomActivity.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ManualZoomActivity.kt @@ -44,22 +44,31 @@ class ManualZoomActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { R.id.action_zoom_in -> { + // # --8<-- [start:zoomIn] maplibreMap.animateCamera(CameraUpdateFactory.zoomIn()) + // # --8<-- [end:zoomIn] true } R.id.action_zoom_out -> { + // # --8<-- [start:zoomOut] maplibreMap.animateCamera(CameraUpdateFactory.zoomOut()) + // # --8<-- [end:zoomOut] true } R.id.action_zoom_by -> { + // # --8<-- [start:zoomBy] maplibreMap.animateCamera(CameraUpdateFactory.zoomBy(2.0)) + // # --8<-- [end:zoomBy] true } R.id.action_zoom_to -> { + // # --8<-- [start:zoomTo] maplibreMap.animateCamera(CameraUpdateFactory.zoomTo(2.0)) + // # --8<-- [end:zoomTo] true } R.id.action_zoom_to_point -> { + // # --8<-- [start:zoomToPoint] val view = window.decorView maplibreMap.animateCamera( CameraUpdateFactory.zoomBy( @@ -67,6 +76,7 @@ class ManualZoomActivity : AppCompatActivity() { Point(view.measuredWidth / 4, view.measuredHeight / 4) ) ) + // # --8<-- [end:zoomToPoint] true } else -> super.onOptionsItemSelected(item) diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/MaxMinZoomActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/MaxMinZoomActivity.kt index 897c59a53f7..9df5ada87c1 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/MaxMinZoomActivity.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/MaxMinZoomActivity.kt @@ -15,12 +15,6 @@ import timber.log.Timber class MaxMinZoomActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mapView: MapView private lateinit var maplibreMap: MapLibreMap - private val clickListener = OnMapClickListener { - if (this::maplibreMap.isInitialized) { - maplibreMap.setStyle(Style.Builder().fromUri(TestStyles.getPredefinedStyleWithFallback("Outdoor"))) - } - true - } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -33,10 +27,20 @@ class MaxMinZoomActivity : AppCompatActivity(), OnMapReadyCallback { override fun onMapReady(map: MapLibreMap) { maplibreMap = map - maplibreMap.setStyle(TestStyles.getPredefinedStyleWithFallback("Streets")) + maplibreMap.setStyle(TestStyles.OPENFREEMAP_LIBERY) + // # --8<-- [start:zoomPreference] maplibreMap.setMinZoomPreference(3.0) maplibreMap.setMaxZoomPreference(5.0) - maplibreMap.addOnMapClickListener(clickListener) + // # --8<-- [end:zoomPreference] + + // # --8<-- [start:addOnMapClickListener] + maplibreMap.addOnMapClickListener { + if (this::maplibreMap.isInitialized) { + maplibreMap.setStyle(Style.Builder().fromUri(TestStyles.AMERICANA)) + } + true + } + // # --8<-- [end:addOnMapClickListener] } override fun onStart() { @@ -66,9 +70,6 @@ class MaxMinZoomActivity : AppCompatActivity(), OnMapReadyCallback { override fun onDestroy() { super.onDestroy() - if (this::maplibreMap.isInitialized) { - maplibreMap.removeOnMapClickListener(clickListener) - } mapView.onDestroy() } diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ScrollByActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ScrollByActivity.kt index 6da5ca7cba5..63a18211081 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ScrollByActivity.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ScrollByActivity.kt @@ -60,10 +60,12 @@ class ScrollByActivity : AppCompatActivity(), OnMapReadyCallback { val fab = findViewById(R.id.fab) fab.setColorFilter(ContextCompat.getColor(this@ScrollByActivity, R.color.primary)) fab.setOnClickListener { _: View? -> + // # --8<-- [start:scrollBy] maplibreMap.scrollBy( (seekBarX.progress * MULTIPLIER_PER_PIXEL).toFloat(), (seekBarY.progress * MULTIPLIER_PER_PIXEL).toFloat() ) + // # --8<-- [end:scrollBy] } } diff --git a/platform/android/MapLibreAndroidTestApp/src/main/res/layout/activity_camera_animation_types.xml b/platform/android/MapLibreAndroidTestApp/src/main/res/layout/activity_camera_animation_types.xml index c2bd0111d57..5a5f2664099 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/res/layout/activity_camera_animation_types.xml +++ b/platform/android/MapLibreAndroidTestApp/src/main/res/layout/activity_camera_animation_types.xml @@ -29,6 +29,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" + android:textColor="@color/white" android:text="@string/button_camera_move"/>