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

Replace syncAnnotations with property setter #614

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class CustomPointAnnotationExample: UIViewController, ExampleProtocol {
customPointAnnotation.image = .custom(image: customImage, name: "my-custom-image-name")

// Add the annotation to the manager in order to render it on the mao.
pointAnnotationManager.syncAnnotations([customPointAnnotation])
pointAnnotationManager.annotations = [customPointAnnotation]

// The annotations added above will show as long as the `PointAnnotationManager` is alive,
// so keep a reference to it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class LineAnnotationExample: UIViewController, ExampleProtocol {
let lineAnnnotationManager = mapView.annotations.makePolylineAnnotationManager()

// Sync the annotation to the manager.
lineAnnnotationManager.syncAnnotations([lineAnnotation])
lineAnnnotationManager.annotations = [lineAnnotation]

// The annotations added above will show as long as the lineAnnotationManager is alive,
// so keep a reference to it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class MultiplePointAnnotationsExample: UIViewController, ExampleProtocol

// Pass the point annotations into the annotation manager.
// This will add them to the map.
pointAnnotationManager.syncAnnotations([pointAnnotation2, pointAnnotation1])
pointAnnotationManager.annotations = [pointAnnotation2, pointAnnotation1]

// The next line is used for internal testing purposes only.
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public class OfflineManagerExample: UIViewController, ExampleProtocol {
pointAnnotation.image = .default

self.pointAnnotationsManager = mapView.annotations.makePointAnnotationManager()
self.pointAnnotationsManager?.syncAnnotations([pointAnnotation])
self.pointAnnotationsManager?.annotations = [pointAnnotation]
}

self.mapView = mapView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class PointAnnotationExample: UIViewController, ExampleProtocol {
customPointAnnotation.image = .default

// Add the annotation to the manager in order to render it on the mao.
pointAnnotationManager.syncAnnotations([customPointAnnotation])
pointAnnotationManager.annotations = [customPointAnnotation]

// The annotations added above will show as long as the `PointAnnotationManager` is alive,
// so keep a reference to it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class PolygonAnnotationExample: UIViewController, ExampleProtocol {
polygonAnnotation.fillOpacity = 0.8

// Add the polygon annotation to the manager
polygonAnnotationManager.syncAnnotations([polygonAnnotation])
polygonAnnotationManager.annotations = [polygonAnnotation]

// The annotations added above will show as long as the `PolygonAnnotationManager` is alive,
// so keep a reference to it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class SelectAnnotationExample: UIViewController, ExampleProtocol {
pointAnnotationManager.delegate = self

// Add the annotation to the map.
pointAnnotationManager.syncAnnotations([pointAnnotation])
pointAnnotationManager.annotations = [pointAnnotation]

// The below line is used for internal testing purposes only.
finish()
Expand Down
8 changes: 2 additions & 6 deletions Apps/Examples/Examples/All Examples/SwiftUIExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ internal class SwiftUIMapViewCoordinator {
/// are set, it synchronizes them to the map
var annotations = [PointAnnotation]() {
didSet {
syncAnnotations()
pointAnnotationManager?.annotations = annotations
}
}

Expand Down Expand Up @@ -195,16 +195,12 @@ internal class SwiftUIMapViewCoordinator {
/// situation, the warning is expected, and should not cause any runtime problems. We
/// expect to clean this up as well in an upcoming release.
pointAnnotationManager = mapView.annotations.makePointAnnotationManager()
syncAnnotations()
pointAnnotationManager?.annotations = annotations

default:
break
}
}

private func syncAnnotations() {
pointAnnotationManager?.syncAnnotations(annotations)
}
}

/// Here's an example usage of `SwiftUIMapView`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class UpdatePointAnnotationPositionExample: UIViewController, ExampleProt
pointAnnotation.image = .default

// Add the annotation to the map
pointAnnotationManager.syncAnnotations([pointAnnotation])
pointAnnotationManager.annotations = [pointAnnotation]

// Add a gesture recognizer to the map
mapView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(updatePosition)))
Expand All @@ -55,6 +55,6 @@ public class UpdatePointAnnotationPositionExample: UIViewController, ExampleProt
pointAnnotation.image = .default

