Hi,
Is there an equivalent Kotlin SDK sample app to the Java SDK:
add_custom_dynamic_entity_data_source
Solved! Go to Solution.
Hey @LeighWoolley,
The Add custom dynamic entity data source Kotlin sample is planned for the next SDK release, although the implementation should be fairly similar to Java. The API is supported in the Kotlin ArcGIS Maps SDK in version 200.2.0: API ref
Configure the custom data source:
val dataSource = CustomDynamicEntityDataSource(
FlowBuilderProvider(lifecycleScope, observationsFile)
)
private class FlowBuilderProvider(
scope: CoroutineScope,
val observationsFile: File
) : CustomDynamicEntityDataSource.EntityFeedProvider {
private val _feed: Flow<CustomDynamicEntityDataSource.FeedEvent> = flow {
// set up the bufferedReader on the observationsFile
// for each line of the file retrieve the geometry, field name and value for the observation
emit(
CustomDynamicEntityDataSource.FeedEvent.NewObservation(
geometry,
mapOf(trackIdField to trackIdValue)
)
)
}
override val feed: SharedFlow<CustomDynamicEntityDataSource.FeedEvent> =
_feed.flowOn(Dispatchers.IO).shareIn(scope, SharingStarted.WhileSubscribed())
override suspend fun onLoad(): DynamicEntityDataSourceInfo {
return DynamicEntityDataSourceInfo(
entityIdFieldName = trackIdField,
fields = listOf(Field(FieldType.Int64, trackIdField, trackIdField))
).apply { spatialReference = SpatialReference.wgs84() }
}
override suspend fun onConnect() {}
override suspend fun onDisconnect() {}
}
Configure the map view:
val layer = DynamicEntityLayer(dataSource).apply {
trackDisplayProperties.showPreviousObservations = false
trackDisplayProperties.showTrackLine = true
trackDisplayProperties.maximumObservations = 40
}
operationalLayers.add(layer)
Hey @LeighWoolley,
The Add custom dynamic entity data source Kotlin sample is planned for the next SDK release, although the implementation should be fairly similar to Java. The API is supported in the Kotlin ArcGIS Maps SDK in version 200.2.0: API ref
Configure the custom data source:
val dataSource = CustomDynamicEntityDataSource(
FlowBuilderProvider(lifecycleScope, observationsFile)
)
private class FlowBuilderProvider(
scope: CoroutineScope,
val observationsFile: File
) : CustomDynamicEntityDataSource.EntityFeedProvider {
private val _feed: Flow<CustomDynamicEntityDataSource.FeedEvent> = flow {
// set up the bufferedReader on the observationsFile
// for each line of the file retrieve the geometry, field name and value for the observation
emit(
CustomDynamicEntityDataSource.FeedEvent.NewObservation(
geometry,
mapOf(trackIdField to trackIdValue)
)
)
}
override val feed: SharedFlow<CustomDynamicEntityDataSource.FeedEvent> =
_feed.flowOn(Dispatchers.IO).shareIn(scope, SharingStarted.WhileSubscribed())
override suspend fun onLoad(): DynamicEntityDataSourceInfo {
return DynamicEntityDataSourceInfo(
entityIdFieldName = trackIdField,
fields = listOf(Field(FieldType.Int64, trackIdField, trackIdField))
).apply { spatialReference = SpatialReference.wgs84() }
}
override suspend fun onConnect() {}
override suspend fun onDisconnect() {}
}
Configure the map view:
val layer = DynamicEntityLayer(dataSource).apply {
trackDisplayProperties.showPreviousObservations = false
trackDisplayProperties.showTrackLine = true
trackDisplayProperties.maximumObservations = 40
}
operationalLayers.add(layer)
Great, thank you,