diff --git a/Readme.md b/Readme.md index bb4075a..83e2c94 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,4 @@ -[ ![Download](https://api.bintray.com/packages/peterlaurence/maven/mapview/images/download.svg?version=1.0.5) ](https://bintray.com/peterlaurence/maven/mapview/1.0.4/link) +[ ![Download](https://api.bintray.com/packages/peterlaurence/maven/mapview/images/download.svg?version=1.0.6) ](https://bintray.com/peterlaurence/maven/mapview/1.0.6/link) # MapView @@ -29,7 +29,7 @@ This project holds the source code of this library, plus a demo app (which is us Add this to your module's build.gradle ```groovy -implementation 'com.peterlaurence:mapview:1.0.5' +implementation 'com.peterlaurence:mapview:1.0.6' ``` ## Origin and motivation diff --git a/mapview/build.gradle b/mapview/build.gradle index d5d01cd..890d99b 100644 --- a/mapview/build.gradle +++ b/mapview/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlinx-serialization' -def version = "1.0.5" +def version = "1.0.6" androidExtensions { experimental = true diff --git a/mapview/src/main/java/com/peterlaurence/mapview/core/VisibleTilesResolver.kt b/mapview/src/main/java/com/peterlaurence/mapview/core/VisibleTilesResolver.kt index dee5451..0a74aec 100644 --- a/mapview/src/main/java/com/peterlaurence/mapview/core/VisibleTilesResolver.kt +++ b/mapview/src/main/java/com/peterlaurence/mapview/core/VisibleTilesResolver.kt @@ -79,8 +79,8 @@ class VisibleTilesResolver(private val levelCount: Int, private val fullWidth: I val relativeScale = scale / scaleAtLevel /* At the current level, row and col index have maximum values */ - val maxCol = (fullWidth * scaleAtLevel / tileSize).toInt() - val maxRow = (fullHeight * scaleAtLevel / tileSize).toInt() + val maxCol = max(0.0, ceil(fullWidth * scaleAtLevel.toDouble() / tileSize) - 1).toInt() + val maxRow = max(0.0, ceil(fullHeight * scaleAtLevel.toDouble() / tileSize) - 1).toInt() fun Int.lowerThan(limit: Int): Int { return if (this <= limit) this else limit diff --git a/mapview/src/main/java/com/peterlaurence/mapview/viewmodel/TileCanvasViewModel.kt b/mapview/src/main/java/com/peterlaurence/mapview/viewmodel/TileCanvasViewModel.kt index 10fafc9..7be4119 100644 --- a/mapview/src/main/java/com/peterlaurence/mapview/viewmodel/TileCanvasViewModel.kt +++ b/mapview/src/main/java/com/peterlaurence/mapview/viewmodel/TileCanvasViewModel.kt @@ -31,7 +31,7 @@ class TileCanvasViewModel(private val scope: CoroutineScope, tileSize: Int, /* Right before sending tiles to the view, reorder them so that tiles from current level are * above others */ tilesToRender.sortBy { - it.zoom == lastVisible.level + it.zoom == lastVisible.level && it.subSample == lastVisible.subSample } tilesToRenderLiveData.postValue(tilesToRender) } diff --git a/mapview/src/test/java/com/peterlaurence/mapview/core/VisibleTilesResolverTest.kt b/mapview/src/test/java/com/peterlaurence/mapview/core/VisibleTilesResolverTest.kt index f2fcc8b..a7ae06f 100644 --- a/mapview/src/test/java/com/peterlaurence/mapview/core/VisibleTilesResolverTest.kt +++ b/mapview/src/test/java/com/peterlaurence/mapview/core/VisibleTilesResolverTest.kt @@ -62,13 +62,22 @@ class VisibleTilesResolverTest { assertEquals(1, visibleTiles.rowBottom) resolver.setScale(0.5f) - viewport = Viewport(0, 0, 200, 300) + viewport = Viewport(0, 0, 512, 512) visibleTiles = resolver.getVisibleTiles(viewport) assertEquals(1, visibleTiles.level) assertEquals(0, visibleTiles.colLeft) assertEquals(0, visibleTiles.rowTop) - assertEquals(0, visibleTiles.colRight) + assertEquals(1, visibleTiles.colRight) assertEquals(1, visibleTiles.rowBottom) + + val resolver2 = VisibleTilesResolver(5, 8192, 8192) + val viewport2 = Viewport(0, 0,8192, 8192) + visibleTiles = resolver2.getVisibleTiles(viewport2) + assertEquals(4, visibleTiles.level) + assertEquals(0, visibleTiles.colLeft) + assertEquals(0, visibleTiles.rowTop) + assertEquals(31, visibleTiles.colRight) + assertEquals(31, visibleTiles.rowBottom) } @Test