-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve map annotation display in the sample app (#345)
* Improve the sample app point annotations * Enable Cluster point annotations * Set Map view border to not render the view overlapped by the tap bar
- Loading branch information
Showing
11 changed files
with
108 additions
and
52 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
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
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
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,15 @@ | ||
import MapboxMaps | ||
import UIKit | ||
|
||
extension MapView { | ||
func makeClusterPointAnnotationManager( | ||
duration: TimeInterval = 0.5 | ||
) -> PointAnnotationManager { | ||
let manager = annotations.makePointAnnotationManager(clusterOptions: .init()) | ||
manager.onClusterTap = { [weak self] context in | ||
let cameraOptions = CameraOptions(center: context.coordinate, zoom: context.expansionZoom) | ||
self?.camera.ease(to: cameraOptions, duration: duration) | ||
} | ||
return manager | ||
} | ||
} |
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,48 @@ | ||
import MapboxMaps | ||
import MapboxSearch | ||
import UIKit | ||
|
||
extension PointAnnotation { | ||
static func pointAnnotation(_ searchResult: SearchResult) -> Self { | ||
Self.pointAnnotation(coordinate: searchResult.coordinate, name: searchResult.name) | ||
} | ||
|
||
static func pointAnnotation(_ searchResult: AddressAutofill.Result) -> Self { | ||
Self.pointAnnotation(coordinate: searchResult.coordinate, name: searchResult.name) | ||
} | ||
|
||
static func pointAnnotation(_ searchResult: PlaceAutocomplete.Result) -> Self? { | ||
guard let coordinate = searchResult.coordinate else { return nil } | ||
return Self.pointAnnotation(coordinate: coordinate, name: searchResult.name) | ||
} | ||
|
||
static func pointAnnotation(_ searchResult: Discover.Result) -> Self { | ||
var point = Self.pointAnnotation(coordinate: searchResult.coordinate, name: searchResult.name, imageName: nil) | ||
|
||
/// Display a corresponding Maki icon for this Result when available | ||
if let name = searchResult.makiIcon, let maki = Maki(rawValue: name) { | ||
point.image = .init(image: maki.icon, name: maki.name) | ||
point.iconOpacity = 0.6 | ||
point.iconAnchor = .bottom | ||
point.textAnchor = .top | ||
} | ||
return point | ||
} | ||
|
||
static func pointAnnotation( | ||
coordinate: CLLocationCoordinate2D, | ||
name: String, | ||
imageName: String? = "pin" | ||
) -> Self { | ||
var point = PointAnnotation(coordinate: coordinate) | ||
point.textField = name | ||
point.textHaloColor = .init(.white) | ||
point.textHaloWidth = 10 | ||
if let imageName, let image = UIImage(named: "pin") { | ||
point.iconAnchor = .bottom | ||
point.textAnchor = .top | ||
point.image = .init(image: image, name: "pin") | ||
} | ||
return point | ||
} | ||
} |