Skip to content

Commit

Permalink
Bump gl-native to v10.0.0-rc.2, introduce addPersistentLayer/isPersis…
Browse files Browse the repository at this point in the history
…tentLayer API.
  • Loading branch information
pengdev committed Jun 14, 2021
1 parent 2b4980e commit be6c59e
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
19 changes: 19 additions & 0 deletions sdk/src/main/java/com/mapbox/maps/NativeMapImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, None> {
return map.addPersistentStyleLayer(properties, layerPosition)
}

override fun addPersistentStyleCustomLayer(
layerId: String,
layerHost: CustomLayerHost,
layerPosition: LayerPosition?
): Expected<String, None> {
return map.addPersistentStyleCustomLayer(layerId, layerHost, layerPosition)
}

override fun isStyleLayerPersistent(layerId: String): Expected<String, Boolean> {
return map.isStyleLayerPersistent(layerId)
}

override fun getResourceOptions(): ResourceOptions {
return map.resourceOptions
}
Expand Down
75 changes: 75 additions & 0 deletions sdk/src/main/java/com/mapbox/maps/Style.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, None> {
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<String, None> {
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<String, Boolean> {
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()
*
Expand Down
25 changes: 25 additions & 0 deletions sdk/src/test/java/com/mapbox/maps/NativeMapTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ class NativeMapTest {
verify { map.addStyleCustomLayer("foobar", value, layerPosition) }
}

@Test
fun addPersistentStyleLayer() {
val value = mockk<Value>()
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<CustomLayerHost>()
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)
Expand Down
22 changes: 22 additions & 0 deletions sdk/src/test/java/com/mapbox/maps/StyleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,28 @@ class StyleTest {
verify { nativeMap.invalidateStyleCustomGeometrySourceTile("id", tileId) }
}

@Test
fun addPersistentStyleLayer() {
val value = mockk<Value>()
val position = mockk<LayerPosition>()
style.addPersistentStyleLayer(value, position)
verify { nativeMap.addPersistentStyleLayer(value, position) }
}

@Test
fun addPersistentStyleCustomLayer() {
val layerHost = mockk<CustomLayerHost>()
val layerPosition = mockk<LayerPosition>()
style.addPersistentStyleCustomLayer("id", layerHost, layerPosition)
verify { nativeMap.addPersistentStyleCustomLayer("id", layerHost, layerPosition) }
}

@Test
fun isStyleLayerPersistent() {
style.isStyleLayerPersistent("id")
verify { nativeMap.isStyleLayerPersistent("id") }
}

@Test
fun setJson() {
style.styleJSON = "foobar"
Expand Down

0 comments on commit be6c59e

Please sign in to comment.