[core] Remove map bearing setters/getters

This commit is contained in:
Bruno de Oliveira Abinader
2019-02-28 12:27:12 +02:00
parent 21a39306da
commit 73ac3c784f
9 changed files with 50 additions and 59 deletions

View File

@@ -100,12 +100,6 @@ public:
// Rotation
void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {});
void setBearing(double degrees, const AnimationOptions& = {});
void setBearing(double degrees, optional<ScreenCoordinate>, const AnimationOptions& = {});
void setBearing(double degrees, const EdgeInsets&, const AnimationOptions& = {});
double getBearing() const;
void resetNorth(const AnimationOptions& = {{mbgl::Milliseconds(500)}});
void resetNorth(const EdgeInsets&, const AnimationOptions& = {{mbgl::Milliseconds(500)}});
// North Orientation
void setNorthOrientation(NorthOrientation);

View File

@@ -439,20 +439,20 @@ void NativeMapView::rotateBy(jni::JNIEnv&, jni::jdouble sx, jni::jdouble sy, jni
}
void NativeMapView::setBearing(jni::JNIEnv&, jni::jdouble degrees, jni::jlong duration) {
map->setBearing(degrees, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
map->easeTo(mbgl::CameraOptions().withAngle(degrees), mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
}
void NativeMapView::setBearingXY(jni::JNIEnv&, jni::jdouble degrees, jni::jdouble cx, jni::jdouble cy, jni::jlong duration) {
mbgl::ScreenCoordinate center(cx, cy);
map->setBearing(degrees, center, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
mbgl::ScreenCoordinate anchor(cx, cy);
map->easeTo(mbgl::CameraOptions().withAngle(degrees).withAnchor(anchor), mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
}
jni::jdouble NativeMapView::getBearing(jni::JNIEnv&) {
return map->getBearing();
return *map->getCameraOptions().angle;
}
void NativeMapView::resetNorth(jni::JNIEnv&) {
map->resetNorth();
map->easeTo(mbgl::CameraOptions().withAngle(0.0), mbgl::AnimationOptions {{mbgl::Milliseconds(500)}});
}
void NativeMapView::setVisibleCoordinateBounds(JNIEnv& env, const jni::Array<jni::Object<LatLng>>& coordinates, const jni::Object<RectF>& padding, jdouble direction, jni::jlong duration) {

View File

@@ -209,7 +209,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
#endif // MBGL_USE_GLES2
case GLFW_KEY_N:
if (!mods)
view->map->resetNorth();
view->map->easeTo(mbgl::CameraOptions().withAngle(0.0), mbgl::AnimationOptions {{mbgl::Milliseconds(500)}});
break;
case GLFW_KEY_Z:
view->nextOrientation();
@@ -267,13 +267,15 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
routeProgress = 0.0;
}
auto camera = routeMap->getCameraOptions();
auto point = ruler.along(lineString, routeProgress * routeDistance);
const mbgl::LatLng center { point.y, point.x };
auto latLng = routeMap->getLatLng();
auto latLng = *camera.center;
double bearing = ruler.bearing({ latLng.longitude(), latLng.latitude() }, point);
double easing = bearing - routeMap->getBearing();
double easing = bearing - *camera.angle;
easing += easing > 180.0 ? -360.0 : easing < -180 ? 360.0 : 0;
bearing = routeMap->getBearing() + (easing / 20);
bearing = *camera.angle + (easing / 20);
routeMap->jumpTo(mbgl::CameraOptions().withCenter(center).withZoom(18.0).withAngle(bearing).withPitch(60.0));
};
view->animateRouteCallback(view->map);

View File

@@ -1775,7 +1775,7 @@ public:
{
[self trackGestureEvent:MMEEventGestureRotateStart forRecognizer:rotate];
self.angle = MGLRadiansFromDegrees(self.mbglMap.getBearing()) * -1;
self.angle = MGLRadiansFromDegrees(*self.mbglMap.getCameraOptions().angle) * -1;
if (self.userTrackingMode != MGLUserTrackingModeNone)
{
@@ -1802,7 +1802,9 @@ public:
if ([self _shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
self.mbglMap.setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
self.mbglMap.jumpTo(mbgl::CameraOptions()
.withAngle(newDegrees)
.withAnchor(mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y}));
}
[self cameraIsChanging];
@@ -1837,8 +1839,11 @@ public:
if ([self _shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
self.mbglMap.setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationFromTimeInterval(decelerationRate));
self.mbglMap.easeTo(mbgl::CameraOptions()
.withAngle(newDegrees)
.withAnchor(mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }),
MGLDurationFromTimeInterval(decelerationRate));
[self notifyGestureDidEndWithDrift:YES];
__weak MGLMapView *weakSelf = self;
@@ -3486,7 +3491,7 @@ public:
- (CLLocationDirection)direction
{
return mbgl::util::wrap(self.mbglMap.getBearing(), 0., 360.);
return *self.mbglMap.getCameraOptions().angle;
}
- (void)setDirection:(CLLocationDirection)direction animated:(BOOL)animated
@@ -3518,15 +3523,18 @@ public:
if (self.userTrackingMode == MGLUserTrackingModeNone)
{
self.mbglMap.setBearing(direction,
MGLEdgeInsetsFromNSEdgeInsets(self.contentInset),
MGLDurationFromTimeInterval(duration));
self.mbglMap.easeTo(mbgl::CameraOptions()
.withAngle(direction)
.withPadding(MGLEdgeInsetsFromNSEdgeInsets(self.contentInset)),
MGLDurationFromTimeInterval(duration));
}
else
{
CGPoint centerPoint = self.userLocationAnnotationViewCenter;
self.mbglMap.setBearing(direction, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y },
MGLDurationFromTimeInterval(duration));
CGPoint anchor = self.userLocationAnnotationViewCenter;
self.mbglMap.easeTo(mbgl::CameraOptions()
.withAngle(direction)
.withAnchor(mbgl::ScreenCoordinate { anchor.x, anchor.y }),
MGLDurationFromTimeInterval(duration));
}
}

View File

@@ -1124,7 +1124,7 @@ public:
}
- (CLLocationDirection)direction {
return mbgl::util::wrap(_mbglMap->getBearing(), 0., 360.);
return *_mbglMap->getCameraOptions().angle;
}
- (void)setDirection:(CLLocationDirection)direction {
@@ -1135,14 +1135,15 @@ public:
- (void)setDirection:(CLLocationDirection)direction animated:(BOOL)animated {
MGLLogDebug(@"Setting direction: %f animated: %@", direction, MGLStringFromBOOL(animated));
[self willChangeValueForKey:@"direction"];
_mbglMap->setBearing(direction,
MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets),
MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
_mbglMap->easeTo(mbgl::CameraOptions()
.withAngle(direction)
.withPadding(MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets)),
MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
[self didChangeValueForKey:@"direction"];
}
- (void)offsetDirectionBy:(CLLocationDegrees)delta animated:(BOOL)animated {
[self setDirection:_mbglMap->getBearing() + delta animated:animated];
[self setDirection:*_mbglMap->getCameraOptions().angle + delta animated:animated];
}
+ (NSSet<NSString *> *)keyPathsForValuesAffectingCamera {
@@ -1486,7 +1487,7 @@ public:
if (self.rotateEnabled) {
CLLocationDirection newDirection = _directionAtBeginningOfGesture - delta.x / 10;
[self willChangeValueForKey:@"direction"];
_mbglMap->setBearing(newDirection, center);
_mbglMap->jumpTo(mbgl::CameraOptions().withAngle(newDirection).withAnchor(center));
didChangeCamera = YES;
[self didChangeValueForKey:@"direction"];
}
@@ -1623,8 +1624,10 @@ public:
MGLMapCamera *oldCamera = self.camera;
NSPoint rotationPoint = [gestureRecognizer locationInView:self];
mbgl::ScreenCoordinate center(rotationPoint.x, self.bounds.size.height - rotationPoint.y);
_mbglMap->setBearing(_directionAtBeginningOfGesture + gestureRecognizer.rotationInDegrees, center);
mbgl::ScreenCoordinate anchor(rotationPoint.x, self.bounds.size.height - rotationPoint.y);
_mbglMap->jumpTo(mbgl::CameraOptions()
.withAngle(_directionAtBeginningOfGesture + gestureRecognizer.rotationInDegrees)
.withAnchor(anchor));
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:self.camera]) {

View File

@@ -976,7 +976,7 @@ void NodeMap::SetBearing(const Nan::FunctionCallbackInfo<v8::Value>& info) {
}
try {
nodeMap->map->setBearing(info[0]->NumberValue());
nodeMap->map->jumpTo(mbgl::CameraOptions().withAngle(info[0]->NumberValue()));
} catch (const std::exception &ex) {
return Nan::ThrowError(ex.what());
}

View File

@@ -855,17 +855,21 @@ void QMapboxGL::jumpTo(const QMapboxGLCameraOptions& camera)
*/
double QMapboxGL::bearing() const
{
return d_ptr->mapObj->getBearing();
return *d_ptr->mapObj->getCameraOptions().angle;
}
void QMapboxGL::setBearing(double degrees)
{
d_ptr->mapObj->setBearing(degrees, d_ptr->margins);
d_ptr->mapObj->jumpTo(mbgl::CameraOptions()
.withAngle(degrees)
.withPadding(d_ptr->margins));
}
void QMapboxGL::setBearing(double degrees, const QPointF &center)
{
d_ptr->mapObj->setBearing(degrees, mbgl::ScreenCoordinate { center.x(), center.y() });
d_ptr->mapObj->jumpTo(mbgl::CameraOptions()
.withAngle(degrees)
.withAnchor(mbgl::ScreenCoordinate { center.x(), center.y() }));
}
/*!

View File

@@ -369,26 +369,6 @@ void Map::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second
impl->onUpdate();
}
void Map::setBearing(double degrees, const AnimationOptions& animation) {
easeTo(CameraOptions().withAngle(degrees), animation);
}
void Map::setBearing(double degrees, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
return easeTo(CameraOptions().withAngle(degrees).withAnchor(anchor), animation);
}
void Map::setBearing(double degrees, const EdgeInsets& padding, const AnimationOptions& animation) {
easeTo(CameraOptions().withAngle(degrees).withPadding(padding), animation);
}
double Map::getBearing() const {
return -impl->transform.getAngle() * util::RAD2DEG;
}
void Map::resetNorth(const AnimationOptions& animation) {
easeTo(CameraOptions().withAngle(0.0), animation);
}
#pragma mark - North Orientation
void Map::setNorthOrientation(NorthOrientation orientation) {

View File

@@ -418,7 +418,7 @@ TEST(Annotations, VisibleFeatures) {
}
// Change bearing *after* adding annotations causes them to be reordered.
test.map.setBearing(45);
test.map.jumpTo(CameraOptions().withAngle(45.0));
test.frontend.render(test.map);
auto features = test.frontend.getRenderer()->queryRenderedFeatures(box, {});