[android] - program against NativeMap interface

This commit is contained in:
tobrun
2019-04-12 14:49:14 +02:00
committed by Tobrun
parent 58da07b563
commit 278d856372
13 changed files with 41 additions and 47 deletions

View File

@@ -65,7 +65,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
private final InitialRenderCallback initialRenderCallback = new InitialRenderCallback();
@Nullable
private NativeMapView nativeMapView;
private NativeMap nativeMapView;
@Nullable
private MapboxMap mapboxMap;
private AttributionClickListener attributionClickListener;
@@ -155,7 +155,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
final CameraChangeDispatcher cameraDispatcher = new CameraChangeDispatcher();
// setup components for MapboxMap creation
Projection proj = new Projection(nativeMapView);
Projection proj = new Projection(nativeMapView, this);
UiSettings uiSettings = new UiSettings(proj, focalInvalidator, compassView, attrView, logoView, getPixelRatio());
LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>();
IconManager iconManager = new IconManager(nativeMapView);

View File

@@ -56,7 +56,7 @@ public final class MapboxMap {
private static final String TAG = "Mbgl-MapboxMap";
private final NativeMapView nativeMapView;
private final NativeMap nativeMapView;
private final UiSettings uiSettings;
private final Projection projection;
private final Transform transform;
@@ -78,7 +78,7 @@ public final class MapboxMap {
private boolean debugActive;
MapboxMap(NativeMapView map, Transform transform, UiSettings ui, Projection projection,
MapboxMap(NativeMap map, Transform transform, UiSettings ui, Projection projection,
OnGesturesManagerInteractionListener listener, CameraChangeDispatcher cameraChangeDispatcher) {
this.nativeMapView = map;
this.uiSettings = ui;
@@ -652,7 +652,7 @@ public final class MapboxMap {
* @return the height of the map
*/
public float getHeight() {
return nativeMapView.getHeight();
return projection.getHeight();
}
/**
@@ -661,7 +661,7 @@ public final class MapboxMap {
* @return the width of the map
*/
public float getWidth() {
return nativeMapView.getWidth();
return projection.getWidth();
}
//

View File

@@ -17,11 +17,11 @@ import java.util.List;
*/
class MarkerContainer implements Markers {
private final NativeMapView nativeMapView;
private final NativeMap nativeMapView;
private final LongSparseArray<Annotation> annotations;
private final IconManager iconManager;
MarkerContainer(NativeMapView nativeMapView, LongSparseArray<Annotation> annotations, IconManager iconManager) {
MarkerContainer(NativeMap nativeMapView, LongSparseArray<Annotation> annotations, IconManager iconManager) {
this.nativeMapView = nativeMapView;
this.annotations = annotations;
this.iconManager = iconManager;

View File

@@ -263,4 +263,10 @@ interface NativeMap {
@NonNull
long[] queryShapeAnnotations(RectF rectF);
@NonNull
RectF getDensityDependantRectangle(RectF rectangle);
long getNativePtr();
void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback);
}

View File

@@ -940,7 +940,9 @@ final class NativeMapView implements NativeMap {
return pixelRatio;
}
RectF getDensityDependantRectangle(final RectF rectangle) {
@NonNull
@Override
public RectF getDensityDependantRectangle(final RectF rectangle) {
return new RectF(
rectangle.left / pixelRatio,
rectangle.top / pixelRatio,
@@ -1373,21 +1375,8 @@ final class NativeMapView implements NativeMap {
@Keep
private native boolean nativeGetPrefetchTiles();
int getWidth() {
if (checkState("") || viewCallback == null) {
return 0;
}
return viewCallback.getWidth();
}
int getHeight() {
if (checkState("") || viewCallback == null) {
return 0;
}
return viewCallback.getHeight();
}
long getNativePtr() {
@Override
public long getNativePtr() {
return nativePtr;
}
@@ -1395,7 +1384,8 @@ final class NativeMapView implements NativeMap {
// Snapshot
//
void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
@Override
public void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
if (checkState("addSnapshotCallback")) {
return;
}
@@ -1447,10 +1437,6 @@ final class NativeMapView implements NativeMap {
}
public interface ViewCallback {
int getWidth();
int getHeight();
@Nullable
Bitmap getViewContent();
}

View File

@@ -21,12 +21,14 @@ import java.util.List;
public class Projection {
@NonNull
private final NativeMapView nativeMapView;
private int[] contentPadding;
private final NativeMap nativeMapView;
@NonNull
private final MapView mapView;
private int[] contentPadding = new int[] {0, 0, 0, 0};
Projection(@NonNull NativeMapView nativeMapView) {
Projection(@NonNull NativeMap nativeMapView, @NonNull MapView mapView) {
this.nativeMapView = nativeMapView;
this.contentPadding = new int[] {0, 0, 0, 0};
this.mapView = mapView;
}
void setContentPadding(int[] contentPadding) {
@@ -120,14 +122,14 @@ public class Projection {
if (ignorePadding) {
left = 0;
right = nativeMapView.getWidth();
right = mapView.getWidth();
top = 0;
bottom = nativeMapView.getHeight();
bottom = mapView.getHeight();
} else {
left = (float) contentPadding[0];
right = (float) (nativeMapView.getWidth() - contentPadding[2]);
right = (float) (mapView.getWidth() - contentPadding[2]);
top = (float) contentPadding[1];
bottom = (float) (nativeMapView.getHeight() - contentPadding[3]);
bottom = (float) (mapView.getHeight() - contentPadding[3]);
}
LatLng center = fromScreenLocation(new PointF(left + (right - left) / 2, top + (bottom - top) / 2));
@@ -258,11 +260,11 @@ public class Projection {
}
float getHeight() {
return nativeMapView.getHeight();
return mapView.getHeight();
}
float getWidth() {
return nativeMapView.getWidth();
return mapView.getWidth();
}
/**

View File

@@ -11,10 +11,10 @@ import java.util.List;
class ShapeAnnotationContainer implements ShapeAnnotations {
private final NativeMapView nativeMapView;
private final NativeMap nativeMapView;
private final LongSparseArray<Annotation> annotations;
ShapeAnnotationContainer(NativeMapView nativeMapView, LongSparseArray<Annotation> annotations) {
ShapeAnnotationContainer(NativeMap nativeMapView, LongSparseArray<Annotation> annotations) {
this.nativeMapView = nativeMapView;
this.annotations = annotations;
}