Skip to content

Commit 2b2e4ea

Browse files
committed
docs
1 parent bbbc6e2 commit 2b2e4ea

5 files changed

Lines changed: 58 additions & 14 deletions

File tree

platform/android/docs/camera/lat-lng-bounds.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,26 @@
1919
Here you can see how the feature collection is loaded and how `MapLibreMap.getCameraForLatLngBounds` is used to set the bounds during map initialization:
2020

2121
```kotlin
22-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/LatLngBoundsActivity.kt:featureCollection"
22+
val featureCollection: FeatureCollection =
23+
fromJson(GeoParseUtil.loadStringFromAssets(this, "points-sf.geojson"))
24+
bounds = createBounds(featureCollection)
25+
26+
map.getCameraForLatLngBounds(bounds, createPadding(peekHeight))?.let {
27+
map.cameraPosition = it
28+
}
2329
```
2430

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

2733
```kotlin
28-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/LatLngBoundsActivity.kt:createBounds"
34+
private fun createBounds(featureCollection: FeatureCollection): LatLngBounds {
35+
val boundsBuilder = LatLngBounds.Builder()
36+
featureCollection.features()?.let {
37+
for (feature in it) {
38+
val point = feature.geometry() as Point
39+
boundsBuilder.include(LatLng(point.latitude(), point.longitude()))
40+
}
41+
}
42+
return boundsBuilder.build()
43+
}
2944
```

platform/android/docs/camera/max-min-zoom.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
This example shows how to configure a maximum and a minimum zoom level.
66

77
```kotlin
8-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/MaxMinZoomActivity.kt:zoomPreference"
8+
maplibreMap.setMinZoomPreference(3.0)
9+
maplibreMap.setMaxZoomPreference(5.0)
910
```
1011

1112
## Bonus: Add Click Listener
1213

1314
As a bonus, this example also shows how you can define a click listener to the map.
1415

1516
```kotlin
16-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/MaxMinZoomActivity.kt:addOnMapClickListener"
17+
maplibreMap.addOnMapClickListener {
18+
if (this::maplibreMap.isInitialized) {
19+
maplibreMap.setStyle(Style.Builder().fromUri(TestStyles.AMERICANA))
20+
}
21+
true
22+
}
1723
```
1824

1925
You can remove a click listener again with `MapLibreMap.removeOnMapClickListener`. To use this API you need to assign the click listener to a variable, since you need to pass the listener to that method.

platform/android/docs/camera/move-map-pixels.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
This example shows how you can move the map by x/y pixels.
66

77
```kotlin
8-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ScrollByActivity.kt:scrollBy"
8+
maplibreMap.scrollBy(
9+
(seekBarX.progress * MULTIPLIER_PER_PIXEL).toFloat(),
10+
(seekBarY.progress * MULTIPLIER_PER_PIXEL).toFloat()
11+
)
912
```
1013

11-
<figure markdown="span">
12-
![Screenshot of Example Activity to move the map by some pixels](https://github.com/user-attachments/assets/f8ae0ec7-a165-4fb3-ab9f-bfb5579c7dd8){ width="300" }
13-
</figure>
14+
[//]: # (<figure markdown="span">)
15+
16+
[//]: # ( ![Screenshot of Example Activity to move the map by some pixels]&#40;https://github.com/user-attachments/assets/f8ae0ec7-a165-4fb3-ab9f-bfb5579c7dd8&#41;{ width="300" })
17+
18+
[//]: # (</figure>)

platform/android/docs/camera/zoom-methods.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,35 @@ Each method uses `MapLibreMap.animateCamera`, but with a different `CameraUpdate
2020
#### Zooming In
2121

2222
```kotlin
23-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ManualZoomActivity.kt:zoomIn"
23+
maplibreMap.animateCamera(CameraUpdateFactory.zoomIn())
2424
```
2525

2626
#### Zooming Out
2727

2828
```kotlin
29-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ManualZoomActivity.kt:zoomOut"
29+
maplibreMap.animateCamera(CameraUpdateFactory.zoomOut())
3030
```
3131

3232
#### Zoom By Some Amount of Zoom Levels
3333

3434
```kotlin
35-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ManualZoomActivity.kt:zoomBy"
35+
maplibreMap.animateCamera(CameraUpdateFactory.zoomBy(2.0))
3636
```
3737

3838
#### Zoom to a Zoom Level
3939

4040
```kotlin
41-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ManualZoomActivity.kt:zoomTo"
41+
maplibreMap.animateCamera(CameraUpdateFactory.zoomTo(2.0))
4242
```
4343

4444
#### Zoom to a Point
4545

4646
```kotlin
47-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/ManualZoomActivity.kt:zoomToPoint"
47+
val view = window.decorView
48+
maplibreMap.animateCamera(
49+
CameraUpdateFactory.zoomBy(
50+
1.0,
51+
Point(view.measuredWidth / 4, view.measuredHeight / 4)
52+
)
53+
)
4854
```

platform/android/docs/data/MVT.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@ You can specify where to load MVTs (which sometimes have `.pbf` extension) by cr
77
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.
88

99
```kotlin
10-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/sources/VectorTileActivity.kt:addTileSet"
10+
val tileset = TileSet(
11+
"openmaptiles",
12+
"https://demotiles.maplibre.org/tiles-omt/{z}/{x}/{y}.pbf"
13+
)
14+
val openmaptiles = VectorSource("openmaptiles", tileset)
15+
style.addSource(openmaptiles)
16+
val roadLayer = LineLayer("road", "openmaptiles").apply {
17+
setSourceLayer("transportation")
18+
setProperties(
19+
lineColor("red"),
20+
lineWidth(2.0f)
21+
)
22+
}
1123
```
1224

1325
[//]: # ()

0 commit comments

Comments
 (0)