jsMain.io.data2viz.geojson.toGeoJsonObject.kt Maven / Gradle / Ivy
package io.data2viz.geojson
import io.data2viz.geojson.js.Typed
import io.data2viz.geojson.js.asGeoJsonObject
/**
* Parse the String as a GeoJsonObject
*/
actual fun String.toGeoJsonObject(): GeoJsonObject = JSON.parse(this).asGeoJsonObject()
actual class FeatureProperties {
var properties: dynamic = null
actual fun stringProperty(name: String): String = properties[name] as String
actual fun intProperty(name: String): Int = properties[name] as Int
actual fun booleanProperty(name: String): Boolean = properties[name] as Boolean
}
actual fun String.toFeaturesAndProperties(extractFunction: FeatureProperties.() -> T): List> {
val features = JSON.parse(this).asGeoJsonObject() as FeatureCollection
val properties = FeatureProperties()
return features.features.map { feature ->
properties.properties = feature.properties
Pair(feature, extractFunction(properties))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy