Skip to content

Commit 9b23e92

Browse files
pengdevgithub-actions[bot]
authored andcommitted
Fix crash in TriangleCustomLayerActivity (#10399)
### Summary Fixes https://mapbox.atlassian.net/browse/MAPSAND-2488 - Fixes a crash in `TriangleCustomLayerActivity` caused by using a removed/incompatible layer insertion API. ### Problem `TriangleCustomLayerActivity` crashed when adding a custom layer because it used `addLayerBelow(CustomLayer(...), below = "building")`, which depends on a specific layer ID (`"building"`) that may not be present in the current style, causing a runtime crash. ### Solution Replace `addLayerBelow` with `addLayer` using the slot-based API (`slot("middle")`), which is the correct modern approach for inserting custom layers at a predefined position in the style without hardcoding a layer ID dependency. ### Key Changes - **`TriangleCustomLayerActivity.kt`**: `addLayerBelow(CustomLayer(...), below = "building")` → `addLayer(customLayer(...) { slot("middle") })` - **Import**: Removed `CustomLayer` and `addLayerBelow` imports; now uses `addLayer` and the `customLayer` DSL builder ### Validation - [x] Activity no longer crashes when loading - [x] Verify the custom triangle layer renders correctly at the expected z-order in the `middle` slot GitOrigin-RevId: 7de2a5108b26d665c4c5091bd120808a01f8ab45
1 parent bcd5faa commit 9b23e92

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/TriangleCustomLayerActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import com.mapbox.geojson.Point
88
import com.mapbox.maps.CameraOptions
99
import com.mapbox.maps.MapboxMap
1010
import com.mapbox.maps.Style
11-
import com.mapbox.maps.extension.style.layers.CustomLayer
12-
import com.mapbox.maps.extension.style.layers.addLayerBelow
11+
import com.mapbox.maps.extension.style.layers.addLayer
1312
import com.mapbox.maps.extension.style.layers.customLayer
1413
import com.mapbox.maps.extension.style.layers.properties.generated.ProjectionName
1514
import com.mapbox.maps.extension.style.projection.generated.projection
@@ -45,9 +44,10 @@ class TriangleCustomLayerActivity : AppCompatActivity() {
4544
}
4645

4746
private fun addCustomLayer(style: Style) {
48-
style.addLayerBelow(
49-
CustomLayer(CUSTOM_LAYER_ID, TriangleCustomLayer()),
50-
below = "building"
47+
style.addLayer(
48+
customLayer(CUSTOM_LAYER_ID, TriangleCustomLayer()) {
49+
slot("middle")
50+
}
5151
)
5252
binding.fab.setImageResource(R.drawable.ic_layers_clear)
5353
}

0 commit comments

Comments
 (0)