Skip to content

Commit 221939b

Browse files
committed
docs
1 parent 2b2e4ea commit 221939b

21 files changed

Lines changed: 2116 additions & 98 deletions

platform/android/docs/camera/animation-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Animation Types
22

3-
{{ activity_source_note("CameraAnimationTypeActivity.kt") }}
3+
[//]: # ({{ activity_source_note("CameraAnimationTypeActivity.kt") }})
44

55
This example showcases the different animation types.
66

platform/android/docs/camera/cameraposition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CameraPosition Capabilities
22

3-
{{ activity_source_note("CameraPositionActivity.kt") }}
3+
[//]: # ({{ activity_source_note("CameraPositionActivity.kt") }})
44

55
[//]: # (This example showcases how to listen to camera change events.)
66

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LatLngBounds API
22

3-
{{ activity_source_note("LatLngBoundsActivity.kt") }}
3+
[//]: # ({{ activity_source_note("LatLngBoundsActivity.kt") }})
44

55
[//]: # (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.)
66

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Max/Min Zoom
22

3-
{{ activity_source_note("MaxMinZoomActivity.kt") }}
3+
[//]: # ({{ activity_source_note("MaxMinZoomActivity.kt") }})
44

55
This example shows how to configure a maximum and a minimum zoom level.
66

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Scroll by Method
22

3-
{{ activity_source_note("ScrollByActivity.kt") }}
3+
[//]: # ({{ activity_source_note("ScrollByActivity.kt") }})
44

55
This example shows how you can move the map by x/y pixels.
66

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Zoom Methods
22

3-
{{ activity_source_note("ManualZoomActivity.kt") }}
3+
[//]: # ({{ activity_source_note("ManualZoomActivity.kt") }})
44

55
[//]: # (This example shows different methods of zooming in.)
66

platform/android/docs/configuration.md

Lines changed: 301 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,116 @@ We will explore how to achieve these configurations in XML layout and programmat
3131
To configure `MapView` within an XML layout, you need to use the right namespace and provide the necessary data in the layout file.
3232

3333
```xml
34-
--8<-- "MapLibreAndroidTestApp/src/main/res/layout/activity_map_options_xml.xml"
34+
<?xml version="1.0" encoding="utf-8"?>
35+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
36+
xmlns:app="http://schemas.android.com/apk/res-auto"
37+
xmlns:tools="http://schemas.android.com/tools"
38+
android:id="@+id/main"
39+
android:layout_width="match_parent"
40+
android:layout_height="match_parent"
41+
tools:context=".activity.options.MapOptionsXmlActivity">
42+
43+
<org.maplibre.android.maps.MapView
44+
android:id="@+id/mapView"
45+
android:layout_width="match_parent"
46+
android:layout_height="match_parent"
47+
app:maplibre_apiBaseUri="https://api.maplibre.org"
48+
app:maplibre_cameraBearing="0.0"
49+
app:maplibre_cameraPitchMax="90.0"
50+
app:maplibre_cameraPitchMin="0.0"
51+
app:maplibre_cameraTargetLat="42.31230486601532"
52+
app:maplibre_cameraTargetLng="64.63967338936439"
53+
app:maplibre_cameraTilt="0.0"
54+
app:maplibre_cameraZoom="3.9"
55+
app:maplibre_cameraZoomMax="26.0"
56+
app:maplibre_cameraZoomMin="2.0"
57+
app:maplibre_localIdeographFontFamilies="@array/array_local_ideograph_family_test"
58+
app:maplibre_localIdeographFontFamily="Droid Sans"
59+
app:maplibre_uiCompass="true"
60+
app:maplibre_uiCompassFadeFacingNorth="true"
61+
app:maplibre_uiCompassGravity="top|end"
62+
app:maplibre_uiDoubleTapGestures="true"
63+
app:maplibre_uiHorizontalScrollGestures="true"
64+
app:maplibre_uiRotateGestures="true"
65+
app:maplibre_uiScrollGestures="true"
66+
app:maplibre_uiTiltGestures="true"
67+
app:maplibre_uiZoomGestures="true" />
68+
69+
</androidx.constraintlayout.widget.ConstraintLayout>
3570
```
3671

3772
This can be found in [`activity_map_options_xml.xml`](https://github.com/MapMetrics/mapmetrics-native-sdk/blob/main/platform/android/MapLibreAndroidTestApp/src/main/res/layout/activity_map_fragment.xml).
3873

3974
You can assign any other existing values to the `maplibre...` tags. Then, you only need to create `MapView` and `MapLibreMap` objects with a simple setup in the Activity.
4075

4176
```kotlin title="MapOptionsXmlActivity.kt"
42-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/options/MapOptionsXmlActivity.kt"
77+
package org.maplibre.android.testapp.activity.options
78+
79+
import android.os.Bundle
80+
import androidx.appcompat.app.AppCompatActivity
81+
import org.maplibre.android.maps.MapLibreMap
82+
import org.maplibre.android.maps.MapView
83+
import org.maplibre.android.maps.OnMapReadyCallback
84+
import org.maplibre.android.maps.Style
85+
import org.maplibre.android.testapp.R
86+
import org.maplibre.android.testapp.styles.TestStyles
87+
88+
/**
89+
* TestActivity demonstrating configuring MapView with XML
90+
*/
91+
92+
class MapOptionsXmlActivity : AppCompatActivity(), OnMapReadyCallback {
93+
private lateinit var mapView: MapView
94+
private lateinit var maplibreMap: MapLibreMap
95+
96+
override fun onCreate(savedInstanceState: Bundle?) {
97+
super.onCreate(savedInstanceState)
98+
setContentView(R.layout.activity_map_options_xml)
99+
mapView = findViewById(R.id.mapView)
100+
mapView.onCreate(savedInstanceState)
101+
mapView.getMapAsync(this)
102+
}
103+
104+
override fun onMapReady(maplibreMap: MapLibreMap) {
105+
this.maplibreMap = maplibreMap
106+
this.maplibreMap.setStyle("https://demotiles.maplibre.org/style.json")
107+
}
108+
109+
override fun onStart() {
110+
super.onStart()
111+
mapView.onStart()
112+
}
113+
114+
override fun onResume() {
115+
super.onResume()
116+
mapView.onResume()
117+
}
118+
119+
override fun onPause() {
120+
super.onPause()
121+
mapView.onPause()
122+
}
123+
124+
override fun onStop() {
125+
super.onStop()
126+
mapView.onStop()
127+
}
128+
129+
override fun onSaveInstanceState(outState: Bundle) {
130+
super.onSaveInstanceState(outState)
131+
mapView.onSaveInstanceState(outState)
132+
}
133+
134+
override fun onDestroy() {
135+
super.onDestroy()
136+
mapView.onDestroy()
137+
}
138+
139+
override fun onLowMemory() {
140+
super.onLowMemory()
141+
mapView.onLowMemory()
142+
}
143+
}
43144
```
44145

45146
This can be found in [`MapOptionsXmlActivity.kt`](https://github.com/MapMetrics/mapmetrics-native-sdk/blob/main/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/options/MapOptionsXmlActivity.kt).
@@ -48,15 +149,119 @@ This can be found in [`MapOptionsXmlActivity.kt`](https://github.com/MapMetrics/
48149

49150
Here we don't have to create MapView from XML since we want to create it programmatically.
50151
```xml
51-
--8<-- "MapLibreAndroidTestApp/src/main/res/layout/activity_map_options_runtime.xml"
152+
<?xml version="1.0" encoding="utf-8"?>
153+
<FrameLayout
154+
xmlns:android="http://schemas.android.com/apk/res/android"
155+
android:id="@+id/container"
156+
android:layout_width="match_parent"
157+
android:layout_height="match_parent"
158+
android:orientation="vertical"/>
52159
```
53160

54161
This can be found in [`activity_map_options_runtime.xml`](https://github.com/MapMetrics/mapmetrics-native-sdk/blob/main/platform/android/MapLibreAndroidTestApp/src/main/res/layout/activity_map_options_runtime.xml).
55162

56163
A `MapLibreMapOptions` object must be created and passed to the MapView constructor. All setup is done in the Activity code:
57164

58165
```kotlin title="MapOptionsRuntimeActivity.kt"
59-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/options/MapOptionsRuntimeActivity.kt"
166+
package org.maplibre.android.testapp.activity.options
167+
168+
import android.os.Bundle
169+
import android.view.View
170+
import android.view.ViewGroup
171+
import androidx.appcompat.app.AppCompatActivity
172+
import org.maplibre.android.camera.CameraPosition
173+
import org.maplibre.android.geometry.LatLng
174+
import org.maplibre.android.maps.MapLibreMap
175+
import org.maplibre.android.maps.MapLibreMapOptions
176+
import org.maplibre.android.maps.MapView
177+
import org.maplibre.android.maps.OnMapReadyCallback
178+
import org.maplibre.android.maps.Style
179+
import org.maplibre.android.testapp.R
180+
import org.maplibre.android.testapp.styles.TestStyles
181+
182+
/**
183+
* TestActivity demonstrating configuring MapView with MapOptions
184+
*/
185+
class MapOptionsRuntimeActivity : AppCompatActivity(), OnMapReadyCallback {
186+
187+
private lateinit var maplibreMap: MapLibreMap
188+
private lateinit var mapView: MapView
189+
override fun onCreate(savedInstanceState: Bundle?) {
190+
super.onCreate(savedInstanceState)
191+
setContentView(R.layout.activity_map_options_runtime)
192+
193+
// Create map configuration
194+
val maplibreMapOptions = MapLibreMapOptions.createFromAttributes(this)
195+
maplibreMapOptions.apply {
196+
apiBaseUri("https://api.maplibre.org")
197+
camera(
198+
CameraPosition.Builder()
199+
.bearing(0.0)
200+
.target(LatLng(42.31230486601532, 64.63967338936439))
201+
.zoom(3.9)
202+
.tilt(0.0)
203+
.build()
204+
)
205+
maxPitchPreference(90.0)
206+
minPitchPreference(0.0)
207+
maxZoomPreference(26.0)
208+
minZoomPreference(2.0)
209+
localIdeographFontFamily("Droid Sans")
210+
zoomGesturesEnabled(true)
211+
compassEnabled(true)
212+
compassFadesWhenFacingNorth(true)
213+
scrollGesturesEnabled(true)
214+
rotateGesturesEnabled(true)
215+
tiltGesturesEnabled(true)
216+
}
217+
218+
// Create map programmatically, add to view hierarchy
219+
mapView = MapView(this, maplibreMapOptions)
220+
mapView.getMapAsync(this)
221+
mapView.onCreate(savedInstanceState)
222+
(findViewById<View>(R.id.container) as ViewGroup).addView(mapView)
223+
}
224+
225+
override fun onMapReady(maplibreMap: MapLibreMap) {
226+
this.maplibreMap = maplibreMap
227+
this.maplibreMap.setStyle("https://demotiles.maplibre.org/style.json")
228+
}
229+
230+
override fun onStart() {
231+
super.onStart()
232+
mapView.onStart()
233+
}
234+
235+
override fun onResume() {
236+
super.onResume()
237+
mapView.onResume()
238+
}
239+
240+
override fun onPause() {
241+
super.onPause()
242+
mapView.onPause()
243+
}
244+
245+
override fun onStop() {
246+
super.onStop()
247+
mapView.onStop()
248+
}
249+
250+
override fun onSaveInstanceState(outState: Bundle) {
251+
super.onSaveInstanceState(outState)
252+
mapView.onSaveInstanceState(outState)
253+
}
254+
255+
override fun onDestroy() {
256+
super.onDestroy()
257+
mapView.onDestroy()
258+
}
259+
260+
override fun onLowMemory() {
261+
super.onLowMemory()
262+
mapView.onLowMemory()
263+
}
264+
}
60265
```
61266

62267
This can be found in [`MapOptionsRuntimeActivity.kt`](https://github.com/MapMetrics/mapmetrics-native-sdk/blob/main/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/options/MapOptionsRuntimeActivity.kt).
@@ -81,7 +286,98 @@ If you are using MapFragment in your project, it is also easy to provide initial
81286
Let's see how this can be done in a sample activity:
82287

83288
```kotlin
84-
--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/fragment/SupportMapFragmentActivity.kt"
289+
package org.maplibre.android.testapp.activity.fragment
290+
291+
import android.os.Bundle // ktlint-disable import-ordering
292+
import androidx.appcompat.app.AppCompatActivity
293+
import org.maplibre.android.camera.CameraPosition
294+
import org.maplibre.android.camera.CameraUpdateFactory
295+
import org.maplibre.android.geometry.LatLng
296+
import org.maplibre.android.maps.* // ktlint-disable no-wildcard-imports
297+
import org.maplibre.android.maps.MapFragment.OnMapViewReadyCallback
298+
import org.maplibre.android.maps.MapView.OnDidFinishRenderingFrameListener
299+
import org.maplibre.android.testapp.R
300+
import org.maplibre.android.testapp.styles.TestStyles
301+
302+
/**
303+
* Test activity showcasing using the MapFragment API using Support Library Fragments.
304+
*
305+
*
306+
* Uses MapLibreMapOptions to initialise the Fragment.
307+
*
308+
*/
309+
class SupportMapFragmentActivity :
310+
AppCompatActivity(),
311+
OnMapViewReadyCallback,
312+
OnMapReadyCallback,
313+
OnDidFinishRenderingFrameListener {
314+
private lateinit var maplibreMap: MapLibreMap
315+
private lateinit var mapView: MapView
316+
private var initialCameraAnimation = true
317+
override fun onCreate(savedInstanceState: Bundle?) {
318+
super.onCreate(savedInstanceState)
319+
setContentView(R.layout.activity_map_fragment)
320+
val mapFragment: SupportMapFragment?
321+
if (savedInstanceState == null) {
322+
mapFragment = SupportMapFragment.newInstance(createFragmentOptions())
323+
supportFragmentManager
324+
.beginTransaction()
325+
.add(R.id.fragment_container, mapFragment, TAG)
326+
.commit()
327+
} else {
328+
mapFragment = supportFragmentManager.findFragmentByTag(TAG) as SupportMapFragment?
329+
}
330+
mapFragment!!.getMapAsync(this)
331+
}
332+
333+
private fun createFragmentOptions(): MapLibreMapOptions {
334+
val options = MapLibreMapOptions.createFromAttributes(this, null)
335+
options.scrollGesturesEnabled(false)
336+
options.zoomGesturesEnabled(false)
337+
options.tiltGesturesEnabled(false)
338+
options.rotateGesturesEnabled(false)
339+
options.debugActive(false)
340+
val dc = LatLng(38.90252, -77.02291)
341+
options.minZoomPreference(9.0)
342+
options.maxZoomPreference(11.0)
343+
options.camera(
344+
CameraPosition.Builder()
345+
.target(dc)
346+
.zoom(11.0)
347+
.build()
348+
)
349+
return options
350+
}
351+
352+
override fun onMapViewReady(map: MapView) {
353+
mapView = map
354+
mapView.addOnDidFinishRenderingFrameListener(this)
355+
}
356+
357+
override fun onMapReady(map: MapLibreMap) {
358+
maplibreMap = map
359+
maplibreMap.setStyle(TestStyles.getPredefinedStyleWithFallback("Satellite Hybrid"))
360+
}
361+
362+
override fun onDestroy() {
363+
super.onDestroy()
364+
mapView.removeOnDidFinishRenderingFrameListener(this)
365+
}
366+
367+
override fun onDidFinishRenderingFrame(fully: Boolean, frameEncodingTime: Double, frameRenderingTime: Double) {
368+
if (initialCameraAnimation && fully && this::maplibreMap.isInitialized) {
369+
maplibreMap.animateCamera(
370+
CameraUpdateFactory.newCameraPosition(CameraPosition.Builder().tilt(45.0).build()),
371+
5000
372+
)
373+
initialCameraAnimation = false
374+
}
375+
}
376+
377+
companion object {
378+
private const val TAG = "com.mapbox.map"
379+
}
380+
}
85381
```
86382

87383
You can also find the full contents of `SupportMapFragmentActivity` in the [MapLibreAndroidTestApp](https://github.com/MapMetrics/mapmetrics-native-sdk/tree/main/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/fragment/SupportMapFragmentActivity.kt).

platform/android/docs/data/MVT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Vector Tiles
22

3-
{{ activity_source_note("VectorTileActivity.kt") }}
3+
[//]: # ({{ activity_source_note&#40;"VectorTileActivity.kt"&#41; }})
44

55
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).
66

0 commit comments

Comments
 (0)