summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/util/geo.hpp13
-rw-r--r--platform/android/jni.cpp4
-rw-r--r--platform/ios/MGLMapView.mm6
-rw-r--r--platform/ios/MGLMultiPoint.mm1
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp2
-rw-r--r--test/ios/MapViewTests.m6
6 files changed, 20 insertions, 12 deletions
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index 98b5daa6f5..4112b183b2 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -41,12 +41,19 @@ struct ProjectedMeters {
};
struct LatLngBounds {
- LatLng sw = {90, 180};
- LatLng ne = {-90, -180};
+ LatLng sw = {-90, -180};
+ LatLng ne = {90, 180};
- inline LatLngBounds(const LatLng& sw_ = {90, 180}, const LatLng& ne_ = {-90, -180})
+ inline LatLngBounds() {}
+
+ inline LatLngBounds(const LatLng& sw_, const LatLng& ne_)
: sw(sw_), ne(ne_) {}
+ static inline LatLngBounds getExtendable() {
+ LatLngBounds bounds;
+ return { bounds.ne, bounds.sw };
+ }
+
inline operator bool() const {
return sw && ne;
}
diff --git a/platform/android/jni.cpp b/platform/android/jni.cpp
index 1e4c4c05f3..9b80013da2 100644
--- a/platform/android/jni.cpp
+++ b/platform/android/jni.cpp
@@ -1186,9 +1186,7 @@ jlongArray JNICALL nativeGetAnnotationsInBounds(JNIEnv *env, jobject obj, jlong
return nullptr;
}
- mbgl::LatLngBounds bounds;
- bounds.sw = { swLat, swLon };
- bounds.ne = { neLat, neLon };
+ mbgl::LatLngBounds bounds({ swLat, swLon }, { neLat, neLon });
// assume only points for now
std::vector<uint32_t> annotations = nativeMapView->getMap().getPointAnnotationsInBounds(bounds);
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 750f3fabbb..81ec18bb7c 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -1099,7 +1099,7 @@ std::chrono::steady_clock::duration durationInSeconds(float duration)
// figure out what that means in coordinate space
CLLocationCoordinate2D coordinate;
- mbgl::LatLngBounds tapBounds;
+ mbgl::LatLngBounds tapBounds = mbgl::LatLngBounds::getExtendable();
coordinate = [self convertPoint:tapRectLowerLeft toCoordinateFromView:self];
tapBounds.extend(MGLLatLngFromLocationCoordinate2D(coordinate));
@@ -1997,7 +1997,7 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
- (mbgl::LatLngBounds)viewportBounds
{
- mbgl::LatLngBounds bounds;
+ mbgl::LatLngBounds bounds = mbgl::LatLngBounds::getExtendable();
bounds.extend(MGLLatLngFromLocationCoordinate2D(
[self convertPoint:CGPointMake(0, 0) toCoordinateFromView:self]));
@@ -2517,7 +2517,7 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
{
if ( ! annotations || ! annotations.count) return;
- mbgl::LatLngBounds bounds;
+ mbgl::LatLngBounds bounds = mbgl::LatLngBounds::getExtendable();
for (id <MGLAnnotation> annotation in annotations)
{
diff --git a/platform/ios/MGLMultiPoint.mm b/platform/ios/MGLMultiPoint.mm
index 624c1658ad..702932f066 100644
--- a/platform/ios/MGLMultiPoint.mm
+++ b/platform/ios/MGLMultiPoint.mm
@@ -19,6 +19,7 @@
{
_count = count;
_coords = (CLLocationCoordinate2D *)malloc(_count * sizeof(CLLocationCoordinate2D));
+ _bounds = mbgl::LatLngBounds::getExtendable();
for (NSUInteger i = 0; i < _count; i++)
{
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index 43dfb8361b..5b1138a14a 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -68,7 +68,7 @@ AnnotationIDs AnnotationManager::getPointAnnotationsInBounds(const LatLngBounds&
}
LatLngBounds AnnotationManager::getBoundsForAnnotations(const AnnotationIDs& ids) const {
- LatLngBounds result;
+ LatLngBounds result = LatLngBounds::getExtendable();
for (const auto& id : ids) {
if (pointAnnotations.find(id) != pointAnnotations.end()) {
diff --git a/test/ios/MapViewTests.m b/test/ios/MapViewTests.m
index a97f2d817b..01c2beafe2 100644
--- a/test/ios/MapViewTests.m
+++ b/test/ios/MapViewTests.m
@@ -317,12 +317,14 @@ const NSTimeInterval MGLAnimationDurationOverDefault = MGLAnimationDurationDefau
tester.mapView.centerCoordinate = newCenterCoordinate;
- XCTAssertEqual(tester.mapView.centerCoordinate.latitude,
+ XCTAssertEqualWithAccuracy(tester.mapView.centerCoordinate.latitude,
newCenterCoordinate.latitude,
+ 0.001,
@"setting center should change latitude");
- XCTAssertEqual(tester.mapView.centerCoordinate.longitude,
+ XCTAssertEqualWithAccuracy(tester.mapView.centerCoordinate.longitude,
newCenterCoordinate.longitude,
+ 0.001,
@"setting center should change longitude");
}