refactor: manage overlays without clear() calls

pull/679/head
andrekir 2023-08-04 17:07:31 -03:00
rodzic d806b37078
commit fce97997d8
1 zmienionych plików z 5 dodań i 7 usunięć

Wyświetl plik

@ -435,7 +435,6 @@ fun MapView(model: UIViewModel = viewModel()) {
} }
fun drawOverlays() = map.apply { fun drawOverlays() = map.apply {
overlays.clear()
if (overlays.none { it is MapEventsOverlay }) { if (overlays.none { it is MapEventsOverlay }) {
overlays.add(0, MapEventsOverlay(mapEventsReceiver)) overlays.add(0, MapEventsOverlay(mapEventsReceiver))
} }
@ -445,9 +444,7 @@ fun MapView(model: UIViewModel = viewModel()) {
addCopyright() // Copyright is required for certain map sources addCopyright() // Copyright is required for certain map sources
createLatLongGrid(false) createLatLongGrid(false)
// overlays.filterIsInstance<MarkerWithLabel>().forEach { overlay -> overlays.removeAll(overlays.filterIsInstance<MarkerWithLabel>())
// overlayManager.remove(overlay)
// }
val nodeMarkers = onNodesChanged(nodes.values) val nodeMarkers = onNodesChanged(nodes.values)
val waypointMarkers = onWaypointChanged(waypoints.values) val waypointMarkers = onWaypointChanged(waypoints.values)
debug("Showing on map: ${nodeMarkers.size} nodes ${waypointMarkers.size} waypoints") debug("Showing on map: ${nodeMarkers.size} nodes ${waypointMarkers.size} waypoints")
@ -509,8 +506,9 @@ fun MapView(model: UIViewModel = viewModel()) {
overlayManager = CustomOverlayManager(TilesOverlay(tileProvider, context)) overlayManager = CustomOverlayManager(TilesOverlay(tileProvider, context))
setMultiTouchControls(false) setMultiTouchControls(false)
zoomLevelMax = tileProvider.tileSource.maximumZoomLevel.toDouble() zoomLevelMax = tileProvider.tileSource.maximumZoomLevel.toDouble()
} else overlays.filterIsInstance<Polygon>().forEach { overlay -> drawOverlays()
overlayManager.remove(overlay) } else {
overlays.removeAll(overlays.filterIsInstance<Polygon>())
} }
val zoomFactor = 1.3 // zoom difference between view and download area polygon val zoomFactor = 1.3 // zoom difference between view and download area polygon
controller.setZoom(zoomLevel - zoomFactor) controller.setZoom(zoomLevel - zoomFactor)
@ -521,7 +519,7 @@ fun MapView(model: UIViewModel = viewModel()) {
GeoPoint(it.latitude, it.longitude) GeoPoint(it.latitude, it.longitude)
} }
} }
overlayManager.add(polygon) overlays.add(polygon)
val tileCount: Int = CacheManager(this).possibleTilesInArea( val tileCount: Int = CacheManager(this).possibleTilesInArea(
downloadRegionBoundingBox, downloadRegionBoundingBox,
zoomLevelMin.toInt(), zoomLevelMin.toInt(),