@@ -10,6 +10,7 @@ import com.google.android.gms.maps.model.BitmapDescriptor
1010import com.google.android.gms.maps.model.BitmapDescriptorFactory
1111import com.google.android.gms.maps.model.LatLng
1212import com.google.android.gms.maps.model.MarkerOptions
13+ import com.rngooglemapsplus.extensions.styleHash
1314import kotlinx.coroutines.CoroutineScope
1415import kotlinx.coroutines.Dispatchers
1516import kotlinx.coroutines.Job
@@ -19,7 +20,7 @@ import kotlinx.coroutines.launch
1920import kotlinx.coroutines.withContext
2021import kotlin.coroutines.coroutineContext
2122
22- class MarkerBuilder (
23+ class MapMarkerBuilder (
2324 private val scope : CoroutineScope = CoroutineScope (SupervisorJob () + Dispatchers .Default ),
2425) {
2526 private val iconCache =
@@ -34,7 +35,7 @@ class MarkerBuilder(
3435
3536 fun build (
3637 m : RNMarker ,
37- icon : BitmapDescriptor ,
38+ icon : BitmapDescriptor ? ,
3839 ): MarkerOptions =
3940 MarkerOptions ().apply {
4041 position(LatLng (m.coordinate.latitude, m.coordinate.longitude))
@@ -46,10 +47,13 @@ class MarkerBuilder(
4647 fun buildIconAsync (
4748 id : String ,
4849 m : RNMarker ,
49- onReady : (BitmapDescriptor ) -> Unit ,
50+ onReady : (BitmapDescriptor ? ) -> Unit ,
5051 ) {
5152 jobsById[id]?.cancel()
52-
53+ if (m.iconSvg == null ) {
54+ onReady(null )
55+ return
56+ }
5357 val key = m.styleHash()
5458 iconCache.get(key)?.let { cached ->
5559 onReady(cached)
@@ -98,17 +102,28 @@ class MarkerBuilder(
98102
99103 private suspend fun renderBitmap (m : RNMarker ): Bitmap ? {
100104 var bmp: Bitmap ? = null
105+ if (m.iconSvg == null ) {
106+ return null
107+ }
101108 try {
102109 coroutineContext.ensureActive()
103- val svg = SVG .getFromString(m.iconSvg)
110+ val svg = SVG .getFromString(m.iconSvg.svgString )
104111
105112 coroutineContext.ensureActive()
106- svg.setDocumentWidth(m.width.dpToPx())
107- svg.setDocumentHeight(m.height.dpToPx())
113+ svg.setDocumentWidth(m.iconSvg. width.dpToPx())
114+ svg.setDocumentHeight(m.iconSvg. height.dpToPx())
108115
109116 coroutineContext.ensureActive()
110117 bmp =
111- createBitmap(m.width.dpToPx().toInt(), m.height.dpToPx().toInt(), Bitmap .Config .ARGB_8888 )
118+ createBitmap(
119+ m.iconSvg.width
120+ .dpToPx()
121+ .toInt(),
122+ m.iconSvg.height
123+ .dpToPx()
124+ .toInt(),
125+ Bitmap .Config .ARGB_8888 ,
126+ )
112127
113128 coroutineContext.ensureActive()
114129 val canvas = Canvas (bmp)
@@ -125,22 +140,3 @@ class MarkerBuilder(
125140 }
126141 }
127142}
128-
129- fun RNMarker.markerEquals (b : RNMarker ): Boolean =
130- id == b.id &&
131- zIndex == b.zIndex &&
132- coordinate == b.coordinate &&
133- anchor == b.anchor &&
134- markerStyleEquals(b)
135-
136- fun RNMarker.markerStyleEquals (b : RNMarker ): Boolean =
137- width == b.width &&
138- height == b.height &&
139- iconSvg == b.iconSvg
140-
141- fun RNMarker.styleHash (): Int =
142- arrayOf<Any ?>(
143- width,
144- height,
145- iconSvg,
146- ).contentHashCode()
0 commit comments