5858: Modification of the event send according to coordinate type

This commit is contained in:
MaximeE
2022-03-31 16:52:16 +02:00
parent e6538d8023
commit 31fedfa215
11 changed files with 71 additions and 29 deletions
@@ -118,8 +118,8 @@ extension LocationSharingMapView {
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
return UserLocationAnnotatonView(userLocationAnnotation: userLocationAnnotation)
} else if annotation is MGLUserLocation, let currentUserAvatarData = locationSharingMapView.userAvatarData {
// Replace default current location annotation view with a UserLocationAnnotatonView
} 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)
}
@@ -38,7 +38,14 @@ class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
// TODO: Use a reuseIdentifier
super.init(annotation: userLocationAnnotation, reuseIdentifier: nil)
self.addUserMarkerView(with: userLocationAnnotation.avatarData)
switch userLocationAnnotation.coordinateType {
case .user:
self.addUserMarkerView(with: userLocationAnnotation.avatarData)
case .pin, .generic:
self.addPinMarkerView()
@unknown default:
return
}
}
required init?(coder: NSCoder) {
@@ -55,12 +62,26 @@ class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
}).view else {
return
}
addMarkerView(with: avatarImageView)
}
private func addPinMarkerView() {
guard let pinImageView = UIHostingController(rootView: LocationSharingMarkerView(backgroundColor: theme.colors.accent) {
Image(uiImage: Asset.Images.locationPinIcon.image)
.resizable()
.shapedBorder(color: theme.colors.accent, borderWidth: 3, shape: Circle())
}).view else {
return
}
addMarkerView(with: pinImageView)
}
private func addMarkerView(with imageView: UIView) {
addSubview(imageView)
addSubview(avatarImageView)
addConstraints([topAnchor.constraint(equalTo: avatarImageView.topAnchor),
leadingAnchor.constraint(equalTo: avatarImageView.leadingAnchor),
bottomAnchor.constraint(equalTo: avatarImageView.bottomAnchor),
trailingAnchor.constraint(equalTo: avatarImageView.trailingAnchor)])
addConstraints([topAnchor.constraint(equalTo: imageView.topAnchor),
leadingAnchor.constraint(equalTo: imageView.leadingAnchor),
bottomAnchor.constraint(equalTo: imageView.bottomAnchor),
trailingAnchor.constraint(equalTo: imageView.trailingAnchor)])
}
}