5858: Factorise some code according to PR comments

This commit is contained in:
MaximeE
2022-04-04 16:33:55 +02:00
parent 540ca3e7f3
commit dae1109a59
7 changed files with 52 additions and 42 deletions
@@ -33,10 +33,10 @@ struct LocationSharingMapView: UIViewRepresentable {
let tileServerMapURL: URL
/// Map annotations
let annotations: [UserLocationAnnotation]
let annotations: [LocationAnnotation]
/// Map annotation to focus on
let highlightedAnnotation: UserLocationAnnotation?
let highlightedAnnotation: LocationAnnotation?
/// Current user avatar data, used to replace current location annotation view with the user avatar
let userAvatarData: AvatarInputProtocol?
@@ -117,10 +117,12 @@ extension LocationSharingMapView {
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
return UserLocationAnnotatonView(userLocationAnnotation: userLocationAnnotation)
return LocationAnnotatonView(userLocationAnnotation: userLocationAnnotation)
} else if let pinLocationAnnotation = annotation as? LocationAnnotation {
return LocationAnnotatonView(pinLocationAnnotation: pinLocationAnnotation)
} else if annotation is MGLUserLocation && locationSharingMapView.mapCenterCoordinate == nil, let currentUserAvatarData = locationSharingMapView.userAvatarData {
// Replace default current location annotation view with a UserLocationAnnotatonView when the map is center on user location
return UserLocationAnnotatonView(avatarData: currentUserAvatarData)
return LocationAnnotatonView(avatarData: currentUserAvatarData)
}
return nil