-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clip offline tiles to downloaded bounds (#1852)
* Remove unused enum * WIP * Update string resources * Fix detekt error * Fix typo * Rename * Refactor * Refactor * Offline area map selector mask and outline * Update Cancel and Download layout * Remove unused resource * Merge offline area estimator with latest UI * Fix force quit * Remove Apache Commons dep * Impl local offline area flow * Apply constructor method pattern to TileSource creation * Docs tweaks * Add tile + offset -> latlng * Add clipping tile provider * Minor refactor * Update table name missed on rename * Upgrade Room * WIP * Clip offline imagery to selected areas * checkCode * Add tests * Clean up Flow * Clean up comment * Update comment * Refactor transparency log * Remove redundant setting of map type * Make clip bounds non-nullable * ktfmt
- Loading branch information
Showing
25 changed files
with
366 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
ground/src/main/java/com/google/android/ground/ui/map/gms/ClippingTileProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.ground.ui.map.gms | ||
|
||
import com.google.android.gms.maps.model.LatLngBounds | ||
import com.google.android.gms.maps.model.Tile | ||
import com.google.android.gms.maps.model.TileProvider | ||
import com.google.android.gms.maps.model.TileProvider.NO_TILE | ||
import com.google.android.ground.ui.map.gms.mog.ImageEditor | ||
import com.google.android.ground.ui.map.gms.mog.TileCoordinates | ||
import com.google.android.ground.ui.map.gms.mog.toPixelBounds | ||
import com.google.android.ground.ui.map.gms.mog.toPixelCoordinate | ||
|
||
private const val MAX_ZOOM = 19 | ||
|
||
class ClippingTileProvider( | ||
private val sourceTileProvider: TileProvider, | ||
clipBounds: List<LatLngBounds> | ||
) : TileProvider { | ||
|
||
private val pixelBounds = clipBounds.map { it.toPixelBounds(MAX_ZOOM) } | ||
|
||
override fun getTile(x: Int, y: Int, zoom: Int): Tile { | ||
val sourceTile = sourceTileProvider.getTile(x, y, zoom) ?: NO_TILE | ||
if (sourceTile == NO_TILE) return sourceTile | ||
// We assume if a tile is returned by the source provider that at least some pixels are within | ||
// the clip bounds, so there's no need to optimize by checking before clipping. | ||
return clipToBounds(TileCoordinates(x, y, zoom), sourceTile) | ||
} | ||
|
||
private fun clipToBounds(tileCoords: TileCoordinates, tile: Tile): Tile { | ||
if (tile.data == null) return NO_TILE | ||
val output = | ||
ImageEditor.setTransparentIf(tile.data!!) { _, x, y -> | ||
val pixelCoords = tileCoords.toPixelCoordinate(x, y) | ||
pixelBounds.none { it.contains(pixelCoords) } | ||
} | ||
return Tile(tile.width, tile.height, output) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.