diff --git a/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt b/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt index b283e9744..bcfaecd12 100644 --- a/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt +++ b/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt @@ -9,10 +9,9 @@ import org.osmdroid.util.MapTileIndex class CustomTileSource { - //https://tile.openweathermap.org/map/{layer}/{z}/{x}/{y}.png?appid={API key} companion object { - val OPENWEATHER_RADAR = object : OnlineTileSourceBase( - "Open Weather Map", 1, 15, 256, ".png", arrayOf( + val OPENWEATHER_RADAR = OnlineTileSourceAuth( + "Open Weather Map", 1, 22, 256, ".png", arrayOf( "https://tile.openweathermap.org/map/" ), "Openweathermap", TileSourcePolicy( @@ -21,16 +20,10 @@ class CustomTileSource { or TileSourcePolicy.FLAG_NO_PREVENTIVE or TileSourcePolicy.FLAG_USER_AGENT_MEANINGFUL or TileSourcePolicy.FLAG_USER_AGENT_NORMALIZED - ) - ) { - //{layer}/{z}/{x}/{y}.png?appid={API key} - override fun getTileURLString(pMapTileIndex: Long): String { - return baseUrl + "precipitation/" + (MapTileIndex.getZoom(pMapTileIndex) - .toString() + "/" + MapTileIndex.getX(pMapTileIndex) - + "/" + MapTileIndex.getY(pMapTileIndex) - + mImageFilenameEnding + "?appid=") - } - } + ), + "precipitation", + "" + ) // // val RAIN_VIEWER = object : OnlineTileSourceBase( // "RainViewer", 1, 15, 256, ".png", arrayOf( @@ -98,34 +91,6 @@ class CustomTileSource { + mImageFilenameEnding) } } - - //Transparent Background - //https://earthlive.maptiles.arcgis.com/arcgis/rest/services/GOES/GOES31D/MapServer/tile/ - private val NOAA_RADAR = object : OnlineTileSourceBase( - "NOAA GOES Radar", - 0, - 18, - 256, - "", - arrayOf( - "https://earthlive.maptiles.arcgis.com/arcgis/rest/services/GOES/GOES31D/MapServer/tile/" - ), - "Dataset Citation: GOES-R Calibration Working Group and GOES-R Series Program, (2017): NOAA GOES-R Series Advanced Baseline Imager (ABI) Level 1b Radiances Band 13. NOAA National Centers for Environmental Information. doi:10.7289/V5BV7DSR", - TileSourcePolicy( - 2, - TileSourcePolicy.FLAG_NO_BULK - or TileSourcePolicy.FLAG_NO_PREVENTIVE - or TileSourcePolicy.FLAG_USER_AGENT_MEANINGFUL - or TileSourcePolicy.FLAG_USER_AGENT_NORMALIZED - ) - ) { - override fun getTileURLString(pMapTileIndex: Long): String { - return baseUrl + (MapTileIndex.getZoom(pMapTileIndex) - .toString() + "/" + MapTileIndex.getY(pMapTileIndex) - + "/" + MapTileIndex.getX(pMapTileIndex) - + mImageFilenameEnding) - } - } private val USGS_HYDRO_CACHE = object : OnlineTileSourceBase( "USGS Hydro Cache", 0, diff --git a/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt b/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt index 221ce9438..a99cf1f9b 100644 --- a/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt +++ b/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt @@ -4,6 +4,7 @@ import android.content.res.Resources import android.util.Log import org.osmdroid.api.IMapView import org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase +import org.osmdroid.tileprovider.tilesource.TileSourcePolicy import org.osmdroid.util.MapTileIndex import kotlin.math.atan import kotlin.math.pow @@ -18,7 +19,15 @@ open class NOAAWmsTileSource( srs: String, style: String?, format: String, -) : OnlineTileSourceBase(aName, 0, 9, 256, "png", aBaseUrl) { +) : OnlineTileSourceBase( + aName, 0, 5, 256, "png", aBaseUrl, "", TileSourcePolicy( + 2, + TileSourcePolicy.FLAG_NO_BULK + or TileSourcePolicy.FLAG_NO_PREVENTIVE + or TileSourcePolicy.FLAG_USER_AGENT_MEANINGFUL + or TileSourcePolicy.FLAG_USER_AGENT_NORMALIZED + ) +) { // array indexes for array to hold bounding boxes. private val MINX = 0 diff --git a/app/src/main/java/com/geeksville/mesh/model/map/OnlineTileSourceAuth.kt b/app/src/main/java/com/geeksville/mesh/model/map/OnlineTileSourceAuth.kt new file mode 100644 index 000000000..1e4e37a39 --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/model/map/OnlineTileSourceAuth.kt @@ -0,0 +1,47 @@ +package com.geeksville.mesh.model.map + +import org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase +import org.osmdroid.tileprovider.tilesource.TileSourcePolicy +import org.osmdroid.util.MapTileIndex + +open class OnlineTileSourceAuth( + aName: String, + aZoomLevel: Int, + aZoomMaxLevel: Int, + aTileSizePixels: Int, + aImageFileNameEnding: String, + aBaseUrl: Array, + pCopyright: String, + tileSourcePolicy: TileSourcePolicy, + layerName: String?, + apiKey: String +) : + OnlineTileSourceBase( + aName, + aZoomLevel, + aZoomMaxLevel, + aTileSizePixels, + aImageFileNameEnding, + aBaseUrl, + pCopyright, + tileSourcePolicy + + ) { + private var layerName = "" + private var apiKey = "" + + init { + if (layerName != null) { + this.layerName = layerName + } + this.apiKey = apiKey + + } + + override fun getTileURLString(pMapTileIndex: Long): String { + return "$baseUrl$layerName/" + (MapTileIndex.getZoom(pMapTileIndex) + .toString() + "/" + MapTileIndex.getX(pMapTileIndex) + .toString() + "/" + MapTileIndex.getY(pMapTileIndex) + .toString()) + mImageFilenameEnding + "?appId=$apiKey" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index e745e44d9..4e7413fd9 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -490,7 +490,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { val layer = TilesOverlay( MapTileProviderBasic( activity, - CustomTileSource.NOAA_RADAR_WMS + CustomTileSource.OPENWEATHER_RADAR ), context ) layer.loadingBackgroundColor = Color.TRANSPARENT