android-maps-compose icon indicating copy to clipboard operation
android-maps-compose copied to clipboard

Adding support for KmlLayer without relying on MapEffect

Open br00 opened this issue 2 years ago • 2 comments

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()
                }
            }
        }
    }
}

br00 avatar Oct 27 '23 13:10 br00

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:

This is an automated message, feel free to ignore.

wangela avatar Oct 27 '23 14:10 wangela

There is another issue of using MapEffect. It blocks the onClick functionality of polygon, polyline and circles. Anyone has any solution? @br00 man

AwaisKhan128 avatar Feb 16 '24 06:02 AwaisKhan128