Skip to content

Commit 2b78c19

Browse files
committed
Fix basemap loading
Signed-off-by: Kyle Corry <[email protected]>
1 parent b98138f commit 2b78c19

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

app/src/main/java/com/kylecorry/trail_sense/shared/map_layers/ui/layers/tiles/TileMapLayer.kt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,19 @@ abstract class TileMapLayer<T : ITileSourceSelector>(
4545
shouldReloadTiles = true
4646
}
4747

48-
init {
48+
override fun draw(drawer: ICanvasDrawer, map: IMapView) {
49+
// Avoid drawing while in safe mode
50+
if (SafeMode.isEnabled()) {
51+
return
52+
}
53+
4954
// Load tiles if needed
50-
taskRunner.addTask { viewBounds: Rectangle, bounds: CoordinateBounds, projection: IMapViewProjection ->
55+
taskRunner.scheduleUpdate(
56+
drawer.getBounds(45f), // TODO: Cache this
57+
map.mapBounds,
58+
map.mapProjection,
59+
shouldReloadTiles
60+
){ viewBounds: Rectangle, bounds: CoordinateBounds, projection: IMapViewProjection ->
5161
shouldReloadTiles = false
5262
try {
5363
loader.loadTiles(
@@ -72,21 +82,6 @@ abstract class TileMapLayer<T : ITileSourceSelector>(
7282
shouldReloadTiles = true
7383
}
7484
}
75-
}
76-
77-
override fun draw(drawer: ICanvasDrawer, map: IMapView) {
78-
// Avoid drawing while in safe mode
79-
if (SafeMode.isEnabled()) {
80-
return
81-
}
82-
83-
// Load tiles if needed
84-
taskRunner.scheduleUpdate(
85-
drawer.getBounds(45f), // TODO: Cache this
86-
map.mapBounds,
87-
map.mapProjection,
88-
shouldReloadTiles
89-
)
9085

9186
// Render loaded tiles
9287
synchronized(loader.lock) {

app/src/main/java/com/kylecorry/trail_sense/tools/photo_maps/map_layers/PhotoMapTileSource.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,30 @@ import com.kylecorry.trail_sense.shared.map_layers.tiles.IGeographicImageRegionL
66
import com.kylecorry.trail_sense.shared.map_layers.tiles.ITileSourceSelector
77
import com.kylecorry.trail_sense.tools.photo_maps.infrastructure.MapRepo
88
import com.kylecorry.trail_sense.tools.photo_maps.infrastructure.tiles.PhotoMapTileSourceSelector
9+
import kotlinx.coroutines.sync.Mutex
10+
import kotlinx.coroutines.sync.withLock
911

1012
class PhotoMapTileSource : ITileSourceSelector {
1113

1214
var loadPdfs = true
1315
private var lastLoadPdfs = loadPdfs
1416
private var internalSelector: ITileSourceSelector? = null
17+
private val lock = Mutex()
1518

1619
override suspend fun getRegionLoaders(bounds: CoordinateBounds): List<IGeographicImageRegionLoader> {
17-
if (internalSelector == null || loadPdfs != lastLoadPdfs) {
18-
val repo = AppServiceRegistry.get<MapRepo>()
19-
internalSelector = PhotoMapTileSourceSelector(
20-
AppServiceRegistry.get(),
21-
repo.getAllMaps().filter { it.visible },
22-
8,
23-
loadPdfs
24-
)
25-
lastLoadPdfs = loadPdfs
20+
val selector = lock.withLock {
21+
if (internalSelector == null || loadPdfs != lastLoadPdfs) {
22+
val repo = AppServiceRegistry.get<MapRepo>()
23+
internalSelector = PhotoMapTileSourceSelector(
24+
AppServiceRegistry.get(),
25+
repo.getAllMaps().filter { it.visible },
26+
8,
27+
loadPdfs
28+
)
29+
lastLoadPdfs = loadPdfs
30+
}
31+
internalSelector
2632
}
27-
return internalSelector?.getRegionLoaders(bounds) ?: emptyList()
33+
return selector?.getRegionLoaders(bounds) ?: emptyList()
2834
}
2935
}

0 commit comments

Comments
 (0)