-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] Map view can now be optionally configured to make pitch adjustments w… #12518
Changes from 4 commits
54a7609
9b26024
0b1e7c2
08d8abd
3c8acb2
b2f60a4
58202ea
d886d3e
41d5768
f3ebdae
60cbedc
16e6ca8
9ecb099
20f880e
4b9ed38
bee605e
b8a1b13
9bd23a7
04705f4
66a09b9
4116940
c96d9df
a3b6fc1
fa7b709
89515de
6e06e55
084c28f
9d72bf8
b1ab362
c2113fd
1771875
7795c76
2424582
d3e3490
2173088
91f934f
59cdb14
1847ef0
fbc39fa
369e688
19325b0
790b9f5
8ca419f
9df9f5f
112bbc7
ff077e9
036a750
1b4398f
bded6c6
b0fcca5
31bdb74
cf0313f
fae0999
4fedcf8
ca0f2f9
fcb6804
5005965
7fc872b
5297f56
2c093e7
7e6331b
5ce64b7
7ce6af3
2ff1ac3
1584d8f
9587f56
a842c19
0218c01
724832c
c5ab61d
516131d
427a7ba
250eaff
33cd094
fd1767e
49cf31d
67f6891
87f73bb
1662be7
520df7f
7395a25
c83012f
be83bb7
d31df6a
5e213d0
4b93e93
cb1f781
52275f8
fb5afd3
fc26f2a
51f3842
f9fd9c0
0f58d95
d297bf1
fd1ed8c
1e45464
3027292
1127e35
48381ef
065f5ca
fcab3a8
bc806d4
eb72fe5
d4f4136
361d83a
4061e90
8c58842
b8dfd2f
330ec0b
65ae976
5c8ad4d
0dac3bc
abc5043
f97ba60
748e6bd
5e9bbfd
ec62e32
4a5dc37
2cdbe93
4cf6138
7b3edb6
f7dcd5d
d197fc7
95b89e6
59ebe02
af0de6e
e7642f2
1099bb4
69b7c2f
18b43f2
42aaf3e
3f02197
e4bcd1a
7227b4a
260f96c
fe3fe2d
c9803e3
7017ac5
c62fabf
0e95e8f
679d66f
f006eb9
e51eb0f
e082af1
e5bc05e
5aca8e9
315a9e3
5fb096a
15c9ed4
0a26333
cb141e8
21ed57a
5d8abb6
50f9381
3ca2050
794ba54
1c103fa
6806ba5
53c3c32
115e862
3948bbd
6be8302
5911e3b
79bf0e8
31cca05
435241c
e947fa0
06ff49d
536652c
30e570a
4a3c4ed
bc9b224
2fccdec
6e171a6
511fca7
e70fe05
5d000d0
cb771f6
465316b
bfe0b67
fa3f6f0
cf7752c
907612e
8cd86fe
d4a2123
caebcd0
d625993
b2d4b82
229e35e
079ba02
d735d89
5238c77
46853dc
3263387
e4e43bb
05a7b78
5b1925d
6367fcb
071129b
28b14f0
cc75530
862b4ff
c470bd2
c63e628
9efdc4c
df93047
c044dd8
2c48b5a
b64b4cd
20adb48
29f940d
235f789
b9ef805
1c53dc9
68d463e
f3efa62
12809db
153e97c
a938c3e
80bdbeb
cd031be
47eaea2
60b8469
5af8c53
a991eec
89b075f
2e93a9d
ab8b6b7
9b09ec1
f7a69d1
bee9a54
41427ff
2f7a147
fc28f39
15c76d0
071b14a
c1b1e29
38d01ad
9d984d2
b9992f5
55cd73d
82077ce
ce2d2aa
4ea4a94
adab22a
39b4f62
666ec34
959126f
a1c898f
13000b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -856,6 +856,15 @@ MGL_EXPORT IB_DESIGNABLE | |
*/ | ||
- (void)setCamera:(MGLMapCamera *)camera animated:(BOOL)animated; | ||
|
||
/** | ||
Moves the viewpoint to a different location without using a transition. | ||
|
||
@param camera The new viewpoint. | ||
@param edgePadding The minimum padding (in screen points) that would be visible | ||
|
||
*/ | ||
- (void)setCamera:(MGLMapCamera *)camera edgePadding:(UIEdgeInsets)edgePadding; | ||
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. This method should accept an |
||
|
||
/** | ||
Moves the viewpoint to a different location with respect to the map with an | ||
optional transition duration and timing function. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,9 @@ @interface MGLMapView () <UIGestureRecognizerDelegate, | |
@property (nonatomic) MGLUserLocation *userLocation; | ||
@property (nonatomic) NSMutableDictionary<NSString *, NSMutableArray<MGLAnnotationView *> *> *annotationViewReuseQueueByIdentifier; | ||
|
||
/// A Boolean value that determines whether the updating pitch will also affect the altitude. | ||
@property(nonatomic, getter=isCameraAltitudeAffectedByPitch) BOOL cameraAltitudeAffectedByPitch; | ||
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. A more natural name for the getter would be |
||
|
||
@end | ||
|
||
@implementation MGLMapView | ||
|
@@ -536,6 +539,8 @@ - (void)commonInit | |
[self addGestureRecognizer:_twoFingerTap]; | ||
|
||
_hapticFeedbackEnabled = YES; | ||
|
||
_cameraAltitudeAffectedByPitch = YES; | ||
|
||
_decelerationRate = MGLMapViewDecelerationRateNormal; | ||
|
||
|
@@ -2352,7 +2357,8 @@ - (void)resetPosition | |
auto camera = _mbglMap->getStyle().getDefaultCamera(); | ||
CGFloat pitch = *camera.pitch; | ||
CLLocationDirection heading = mbgl::util::wrap(*camera.angle, 0., 360.); | ||
CLLocationDistance distance = MGLAltitudeForZoomLevel(*camera.zoom, pitch, 0, self.frame.size); | ||
CLLocationDegrees pitchForAltitude = self.isCameraAltitudeAffectedByPitch ? pitch : 0.0; | ||
CLLocationDistance distance = MGLAltitudeForZoomLevel(*camera.zoom, pitchForAltitude, 0, self.frame.size); | ||
self.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:MGLLocationCoordinate2DFromLatLng(*camera.center) | ||
fromDistance:distance | ||
pitch:pitch | ||
|
@@ -3257,6 +3263,11 @@ - (void)setCamera:(MGLMapCamera *)camera | |
[self setCamera:camera animated:NO]; | ||
} | ||
|
||
- (void)setCamera:(MGLMapCamera *)camera edgePadding:(UIEdgeInsets)edgePadding | ||
{ | ||
[self setCamera:camera withDuration:0 animationTimingFunction:nil edgePadding:edgePadding completionHandler:nil]; | ||
} | ||
|
||
- (void)setCamera:(MGLMapCamera *)camera animated:(BOOL)animated | ||
{ | ||
[self setCamera:camera withDuration:animated ? MGLAnimationDuration : 0 animationTimingFunction:nil]; | ||
|
@@ -3428,7 +3439,8 @@ - (MGLMapCamera *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOpti | |
double zoomLevel = cameraOptions.zoom ? *cameraOptions.zoom : self.zoomLevel; | ||
CLLocationDirection direction = cameraOptions.angle ? mbgl::util::wrap(-MGLDegreesFromRadians(*cameraOptions.angle), 0., 360.) : self.direction; | ||
CGFloat pitch = cameraOptions.pitch ? MGLDegreesFromRadians(*cameraOptions.pitch) : _mbglMap->getPitch(); | ||
CLLocationDistance altitude = MGLAltitudeForZoomLevel(zoomLevel, pitch, centerCoordinate.latitude, self.frame.size); | ||
CLLocationDegrees pitchForAltitude = self.isCameraAltitudeAffectedByPitch ? pitch : 0.0; | ||
CLLocationDistance altitude = MGLAltitudeForZoomLevel(zoomLevel, pitchForAltitude, centerCoordinate.latitude, self.frame.size); | ||
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. Pitch is by definition affected by zoom level: when the map is tilted and the zoom level changes (whether programmatically or via a gesture), the viewing distance from the focal point and the viewpoint’s distance from the ground (the altitude) both change. These changes affect the camera getters only. So the new property is a strange way of telling the getter to effectively lie about the camera relative to what mbgl thinks the camera is. Is there no way to derive the correct value from the existing return value, perhaps by exposing MGLAltitudeForZoomLevel publicly, as proposed in #5583? 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. I don't think mbgl comes in to this at all. As far as I can tell this is all happening in MGLGeometry in the iOS SDK. The pure values in mbgl are what I want. 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.
This is wrong. 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. If you want to change the zoom level without changing the pitch, set a camera whose pitch is -1. This behavior is documented in MGLMapCamera but it could stand to be documented more discoverably. (If this SDK were written in Swift without regard for Obective-C compatibility, the various properties of MGLMapView would all be optional.) 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. @d-prukop and I chatted about this today. The pitch is considered twice when calculating the camera options, once for setting the camera’s actual pitch and once in calculating the zoom level. I would’ve thought that this is ideal, because the zoom level on a tilted map is really the viewing distance, but I suppose if the intention is to iteratively change the viewing distance by getting and setting the camera iteratively, then there could be a sort of feedback effect. The essence of my concern here is that we’re adding a separate code path for a specific use case. If we really believe that the altitude-to-zoom-level conversion shouldn’t be affected by the pitch, then why not remove the pitch argument from In other words, |
||
return [MGLMapCamera cameraLookingAtCenterCoordinate:centerCoordinate fromDistance:altitude pitch:pitch heading:direction]; | ||
} | ||
|
||
|
@@ -3442,7 +3454,8 @@ - (MGLMapCamera *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOpti | |
options.center = MGLLatLngFromLocationCoordinate2D(camera.centerCoordinate); | ||
} | ||
options.padding = MGLEdgeInsetsFromNSEdgeInsets(insets); | ||
options.zoom = MGLZoomLevelForAltitude(camera.altitude, camera.pitch, | ||
CLLocationDegrees pitch = (self.isCameraAltitudeAffectedByPitch) ? camera.pitch : 0.0; | ||
options.zoom = MGLZoomLevelForAltitude(camera.altitude, pitch, | ||
camera.centerCoordinate.latitude, | ||
self.frame.size); | ||
if (camera.heading >= 0) | ||
|
@@ -5144,10 +5157,11 @@ - (void)didUpdateLocationSignificantlyAnimated:(BOOL)animated | |
MGLMapCamera *camera = self.camera; | ||
camera.centerCoordinate = self.userLocation.location.coordinate; | ||
camera.heading = self.directionByFollowingWithCourse; | ||
CLLocationDegrees pitch = (self.isCameraAltitudeAffectedByPitch) ? camera.pitch : 0.0; | ||
if (self.zoomLevel < MGLMinimumZoomLevelForUserTracking) | ||
{ | ||
camera.altitude = MGLAltitudeForZoomLevel(MGLDefaultZoomLevelForUserTracking, | ||
camera.pitch, | ||
pitch, | ||
camera.centerCoordinate.latitude, | ||
self.frame.size); | ||
} | ||
|
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.
Nit: In this case it may not be necessary to set a specific use case since this falls into the
setCamera
methods.