Skip to content

Commit dbd30eb

Browse files
committed
Improve DEM tiles
Signed-off-by: Kyle Corry <[email protected]>
1 parent 69a515a commit dbd30eb

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

app/src/main/java/com/kylecorry/trail_sense/shared/dem/DEM.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ object DEM {
167167
Color.rgb(gray, gray, gray)
168168
}
169169
): Bitmap = onDefault {
170+
val expandBy = 1
170171
val grid = getElevationGrid(bounds, resolution)
171-
val height = grid.size
172-
val width = grid[0].size
172+
val width = grid[0].size - expandBy * 2
173+
val height = grid.size - expandBy * 2
173174
val pixels = IntArray(height * width)
174175

175176
try {
@@ -186,10 +187,10 @@ object DEM {
186187
}
187188
}
188189

189-
for (y in grid.indices) {
190-
for (x in grid[y].indices) {
190+
for (y in expandBy .. grid.lastIndex - expandBy) {
191+
for (x in expandBy .. grid[y].lastIndex - expandBy) {
191192
val color = colorMap(grid[y][x].second, minElevation, maxElevation)
192-
pixels.set(x, y, width, color)
193+
pixels.set(x - expandBy, y - expandBy, width, color)
193194
}
194195
}
195196
Bitmap.createBitmap(pixels, width, height, Bitmap.Config.RGB_565)
@@ -207,9 +208,10 @@ object DEM {
207208
samples: Int = 1,
208209
sampleSpacing: Float = 3f
209210
): Bitmap = onDefault {
211+
val expandBy = 1
210212
val grid = getElevationGrid(bounds, resolution)
211-
val width = grid[0].size
212-
val height = grid.size
213+
val width = grid[0].size - expandBy * 2
214+
val height = grid.size - expandBy * 2
213215
val pixels = IntArray(width * height)
214216

215217
try {
@@ -231,8 +233,8 @@ object DEM {
231233
val cosZenith = cos(zenithRad)
232234
val sinZenith = sin(zenithRad)
233235

234-
for (y in grid.indices) {
235-
for (x in grid[y].indices) {
236+
for (y in expandBy .. grid.lastIndex - expandBy) {
237+
for (x in expandBy .. grid[y].lastIndex - expandBy) {
236238
val a = getElevation(x - 1, y - 1)
237239
val b = getElevation(x, y - 1)
238240
val c = getElevation(x + 1, y - 1)
@@ -263,7 +265,7 @@ object DEM {
263265
}
264266

265267
val gray = hillshade.toInt().coerceIn(0, 255)
266-
pixels.set(x, y, width, Color.rgb(gray, gray, gray))
268+
pixels.set(x - expandBy, y - expandBy, width, Color.rgb(gray, gray, gray))
267269
}
268270
}
269271
Bitmap.createBitmap(pixels, width, height, Bitmap.Config.RGB_565)

app/src/main/java/com/kylecorry/trail_sense/shared/dem/map_layers/ElevationLayer.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class ElevationLayer(taskRunner: MapLayerBackgroundTask2 = MapLayerBackgroundTas
1414
init {
1515
preRenderBitmaps = true
1616
loader.useFirstImageSize = true
17-
loader.alwaysReloadTiles = true
18-
loader.clearTileWhenNullResponse = false
1917
}
2018

2119
fun setPreferences(prefs: ElevationMapLayerPreferences) {

app/src/main/java/com/kylecorry/trail_sense/shared/dem/map_layers/HillshadeLayer.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ class HillshadeLayer(taskRunner: MapLayerBackgroundTask2 = MapLayerBackgroundTas
1313
init {
1414
preRenderBitmaps = true
1515
loader.useFirstImageSize = true
16-
loader.alwaysReloadTiles = true
17-
loader.clearTileWhenNullResponse = false
1816
alpha = 127
1917
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
2018
tilePaint.setBlendMode(BlendModeCompat.MULTIPLY)

app/src/main/java/com/kylecorry/trail_sense/shared/map_layers/tiles/TileLoader.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ class TileLoader {
153153
synchronized(lock) {
154154
if (clearTileWhenNullResponse || image != null) {
155155
val old = tileCache[source.key]
156-
tileCache += source.key to listOfNotNull(image)
156+
if (image == null){
157+
tileCache -= source.key
158+
} else {
159+
tileCache += source.key to listOfNotNull(image)
160+
}
157161
old?.forEach { it.recycle() }
158162
}
159163
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ abstract class TileMapLayer<T : ITileSourceSelector>(
162162

163163
preRenderedBitmap = createBitmap(bitmapWidth, bitmapHeight)
164164
val mergeCanvas = Canvas(preRenderedBitmap!!)
165-
mergeCanvas.drawColor(backgroundColor)
165+
mergeCanvas.drawColor(Color.TRANSPARENT)
166166

167167
// Render all tiles into the merged bitmap
168168
loader.tileCache.entries.sortedBy { it.key.z }.forEach { (tile, bitmaps) ->

0 commit comments

Comments
 (0)