-
Notifications
You must be signed in to change notification settings - Fork 157
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
Add internal map delegates, create platform Projection class #390
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
665322e
Add MapTransformable
julianrex fff7c0b
Added MapProjectionDelegate
julianrex d1e34fd
Fix bug in tileRegionGeometry
julianrex 44b7f2c
Align with Android naming
julianrex af7be52
Update changelog
julianrex 6950274
Add tests
julianrex 03da9c6
Update package.resolved (incorrect sha)
julianrex a9454ce
Linting
julianrex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import CoreLocation | ||
|
||
internal protocol MapProjectionDelegate: AnyObject { | ||
/// Calculate distance spanned by one pixel at the specified latitude and | ||
/// zoom level. | ||
/// | ||
/// - Parameters: | ||
/// - latitude: The latitude for which to return the value | ||
/// - zoom: The zoom level | ||
/// | ||
/// - Returns: Meters | ||
static func metersPerPoint(for latitude: CLLocationDegrees, zoom: CGFloat) -> Double | ||
|
||
/// Calculate Spherical Mercator ProjectedMeters coordinates. | ||
/// - Parameter coordinate: Coordinate at which to calculate the projected | ||
/// meters | ||
/// | ||
/// - Returns: Spherical Mercator ProjectedMeters coordinates | ||
static func projectedMeters(for coordinate: CLLocationCoordinate2D) -> ProjectedMeters | ||
|
||
/// Calculate a coordinate for a Spherical Mercator projected | ||
/// meters. | ||
/// | ||
/// - Parameter projectedMeters: Spherical Mercator ProjectedMeters coordinates | ||
/// | ||
/// - Returns: A coordinate | ||
static func coordinate(for projectedMeters: ProjectedMeters) -> CLLocationCoordinate2D | ||
|
||
/// Calculate a point on the map in Mercator Projection for a given | ||
/// coordinate at the specified zoom scale. | ||
/// | ||
/// - Parameters: | ||
/// - coordinate: The coordinate for which to return the value. | ||
/// - zoomScale: The current zoom factor applied on the map, is used to | ||
/// calculate the world size as tileSize * zoomScale (i.e. | ||
/// 512 * 2 ^ Zoom level) where tileSize is the width of a tile | ||
/// in points. | ||
/// - Returns: Mercator coordinate | ||
static func project(_ coordinate: CLLocationCoordinate2D, zoomScale: CGFloat) -> MercatorCoordinate | ||
|
||
/// Calculate a coordinate for a given point on the map in Mercator Projection. | ||
/// | ||
/// - Parameters: | ||
/// - mercatorCoordinate: Point on the map in Mercator projection. | ||
/// - zoomScale: The current zoom factor applied on the map, is used to | ||
/// calculate the world size as tileSize * zoomScale (i.e. | ||
/// 512 * 2 ^ Zoom level) where tileSize is the width of a tile in | ||
/// points. | ||
/// - Returns: Unprojected coordinate | ||
static func unproject(_ mercatorCoordinate: MercatorCoordinate, zoomScale: CGFloat) -> CLLocationCoordinate2D | ||
} | ||
|
||
public class Projection: MapProjectionDelegate { | ||
internal init() {} | ||
|
||
public static func metersPerPoint(for latitude: CLLocationDegrees, zoom: CGFloat) -> Double { | ||
return MapboxCoreMaps.Projection.getMetersPerPixelAtLatitude(forLatitude: latitude, zoom: Double(zoom)) | ||
} | ||
|
||
public static func projectedMeters(for coordinate: CLLocationCoordinate2D) -> ProjectedMeters { | ||
return MapboxCoreMaps.Projection.projectedMetersForCoordinate(for: coordinate) | ||
} | ||
|
||
public static func coordinate(for projectedMeters: ProjectedMeters) -> CLLocationCoordinate2D { | ||
return MapboxCoreMaps.Projection.coordinateForProjectedMeters(for: projectedMeters) | ||
} | ||
|
||
public static func project(_ coordinate: CLLocationCoordinate2D, zoomScale: CGFloat) -> MercatorCoordinate { | ||
return MapboxCoreMaps.Projection.project(for: coordinate, zoomScale: Double(zoomScale)) | ||
} | ||
|
||
public static func unproject(_ mercatorCoordinate: MercatorCoordinate, zoomScale: CGFloat) -> CLLocationCoordinate2D { | ||
return MapboxCoreMaps.Projection.unproject(for: mercatorCoordinate, zoomScale: Double(zoomScale)) | ||
} | ||
} |
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,31 @@ | ||
internal protocol MapTransformDelegate: AnyObject { | ||
/// Gets the size of the map in points | ||
var size: CGSize { get set } | ||
julianrex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Notify map about gesture being in progress. | ||
var isGestureInProgress: Bool { get set } | ||
|
||
/// Tells the map rendering engine that the animation is currently performed | ||
/// by the user (e.g. with a `setCamera()` calls series). It adjusts the | ||
/// engine for the animation use case. | ||
/// In particular, it brings more stability to symbol placement and rendering. | ||
var isUserAnimationInProgress: Bool { get set } | ||
|
||
/// Returns the map's options | ||
var options: MapOptions { get } | ||
|
||
/// Set the map north orientation | ||
/// | ||
/// - Parameter northOrientation: The map north orientation to set | ||
func setNorthOrientation(northOrientation: NorthOrientation) | ||
|
||
/// Set the map constrain mode | ||
/// | ||
/// - Parameter constrainMode: The map constraint mode to set | ||
func setConstrainMode(_ constrainMode: ConstrainMode) | ||
|
||
/// Set the map viewport mode | ||
/// | ||
/// - Parameter viewportMode: The map viewport mode to set | ||
func setViewportMode(_ viewportMode: ViewportMode) | ||
} |
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 |
---|---|---|
|
@@ -140,4 +140,15 @@ final class MapboxMapTests: XCTestCase { | |
XCTAssertEqual(camera.padding, .zero) | ||
XCTAssertEqual(camera.pitch, 0) | ||
} | ||
|
||
func testProtocolConformance() { | ||
let map = MapboxMap(mapClient: MockMapClient(), mapInitOptions: MapInitOptions()) | ||
|
||
// Compilation check only | ||
_ = map as MapTransformDelegate | ||
_ = map as CameraManagerProtocol | ||
_ = map as MapFeatureQueryable | ||
_ = map as ObservableProtocol | ||
_ = map as MapEventsObservable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, this is an interesting concept as a test I like it |
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Android the
MapboxMap : MapProjectionDelegate
to be more discoverable, where the functions inside MapProjectionDelegate are not static.gl-native exposed generated static APIs can be directly used as
Projection.project(point, zoomScale)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave this as a point of difference? At the moment there's no need on iOS because of the lack of plugins. /cc @tobrun