GeoPointUtils: calculate scale to display a BoundingBox #396
This commit is contained in:
parent
4f7675d2a8
commit
8ad2036ec1
@ -15,8 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.utils;
|
package org.oscim.utils;
|
||||||
|
|
||||||
|
import org.oscim.core.BoundingBox;
|
||||||
import org.oscim.core.GeoPoint;
|
import org.oscim.core.GeoPoint;
|
||||||
|
import org.oscim.core.MercatorProjection;
|
||||||
import org.oscim.core.Point;
|
import org.oscim.core.Point;
|
||||||
|
import org.oscim.core.Tile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The coordinate validation functions come from Mapsforge <a href="https://github.com/mapsforge/mapsforge/blob/master/mapsforge-core/src/main/java/org/mapsforge/core/util/LatLongUtils.java">LatLongUtils</a> class.
|
* The coordinate validation functions come from Mapsforge <a href="https://github.com/mapsforge/mapsforge/blob/master/mapsforge-core/src/main/java/org/mapsforge/core/util/LatLongUtils.java">LatLongUtils</a> class.
|
||||||
@ -97,6 +100,28 @@ public final class GeoPointUtils {
|
|||||||
return new Point(startX + t * (endX - startX), startY + t * (endY - startY));
|
return new Point(startX + t * (endX - startX), startY + t * (endY - startY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the scale that allows to display the {@link BoundingBox} on a view with width and
|
||||||
|
* height.
|
||||||
|
*
|
||||||
|
* @param bbox the {@link BoundingBox} to display.
|
||||||
|
* @param viewWidth the width of the view.
|
||||||
|
* @param viewHeight the height of the view.
|
||||||
|
* @return the scale that allows to display the {@link BoundingBox} on a view with width and
|
||||||
|
* height.
|
||||||
|
*/
|
||||||
|
public static double scaleForBounds(BoundingBox bbox, int viewWidth, int viewHeight) {
|
||||||
|
double minx = MercatorProjection.longitudeToX(bbox.getMinLongitude());
|
||||||
|
double miny = MercatorProjection.latitudeToY(bbox.getMaxLatitude());
|
||||||
|
|
||||||
|
double dx = Math.abs(MercatorProjection.longitudeToX(bbox.getMaxLongitude()) - minx);
|
||||||
|
double dy = Math.abs(MercatorProjection.latitudeToY(bbox.getMinLatitude()) - miny);
|
||||||
|
double zx = viewWidth / (dx * Tile.SIZE);
|
||||||
|
double zy = viewHeight / (dy * Tile.SIZE);
|
||||||
|
|
||||||
|
return Math.min(zx, zy);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param latitude the latitude coordinate in degrees which should be validated.
|
* @param latitude the latitude coordinate in degrees which should be validated.
|
||||||
* @return the latitude value
|
* @return the latitude value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user