Skip to content

Commit fcebebe

Browse files
lyydikoigithub-actions[bot]
authored andcommitted
Add setStyleSourceProperty overload with importId parameter (#8205)
Adds a new overloaded `setStyleSourceProperty` method to `MapboxStyleManager` that supports modifying source properties within imported styles. ### Changes - Added new `setStyleSourceProperty(importId, sourceId, property, value)` method - Annotated with `@MapboxExperimental` as this wraps experimental functionality - Maintains thread safety with `@MainThread` and `ThreadChecker` validation - Falls back to root style when `importId` is empty This PR is a hotfix for [this issue](https://mapbox.slack.com/archives/C08UBP5UMPB/p1763547109463079) and exceptionally merging to release/v0.17 as it needs to be included ASAP to v0.17-rc.1 release. A separate PR will be crated to merge to main branch. cc @mapbox/maps-android GitOrigin-RevId: c2fa32554cae55b0ffde9a96478eefdd4fdafcfc
1 parent 08af3bf commit fcebebe

File tree

8 files changed

+81
-0
lines changed

8 files changed

+81
-0
lines changed

maps-sdk/api/maps-sdk.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ public final class com/mapbox/maps/Style : com/mapbox/maps/MapboxStyleManager {
559559
public fun setStyleProjectionProperty (Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
560560
public fun setStyleSourceProperties (Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
561561
public fun setStyleSourceProperty (Ljava/lang/String;Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
562+
public fun setStyleSourceProperty (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
562563
public fun setStyleTerrain (Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
563564
public fun setStyleTerrainProperty (Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
564565
public fun setStyleTransition (Lcom/mapbox/maps/TransitionOptions;)V

maps-sdk/src/main/java/com/mapbox/maps/NativeMapImpl.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,17 @@ internal class NativeMapImpl(val map: Map) {
615615
return map.setStyleSourceProperty(sourceId, property, value)
616616
}
617617

618+
@MapboxExperimental
619+
@OptIn(com.mapbox.annotation.MapboxExperimental::class)
620+
fun setStyleSourceProperty(
621+
importId: String,
622+
sourceId: String,
623+
property: String,
624+
value: Value
625+
): Expected<String, None> {
626+
return map.setStyleSourceProperty(importId, sourceId, property, value)
627+
}
628+
618629
fun coordinateBoundsZoomForCamera(camera: CameraOptions): CoordinateBoundsZoom {
619630
return map.coordinateBoundsZoomForCamera(camera)
620631
}

maps-sdk/src/main/java/com/mapbox/maps/Style.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,32 @@ class Style internal constructor(
101101
return super.setStyleSourceProperty(sourceId, property, value)
102102
}
103103

104+
/**
105+
* Sets a value to a style source property for a source that belongs to a specific style import.
106+
*
107+
* This method allows modification of source properties within imported styles, enabling
108+
* fine-grained control over sources from different style fragments or imports.
109+
* If `importId` is empty, this method falls back to updating the root style.
110+
*
111+
* @param importId An identifier of the style import containing the target source.
112+
* @param sourceId A style source identifier.
113+
* @param property The style source property name.
114+
* @param value The style source property value.
115+
*
116+
* @return A string describing an error if the operation was not successful, empty otherwise.
117+
*/
118+
@MapboxExperimental
119+
@MainThread
120+
override fun setStyleSourceProperty(
121+
importId: String,
122+
sourceId: String,
123+
property: String,
124+
value: Value
125+
): Expected<String, None> {
126+
checkNativeStyle("setStyleSourceProperty")
127+
return super.setStyleSourceProperty(importId, sourceId, property, value)
128+
}
129+
104130
/**
105131
* Returns the map style's transition options. By default, the style parser will attempt
106132
* to read the style default transition options, if any, fallbacking to an immediate transition

maps-sdk/src/test/java/com/mapbox/maps/NativeMapTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ class NativeMapTest {
277277
verify { map.setStyleSourceProperty("foo", "bar", value) }
278278
}
279279

280+
@Test
281+
fun setStyleSourcePropertyWithImportId() {
282+
val value = mockk<Value>()
283+
val nativeMap = NativeMapImpl(map)
284+
nativeMap.setStyleSourceProperty("importId", "foo", "bar", value)
285+
verify { map.setStyleSourceProperty("importId", "foo", "bar", value) }
286+
}
287+
280288
@Test
281289
fun getStyleSourceProperties() {
282290
val nativeMap = NativeMapImpl(map)

maps-sdk/src/test/java/com/mapbox/maps/StyleTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ class StyleTest {
270270
verify { styleManager.setStyleSourceProperty("id", "foobar", value) }
271271
}
272272

273+
@Test
274+
fun setSourcePropertyWithImportId() {
275+
val value = mockk<Value>()
276+
style.setStyleSourceProperty("importId", "id", "foobar", value)
277+
verify { styleManager.setStyleSourceProperty("importId", "id", "foobar", value) }
278+
}
273279
@Test
274280
fun getSourceProperty() {
275281
style.getStyleSourceProperty("id", "foobar")

sdk-base/api/Release/metalava.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ package com.mapbox.maps {
237237
method @CallSuper @MainThread @com.mapbox.maps.MapboxExperimental public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleSnowProperty(String property, com.mapbox.bindgen.Value value);
238238
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleSourceProperties(String sourceId, com.mapbox.bindgen.Value properties);
239239
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleSourceProperty(String sourceId, String property, com.mapbox.bindgen.Value value);
240+
method @CallSuper @MainThread @com.mapbox.maps.MapboxExperimental public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleSourceProperty(String importId, String sourceId, String property, com.mapbox.bindgen.Value value);
240241
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleTerrain(com.mapbox.bindgen.Value properties);
241242
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleTerrainProperty(String property, com.mapbox.bindgen.Value value);
242243
method @CallSuper @MainThread public void setStyleTransition(com.mapbox.maps.TransitionOptions transitionOptions);

sdk-base/api/sdk-base.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ public class com/mapbox/maps/MapboxStyleManager {
261261
public fun setStyleSnowProperty (Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
262262
public fun setStyleSourceProperties (Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
263263
public fun setStyleSourceProperty (Ljava/lang/String;Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
264+
public fun setStyleSourceProperty (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
264265
public fun setStyleTerrain (Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
265266
public fun setStyleTerrainProperty (Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
266267
public fun setStyleTransition (Lcom/mapbox/maps/TransitionOptions;)V

sdk-base/src/main/java/com/mapbox/maps/MapboxStyleManager.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,33 @@ open class MapboxStyleManager @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
747747
return styleManager.setStyleSourceProperty(sourceId, property, value)
748748
}
749749

750+
/**
751+
* Sets a value to a style source property for a source that belongs to a specific style import.
752+
*
753+
* This method allows modification of source properties within imported styles, enabling
754+
* fine-grained control over sources from different style fragments or imports.
755+
* If `importId` is empty, this method falls back to updating the root style.
756+
*
757+
* @param importId An identifier of the style import containing the target source.
758+
* @param sourceId A style source identifier.
759+
* @param property The style source property name.
760+
* @param value The style source property value.
761+
*
762+
* @return A string describing an error if the operation was not successful, empty otherwise.
763+
*/
764+
@MapboxExperimental
765+
@CallSuper
766+
@MainThread
767+
open fun setStyleSourceProperty(
768+
importId: String,
769+
sourceId: String,
770+
property: String,
771+
value: Value
772+
): Expected<String, None> {
773+
ThreadChecker.throwIfNotMainThread()
774+
return styleManager.setStyleSourceProperty(importId, sourceId, property, value)
775+
}
776+
750777
/**
751778
* Gets style source properties.
752779
*

0 commit comments

Comments
 (0)