[android] LatLngBounds.union() should take date line into account

This commit is contained in:
Osana Babayan
2018-02-28 10:10:09 -05:00
committed by GitHub
parent ab27e24ab0
commit f4833a2c4e
3 changed files with 54 additions and 4 deletions

View File

@@ -444,10 +444,21 @@ public class LatLngBounds implements Parcelable {
* @return BoundingBox
*/
public LatLngBounds union(final double latNorth, final double lonEast, final double latSouth, final double lonWest) {
return new LatLngBounds((this.latitudeNorth < latNorth) ? latNorth : this.latitudeNorth,
(this.longitudeEast < lonEast) ? lonEast : this.longitudeEast,
(this.latitudeSouth > latSouth) ? latSouth : this.latitudeSouth,
(this.longitudeWest > lonWest) ? lonWest : this.longitudeWest);
double north = (this.latitudeNorth < latNorth) ? latNorth : this.latitudeNorth;
double south = (this.latitudeSouth > latSouth) ? latSouth : this.latitudeSouth;
if (LatLngSpan.getLongitudeSpan(lonEast, this.longitudeWest)
< LatLngSpan.getLongitudeSpan(this.longitudeEast, lonWest)) {
return new LatLngBounds(north,
lonEast,
south,
this.longitudeWest);
}
return new LatLngBounds(north,
this.longitudeEast,
south,
lonWest);
}
/**

View File

@@ -4,6 +4,8 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.constants.GeometryConstants;
/**
* A geographical span defined by its latitude and longitude span.
*/
@@ -136,4 +138,20 @@ public class LatLngSpan implements Parcelable {
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
/**
* Get the absolute distance, in degrees, between the west and
* east boundaries of this LatLngBounds
*
* @return Span distance
*/
static double getLongitudeSpan(double east, double west) {
double longSpan = Math.abs(east - west);
if (east > west) {
return longSpan;
}
// shortest span contains antimeridian
return GeometryConstants.LONGITUDE_SPAN - longSpan;
}
}