This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix MGLMapCamera initialization and viewing distance calculations #12966
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,106 @@ | ||
#import <XCTest/XCTest.h> | ||
#import <CoreLocation/CoreLocation.h> | ||
#import <Mapbox/Mapbox.h> | ||
#import <MapKit/MapKit.h> | ||
|
||
@interface MGLMapCameraTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation MGLMapCameraTests | ||
|
||
- (void)testEyeCoordinateInitialization { | ||
CLLocationCoordinate2D fountainSquare = CLLocationCoordinate2DMake(39.10152215, -84.5124439696089); | ||
CLLocationCoordinate2D unionTerminal = CLLocationCoordinate2DMake(39.10980955, -84.5352778794236); | ||
|
||
MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
fromEyeCoordinate:fountainSquare | ||
eyeAltitude:1000]; | ||
MKMapCamera *mkCamera = [MKMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
fromEyeCoordinate:fountainSquare | ||
eyeAltitude:1000]; | ||
XCTAssertEqual(camera.centerCoordinate.latitude, fountainSquare.latitude); | ||
XCTAssertEqual(camera.centerCoordinate.longitude, fountainSquare.longitude); | ||
XCTAssertEqual(camera.centerCoordinate.latitude, mkCamera.centerCoordinate.latitude); | ||
XCTAssertEqual(camera.centerCoordinate.longitude, mkCamera.centerCoordinate.longitude); | ||
XCTAssertEqual(camera.altitude, 1000, @"Eye altitude should be equivalent to altitude in untilted camera."); | ||
XCTAssertEqual(camera.altitude, mkCamera.altitude, @"Eye altitude in untilted camera should match MapKit."); | ||
XCTAssertEqual(camera.pitch, 0, @"Camera directly over center coordinate should be untilted."); | ||
XCTAssertEqual(camera.pitch, mkCamera.pitch, @"Camera directly over center coordinate should have same pitch as MapKit."); | ||
XCTAssertEqual(camera.heading, 0, @"Camera directly over center coordinate should be unrotated."); | ||
XCTAssertEqual(camera.heading, mkCamera.heading, @"Camera directly over center coordinate should have same heading as MapKit."); | ||
|
||
camera = [MGLMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
fromEyeCoordinate:unionTerminal | ||
eyeAltitude:1000]; | ||
mkCamera = [MKMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
fromEyeCoordinate:unionTerminal | ||
eyeAltitude:1000]; | ||
XCTAssertEqual(camera.centerCoordinate.latitude, fountainSquare.latitude); | ||
XCTAssertEqual(camera.centerCoordinate.longitude, fountainSquare.longitude); | ||
XCTAssertEqual(camera.centerCoordinate.latitude, mkCamera.centerCoordinate.latitude); | ||
XCTAssertEqual(camera.centerCoordinate.longitude, mkCamera.centerCoordinate.longitude); | ||
XCTAssertEqual(camera.altitude, 1000); | ||
XCTAssertEqual(camera.altitude, mkCamera.altitude, @"Eye altitude in tilted camera should match MapKit."); | ||
XCTAssertEqualWithAccuracy(camera.pitch, 65.3469146074, 0.01); | ||
XCTAssertEqual(camera.pitch, mkCamera.pitch); | ||
XCTAssertEqualWithAccuracy(camera.heading, 115.066396383, 0.01); | ||
XCTAssertEqualWithAccuracy(camera.heading, mkCamera.heading, 0.01); | ||
} | ||
|
||
- (void)testViewingDistanceInitialization { | ||
CLLocationCoordinate2D fountainSquare = CLLocationCoordinate2DMake(39.10152215, -84.5124439696089); | ||
MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
acrossDistance:10000 | ||
pitch:0 | ||
heading:0]; | ||
MKMapCamera *mkCamera = [MKMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
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. As far as I can tell, this is the first time we’re explicitly testing the iOS/macOS SDK against MapKit. I think we should try to test against MapKit like this whenever an API is intended to match a MapKit API one-for-one. 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. 👍 |
||
fromDistance:10000 | ||
pitch:0 | ||
heading:0]; | ||
XCTAssertEqualWithAccuracy(camera.altitude, 10000, 0.01, @"Untilted camera should use distance verbatim."); | ||
XCTAssertEqualWithAccuracy(camera.altitude, mkCamera.altitude, 0.01, @"Untilted camera altitude should match MapKit."); | ||
|
||
camera = [MGLMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
altitude:10000 | ||
pitch:0 | ||
heading:0]; | ||
XCTAssertEqual(camera.altitude, 10000, @"Untilted camera should use altitude verbatim."); | ||
|
||
camera = [MGLMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
acrossDistance:10000 | ||
pitch:60 | ||
heading:0]; | ||
mkCamera = [MKMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
fromDistance:10000 | ||
pitch:60 | ||
heading:0]; | ||
XCTAssertEqualWithAccuracy(camera.altitude, 5000, 0.01, @"Tilted camera altitude should account for pitch."); | ||
XCTAssertEqualWithAccuracy(camera.altitude, mkCamera.altitude, 0.01, @"Tilted camera altitude should match MapKit."); | ||
|
||
camera = [MGLMapCamera cameraLookingAtCenterCoordinate:fountainSquare | ||
altitude:10000 | ||
pitch:60 | ||
heading:0]; | ||
XCTAssertEqual(camera.altitude, 10000, @"Tilted camera should use altitude verbatim."); | ||
} | ||
|
||
- (void)testViewingDistance { | ||
MGLMapCamera *camera = [MGLMapCamera camera]; | ||
camera.altitude = 10000; | ||
XCTAssertEqual(camera.altitude, 10000); | ||
XCTAssertEqual(camera.viewingDistance, 10000); | ||
camera.viewingDistance = 10000; | ||
XCTAssertEqual(camera.altitude, 10000); | ||
XCTAssertEqual(camera.viewingDistance, 10000); | ||
|
||
camera.pitch = 60; | ||
camera.altitude = 10000; | ||
XCTAssertEqual(camera.altitude, 10000); | ||
XCTAssertEqualWithAccuracy(camera.viewingDistance, 20000, 0.01); | ||
camera.viewingDistance = 10000; | ||
XCTAssertEqualWithAccuracy(camera.altitude, 5000, 0.01); | ||
XCTAssertEqual(camera.viewingDistance, 10000); | ||
} | ||
|
||
@end |
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
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.
Can we make it clear that the
across
distance here is the same as theviewingDistance
above? Either by documentation, by an alternative parameter name?If we don't want to explicitly use
viewingDistance
due to Swift bridging, are there any alternatives that would be clearer?radius
,orbit
,span
? Actually I quite likeradius
in this context.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.
I’m not sure any of those alternatives distinguishes between the hypotenuse and adjacent any more than
acrossDistance
would, but I just don’t think that distinction is very important. Consider that the original method – which I want to return to eventually, once we remove the incorrect implementation – calls itfromDistance
, for simplicity and consistency with MapKit. The point is to distinguish from the opposite (altitude), which all these options accomplish to varying degrees. (The property, meanwhile, is still calledviewingDistance
– do you think it needs to be revisited?)If
acrossDistance
doesn’t work, then my next suggestion would be-cameraLookingAtDistance:toCoordinate:pitch:heading:
(camera(lookingAt:to:pitch:heading:)
) or something like that. But honestly, I keep getting frustrated because all the good ways to express this concept in English require putting a word after the quantity (e.g., “from … away”), which doesn’t work here.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.
Yep - I totally hear you about language frustrations. I think the truth is that we have the best one, it's just that we need to deprecate it first before re-using it! 🔀
Let's get this one in 👍
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.
Thanks, for what it’s worth, there is a more detailed explanation of this parameter a few lines further up:
mapbox-gl-native/platform/darwin/src/MGLMapCamera.h
Lines 71 to 73 in 44aa4f4