Adding support for KmlLayer without relying on MapEffect
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()
}
}
}
}
}
If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.
@br00 Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:
- Check the issue tracker - bugs and feature requests for Google Maps Platform APIs and SDKs
- Open a support case - Get 1:1 support in Cloud Console.
- Discord - chat with other developers
- StackOverflow - use the
google-mapstag
This is an automated message, feel free to ignore.
There is another issue of using MapEffect. It blocks the onClick functionality of polygon, polyline and circles. Anyone has any solution? @br00 man