Skip to content

Commit 868960e

Browse files
committed
Use new map layer background task for tile layers
Signed-off-by: Kyle Corry <[email protected]>
1 parent 20f874e commit 868960e

File tree

1 file changed

+13
-5
lines changed
  • app/src/main/java/com/kylecorry/trail_sense/shared/map_layers/ui/layers

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import android.graphics.Color
55
import android.graphics.Paint
66
import com.kylecorry.andromeda.canvas.ICanvasDrawer
77
import com.kylecorry.andromeda.core.units.PixelCoordinate
8+
import com.kylecorry.sol.math.geometry.Rectangle
9+
import com.kylecorry.sol.science.geology.CoordinateBounds
810
import com.kylecorry.trail_sense.main.errors.SafeMode
9-
import com.kylecorry.trail_sense.shared.map_layers.MapLayerBackgroundTask
11+
import com.kylecorry.trail_sense.shared.getBounds
12+
import com.kylecorry.trail_sense.shared.map_layers.MapLayerBackgroundTask2
1013
import com.kylecorry.trail_sense.shared.map_layers.tiles.ITileSourceSelector
1114
import com.kylecorry.trail_sense.shared.map_layers.tiles.TileLoader
1215
import kotlinx.coroutines.CancellationException
1316

1417
abstract class TileMapLayer<T : ITileSourceSelector>(
1518
protected val source: T,
16-
private val taskRunner: MapLayerBackgroundTask = MapLayerBackgroundTask(),
19+
private val taskRunner: MapLayerBackgroundTask2 = MapLayerBackgroundTask2(),
1720
private val minZoomLevel: Int? = null
1821
) : IAsyncLayer {
1922

@@ -34,13 +37,13 @@ abstract class TileMapLayer<T : ITileSourceSelector>(
3437

3538
init {
3639
// Load tiles if needed
37-
taskRunner.addTask { bounds, metersPerPixel ->
40+
taskRunner.addTask { viewBounds: Rectangle, bounds: CoordinateBounds, projection: IMapViewProjection ->
3841
shouldReloadTiles = false
3942
try {
4043
loader.loadTiles(
4144
source,
4245
bounds,
43-
metersPerPixel,
46+
projection.metersPerPixel,
4447
minZoomLevel ?: 0,
4548
backgroundColor,
4649
controlsPdfCache
@@ -64,7 +67,12 @@ abstract class TileMapLayer<T : ITileSourceSelector>(
6467
}
6568

6669
// Load tiles if needed
67-
taskRunner.scheduleUpdate(map.mapBounds, map.metersPerPixel, shouldReloadTiles)
70+
taskRunner.scheduleUpdate(
71+
drawer.getBounds(45f), // TODO: Cache this
72+
map.mapBounds,
73+
map.mapProjection,
74+
shouldReloadTiles
75+
)
6876

6977
// Render loaded tiles
7078
synchronized(loader.lock) {

0 commit comments

Comments
 (0)