[projection] add bulk conversion of geographic coordinates to screen coordinates with reusable objects (#91)

This commit is contained in:
Tobrun
2019-12-06 15:30:36 +01:00
committed by GitHub
parent c51eab4001
commit c85c99f8e8
6 changed files with 164 additions and 1 deletions

View File

@@ -193,8 +193,12 @@ interface NativeMap {
@NonNull
PointF pixelForLatLng(@NonNull LatLng latLng);
void pixelsForLatLngs(@NonNull double[] input, @NonNull double[] output);
LatLng latLngForPixel(@NonNull PointF pixel);
void latLngsForPixels(@NonNull double[] input, @NonNull double[] output);
//
// Utils API
//

View File

@@ -651,6 +651,13 @@ final class NativeMapView implements NativeMap {
return pointF;
}
@Override
public void pixelsForLatLngs(@NonNull double[] input, @NonNull double[] output) {
if (!checkState("pixelsForLatLngs")) {
nativePixelsForLatLngs(input, output, pixelRatio);
}
}
@Override
public LatLng latLngForPixel(@NonNull PointF pixel) {
if (checkState("latLngForPixel")) {
@@ -659,6 +666,14 @@ final class NativeMapView implements NativeMap {
return nativeLatLngForPixel(pixel.x / pixelRatio, pixel.y / pixelRatio);
}
@Override
public void latLngsForPixels(@NonNull double[] input, @NonNull double[] output) {
if (!checkState("latLngsForPixels")) {
nativeLatLngsForPixels(input, output, pixelRatio);
}
}
@Override
public double getTopOffsetPixelsForAnnotationSymbol(String symbolName) {
if (checkState("getTopOffsetPixelsForAnnotationSymbol")) {
@@ -1275,10 +1290,16 @@ final class NativeMapView implements NativeMap {
@Keep
private native PointF nativePixelForLatLng(double lat, double lon);
@Keep
private native void nativePixelsForLatLngs(double[] input, double[] output, float pixelRatio);
@NonNull
@Keep
private native LatLng nativeLatLngForPixel(float x, float y);
@Keep
private native void nativeLatLngsForPixels(double[] input, double[] output, float pixelRatio);
@Keep
private native double nativeGetTopOffsetPixelsForAnnotationSymbol(String symbolName);

View File

@@ -95,6 +95,19 @@ public class Projection {
return nativeMapView.latLngForPixel(point);
}
/**
* Returns the geographic locations that corresponds to screen locations.
* The screen locations are specified in screen pixels (not display pixels) relative to the
* top left of the map (not the top left of the whole screen).
*
* @param input an array of input values representing screen coordinates
* @param output an array of output values representing geographic locations
*/
public void fromScreenLocations(@NonNull double[] input, @NonNull double[] output) {
nativeMapView.latLngsForPixels(input, output);
}
/**
* Gets a projection of the viewing frustum for converting between screen coordinates and
* geo-latitude/longitude coordinates.
@@ -263,6 +276,18 @@ public class Projection {
return nativeMapView.pixelForLatLng(location);
}
/**
* Returns a screen locations that corresponds to a geographical coordinates.
* The screen locations are in screen pixels (not display pixels) relative to the top left
* of the map (not of the whole screen).
*
* @param input an array of input values representing geographic locations
* @param output an array of output values representing screen coordinates
*/
public void toScreenLocations(@NonNull double[] input, @NonNull double[] output) {
nativeMapView.pixelsForLatLngs(input, output);
}
float getHeight() {
return mapView.getHeight();
}