Setup new class to handle "auth" urls

pull/505/head
PWRxPSYCHO 2022-10-11 18:36:44 -04:00
rodzic 11915df72e
commit 42cba353fa
4 zmienionych plików z 64 dodań i 43 usunięć

Wyświetl plik

@ -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,

Wyświetl plik

@ -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

Wyświetl plik

@ -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<String>,
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"
}
}

Wyświetl plik

@ -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