From 5146be2b6b887a4ccaaa6f004b4d205760472996 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Mon, 14 Jun 2021 11:00:39 +0300 Subject: [PATCH] Bump gl-native to v10.0.0-rc.2, introduce addPersistentLayer/isPersistentLayer API. --- .../java/com/mapbox/maps/NativeMapImpl.kt | 19 +++++ sdk/src/main/java/com/mapbox/maps/Style.kt | 75 +++++++++++++++++++ .../java/com/mapbox/maps/NativeMapTest.kt | 25 +++++++ .../test/java/com/mapbox/maps/StyleTest.kt | 22 ++++++ 4 files changed, 141 insertions(+) diff --git a/sdk/src/main/java/com/mapbox/maps/NativeMapImpl.kt b/sdk/src/main/java/com/mapbox/maps/NativeMapImpl.kt index 072ea5ec73..c03e4247bc 100644 --- a/sdk/src/main/java/com/mapbox/maps/NativeMapImpl.kt +++ b/sdk/src/main/java/com/mapbox/maps/NativeMapImpl.kt @@ -223,6 +223,25 @@ internal class NativeMapImpl(private val map: MapInterface) : return map.addStyleCustomLayer(layerId, layerHost, layerPosition) } + override fun addPersistentStyleLayer( + properties: Value, + layerPosition: LayerPosition? + ): Expected { + return map.addPersistentStyleLayer(properties, layerPosition) + } + + override fun addPersistentStyleCustomLayer( + layerId: String, + layerHost: CustomLayerHost, + layerPosition: LayerPosition? + ): Expected { + return map.addPersistentStyleCustomLayer(layerId, layerHost, layerPosition) + } + + override fun isStyleLayerPersistent(layerId: String): Expected { + return map.isStyleLayerPersistent(layerId) + } + override fun getResourceOptions(): ResourceOptions { return map.resourceOptions } diff --git a/sdk/src/main/java/com/mapbox/maps/Style.kt b/sdk/src/main/java/com/mapbox/maps/Style.kt index 41f49ba29e..8e656ea7b8 100644 --- a/sdk/src/main/java/com/mapbox/maps/Style.kt +++ b/sdk/src/main/java/com/mapbox/maps/Style.kt @@ -613,6 +613,81 @@ class Style internal constructor( } } + /** + * Adds a new [style layer](https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers). + * + * Note: This is an experimental API and is a subject to change. + * + * Whenever a new style is being parsed and currently used style has persistent layers, + * an engine will try to do following: + * - keep the persistent layer at its relative position + * - keep the source used by a persistent layer + * - keep images added through `addStyleImage` method + * + * In cases when a new style has the same layer, source or image resource, style's resources would be + * used instead and `MapLoadingError` event will be emitted. + * + * @param properties A map of style layer properties. + * @param layerPosition If not empty, the new layer will be positioned according to `layer position` parameters. + * + * @return A string describing an error if the operation was not successful, or empty otherwise. + */ + @MapboxExperimental + override fun addPersistentStyleLayer( + properties: Value, + layerPosition: LayerPosition? + ): Expected { + return styleManagerRef.call { + this.addPersistentStyleLayer(properties, layerPosition) + } + } + + /** + * Adds a new [style custom layer](https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers). + * + * Note: This is an experimental API and is a subject to change. + * + * Whenever a new style is being parsed and currently used style has persistent layers, + * an engine will try to do following: + * - keep the persistent layer at its relative position + * - keep the source used by a persistent layer + * - keep images added through `addStyleImage` method + * + * In cases when a new style has the same layer, source or image resource, style's resources would be + * used instead and `MapLoadingError` event will be emitted. + * + * @param layerId A style layer identifier. + * @param layerHost The `custom layer host`. + * @param layerPosition If not empty, the new layer will be positioned according to `layer position` parameters. + * + * @return A string describing an error if the operation was not successful, or empty otherwise. + */ + @MapboxExperimental + override fun addPersistentStyleCustomLayer( + layerId: String, + layerHost: CustomLayerHost, + layerPosition: LayerPosition? + ): Expected { + return styleManagerRef.call { + this.addPersistentStyleCustomLayer(layerId, layerHost, layerPosition) + } + } + + /** + * Checks if a style layer is persistent. + * + * Note: This is an experimental API and is a subject to change. + * + * @param layerId A style layer identifier. + * @return A string describing an error if the operation was not successful, boolean representing state otherwise. + */ + @MapboxExperimental + override fun isStyleLayerPersistent(layerId: String): Expected { + return styleManagerRef.call { + this.isStyleLayerPersistent(layerId) + } + } + /** * Adds a custom geometry to be used in the style. To add the data, implement the fetchTileFunction callback in the options and call setStyleCustomGeometrySourceTileData() * diff --git a/sdk/src/test/java/com/mapbox/maps/NativeMapTest.kt b/sdk/src/test/java/com/mapbox/maps/NativeMapTest.kt index 869c028e77..654a0e1478 100644 --- a/sdk/src/test/java/com/mapbox/maps/NativeMapTest.kt +++ b/sdk/src/test/java/com/mapbox/maps/NativeMapTest.kt @@ -115,6 +115,31 @@ class NativeMapTest { verify { map.addStyleCustomLayer("foobar", value, layerPosition) } } + @Test + fun addPersistentStyleLayer() { + val value = mockk() + val layerPosition = LayerPosition(null, null, null) + val nativeMap = NativeMapImpl(map) + nativeMap.addPersistentStyleLayer(value, layerPosition) + verify { map.addPersistentStyleLayer(value, layerPosition) } + } + + @Test + fun addPersistentStyleCustomLayer() { + val value = mockk() + val layerPosition = LayerPosition(null, null, null) + val nativeMap = NativeMapImpl(map) + nativeMap.addPersistentStyleCustomLayer("foobar", value, layerPosition) + verify { map.addPersistentStyleCustomLayer("foobar", value, layerPosition) } + } + + @Test + fun isStyleLayerPersistent() { + val nativeMap = NativeMapImpl(map) + nativeMap.isStyleLayerPersistent("foobar") + verify { map.isStyleLayerPersistent("foobar") } + } + @Test fun removeStyleLayer() { val nativeMap = NativeMapImpl(map) diff --git a/sdk/src/test/java/com/mapbox/maps/StyleTest.kt b/sdk/src/test/java/com/mapbox/maps/StyleTest.kt index 6e672f59fb..65706e998a 100644 --- a/sdk/src/test/java/com/mapbox/maps/StyleTest.kt +++ b/sdk/src/test/java/com/mapbox/maps/StyleTest.kt @@ -246,6 +246,28 @@ class StyleTest { verify { nativeMap.invalidateStyleCustomGeometrySourceTile("id", tileId) } } + @Test + fun addPersistentStyleLayer() { + val value = mockk() + val position = mockk() + style.addPersistentStyleLayer(value, position) + verify { nativeMap.addPersistentStyleLayer(value, position) } + } + + @Test + fun addPersistentStyleCustomLayer() { + val layerHost = mockk() + val layerPosition = mockk() + style.addPersistentStyleCustomLayer("id", layerHost, layerPosition) + verify { nativeMap.addPersistentStyleCustomLayer("id", layerHost, layerPosition) } + } + + @Test + fun isStyleLayerPersistent() { + style.isStyleLayerPersistent("id") + verify { nativeMap.isStyleLayerPersistent("foobar") } + } + @Test fun setJson() { style.styleJSON = "foobar"