summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/util/geo.hpp12
-rw-r--r--src/mbgl/map/transform.cpp8
2 files changed, 18 insertions, 2 deletions
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index 307134f666..bfcb84bd7c 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -14,6 +14,10 @@ struct LatLng {
inline LatLng(double lat = 0, double lon = 0)
: latitude(lat), longitude(lon) {}
+ inline bool isValid() const {
+ return !(std::isnan(latitude) || std::isnan(longitude));
+ }
+
// Constructs a LatLng object with the top left position of the specified tile.
LatLng(const TileID& id);
@@ -26,6 +30,10 @@ struct ProjectedMeters {
inline ProjectedMeters(double n = 0, double e = 0)
: northing(n), easting(e) {}
+
+ inline bool isValid() const {
+ return !(std::isnan(northing) || std::isnan(easting));
+ }
};
struct LatLngBounds {
@@ -35,6 +43,10 @@ struct LatLngBounds {
inline LatLngBounds(LatLng sw_ = {90, 180}, LatLng ne_ = {-90, -180})
: sw(sw_), ne(ne_) {}
+ inline bool isValid() const {
+ return sw.isValid() && ne.isValid();
+ }
+
// Constructs a LatLngBounds object with the tile's exact boundaries.
LatLngBounds(const TileID& id);
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index f0c5a136e0..1a6cbb77be 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -65,7 +65,7 @@ void Transform::easeTo(CameraOptions options) {
LatLng latLng = options.center ? *options.center : getLatLng();
double zoom = options.zoom ? *options.zoom : getZoom();
double angle = options.angle ? *options.angle : getAngle();
- if (std::isnan(latLng.latitude) || std::isnan(latLng.longitude) || std::isnan(zoom)) {
+ if (!latLng.isValid() || std::isnan(zoom)) {
return;
}
@@ -108,6 +108,10 @@ void Transform::_moveBy(const double dx, const double dy, const Duration& durati
}
void Transform::setLatLng(const LatLng latLng, const Duration& duration) {
+ if (!latLng.isValid()) {
+ return;
+ }
+
CameraOptions options;
options.center = latLng;
options.duration = duration;
@@ -115,7 +119,7 @@ void Transform::setLatLng(const LatLng latLng, const Duration& duration) {
}
void Transform::setLatLng(const LatLng latLng, vec2<double> point, const Duration& duration) {
- if (std::isnan(latLng.latitude) || std::isnan(latLng.longitude)) {
+ if (!latLng.isValid()) {
return;
}