googlemaps / googlemaps/android-maps-compose

Adding support for KmlLayer without relying on MapEffect

Open
#447 2 comments 9 reactions 0 assignees View on GitHub
priority: p2 type: feature request
Dominant language
Kotlin
Stars
1.3k
Forks
181
Avg merge
2d 23h
Merged PRs (30d)
18

Description

As developer I would like to be able to add different layers (Kml, GeoJson, etc) to the GoogleMap composable.

A KmlLayer needs a GoogleMap instance to be built. `KmlLayer(GoogleMap map, int resourceId, Context context)`
At the moment the only way to add a Kml layer is using the experimental `MapEffect` (which it may get removed in the future).

Loading a KmlLayer is also slow so it needs to be done in a background thread.

Considering all of the above I came up with a solution but it would be nice to have a different way to do it.
This solution will not work anymore if MapEffect is removed.

```
val scope = rememberCoroutineScope()
val context = LocalContext.current
val aKmlLayer: KmlLayer? = null
GoogleMap(
...
) {
MapEffect { gMap ->
scope.launch {
withContext(Dispatchers.IO) {
aKmlLayer = KmlLayer(gMap, R.raw.kml_file, context)
withContext(Dispatchers.Main) {
aKmlLayer?.addLayerToMap()
}
}
}
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.