// Update the annotations being managed by the manager
pointAnnotationManager.syncAnnotations([pointAnnotation])
pointAnnotationManager.annotations = [pointAnnotation]
}
}
8 changes: 4 additions & 4 deletions Apps/StressTest/StressTest/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ class ViewController: UIViewController {

// Add the annotation to the map.
print("Adding line annotation")
lineAnnotationManager?.syncAnnotations([lineAnnotation])
lineAnnotationManager?.annotations = [lineAnnotation]

let endOptions = CameraOptions(center: end, zoom: 17)

var cancelableAnimator: Cancelable?
cancelableAnimator = mapView.camera.fly(to: endOptions) { _ in
print("Removing line annotation for animator \(String(describing: cancelableAnimator))")
self.lineAnnotationManager?.syncAnnotations([])
self.lineAnnotationManager?.annotations = []
cancelableAnimator = nil
completion()
}
Expand All @@ -224,7 +224,7 @@ class ViewController: UIViewController {
func removeAnnotations() {
print("Removing \(annotations.count) annotations")
annotations = []
pointAnnotationManager?.syncAnnotations([])
pointAnnotationManager?.annotations = []
}

func addAnnotations(around coord: CLLocationCoordinate2D) {
Expand All @@ -237,7 +237,7 @@ class ViewController: UIViewController {
}

print("Adding \(annotations.count) annotations")
pointAnnotationManager?.syncAnnotations(annotations)
pointAnnotationManager?.annotations = annotations
}

func pushColorExpression() {
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Mapbox welcomes participation and contributions from everyone.

* Removed GeoJSONManager. Please use Turf directly instead to serialize and deserialize GeoJSON. ([#603](https://github.com/mapbox/mapbox-maps-ios/pull/603))
* Add specific geometry types to annotations. ([#612](https://github.com/mapbox/mapbox-maps-ios/pull/612))
* Replace syncAnnotations with property setter. ([#614](https://github.com/mapbox/mapbox-maps-ios/pull/614))

### Bug fixes 🐞

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ public class CircleAnnotationManager: AnnotationManager {
// MARK: - Annotations -

/// The collection of CircleAnnotations being managed
public private(set) var annotations = [CircleAnnotation]() {
public var annotations = [CircleAnnotation]() {
didSet {
syncAnnotations()
}
}

/// Syncs `CircleAnnotation`s to the map
/// NOTE: calling this repeatedly results in degraded performance
public func syncAnnotations(_ annotations: [CircleAnnotation]) {
self.annotations = annotations
}

// MARK: - AnnotationManager protocol conformance -

public let sourceId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ public class PointAnnotationManager: AnnotationManager {
// MARK: - Annotations -

/// The collection of PointAnnotations being managed
public private(set) var annotations = [PointAnnotation]() {
public var annotations = [PointAnnotation]() {
didSet {
addImageToStyleIfNeeded(style: style)
syncAnnotations()
}
}

/// Syncs `PointAnnotation`s to the map
/// NOTE: calling this repeatedly results in degraded performance
public func syncAnnotations(_ annotations: [PointAnnotation]) {
self.annotations = annotations
}

// MARK: - AnnotationManager protocol conformance -

public let sourceId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ public class PolygonAnnotationManager: AnnotationManager {
// MARK: - Annotations -

/// The collection of PolygonAnnotations being managed
public private(set) var annotations = [PolygonAnnotation]() {
public var annotations = [PolygonAnnotation]() {
macdrevx marked this conversation as resolved.
Show resolved Hide resolved
didSet {
syncAnnotations()
}
}

/// Syncs `PolygonAnnotation`s to the map
/// NOTE: calling this repeatedly results in degraded performance
public func syncAnnotations(_ annotations: [PolygonAnnotation]) {
self.annotations = annotations
}

// MARK: - AnnotationManager protocol conformance -

public let sourceId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ public class PolylineAnnotationManager: AnnotationManager {
// MARK: - Annotations -

/// The collection of PolylineAnnotations being managed
public private(set) var annotations = [PolylineAnnotation]() {
public var annotations = [PolylineAnnotation]() {
didSet {
syncAnnotations()
}
}

/// Syncs `PolylineAnnotation`s to the map
/// NOTE: calling this repeatedly results in degraded performance
public func syncAnnotations(_ annotations: [PolylineAnnotation]) {
self.annotations = annotations
}

// MARK: - AnnotationManager protocol conformance -

public let sourceId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CircleAnnotationIntegrationTests: MapViewIntegrationTestCase {
annotation.circleStrokeOpacity = Double.testConstantValue()
annotation.circleStrokeWidth = Double.testConstantValue()

manager.syncAnnotations([annotation])
manager.annotations = [annotation]
self.manager = manager
successfullyLoadedStyleExpectation.fulfill()
}
Expand All @@ -59,7 +59,7 @@ class CircleAnnotationIntegrationTests: MapViewIntegrationTestCase {

let annotation = CircleAnnotation(point: .init(.init(latitude: 0, longitude: 0)))

manager.syncAnnotations([annotation])
manager.annotations = [annotation]
self.manager = manager

do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PointAnnotationIntegrationTests: MapViewIntegrationTestCase {
annotation.textHaloWidth = Double.testConstantValue()
annotation.textOpacity = Double.testConstantValue()

manager.syncAnnotations([annotation])
manager.annotations = [annotation]
self.manager = manager
successfullyLoadedStyleExpectation.fulfill()
}
Expand All @@ -77,7 +77,7 @@ class PointAnnotationIntegrationTests: MapViewIntegrationTestCase {

let annotation = PointAnnotation(point: .init(.init(latitude: 0, longitude: 0)))

manager.syncAnnotations([annotation])
manager.annotations = [annotation]
self.manager = manager

do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PolygonAnnotationIntegrationTests: MapViewIntegrationTestCase {
annotation.fillOutlineColor = ColorRepresentable.testConstantValue()
annotation.fillPattern = String.testConstantValue()

manager.syncAnnotations([annotation])
manager.annotations = [annotation]
self.manager = manager
successfullyLoadedStyleExpectation.fulfill()
}
Expand Down Expand Up @@ -70,7 +70,7 @@ class PolygonAnnotationIntegrationTests: MapViewIntegrationTestCase {
]
let annotation = PolygonAnnotation(polygon: .init(outerRing: .init(coordinates: polygonCoords)))

manager.syncAnnotations([annotation])
manager.annotations = [annotation]
self.manager = manager

do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PolylineAnnotationIntegrationTests: MapViewIntegrationTestCase {
annotation.linePattern = String.testConstantValue()
annotation.lineWidth = Double.testConstantValue()

manager.syncAnnotations([annotation])
manager.annotations = [annotation]
self.manager = manager
successfullyLoadedStyleExpectation.fulfill()
}
Expand All @@ -62,7 +62,7 @@ class PolylineAnnotationIntegrationTests: MapViewIntegrationTestCase {
let lineCoordinates = [ CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10) ]
let annotation = PolylineAnnotation(lineString: .init(lineCoordinates))

manager.syncAnnotations([annotation])
manager.annotations = [annotation]
self.manager = manager

do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class MigrationGuideIntegrationTests: IntegrationTestCase {
let coordinate = CLLocationCoordinate2DMake(24, -89)
var pointAnnotation = PointAnnotation(coordinate: coordinate)
pointAnnotation.image = .default
self.pointAnnotationManager.syncAnnotations([pointAnnotation])
self.pointAnnotationManager.annotations = [pointAnnotation]
}
}

Expand Down