Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure AnnotationManager's mapLoaded happens first #246

Merged
merged 5 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions Sources/MapboxMaps/Annotations/AnnotationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import MapboxMapsFoundation

All annotations added with this class belong to a single source and style layer.
*/
public class AnnotationManager: Observer {

public var peer: MBXPeerWrapper?
public class AnnotationManager {

// MARK: - Public properties

Expand Down Expand Up @@ -130,7 +128,6 @@ public class AnnotationManager: Observer {

deinit {
self.tapGesture = nil
try! self.mapView?.observable?.unsubscribe(for: self, events: [MapEvents.mapLoaded])
}

/**
Expand All @@ -155,7 +152,15 @@ public class AnnotationManager: Observer {
userInteractionEnabled = true

configureTapGesture()
try! mapView.observable?.subscribe(for: self, events: [MapEvents.mapLoaded])
mapView.on(.mapLoaded) { [weak self] _ in
// Reset the annotation source and default layers.
guard let self = self else { return }
self.annotations = [:]
self.annotationSource = nil
self.symbolLayer = nil
self.lineLayer = nil
self.fillLayer = nil
}
}

internal func updateAnnotationOptions(with newOptions: AnnotationOptions) {
Expand Down Expand Up @@ -664,17 +669,4 @@ public class AnnotationManager: Observer {
// Updating the annotation failed.
case updateAnnotationFailed(Error?)
}

public func notify(for event: MapboxCoreMaps.Event) {
guard event.type == MapEvents.mapLoaded else {
return
}

// Reset the annotation source and default layers.
annotations = [:]
annotationSource = nil
symbolLayer = nil
lineLayer = nil
fillLayer = nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import MapboxMapsStyle
import MapboxMapsFoundation
#endif

public protocol AnnotationSupportableMap: UIView {
var observable: Observable? { get }
internal protocol AnnotationSupportableMap: UIView {
func visibleFeatures(in rect: CGRect,
styleLayers: Set<String>?,
filter: Expression?,
completion: @escaping (Result<[Feature], BaseMapView.QueryRenderedFeaturesError>) -> Void)
func on(_ eventType: MapEvents.EventKind, handler: @escaping (MapboxCoreMaps.Event) -> Void)
}

extension BaseMapView: AnnotationSupportableMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import MapboxMapsStyle
//swiftlint:disable explicit_acl explicit_top_level_acl
class AnnotationSupportableMapMock: UIView, AnnotationSupportableMap {

var observable: Observable? {
nil
}

func visibleFeatures(in rect: CGRect,
styleLayers: Set<String>?,
filter: Expression?,
Expand All @@ -27,4 +23,7 @@ class AnnotationSupportableMapMock: UIView, AnnotationSupportableMap {
let feature = Feature(Point.init(coord))
completion(.success([feature]))
}

func on(_ eventType: MapEvents.EventKind, handler: @escaping (Event) -> Void) {
}
}