-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMapUrlTileOverlayBuilder.kt
More file actions
43 lines (38 loc) · 1.13 KB
/
MapUrlTileOverlayBuilder.kt
File metadata and controls
43 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.rngooglemapsplus
import com.google.android.gms.maps.model.TileOverlayOptions
import com.google.android.gms.maps.model.UrlTileProvider
import java.net.URL
class MapUrlTileOverlayBuilder(
private val mapErrorHandler: MapErrorHandler,
) {
fun build(t: RNUrlTileOverlay): TileOverlayOptions {
val provider =
object : UrlTileProvider(
t.tileSize.toInt(),
t.tileSize.toInt(),
) {
override fun getTileUrl(
x: Int,
y: Int,
zoom: Int,
): URL? {
val url =
t.url
.replace("{x}", x.toString())
.replace("{y}", y.toString())
.replace("{z}", zoom.toString())
return try {
URL(url)
} catch (e: Exception) {
mapErrorHandler.report(RNMapErrorCode.TILE_OVERLAY_FAILED, "tile url invalid: $url", e)
null
}
}
}
val opts = TileOverlayOptions().tileProvider(provider)
t.fadeIn?.let { opts.fadeIn(it) }
t.zIndex?.let { opts.zIndex(it.toFloat()) }
t.opacity?.let { opts.transparency(1f - it.toFloat()) }
return opts
}
}