@@ -5,15 +5,18 @@ import android.graphics.Color
55import android.graphics.Paint
66import com.kylecorry.andromeda.canvas.ICanvasDrawer
77import com.kylecorry.andromeda.core.units.PixelCoordinate
8+ import com.kylecorry.sol.math.geometry.Rectangle
9+ import com.kylecorry.sol.science.geology.CoordinateBounds
810import 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
1013import com.kylecorry.trail_sense.shared.map_layers.tiles.ITileSourceSelector
1114import com.kylecorry.trail_sense.shared.map_layers.tiles.TileLoader
1215import kotlinx.coroutines.CancellationException
1316
1417abstract 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