Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Program against NativeMap #14412

Merged
merged 1 commit into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -155,7 +155,7 @@ private void initialiseMap() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -652,7 +652,7 @@ public void setFocalBearing(double bearing, float focalX, float focalY, long dur
* @return the height of the map
*/
public float getHeight() {
return nativeMapView.getHeight();
return projection.getHeight();
}

/**
Expand All @@ -661,7 +661,7 @@ public float getHeight() {
* @return the width of the map
*/
public float getWidth() {
return nativeMapView.getWidth();
return projection.getWidth();
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,10 @@ List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
@NonNull
long[] queryShapeAnnotations(RectF rectF);

@NonNull
RectF getDensityDependantRectangle(RectF rectangle);

long getNativePtr();

void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,9 @@ public float getPixelRatio() {
return pixelRatio;
}

RectF getDensityDependantRectangle(final RectF rectangle) {
@NonNull
@Override
public RectF getDensityDependantRectangle(final RectF rectangle) {
return new RectF(
rectangle.left / pixelRatio,
rectangle.top / pixelRatio,
Expand Down Expand Up @@ -1358,29 +1360,17 @@ private native Feature[] nativeQueryRenderedFeaturesForBox(float left, float top
@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;
}

//
// Snapshot
//

void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
@Override
public void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
if (checkState("addSnapshotCallback")) {
return;
}
Expand Down Expand Up @@ -1432,10 +1422,6 @@ public void setHasSurface(boolean hasSurface) {
}

public interface ViewCallback {
int getWidth();

int getHeight();

@Nullable
Bitmap getViewContent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
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) {
Expand Down Expand Up @@ -120,14 +122,14 @@ public VisibleRegion getVisibleRegion(boolean ignorePadding) {

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));
Expand Down Expand Up @@ -258,11 +260,11 @@ public PointF toScreenLocation(@NonNull LatLng location) {
}

float getHeight() {
return nativeMapView.getHeight();
return mapView.getHeight();
}

float getWidth() {
return nativeMapView.getWidth();
return mapView.getWidth();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AnnotationManagerTest {

@Test
public void checksAddAMarker() throws Exception {
NativeMapView aNativeMapView = mock(NativeMapView.class);
NativeMap aNativeMapView = mock(NativeMapView.class);
MapView aMapView = mock(MapView.class);
LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>();
IconManager aIconManager = mock(IconManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MapboxMapTest {

private lateinit var mapboxMap: MapboxMap

private lateinit var nativeMapView: NativeMapView
private lateinit var nativeMapView: NativeMap

private lateinit var transform: Transform

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StyleTest {

private lateinit var mapboxMap: MapboxMap

private lateinit var nativeMapView: NativeMapView
private lateinit var nativeMapView: NativeMap

@Before
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.robolectric.RobolectricTestRunner
class TransformTest {

private lateinit var mapView: MapView
private lateinit var nativeMapView: NativeMapView
private lateinit var nativeMapView: NativeMap
private lateinit var transform: Transform

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
abstract class BaseLayerTest {
private lateinit var nativeMapView: NativeMapView
private lateinit var nativeMapView: NativeMap

companion object {
const val WIDTH = 500
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class NativeMapViewTest {

private lateinit var nativeMapView: NativeMapView
private lateinit var nativeMapView: NativeMap

companion object {
const val DELTA = 0.000001
Expand Down