-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
- Loading branch information
There are no files selected for viewing
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.