[core] Fix LatLngBounds default coordinates
LatLngBounds southwest and northeast coordinate points were inverted, so they could be extended via LatLngBounds::extend(). However, this looks confusing and error-prone. A static LatLngBounds::getExtendable() is added to address cases when we want to extend LatLngBounds.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
{
|
||||
_count = count;
|
||||
_coords = (CLLocationCoordinate2D *)malloc(_count * sizeof(CLLocationCoordinate2D));
|
||||
_bounds = mbgl::LatLngBounds::getExtendable();
|
||||
|
||||
for (NSUInteger i = 0; i < _count; i++)
|
||||
{
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user