-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Send unique report per each run measurement (#1633) * Prevent view annotation being shown erroneously after options update (#1627) * Add an example animating a view annotation along a route line (#1639) * Fix unit tests on iPhone mini 12/13 (#1643) * Add generated Annotation Manager Tests (#1617) * Add Initial Annotation Manager Tests * Add generated tests for all annotation managers * Resolve swiftlint issues * Reduce location provider heading orientation update frequency (#1618) * Increase timeout for view annotation animation example (#1645) * Expose list of added view annotations (#1621) * Fix view annotation animation example crashing on iOS 13 (#1653) * Delay view annotation animation start * Fiddle with CircleCI * Delaying animation start * Fix build errors * Tangible animation delay + window scene link * Disable animation altogether * Finish the example right after setting it up * Throw away unneeded tests * Remove all setup * Uncomment source * Uncomment layer * Uncomment view annotations * Wait for 21 sec * Wait for 1 sec * Run animation with 3s delay * Start the animation immediatedly * Common mode for display link * Default mode for display link * Revert test setup * Bump CoreMaps to 10.9.0 MapboxCommon to 23.1.0 (#1652) * Support 120Hz in DebugMap example (#1647) * Enable 120Hz on supported screens in DebugMap example * Drop pre-Xcode 13 compilation conditions * Fix swiftlint warning * Bump version to 10.9.0 (#1656) * Use different set of devices for Examples tests (#1660) * Feature/fix warnings (#1661) * Ignore deprecated examples in Release config * Fix warnings * Update the latest Xcode * Improve swiftlint configuration * Store correct artifacts for Examples Tests * Avoid triggering assertion for the 3D puck layer when returning `allLayerIdentifiers` (#1650) * Improve reduced accuracy authorization location indicator behavior while zooming (#1644) * Use iPhone 13 Pro for individul device tests (#1664) * Add Cluster Support for Point Annotation Managers (#1651) * Enable clustering of point annotations, create cluster options, add example and tests * Add first tests for clustering * Add tests and documentation * Update Project file paths * Add new function definition to allowlist * Improve example, add better documentation * Add and fix unit tests * Update access level and fix swiftlint * Respond to PR comments * Add changelog entry * Jazzy docs * Remove colorLevels in favor of circleColorExpression * Update destoy to include the added cluster layers * Reorganize cluster options, expand example * Adjust documentation * Bugfix/mapsios 328 better handling set style result observers (#1665) * Add test case to verify loadStyle handler is invoked exactly once * Cancel loadStyle observers on first expected events received * Update CHANGELOG.md (#1667) * Disable indexing on CI machines (#1672) * Remove outdated performance baseline (#1671) * Remove outdates performance baseline * Remove Baseline related code from XCParty * Update XCParty to support Xcode 14 * Feature/mapsios 367 frame view annotations (#1634) * API to get camera options to fit a list of view annotations. * Run MetricsV2 tests when CIRCLECI_TAG is set (#1674) * Remove ornament position deprecation (#1676) Co-authored-by: Roman Gardukevich <roman.gardukevich@mapbox.com> Co-authored-by: Roman Laitarenko <roman.laitarenko@mapbox.com> Co-authored-by: Patrick Leonard <pjleonard37@users.noreply.github.com> Co-authored-by: Mai Mai <mai.mai@mapbox.com> Co-authored-by: ZiZi <44972592+ZiZasaurus@users.noreply.github.com>
- Loading branch information
1 parent
a494028
commit c78df43
Showing
31 changed files
with
973 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
Apps/Examples/Examples/All Examples/Annotations/FrameViewAnnotationsExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import UIKit | ||
import MapboxMaps | ||
|
||
final class FrameViewAnnotationsExample: UIViewController, ExampleProtocol { | ||
|
||
private enum Animator { | ||
case flyTo, easeTo, viewport | ||
} | ||
|
||
private var flyToButton: UIButton! | ||
private var easeToButton: UIButton! | ||
private var viewportButton: UIButton! | ||
private var resetButton: UIButton! | ||
|
||
private var mapView: MapView! | ||
private let initialCamera = CameraOptions( | ||
center: .random, | ||
padding: UIEdgeInsets(top: .random(in: 0...20), left: .random(in: 0...20), bottom: .random(in: 0...20), right: .random(in: 0...20)), | ||
zoom: 0, | ||
bearing: 0, | ||
pitch: 0 | ||
) | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
view.backgroundColor = .white | ||
|
||
mapView = MapView(frame: view.bounds, mapInitOptions: MapInitOptions(cameraOptions: initialCamera)) | ||
let buttonsView = makeButtonsView() | ||
|
||
view.addSubview(mapView) | ||
view.addSubview(buttonsView) | ||
|
||
mapView.translatesAutoresizingMaskIntoConstraints = false | ||
buttonsView.translatesAutoresizingMaskIntoConstraints = false | ||
NSLayoutConstraint.activate([ | ||
mapView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), | ||
mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor), | ||
mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor), | ||
mapView.trailingAnchor.constraint(equalTo: view.trailingAnchor), | ||
buttonsView.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
buttonsView.leadingAnchor.constraint(greaterThanOrEqualTo: view.safeAreaLayoutGuide.leadingAnchor), | ||
buttonsView.bottomAnchor.constraint(equalTo: mapView.ornaments.logoView.topAnchor, constant: -10), | ||
]) | ||
|
||
addAnnotations() | ||
|
||
mapView.mapboxMap.onNext(event: .mapLoaded) { [weak self] _ in | ||
// The below line is used for internal testing purposes only. | ||
self?.finish() | ||
} | ||
} | ||
|
||
private func makeButtonsView() -> UIView { | ||
func makeButton(title: String, selector: Selector) -> UIButton { | ||
let button = UIButton() | ||
button.setTitle(title, for: .normal) | ||
button.contentEdgeInsets = UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20) | ||
button.backgroundColor = .black | ||
button.addTarget(self, action: selector, for: .touchUpInside) | ||
return button | ||
} | ||
|
||
flyToButton = makeButton(title: "FlyTo", selector: #selector(flyToButtonTapped(_:))) | ||
easeToButton = makeButton(title: "EaseTo", selector: #selector(easeToButtonTapped(_:))) | ||
viewportButton = makeButton(title: "Viewport", selector: #selector(viewportButtonTapped(_:))) | ||
resetButton = makeButton(title: "Reset camera", selector: #selector(resetButtonTapped(_:))) | ||
|
||
let buttonsView = UIStackView(arrangedSubviews: [flyToButton, easeToButton, viewportButton, resetButton]) | ||
buttonsView.axis = .horizontal | ||
buttonsView.spacing = 10 | ||
buttonsView.distribution = .fillEqually | ||
|
||
resetButton.isHidden = true | ||
|
||
return buttonsView | ||
} | ||
|
||
@objc private func flyToButtonTapped(_ sender: UIButton) { | ||
frameViewAnnotation(with: .flyTo, sender: sender) | ||
} | ||
|
||
@objc private func easeToButtonTapped(_ sender: UIButton) { | ||
frameViewAnnotation(with: .easeTo, sender: sender) | ||
} | ||
|
||
@objc private func viewportButtonTapped(_ sender: UIButton) { | ||
frameViewAnnotation(with: .viewport, sender: sender) | ||
} | ||
|
||
@objc private func resetButtonTapped(_ sender: UIButton) { | ||
mapView.mapboxMap.setCamera(to: initialCamera) | ||
resetButton.isHidden = true | ||
flyToButton.isHidden = false | ||
easeToButton.isHidden = false | ||
viewportButton.isHidden = false | ||
} | ||
|
||
private func frameViewAnnotation(with animator: Animator, sender: UIButton) { | ||
flyToButton.isHidden = true | ||
easeToButton.isHidden = true | ||
viewportButton.isHidden = true | ||
resetButton.isHidden = false | ||
|
||
let camera = self.mapView.viewAnnotations.camera( | ||
forAnnotations: Array(self.coordinates.keys), | ||
padding: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10), | ||
bearing: nil, | ||
pitch: nil | ||
)! | ||
|
||
switch animator { | ||
case .flyTo: | ||
mapView.camera.fly(to: camera, duration: 1) | ||
case .easeTo: | ||
mapView.camera.ease(to: camera, duration: 1) | ||
case .viewport: | ||
let bounds = mapView.mapboxMap.coordinateBounds(for: camera) | ||
let overviewViewportStateOptions = OverviewViewportStateOptions( | ||
geometry: MultiPoint([bounds.northeast, bounds.southeast, bounds.southwest, bounds.northwest]), | ||
padding: .zero, | ||
bearing: camera.bearing, | ||
pitch: camera.pitch, | ||
animationDuration: 1 | ||
) | ||
let overviewViewportState = mapView.viewport.makeOverviewViewportState(options: overviewViewportStateOptions) | ||
mapView.viewport.transition(to: overviewViewportState) | ||
} | ||
} | ||
|
||
private func addAnnotations() { | ||
for (id, point) in coordinates { | ||
let options = ViewAnnotationOptions( | ||
geometry: point.geometry, | ||
width: 40, | ||
height: 40, | ||
allowOverlap: true, | ||
anchor: .center, | ||
offsetX: 0, | ||
offsetY: 0) | ||
let annotation = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40)) | ||
annotation.backgroundColor = .green | ||
try! mapView.viewAnnotations.add(annotation, id: id, options: options) | ||
} | ||
} | ||
|
||
private let coordinates: [String: Point] = [ | ||
"Saigon": .init(LocationCoordinate2D(latitude: 10.823099, longitude: 106.629662)), | ||
"Hanoi": .init(LocationCoordinate2D(latitude: 21.027763, longitude: 105.834160)), | ||
"Tokyo": .init(LocationCoordinate2D(latitude: 35.689487, longitude: 139.691711)), | ||
"Bangkok": .init(LocationCoordinate2D(latitude: 13.756331, longitude: 100.501762)), | ||
"Jakarta": .init(LocationCoordinate2D(latitude: -6.175110, longitude: 106.865036)), | ||
] | ||
} |
Oops, something went wrong.