@@ -18,6 +18,7 @@ package im.vector.app.features.location
18
18
19
19
import android.content.Context
20
20
import android.content.res.TypedArray
21
+ import android.graphics.drawable.Drawable
21
22
import android.util.AttributeSet
22
23
import android.view.Gravity
23
24
import android.widget.ImageView
@@ -170,12 +171,7 @@ class MapTilerMapView @JvmOverloads constructor(
170
171
}
171
172
172
173
val pinDrawable = state.pinDrawable ? : userLocationDrawable
173
- pinDrawable?.let { drawable ->
174
- if (! safeMapRefs.style.isFullyLoaded ||
175
- safeMapRefs.style.getImage(state.pinId) == null ) {
176
- safeMapRefs.style.addImage(state.pinId, drawable.toBitmap())
177
- }
178
- }
174
+ addImageToMapStyle(pinDrawable, state.pinId, safeMapRefs)
179
175
180
176
safeMapRefs.symbolManager.deleteAll()
181
177
state.pinLocationData?.let { locationData ->
@@ -185,30 +181,35 @@ class MapTilerMapView @JvmOverloads constructor(
185
181
}
186
182
187
183
if (pinDrawable != null && state.showPin) {
188
- safeMapRefs.symbolManager.create(
189
- SymbolOptions ()
190
- .withLatLng(LatLng (locationData.latitude, locationData.longitude))
191
- .withIconImage(state.pinId)
192
- .withIconAnchor(Property .ICON_ANCHOR_BOTTOM )
193
- )
184
+ createSymbol(locationData, state.pinId, safeMapRefs)
194
185
}
195
186
}
196
187
197
188
state.userLocationData?.let { locationData ->
198
- if (! safeMapRefs.style.isFullyLoaded || safeMapRefs.style.getImage(USER_PIN_ID ) == null ) {
199
- userLocationDrawable?.let { drawable ->
200
- safeMapRefs.style.addImage(USER_PIN_ID , drawable.toBitmap())
201
- }
189
+ addImageToMapStyle(userLocationDrawable, USER_PIN_ID , safeMapRefs)
190
+ if (userLocationDrawable != null ) {
191
+ createSymbol(locationData, USER_PIN_ID , safeMapRefs)
202
192
}
203
- safeMapRefs.symbolManager.create(
204
- SymbolOptions ()
205
- .withLatLng(LatLng (locationData.latitude, locationData.longitude))
206
- .withIconImage(USER_PIN_ID )
207
- .withIconAnchor(Property .ICON_ANCHOR_BOTTOM )
208
- )
209
193
}
210
194
}
211
195
196
+ private fun addImageToMapStyle (image : Drawable ? , imageId : String , mapRefs : MapRefs ) {
197
+ image?.let { drawable ->
198
+ if (! mapRefs.style.isFullyLoaded || mapRefs.style.getImage(imageId) == null ) {
199
+ mapRefs.style.addImage(imageId, drawable.toBitmap())
200
+ }
201
+ }
202
+ }
203
+
204
+ private fun createSymbol (locationData : LocationData , imageId : String , mapRefs : MapRefs ) {
205
+ mapRefs.symbolManager.create(
206
+ SymbolOptions ()
207
+ .withLatLng(LatLng (locationData.latitude, locationData.longitude))
208
+ .withIconImage(imageId)
209
+ .withIconAnchor(Property .ICON_ANCHOR_BOTTOM )
210
+ )
211
+ }
212
+
212
213
fun zoomToLocation (locationData : LocationData ) {
213
214
Timber .d(" ## Location: zoomToLocation" )
214
215
mapRefs?.map?.zoomToLocation(locationData)
0 commit comments