[core] Remove map coordinate setters/getters
This commit is contained in:
@@ -75,10 +75,6 @@ public:
|
||||
|
||||
// Position
|
||||
void moveBy(const ScreenCoordinate&, const AnimationOptions& = {});
|
||||
void setLatLng(const LatLng&, const EdgeInsets&, const AnimationOptions& = {});
|
||||
void setLatLng(const LatLng&, const AnimationOptions& = {});
|
||||
LatLng getLatLng(const EdgeInsets& = {}) const;
|
||||
void resetPosition(const EdgeInsets& = {});
|
||||
|
||||
// Zoom
|
||||
void scaleBy(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation = {});
|
||||
|
||||
@@ -366,11 +366,12 @@ void NativeMapView::flyTo(jni::JNIEnv&, jni::jdouble bearing, jni::jdouble latit
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<LatLng>> NativeMapView::getLatLng(JNIEnv& env) {
|
||||
return LatLng::New(env, map->getLatLng(insets));
|
||||
return LatLng::New(env, *map->getCameraOptions(insets).center);
|
||||
}
|
||||
|
||||
void NativeMapView::setLatLng(jni::JNIEnv&, jni::jdouble latitude, jni::jdouble longitude, jni::jlong duration) {
|
||||
map->setLatLng(mbgl::LatLng(latitude, longitude), insets, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
|
||||
map->easeTo(mbgl::CameraOptions().withCenter(mbgl::LatLng(latitude, longitude)).withPadding(insets),
|
||||
mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<CameraPosition>> NativeMapView::getCameraForLatLngBounds(jni::JNIEnv& env, const jni::Object<LatLngBounds>& jBounds, double top, double left, double bottom, double right, double bearing, double tilt) {
|
||||
@@ -391,7 +392,7 @@ void NativeMapView::setReachability(jni::JNIEnv&, jni::jboolean reachable) {
|
||||
}
|
||||
|
||||
void NativeMapView::resetPosition(jni::JNIEnv&) {
|
||||
map->resetPosition();
|
||||
map->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng {}).withZoom(0.0).withBearing(0.0).withPitch(0.0));
|
||||
}
|
||||
|
||||
jni::jdouble NativeMapView::getPitch(jni::JNIEnv&) {
|
||||
|
||||
@@ -82,7 +82,7 @@ void MapSnapshotter::Impl::snapshot(ActorRef<MapSnapshotter::Callback> callback)
|
||||
// and can be used to translate for geographic to screen
|
||||
// coordinates
|
||||
assert (frontend.getTransformState());
|
||||
PointForFn pointForFn { [=, center=map.getLatLng(), transformState = *frontend.getTransformState()] (const LatLng& latLng) {
|
||||
PointForFn pointForFn { [=, center = *map.getCameraOptions().center, transformState = *frontend.getTransformState()] (const LatLng& latLng) {
|
||||
LatLng unwrappedLatLng = latLng.wrapped();
|
||||
unwrappedLatLng.unwrapForShortestPath(center);
|
||||
Transform transform { transformState };
|
||||
|
||||
@@ -184,7 +184,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
|
||||
break;
|
||||
case GLFW_KEY_X:
|
||||
if (!mods)
|
||||
view->map->resetPosition();
|
||||
view->map->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng {}).withZoom(0.0).withBearing(0.0).withPitch(0.0));
|
||||
break;
|
||||
case GLFW_KEY_O:
|
||||
view->onlineStatusCallback();
|
||||
|
||||
@@ -1697,8 +1697,10 @@ public:
|
||||
if (self.userTrackingMode == MGLUserTrackingModeNone && pinch.numberOfTouches == _previousPinchNumberOfTouches)
|
||||
{
|
||||
CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
|
||||
self.mbglMap.setLatLng(MGLLatLngFromLocationCoordinate2D(centerCoordinate),
|
||||
mbgl::EdgeInsets { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x });
|
||||
mbgl::EdgeInsets padding { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x };
|
||||
self.mbglMap.jumpTo(mbgl::CameraOptions()
|
||||
.withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate))
|
||||
.withPadding(padding));
|
||||
}
|
||||
}
|
||||
[self cameraIsChanging];
|
||||
@@ -3177,7 +3179,7 @@ public:
|
||||
- (CLLocationCoordinate2D)centerCoordinate
|
||||
{
|
||||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
|
||||
return MGLLocationCoordinate2DFromLatLng(self.mbglMap.getLatLng(padding));
|
||||
return MGLLocationCoordinate2DFromLatLng(*self.mbglMap.getCameraOptions(padding).center);
|
||||
}
|
||||
|
||||
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel animated:(BOOL)animated
|
||||
@@ -3795,7 +3797,7 @@ public:
|
||||
}
|
||||
|
||||
mbgl::CameraOptions mapCamera = self.mbglMap.getCameraOptions();
|
||||
CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : self.mbglMap.getLatLng());
|
||||
CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : *mapCamera.center);
|
||||
double zoomLevel = cameraOptions.zoom ? *cameraOptions.zoom : self.zoomLevel;
|
||||
CLLocationDirection direction = cameraOptions.bearing ? mbgl::util::wrap(*cameraOptions.bearing, 0., 360.) : self.direction;
|
||||
CGFloat pitch = cameraOptions.pitch ? *cameraOptions.pitch : *mapCamera.pitch;
|
||||
|
||||
@@ -996,7 +996,7 @@ public:
|
||||
|
||||
- (CLLocationCoordinate2D)centerCoordinate {
|
||||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets);
|
||||
return MGLLocationCoordinate2DFromLatLng(_mbglMap->getLatLng(padding));
|
||||
return MGLLocationCoordinate2DFromLatLng(*_mbglMap->getCameraOptions(padding).center);
|
||||
}
|
||||
|
||||
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate {
|
||||
@@ -1007,9 +1007,10 @@ public:
|
||||
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate animated:(BOOL)animated {
|
||||
MGLLogDebug(@"Setting centerCoordinate: %@ animated: %@", MGLStringFromCLLocationCoordinate2D(centerCoordinate), MGLStringFromBOOL(animated));
|
||||
[self willChangeValueForKey:@"centerCoordinate"];
|
||||
_mbglMap->setLatLng(MGLLatLngFromLocationCoordinate2D(centerCoordinate),
|
||||
MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets),
|
||||
MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
|
||||
_mbglMap->easeTo(mbgl::CameraOptions()
|
||||
.withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate))
|
||||
.withPadding(MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets)),
|
||||
MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
|
||||
[self didChangeValueForKey:@"centerCoordinate"];
|
||||
}
|
||||
|
||||
@@ -1359,7 +1360,7 @@ public:
|
||||
|
||||
- (MGLMapCamera *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOptions {
|
||||
mbgl::CameraOptions mapCamera = _mbglMap->getCameraOptions();
|
||||
CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : _mbglMap->getLatLng());
|
||||
CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : *mapCamera.center);
|
||||
double zoomLevel = cameraOptions.zoom ? *cameraOptions.zoom : self.zoomLevel;
|
||||
CLLocationDirection direction = cameraOptions.bearing ? mbgl::util::wrap(*cameraOptions.bearing, 0., 360.) : self.direction;
|
||||
CGFloat pitch = cameraOptions.pitch ? *cameraOptions.pitch : *mapCamera.pitch;
|
||||
|
||||
@@ -942,7 +942,7 @@ void NodeMap::SetCenter(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
||||
if (center->Length() > 1) { latitude = Nan::Get(center, 1).ToLocalChecked()->NumberValue(); }
|
||||
|
||||
try {
|
||||
nodeMap->map->setLatLng(mbgl::LatLng { latitude, longitude });
|
||||
nodeMap->map->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng { latitude, longitude }));
|
||||
} catch (const std::exception &ex) {
|
||||
return Nan::ThrowError(ex.what());
|
||||
}
|
||||
|
||||
@@ -685,12 +685,12 @@ void QMapboxGL::setStyleUrl(const QString &url)
|
||||
*/
|
||||
double QMapboxGL::latitude() const
|
||||
{
|
||||
return d_ptr->mapObj->getLatLng(d_ptr->margins).latitude();
|
||||
return d_ptr->mapObj->getCameraOptions(d_ptr->margins).center->latitude();
|
||||
}
|
||||
|
||||
void QMapboxGL::setLatitude(double latitude_)
|
||||
{
|
||||
d_ptr->mapObj->setLatLng(mbgl::LatLng { latitude_, longitude() }, d_ptr->margins);
|
||||
d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng { latitude_, longitude() }).withPadding(d_ptr->margins));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -703,12 +703,12 @@ void QMapboxGL::setLatitude(double latitude_)
|
||||
*/
|
||||
double QMapboxGL::longitude() const
|
||||
{
|
||||
return d_ptr->mapObj->getLatLng(d_ptr->margins).longitude();
|
||||
return d_ptr->mapObj->getCameraOptions(d_ptr->margins).center->longitude();
|
||||
}
|
||||
|
||||
void QMapboxGL::setLongitude(double longitude_)
|
||||
{
|
||||
d_ptr->mapObj->setLatLng(mbgl::LatLng { latitude(), longitude_ }, d_ptr->margins);
|
||||
d_ptr->mapObj->jumpTo(mbgl::CameraOptions().withCenter(mbgl::LatLng { latitude(), longitude_ }).withPadding(d_ptr->margins));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -784,13 +784,15 @@ double QMapboxGL::maximumZoom() const
|
||||
*/
|
||||
Coordinate QMapboxGL::coordinate() const
|
||||
{
|
||||
const mbgl::LatLng& latLng = d_ptr->mapObj->getLatLng(d_ptr->margins);
|
||||
const mbgl::LatLng& latLng = *d_ptr->mapObj->getCameraOptions(d_ptr->margins).center;
|
||||
return Coordinate(latLng.latitude(), latLng.longitude());
|
||||
}
|
||||
|
||||
void QMapboxGL::setCoordinate(const QMapbox::Coordinate &coordinate_)
|
||||
{
|
||||
d_ptr->mapObj->setLatLng(mbgl::LatLng { coordinate_.first, coordinate_.second }, d_ptr->margins);
|
||||
d_ptr->mapObj->jumpTo(mbgl::CameraOptions()
|
||||
.withCenter(mbgl::LatLng { coordinate_.first, coordinate_.second })
|
||||
.withPadding(d_ptr->margins));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -167,24 +167,6 @@ void Map::moveBy(const ScreenCoordinate& point, const AnimationOptions& animatio
|
||||
impl->onUpdate();
|
||||
}
|
||||
|
||||
void Map::setLatLng(const LatLng& latLng, const AnimationOptions& animation) {
|
||||
easeTo(CameraOptions().withCenter(latLng), animation);
|
||||
}
|
||||
|
||||
void Map::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const AnimationOptions& animation) {
|
||||
easeTo(CameraOptions().withCenter(latLng).withPadding(padding), animation);
|
||||
}
|
||||
|
||||
LatLng Map::getLatLng(const EdgeInsets& padding) const {
|
||||
return impl->transform.getLatLng(padding);
|
||||
}
|
||||
|
||||
void Map::resetPosition(const EdgeInsets& padding) {
|
||||
impl->cameraMutated = true;
|
||||
impl->transform.jumpTo(CameraOptions().withCenter(LatLng()).withPadding(padding).withZoom(0.0).withBearing(0.0).withPitch(0.0));
|
||||
impl->onUpdate();
|
||||
}
|
||||
|
||||
#pragma mark - Zoom
|
||||
|
||||
void Map::scaleBy(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
|
||||
@@ -438,7 +420,7 @@ ScreenCoordinate Map::pixelForLatLng(const LatLng& latLng) const {
|
||||
// antimeridian, we unwrap the point longitude so it would be seen if
|
||||
// e.g. the next antimeridian side is visible.
|
||||
LatLng unwrappedLatLng = latLng.wrapped();
|
||||
unwrappedLatLng.unwrapForShortestPath(getLatLng());
|
||||
unwrappedLatLng.unwrapForShortestPath(impl->transform.getLatLng());
|
||||
return impl->transform.latLngToScreenCoordinate(unwrappedLatLng);
|
||||
}
|
||||
|
||||
|
||||
@@ -127,10 +127,10 @@ TEST(Map, LatLngBehavior) {
|
||||
MapTest<> test;
|
||||
|
||||
test.map.jumpTo(CameraOptions().withCenter(LatLng { 1.0, 1.0 }).withZoom(0.0));
|
||||
auto latLng1 = test.map.getLatLng();
|
||||
auto latLng1 = *test.map.getCameraOptions().center;
|
||||
|
||||
test.map.setLatLng({ 1, 1 });
|
||||
auto latLng2 = test.map.getLatLng();
|
||||
test.map.jumpTo(CameraOptions().withCenter(LatLng { 1.0, 1.0 }));
|
||||
auto latLng2 = *test.map.getCameraOptions().center;
|
||||
|
||||
ASSERT_DOUBLE_EQ(latLng1.latitude(), latLng2.latitude());
|
||||
ASSERT_DOUBLE_EQ(latLng1.longitude(), latLng2.longitude());
|
||||
|
||||
Reference in New Issue
Block a user