-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMapHeatmapBuilder.kt
More file actions
31 lines (28 loc) · 1.09 KB
/
MapHeatmapBuilder.kt
File metadata and controls
31 lines (28 loc) · 1.09 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
package com.rngooglemapsplus
import com.facebook.react.uimanager.PixelUtil.dpToPx
import com.google.android.gms.maps.model.TileOverlayOptions
import com.google.maps.android.heatmaps.Gradient
import com.google.maps.android.heatmaps.HeatmapTileProvider
import com.rngooglemapsplus.extensions.toColor
import com.rngooglemapsplus.extensions.toWeightedLatLngs
class MapHeatmapBuilder {
fun build(heatmap: RNHeatmap): TileOverlayOptions {
val provider =
HeatmapTileProvider
.Builder()
.apply {
weightedData(heatmap.weightedData.toWeightedLatLngs())
heatmap.radius?.let { radius(it.dpToPx().toInt().coerceIn(10, 50)) }
heatmap.opacity?.let { opacity(it) }
heatmap.gradient?.let {
val colors = it.colors.map { c -> c.toColor() }.toIntArray()
val startPoints = it.startPoints.map { p -> p.toFloat() }.toFloatArray()
gradient(Gradient(colors, startPoints))
}
}.build()
return TileOverlayOptions().apply {
tileProvider(provider)
heatmap.zIndex?.let { zIndex(it.toFloat()) }
}
}
}