mirror of
https://github.com/ev-map/EVMap.git
synced 2026-04-20 14:18:20 -04:00
add icon to map marker to show fault reports
This commit is contained in:
@@ -385,7 +385,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
|
||||
markers.forEach { (m, c) ->
|
||||
m.setIcon(
|
||||
chargerIconGenerator.getBitmapDescriptor(
|
||||
getMarkerTint(c)
|
||||
getMarkerTint(c), fault = c.faultReport != null
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -396,7 +396,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
|
||||
// highlight this marker
|
||||
marker.setIcon(
|
||||
chargerIconGenerator.getBitmapDescriptor(
|
||||
getMarkerTint(charger), highlight = true
|
||||
getMarkerTint(charger), highlight = true, fault = charger.faultReport != null
|
||||
)
|
||||
)
|
||||
animator.animateMarkerBounce(marker)
|
||||
@@ -406,7 +406,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
|
||||
if (m != marker) {
|
||||
m.setIcon(
|
||||
chargerIconGenerator.getBitmapDescriptor(
|
||||
getMarkerTint(c)
|
||||
getMarkerTint(c), fault = c.faultReport != null
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -630,7 +630,8 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
|
||||
if (it.key.isVisible) {
|
||||
val tint = getMarkerTint(it.value)
|
||||
val highlight = it.value == vm.chargerSparse.value
|
||||
animator.animateMarkerDisappear(it.key, tint, highlight)
|
||||
val fault = it.value.faultReport != null
|
||||
animator.animateMarkerDisappear(it.key, tint, highlight, fault)
|
||||
} else {
|
||||
it.key.remove()
|
||||
}
|
||||
@@ -643,14 +644,18 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
|
||||
}.forEach { charger ->
|
||||
val tint = getMarkerTint(charger)
|
||||
val highlight = charger == vm.chargerSparse.value
|
||||
val fault = charger.faultReport != null
|
||||
val marker = map.addMarker(
|
||||
MarkerOptions()
|
||||
.position(LatLng(charger.coordinates.lat, charger.coordinates.lng))
|
||||
.icon(
|
||||
chargerIconGenerator.getBitmapDescriptor(tint, highlight = highlight)
|
||||
chargerIconGenerator.getBitmapDescriptor(
|
||||
tint, highlight = highlight,
|
||||
fault = charger.faultReport != null
|
||||
)
|
||||
)
|
||||
)
|
||||
animator.animateMarkerAppear(marker, tint, highlight)
|
||||
animator.animateMarkerAppear(marker, tint, highlight, fault)
|
||||
markers[marker] = charger
|
||||
}
|
||||
clusterMarkers = clusters.map { cluster ->
|
||||
|
||||
@@ -42,17 +42,24 @@ class ClusterIconGenerator(context: Context) : IconGenerator(context) {
|
||||
|
||||
|
||||
class ChargerIconGenerator(val context: Context) {
|
||||
data class BitmapData(val tint: Int, val scale: Int, val alpha: Int, val highlight: Boolean)
|
||||
data class BitmapData(
|
||||
val tint: Int,
|
||||
val scale: Int,
|
||||
val alpha: Int,
|
||||
val highlight: Boolean,
|
||||
val fault: Boolean
|
||||
)
|
||||
|
||||
val cacheSize = 4 * 1024 * 1024; // 4MiB
|
||||
val cacheSize = 8 * 1024 * 1024; // 8MiB
|
||||
val cache = object : LruCache<BitmapData, Bitmap>(cacheSize) {
|
||||
override fun sizeOf(key: BitmapData, value: Bitmap): Int {
|
||||
return value.byteCount
|
||||
}
|
||||
}
|
||||
val oversize = 1f // increase to add padding for overshoot scale animation
|
||||
val oversize = 1.4f // increase to add padding for fault icon or scale > 1
|
||||
val icon = R.drawable.ic_map_marker_charging
|
||||
val highlightIcon = R.drawable.ic_map_marker_highlight
|
||||
val faultIcon = R.drawable.ic_map_marker_fault
|
||||
|
||||
init {
|
||||
preloadCache()
|
||||
@@ -67,11 +74,13 @@ class ChargerIconGenerator(val context: Context) {
|
||||
R.color.charger_11kw,
|
||||
R.color.charger_low
|
||||
)
|
||||
for (highlight in listOf(false, true)) {
|
||||
for (tint in tints) {
|
||||
for (scale in 0..20) {
|
||||
val data = BitmapData(tint, scale, 255, highlight)
|
||||
cache.put(data, generateBitmap(data))
|
||||
for (fault in listOf(false, true)) {
|
||||
for (highlight in listOf(false, true)) {
|
||||
for (tint in tints) {
|
||||
for (scale in 0..20) {
|
||||
val data = BitmapData(tint, scale, 255, highlight, fault)
|
||||
cache.put(data, generateBitmap(data))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,9 +90,10 @@ class ChargerIconGenerator(val context: Context) {
|
||||
@ColorRes tint: Int,
|
||||
scale: Int = 20,
|
||||
alpha: Int = 255,
|
||||
highlight: Boolean = false
|
||||
highlight: Boolean = false,
|
||||
fault: Boolean = false
|
||||
): BitmapDescriptor? {
|
||||
val data = BitmapData(tint, scale, alpha, highlight)
|
||||
val data = BitmapData(tint, scale, alpha, highlight, fault)
|
||||
val cachedImg = cache[data]
|
||||
return if (cachedImg != null) {
|
||||
BitmapDescriptorFactory.fromBitmap(cachedImg)
|
||||
@@ -136,6 +146,21 @@ class ChargerIconGenerator(val context: Context) {
|
||||
highlightDrawable.draw(canvas)
|
||||
}
|
||||
|
||||
if (data.fault) {
|
||||
val faultDrawable = context.getDrawable(faultIcon)!!
|
||||
val faultSize = 0.75
|
||||
val faultShift = 0.25
|
||||
val base = vd.intrinsicWidth
|
||||
faultDrawable.setBounds(
|
||||
(leftPadding.toInt() + base * (1 - faultSize + faultShift)).toInt(),
|
||||
(topPadding.toInt() - base * faultShift).toInt(),
|
||||
(leftPadding.toInt() + base * (1 + faultShift)).toInt(),
|
||||
(topPadding.toInt() + base * (faultSize - faultShift)).toInt()
|
||||
)
|
||||
faultDrawable.alpha = data.alpha
|
||||
faultDrawable.draw(canvas)
|
||||
}
|
||||
|
||||
return bm
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,8 @@ class MarkerAnimator(val gen: ChargerIconGenerator) {
|
||||
fun animateMarkerAppear(
|
||||
marker: Marker,
|
||||
tint: Int,
|
||||
highlight: Boolean
|
||||
highlight: Boolean,
|
||||
fault: Boolean
|
||||
) {
|
||||
animatingMarkers[marker]?.cancel()
|
||||
animatingMarkers.remove(marker)
|
||||
@@ -40,7 +41,12 @@ class MarkerAnimator(val gen: ChargerIconGenerator) {
|
||||
}
|
||||
val scale = animationState.animatedValue as Int
|
||||
marker.setIcon(
|
||||
gen.getBitmapDescriptor(tint, scale = scale, highlight = highlight)
|
||||
gen.getBitmapDescriptor(
|
||||
tint,
|
||||
scale = scale,
|
||||
highlight = highlight,
|
||||
fault = fault
|
||||
)
|
||||
)
|
||||
}
|
||||
addListener(onEnd = {
|
||||
@@ -54,7 +60,8 @@ class MarkerAnimator(val gen: ChargerIconGenerator) {
|
||||
fun animateMarkerDisappear(
|
||||
marker: Marker,
|
||||
tint: Int,
|
||||
highlight: Boolean
|
||||
highlight: Boolean,
|
||||
fault: Boolean
|
||||
) {
|
||||
animatingMarkers[marker]?.cancel()
|
||||
animatingMarkers.remove(marker)
|
||||
@@ -70,7 +77,12 @@ class MarkerAnimator(val gen: ChargerIconGenerator) {
|
||||
}
|
||||
val scale = animationState.animatedValue as Int
|
||||
marker.setIcon(
|
||||
gen.getBitmapDescriptor(tint, scale = scale, highlight = highlight)
|
||||
gen.getBitmapDescriptor(
|
||||
tint,
|
||||
scale = scale,
|
||||
highlight = highlight,
|
||||
fault = fault
|
||||
)
|
||||
)
|
||||
}
|
||||
addListener(onEnd = {
|
||||
|
||||
12
app/src/main/res/drawable/ic_map_marker_fault.xml
Normal file
12
app/src/main/res/drawable/ic_map_marker_fault.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<vector android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24"
|
||||
android:width="24dp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path
|
||||
android:fillColor="@android:color/black"
|
||||
android:pathData="M 1 21 h 22 L 12 2 L 1 21 z" />
|
||||
<path
|
||||
android:fillColor="#FF9100"
|
||||
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z" />
|
||||
</vector>
|
||||
Reference in New Issue
Block a user