mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
5858: Factorise some code according to PR comments
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -19,7 +19,7 @@ import SwiftUI
|
||||
import Mapbox
|
||||
|
||||
@available(iOS 14, *)
|
||||
class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
class LocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@@ -38,14 +38,15 @@ class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
// TODO: Use a reuseIdentifier
|
||||
super.init(annotation: userLocationAnnotation, reuseIdentifier: nil)
|
||||
|
||||
switch userLocationAnnotation.coordinateType {
|
||||
case .user:
|
||||
self.addUserMarkerView(with: userLocationAnnotation.avatarData)
|
||||
case .pin, .generic:
|
||||
self.addPinMarkerView()
|
||||
@unknown default:
|
||||
return
|
||||
}
|
||||
self.addUserMarkerView(with: userLocationAnnotation.avatarData)
|
||||
|
||||
}
|
||||
|
||||
init(pinLocationAnnotation: LocationAnnotation) {
|
||||
// TODO: Use a reuseIdentifier
|
||||
super.init(annotation: pinLocationAnnotation, reuseIdentifier: nil)
|
||||
|
||||
self.addPinMarkerView()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
|
||||
Reference in New Issue
Block a user