Skip to content

Commit 61f9947

Browse files
aleksprogergithub-actions[bot]
authored andcommitted
Update Android indoor example (#9819)
- Update indoor example and plugin documentation to allow setting style in example and show the use location cc @mapbox/maps-android cc @mapbox/maps-ios GitOrigin-RevId: 9e1cb02532b1d5d56f7214bef053ec060da2b46b
1 parent a4d5f14 commit 61f9947

5 files changed

Lines changed: 143 additions & 2 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,5 +1458,17 @@
14581458
android:name="android.support.PARENT_ACTIVITY"
14591459
android:value=".ExampleOverviewActivity" />
14601460
</activity>
1461+
<activity
1462+
android:name=".examples.IndoorExampleActivity"
1463+
android:description="@string/description_indoor_example"
1464+
android:exported="true"
1465+
android:label="@string/activity_indoor_example">
1466+
<meta-data
1467+
android:name="@string/category"
1468+
android:value="@string/category_lab" />
1469+
<meta-data
1470+
android:name="android.support.PARENT_ACTIVITY"
1471+
android:value=".ExampleOverviewActivity" />
1472+
</activity>
14611473
</application>
14621474
</manifest>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.mapbox.maps.testapp.examples
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import com.mapbox.geojson.Point
6+
import com.mapbox.maps.CameraOptions
7+
import com.mapbox.maps.MapInitOptions
8+
import com.mapbox.maps.MapView
9+
import com.mapbox.maps.MapboxExperimental
10+
import com.mapbox.maps.dsl.cameraOptions
11+
import com.mapbox.maps.plugin.Plugin
12+
import com.mapbox.maps.plugin.indoorselector.indoorSelector
13+
import com.mapbox.maps.plugin.locationcomponent.createDefault2DPuck
14+
import com.mapbox.maps.plugin.locationcomponent.location
15+
import com.mapbox.maps.plugin.scalebar.scalebar
16+
import com.mapbox.maps.testapp.R
17+
import com.mapbox.maps.testapp.utils.LocationPermissionHelper
18+
import java.lang.ref.WeakReference
19+
20+
/**
21+
* Example showcasing the Indoor Manager API for controlling indoor map floor display.
22+
*/
23+
class IndoorExampleActivity : AppCompatActivity() {
24+
private lateinit var locationPermissionHelper: LocationPermissionHelper
25+
26+
override fun onRequestPermissionsResult(
27+
requestCode: Int,
28+
permissions: Array<String>,
29+
grantResults: IntArray
30+
) {
31+
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
32+
locationPermissionHelper.onRequestPermissionsResult(requestCode, permissions, grantResults)
33+
}
34+
35+
@OptIn(MapboxExperimental::class)
36+
override fun onCreate(savedInstanceState: Bundle?) {
37+
super.onCreate(savedInstanceState)
38+
val mapInitOptions = MapInitOptions(
39+
context = this,
40+
cameraOptions = cameraOptions {
41+
center(Point.fromLngLat(LONGITUDE, LATITUDE))
42+
zoom(ZOOM)
43+
bearing(BEARING)
44+
pitch(PITCH)
45+
},
46+
styleUri = STYLE_URI,
47+
plugins = MapInitOptions.defaultPluginList + Plugin.Mapbox(Plugin.MAPBOX_INDOOR_SELECTOR_PLUGIN_ID)
48+
)
49+
50+
setContentView(R.layout.activity_indoor_example)
51+
val container = findViewById<android.view.ViewGroup>(R.id.container)
52+
val mapView = MapView(this, mapInitOptions)
53+
container.addView(mapView, 0)
54+
55+
val styleInput = findViewById<android.widget.EditText>(R.id.styleInput)
56+
findViewById<android.view.View>(R.id.loadStyleButton).setOnClickListener {
57+
val style = styleInput.text.toString()
58+
if (style.trim().startsWith("{")) {
59+
mapView.mapboxMap.loadStyleJson(style)
60+
} else {
61+
mapView.mapboxMap.loadStyle(style)
62+
}
63+
}
64+
65+
mapView.scalebar.enabled = true
66+
67+
mapView.indoorSelector.enabled = true
68+
mapView.indoorSelector.marginTop = 160f
69+
70+
locationPermissionHelper = LocationPermissionHelper(WeakReference(this))
71+
locationPermissionHelper.checkPermissions {
72+
mapView.location.apply {
73+
enabled = true
74+
puckBearingEnabled = true
75+
locationPuck = createDefault2DPuck(withBearing = true)
76+
77+
addOnIndicatorPositionChangedListener { point ->
78+
mapView.mapboxMap.setCamera(
79+
CameraOptions.Builder()
80+
.center(point)
81+
.zoom(18.0)
82+
.build()
83+
)
84+
}
85+
}
86+
}
87+
}
88+
89+
companion object {
90+
private const val STYLE_URI = "mapbox://styles/mapbox/standard"
91+
private const val LATITUDE = 35.55025
92+
private const val LONGITUDE = 139.794131
93+
private const val ZOOM = 16.0
94+
private const val BEARING = 12.0
95+
private const val PITCH = 60.0
96+
}
97+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:id="@+id/container"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<LinearLayout
7+
android:layout_width="match_parent"
8+
android:layout_height="wrap_content"
9+
android:orientation="horizontal"
10+
android:background="#E0FFFFFF"
11+
android:padding="8dp"
12+
android:layout_gravity="bottom">
13+
14+
<EditText
15+
android:id="@+id/styleInput"
16+
android:layout_width="0dp"
17+
android:layout_height="wrap_content"
18+
android:layout_weight="1"
19+
android:hint="Style URI or JSON"
20+
android:text="mapbox://styles/mapbox/standard"
21+
android:inputType="textUri"
22+
android:singleLine="true" />
23+
24+
<Button
25+
android:id="@+id/loadStyleButton"
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content"
28+
android:text="Load" />
29+
</LinearLayout>
30+
31+
</FrameLayout>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,7 @@
192192

193193
<!-- Standard style interactions activity -->
194194
<string name="select_all">Select All</string>
195+
<!-- Indoor Example Activity -->
196+
<string name="activity_indoor_example">Indoor Example</string>
197+
<string name="description_indoor_example">Showcase Indoor Manager API with Mapbox Standard Style</string>
195198
</resources>

plugin-indoorselector/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ This README is intended for developers who are interested in [contributing](http
1414

1515
⚠️ **Important**: The indoor selector plugin is **not included in the default plugin list**. You must explicitly add it when creating your MapView.
1616

17-
⚠️ **Known Issue - Native Memory Leak**: The indoor selector plugin currently registers a callback with `IndoorManager` that cannot be unregistered during the plugin lifecycle (see `IndoorSelectorPluginImpl.kt:138-140`). This callback remains active for the lifetime of the map instance, potentially causing native memory leaks. While the callback has an early-return guard when the plugin is disabled, it still incurs a small performance overhead on every indoor state update. A Flow-based implementation is planned to address this issue in a future release.
18-
1917
**Recommendation**: Only add this plugin to your application if you specifically need indoor mapping functionality and have access to indoor map data with a supported style.
2018

2119
```kotlin

0 commit comments

Comments
 (0)