Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from nodes-ios/feature/annotationSeletion
Browse files Browse the repository at this point in the history
Annotation selected content
  • Loading branch information
BucekJiri authored Jun 30, 2022
2 parents 1324f7a + b595fde commit 1bedc67
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Sources/CustomAnnotatedMap/Annotations/MapAnnotation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ where
anchorPoint: CGPoint = .init(x: 0.5, y: 0.5),
@ViewBuilder content: () -> Content,
@ViewBuilder selectedContent: () -> SelectedContent,
@ViewBuilder contentCluster: () -> ContentCluster
@ViewBuilder contentCluster: @escaping ((Int) -> ContentCluster)
) {
self.mkAnnotation = _CustomMKAnnotation.init(
coordinate: location.coordinate,
clusteringIdentifier: clusteringIdentifier,
anchorPoint: anchorPoint,
content: content(),
selectedContent: selectedContent(),
contentCluster: contentCluster()
contentCluster: contentCluster
)
}
}
Expand All @@ -42,6 +43,7 @@ where
) {
self.mkAnnotation = _CustomMKAnnotation.init(
coordinate: location.coordinate,
anchorPoint: anchorPoint,
content: content(),
selectedContent: selectedContent()
)
Expand Down
34 changes: 24 additions & 10 deletions Sources/CustomAnnotatedMap/Annotations/_CustomMKAnnotation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ public class _CustomMKAnnotation<Content, SelectedContent, ContentCluster>: NSOb
let clusteringIdentifier: String?
let content: Content
let selectedContent: SelectedContent?
let contentCluster: ContentCluster?
let contentCluster: ((Int) -> ContentCluster)?
let anchorPoint: CGPoint

init(
coordinate: CLLocationCoordinate2D,
clusteringIdentifier: String? = nil,
anchorPoint: CGPoint,
content: Content,
selectedContent: SelectedContent,
contentCluster: ContentCluster? = nil
) {
contentCluster: ((Int) -> ContentCluster)? = nil
){
self.anchorPoint = anchorPoint
self.coordinate = coordinate
self.clusteringIdentifier = clusteringIdentifier
self.content = content
Expand Down Expand Up @@ -51,26 +54,36 @@ where
}
self.notSelectedView = UIHostingController(rootView: customMKAnnotation.content.ignoresSafeArea()).view
self.selectedView = UIHostingController(rootView: customMKAnnotation.selectedContent.ignoresSafeArea()).view
notSelectedView.backgroundColor = .clear
selectedView.backgroundColor = .clear

super.init(
annotation: customMKAnnotation,
reuseIdentifier: "customAnnotationViewReuseIdentifier"
)

self.clusteringIdentifier = customMKAnnotation.clusteringIdentifier
self.addSubview(notSelectedView)
frame = CGRect(x: 0, y: 0, width: 30, height: 40)

centerOffset = CGPoint(x: 0, y: -frame.size.height)
addSubview(notSelectedView)
notSelectedView.frame = bounds
}



required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func setSelected(_ selected: Bool, animated: Bool) {
// Toogles the selection views
// Toogles the selection views
if selected {
self.addSubview(selectedView)
notSelectedView.removeFromSuperview()
addSubview(selectedView)
selectedView.frame = bounds
} else {
self.addSubview(notSelectedView)
selectedView.removeFromSuperview()
addSubview(notSelectedView)
notSelectedView.frame = bounds
}
}
}
Expand Down Expand Up @@ -102,7 +115,8 @@ where
annotation: cluster,
reuseIdentifier: "customClusterAnnotationViewReuseIdentifier"
)
self.addSubview(UIHostingController(rootView: contentCluster.ignoresSafeArea()).view)

self.addSubview(UIHostingController(rootView: contentCluster(members.count).ignoresSafeArea()).view)
}

required init?(coder aDecoder: NSCoder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ extension _CustomAnnotatedMapContent {
animated: Bool
) {
if let userTrackingMode = UserTrackingMode(rawValue: mode.rawValue) {
self.mapContent.userTrackingMode = userTrackingMode
DispatchQueue.main.async {
self.mapContent.userTrackingMode = userTrackingMode
}
}
}
}
Expand Down

0 comments on commit 1bedc67

Please sign in to comment.