Skip to content

Commit

Permalink
Fix minor issue on visible tile calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
p-lr committed Nov 16, 2019
1 parent 23da41e commit 26373c1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mapview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26373c1

Please sign in to comment.