Skip to content

Commit

Permalink
add support for promoteId
Browse files Browse the repository at this point in the history
  • Loading branch information
ank27 committed Sep 14, 2021
1 parent c5c0ba5 commit 343c68f
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.mapbox.maps.extension.style.types

import androidx.annotation.Keep
import com.mapbox.bindgen.Value
import com.mapbox.maps.extension.style.sources.generated.GeoJsonSource
import com.mapbox.maps.extension.style.sources.generated.VectorSource

/**
* Holds a property type to promote a specific feature for feature state API.
*
* @param sourceId source layer id of the feature, either source [GeoJsonSource] or [VectorSource].
* @param propertyName feature property name.
*
* For more information see [The online documentation]https://docs.mapbox.com/mapbox-gl-js/style-spec/types/#promoteId).
*/
@Keep
data class PromoteId @JvmOverloads constructor(
val sourceId: String? = null,
val propertyName: String
) {
internal fun toValue(): Value {
sourceId?.let {
return Value(hashMapOf(sourceId to Value(propertyName)))
}
return Value(propertyName)
}

companion object {
/**
* Construct a [PromoteId] object from a Property returned from the core.
* Can be either of type [String] or [HashMap] of <String,String>
*/
fun fromProperty(propertyName: Any): PromoteId {
return when (propertyName) {
is String -> {
PromoteId(propertyName = propertyName)
}
is HashMap<*, *> -> {
@Suppress("UNCHECKED_CAST")
val propertyMap = propertyName as HashMap<String, String>
val key = propertyMap.keys.iterator().next()
PromoteId(key, propertyMap[key] ?: "")
}
else -> throw RuntimeException("Wrapping \"${propertyName}\" to PromoteId is not supported.")
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 343c68f

Please sign in to comment.