Skip to content

Commit

Permalink
Add lat-lng-bounds.md documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
louwers committed Nov 13, 2024
1 parent debdc7a commit 3329112
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class GestureDetectorActivity : AppCompatActivity() {
}

fun attachListeners() {
// # --8<-- [start:addOnMoveListener]
maplibreMap.addOnMoveListener(
object : OnMoveListener {
override fun onMoveBegin(detector: MoveGestureDetector) {
Expand All @@ -132,6 +133,7 @@ class GestureDetectorActivity : AppCompatActivity() {
}
}
)
// # --8<-- [end:addOnMoveListener]
maplibreMap.addOnRotateListener(
object : OnRotateListener {
override fun onRotateBegin(detector: RotateGestureDetector) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ class LatLngBoundsActivity : AppCompatActivity() {
binding.mapView.getMapAsync { map ->
maplibreMap = map

// # --8<-- [start:featureCollection]
val featureCollection: FeatureCollection =
fromJson(GeoParseUtil.loadStringFromAssets(this, "points-sf.geojson"))
bounds = createBounds(featureCollection)

map.getCameraForLatLngBounds(bounds, createPadding(peekHeight))?.let {
map.cameraPosition = it
}
// # --8<-- [end:featureCollection]

try {
loadStyle(featureCollection)
Expand All @@ -71,7 +73,7 @@ class LatLngBoundsActivity : AppCompatActivity() {
private fun loadStyle(featureCollection: FeatureCollection) {
maplibreMap.setStyle(
Style.Builder()
.fromUri(TestStyles.getPredefinedStyleWithFallback("Streets"))
.fromUri(TestStyles.VERSATILES)
.withLayer(
SymbolLayer("symbol", "symbol")
.withProperties(
Expand Down Expand Up @@ -129,6 +131,7 @@ class LatLngBoundsActivity : AppCompatActivity() {
return intArrayOf(additionalPadding, additionalPadding, additionalPadding, bottomPadding)
}

// # --8<-- [start:createBounds]
private fun createBounds(featureCollection: FeatureCollection): LatLngBounds {
val boundsBuilder = LatLngBounds.Builder()
featureCollection.features()?.let {
Expand All @@ -139,6 +142,7 @@ class LatLngBoundsActivity : AppCompatActivity() {
}
return boundsBuilder.build()
}
// # --8<-- [end:createBounds]

override fun onStart() {
super.onStart()
Expand Down
2 changes: 1 addition & 1 deletion platform/android/docs/annotations/marker-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Then add markers to the map with GeoJSON:
[marker image]: https://raw.githubusercontent.com/maplibre/maplibre-native/main/test/fixtures/sprites/default_marker.png
[IconFactory]: https://maplibre.org/maplibre-native/android/api/-map-libre%20-native%20-android/org.maplibre.android.annotations/-icon-factory/index.html
[Icon]: https://maplibre.org/maplibre-native/android/api/-map-libre%20-native%20-android/org.maplibre.android.annotations/-icon/index.html
[Quickstart]: ./getting-started.md
[Quickstart]: ../getting-started.md
[mvn]: https://mvnrepository.com/artifact/org.maplibre.gl/android-plugin-annotation-v9
[Android Developer Documentation]: https://developer.android.com/topic/libraries/architecture/coroutines
[MarkerOptions]: https://maplibre.org/maplibre-native/android/api/-map-libre%20-native%20-android/org.maplibre.android.annotations/-marker-options/index.html
Expand Down
28 changes: 28 additions & 0 deletions platform/android/docs/camera/gesture-detector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Gesture Detector

The gesture detector of MapLibre Android is encapsulated in the [`maplibre-gestures-android`](https://github.com/maplibre/maplibre-gestures-android) package.

#### Gesture Listeners

You can add listeners for move, rotate, scale and shove gestures. For example, adding a move gesture listener with `MapLibreMap.addOnRotateListener`:

```kotlin
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/GestureDetectorActivity.kt:addOnMoveListener"
```

Refer to the full example below for examples of listeners for the other gesture types.

#### Settings

You can access an `UISettings` object via `MapLibreMap.uiSettings`. Available settings include:

- **Toggle Quick Zoom**. You can double tap on the map to use quick zoom. You can toggle this behavior on and off (`UiSettings.isQuickZoomGesturesEnabled`).
- **Toggle Velocity Animations**. By default flicking causes the map to continue panning (while decelerating). You can turn this off with `UiSettings.isScaleVelocityAnimationEnabled`.
- **Toggle Rotate Enabled**. Use `uiSettings.isRotateGesturesEnabled`.
- **Toggle Zoom Enabled**. Use `uiSettings.isZoomGesturesEnabled`.

## Full Example Activity

```kotlin title="GestureDetectorActivity.kt"
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/GestureDetectorActivity.kt"
```
26 changes: 26 additions & 0 deletions platform/android/docs/camera/lat-lng-bounds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# LatLngBounds API


!!! note

You can find the full source code of this example in [`LatLngBoundsActivity.kt`](https://github.com/maplibre/maplibre-native/blob/main/platform/android/testapp/activity/camera/LatLngBoundsActivity.kt) of the MapLibreAndroidTestApp.

This example demonstrates setting the camera to some bounds defined by some features. It sets these bounds when the map is initialized and when the [bottom sheet](https://m2.material.io/components/sheets-bottom) is opened or closed.

<figure markdown="span">
<video controls width="250">
<source src="https://github.com/user-attachments/assets/46a89dfb-3abc-448a-be53-8abe39b2919b" />
</video>
</figure>

Here you can see how the feature collection is loaded and how `MapLibreMap.getCameraForLatLngBounds` is used to set the bounds during map initialization:

```kotlin
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/LatLngBoundsActivity.kt:featureCollection"
```

The `createBounds` function uses the `LatLngBounds` API to include all points within the bounds:

```kotlin
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/LatLngBoundsActivity.kt:createBounds"
```
8 changes: 0 additions & 8 deletions platform/android/docs/lat-lng-bounds.md

This file was deleted.

0 comments on commit 3329112

Please sign in to comment.