Skip to content

Commit 2b14828

Browse files
jushgithub-actions[bot]
authored andcommitted
Expose async variants of the style layer property setters (#6273)
Added new methods to `MapboxStyleManager` to expose async variants of the style layer property setters. GitOrigin-RevId: 29d0937248a6dd7e4a25a462fd33fc50b2429dd1
1 parent 923c2fe commit 2b14828

File tree

5 files changed

+93
-6
lines changed

5 files changed

+93
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Mapbox welcomes participation and contributions from everyone.
77
# main
88
## Features ✨ and improvements 🏁
99
* Expose `LineLayer.lineCutoutOpacity` and `LineLayer.lineCutoutWidth` to make route lines visible through obstructing 3D buildings and other aboveground features.
10+
* Expose experimental `MapboxMap.setStyleLayerPropertiesAsync` and `MapboxMap.setStyleLayerPropertyAsync` (also available through `Style`) to allow setting properties from a any thread and asynchronously.
1011

1112
## Bug fixes 🐞
1213
* MapboxTracing was deprecated and moved to package com.mapbox.common.

maps-sdk/api/Release/metalava.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,12 @@ package com.mapbox.maps {
395395
public final class MapboxMapsOptionsKt {
396396
}
397397

398-
public final class MapboxTracing {
399-
method public void disableAll();
400-
method public void enableAll();
401-
method public void enableCore();
402-
method public void enablePlatform();
403-
field public static final com.mapbox.maps.MapboxTracing INSTANCE;
398+
@Deprecated public final class MapboxTracing {
399+
method @Deprecated public void disableAll();
400+
method @Deprecated public void enableAll();
401+
method @Deprecated public void enableCore();
402+
method @Deprecated public void enablePlatform();
403+
field @Deprecated public static final com.mapbox.maps.MapboxTracing INSTANCE;
404404
}
405405

406406
public abstract class SnapshotOverlay {

sdk-base/api/Release/metalava.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ package com.mapbox.maps {
224224
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleImportConfigProperties(String importId, java.util.HashMap<java.lang.String,com.mapbox.bindgen.Value> configs);
225225
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleImportConfigProperty(String importId, String config, com.mapbox.bindgen.Value value);
226226
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleLayerProperties(String layerId, com.mapbox.bindgen.Value properties);
227+
method @AnyThread @CallSuper @com.mapbox.maps.MapboxExperimental public com.mapbox.common.Cancelable setStyleLayerPropertiesAsync(String layerId, com.mapbox.bindgen.Value properties, com.mapbox.maps.AsyncOperationResultCallback callback);
227228
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleLayerProperty(String layerId, String property, com.mapbox.bindgen.Value value);
229+
method @AnyThread @CallSuper @com.mapbox.maps.MapboxExperimental public com.mapbox.common.Cancelable setStyleLayerPropertyAsync(String layerId, String property, com.mapbox.bindgen.Value value, com.mapbox.maps.AsyncOperationResultCallback callback);
228230
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleLightProperty(String id, String property, com.mapbox.bindgen.Value value);
229231
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleLights(com.mapbox.bindgen.Value lights);
230232
method @CallSuper @MainThread public com.mapbox.bindgen.Expected<java.lang.String,com.mapbox.bindgen.None> setStyleProjection(com.mapbox.bindgen.Value properties);

sdk-base/api/sdk-base.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ public class com/mapbox/maps/MapboxStyleManager {
248248
public fun setStyleImportConfigProperties (Ljava/lang/String;Ljava/util/HashMap;)Lcom/mapbox/bindgen/Expected;
249249
public fun setStyleImportConfigProperty (Ljava/lang/String;Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
250250
public fun setStyleLayerProperties (Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
251+
public fun setStyleLayerPropertiesAsync (Ljava/lang/String;Lcom/mapbox/bindgen/Value;Lcom/mapbox/maps/AsyncOperationResultCallback;)Lcom/mapbox/common/Cancelable;
251252
public fun setStyleLayerProperty (Ljava/lang/String;Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
253+
public fun setStyleLayerPropertyAsync (Ljava/lang/String;Ljava/lang/String;Lcom/mapbox/bindgen/Value;Lcom/mapbox/maps/AsyncOperationResultCallback;)Lcom/mapbox/common/Cancelable;
252254
public fun setStyleLightProperty (Ljava/lang/String;Ljava/lang/String;Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
253255
public fun setStyleLights (Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;
254256
public fun setStyleProjection (Lcom/mapbox/bindgen/Value;)Lcom/mapbox/bindgen/Expected;

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.annotation.RestrictTo
88
import com.mapbox.bindgen.Expected
99
import com.mapbox.bindgen.None
1010
import com.mapbox.bindgen.Value
11+
import com.mapbox.common.Cancelable
1112
import com.mapbox.geojson.Feature
1213

1314
/**
@@ -580,6 +581,45 @@ open class MapboxStyleManager @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
580581
return styleManager.setStyleLayerProperty(layerId, property, value)
581582
}
582583

584+
/**
585+
* Sets a value to a style layer property asynchronously.
586+
*
587+
* This method provides asynchronous argument parsing which is beneficial when working with
588+
* large or complex style expressions that could block the main thread during parsing.
589+
* The operation is performed on a background thread and the callback is invoked on the
590+
* main thread once the operation completes.
591+
*
592+
* Values will be applied asynchronously at some moment in the future. If multiple calls
593+
* to this method are made, the corresponding values will be applied in the same order
594+
* as the calls were made.
595+
*
596+
* Note: This method should be used only if the given argument is a massive expression
597+
* and its parsing would block the main thread otherwise. For simple property values,
598+
* prefer the synchronous [setStyleLayerProperty] method.
599+
*
600+
* If the style is modified during this asynchronous method call, the scheduled layer
601+
* property change will still be applied as long as a layer with the original name and
602+
* type still exists.
603+
*
604+
* @param layerId A style layer identifier.
605+
* @param property The style layer property name.
606+
* @param value The style layer property value.
607+
* @param callback Called once the request is complete or an error occurred.
608+
*
609+
* @return A [Cancelable] object that can be used to cancel the asynchronous operation.
610+
*/
611+
@MapboxExperimental
612+
@CallSuper
613+
@AnyThread
614+
open fun setStyleLayerPropertyAsync(
615+
layerId: String,
616+
property: String,
617+
value: Value,
618+
callback: AsyncOperationResultCallback
619+
): Cancelable {
620+
return styleManager.setStyleLayerPropertyAsync(layerId, property, value, callback)
621+
}
622+
583623
/**
584624
* Gets style layer properties.
585625
*
@@ -610,6 +650,48 @@ open class MapboxStyleManager @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
610650
return styleManager.setStyleLayerProperties(layerId, properties)
611651
}
612652

653+
/**
654+
* Experimental. Sets style layer properties asynchronously.
655+
*
656+
* This method can be used to perform batch update for a style layer properties with asynchronous
657+
* argument parsing which is beneficial when working with large or complex style expressions that
658+
* could block the main thread during parsing. The operation is performed on a background thread
659+
* and the callback is invoked on the main thread once the operation completes.
660+
*
661+
* Properties will be applied asynchronously at some moment in the future. If multiple calls
662+
* to this method are made, the corresponding properties will be applied in the same order
663+
* as the calls were made.
664+
*
665+
* Note: This method should be used only if the given arguments contain massive expressions
666+
* and their parsing would block the main thread otherwise. For simple property values,
667+
* prefer the synchronous [setStyleLayerProperties] method.
668+
*
669+
* The structure of the provided [properties] value must conform to a format for a corresponding
670+
* [layer type](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/).
671+
* Modification of a layer [id](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#id) and/or
672+
* a [layer type](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#type) is not allowed.
673+
*
674+
* If the style is modified during this asynchronous method call, the scheduled layer
675+
* properties change will still be applied as long as a layer with the original name and
676+
* type still exists.
677+
*
678+
* @param layerId A style layer identifier.
679+
* @param properties A map of style layer properties.
680+
* @param callback Called once the request is complete or an error occurred.
681+
*
682+
* @return A [Cancelable] object that can be used to cancel the asynchronous operation.
683+
*/
684+
@CallSuper
685+
@AnyThread
686+
@MapboxExperimental
687+
open fun setStyleLayerPropertiesAsync(
688+
layerId: String,
689+
properties: Value,
690+
callback: AsyncOperationResultCallback
691+
): Cancelable {
692+
return styleManager.setStyleLayerPropertiesAsync(layerId, properties, callback)
693+
}
694+
613695
/**
614696
* Adds a new [style source](https://docs.mapbox.com/mapbox-gl-js/style-spec/#sources).
615697
* Note: When adding a geojson source, this method does not synchronously parse the GeoJSON data.

0 commit comments

Comments
 (0)