In our application we need to show different KML layers on the map, when user selects different zones.
I invoke removeLayerFromMap for previous KmlLayer instance and addLayerToMap for new KmlLayer. After removeLayerFromMap previous KmlLayer is removed correctly, but the new one is not drawn. Also I tried to clear GoogleMap instance before addLayerToMap, but it does not help either.
To draw another KmlLayer I need to call mapView.getMapAsync(onMapReadyCallback) to receive new GoogleMap instance, which is not efficient.
Here my code:
kmlLayer?.removeLayerFromMap() // remove previous layer
googleMap?.clear() // remove everything from the map to be sure
kmlDisposable?.dispose()
kmlDisposable = Single
.fromCallable {
// create new layer in background
val charset = when {
kml.contains("utf-16") -> Charsets.UTF_16
else -> Charsets.UTF_8
}
KmlLayer(
map,
ByteArrayInputStream(kml.toByteArray(charset)),
context,
markerManager,
polygonManager,
polylineManager,
groundOverlayManager,
null
)
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
kmlLayer = it
kmlLayer?.setOnFeatureClickListener { onMapClick?.invoke() }
kmlLayer?.addLayerToMap() // add new layer on the map
},
{ log.error(it.message, it) }
)
In v0.5 version different KmlLayers can be drawn on single GoogleMap instance multiple times. Do I miss something in my implementation? Can you investigate the issue?
@arriolac Hello,
Do you need additional information about the issue? Looking forward to receive updates.
Hi @TatyanaRTB, you should be able to draw multiple KML layers on the map. The MultiLayerDemoActivity does just that.
Might there be a code path that invokes removeLayerFromMap several times?
@arriolac Ok, I found the issue in my code, sorry.
Actually KML drawing is really improved in v1.0.0.
We receive KMLs from server and on previous v0.5 version KML layers with multiple polygons in single Placemark were not drawn on Google Maps in Android (we had to split such Placemarks on the app side to draw it on the map). KML layers were correct - iOS maps and each browser drew KMLs without problems, it was a problem only for Android. But with v1.0.0 KMLs are drawn on the map without additional workaround on the application side.
Thank you!
Most helpful comment
@arriolac Ok, I found the issue in my code, sorry.
Actually KML drawing is really improved in v1.0.0.
We receive KMLs from server and on previous v0.5 version KML layers with multiple polygons in single Placemark were not drawn on Google Maps in Android (we had to split such Placemarks on the app side to draw it on the map). KML layers were correct - iOS maps and each browser drew KMLs without problems, it was a problem only for Android. But with v1.0.0 KMLs are drawn on the map without additional workaround on the application side.
Thank you!