Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump gl-native to v10.0.0-rc.2, introduce addPersistentLayer/isPersistentLayer API. #422

Merged
merged 2 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object Versions {
const val mapboxGestures = "0.7.0"
const val mapboxJavaServices = "5.4.1"
const val mapboxBase = "0.5.0"
const val mapboxGlNative = "10.0.0-rc.1"
const val mapboxGlNative = "10.0.0-rc.2"
const val mapboxCommon = "14.0.1"
const val mapboxAndroidCore = "4.0.2"
const val mapboxAndroidTelemetry = "7.0.3"
Expand Down
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