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

[android] Expose pre-fetching zoom delta. #15769

Merged
merged 8 commits into from
Oct 8, 2019
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.graphics.RectF;
import android.os.Bundle;
import android.support.annotation.FloatRange;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.Size;
Expand Down Expand Up @@ -274,6 +275,28 @@ public boolean getPrefetchesTiles() {
return nativeMapView.getPrefetchTiles();
pengdev marked this conversation as resolved.
Show resolved Hide resolved
pengdev marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Set the tile pre-fetching zoom delta. Pre-fetching makes sure that a low-resolution
* tile at the (current_zoom_level - delta) is rendered as soon as possible at the
* expense of a little bandwidth.
*
* @param delta zoom delta
*/
public void setPrefetchZoomDelta(@IntRange(from = 0) int delta) {
nativeMapView.setPrefetchZoomDelta(delta);
}

/**
* Check current pre-fetching zoom delta.
*
* @return current zoom delta.
* @see MapboxMap#setPrefetchZoomDelta(int)
*/
@IntRange(from = 0)
public int getPrefetchZoomDelta() {
return nativeMapView.getPrefetchZoomDelta();
}

//
// MinZoom
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.mapbox.geojson.Feature;
import com.mapbox.geojson.Geometry;
import com.mapbox.mapboxsdk.annotations.Marker;
Expand Down Expand Up @@ -214,6 +215,11 @@ List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,

boolean getPrefetchTiles();

void setPrefetchZoomDelta(@IntRange(from = 0) int delta);

@IntRange(from = 0)
int getPrefetchZoomDelta();

void setGestureInProgress(boolean inProgress);

float getPixelRatio();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,23 @@ public boolean getPrefetchTiles() {
return nativeGetPrefetchTiles();
}

@Override
public void setPrefetchZoomDelta(@IntRange(from = 0) int delta) {
if (checkState("nativeSetPrefetchZoomDelta")) {
return;
}
nativeSetPrefetchZoomDelta(delta);
}

@Override
@IntRange(from = 0)
public int getPrefetchZoomDelta() {
if (checkState("nativeGetPrefetchZoomDelta")) {
return 0;
}
return nativeGetPrefetchZoomDelta();
}

// Runtime style Api

@Override
Expand Down Expand Up @@ -1383,6 +1400,12 @@ private native Feature[] nativeQueryRenderedFeaturesForBox(float left, float top
@Keep
private native boolean nativeGetPrefetchTiles();

@Keep
private native void nativeSetPrefetchZoomDelta(int delta);

@Keep
private native int nativeGetPrefetchZoomDelta();

@Override
public long getNativePtr() {
return nativePtr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ class MapboxMapTest {
verify { nativeMapView.prefetchTiles = true }
}

@Test
fun testGetPrefetchZoomDelta() {
every { nativeMapView.prefetchZoomDelta } answers { 3 }
assertEquals(3, mapboxMap.prefetchZoomDelta)
}

@Test
fun testSetPrefetchZoomDelta() {
mapboxMap.prefetchZoomDelta = 2
verify { nativeMapView.prefetchZoomDelta = 2 }
}

@Test
fun testCameraForLatLngBounds() {
val bounds = LatLngBounds.Builder().include(LatLng()).include(LatLng(1.0, 1.0)).build()
Expand Down
201 changes: 109 additions & 92 deletions platform/android/src/native_map_view.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@
#include "style/conversion/filter.hpp"
#include "geojson/feature.hpp"

#include "jni.hpp"
#include "attach_env.hpp"
#include "map_renderer.hpp"
#include "android_renderer_frontend.hpp"
#include "file_source.hpp"
#include "attach_env.hpp"
#include "bitmap.hpp"
#include "run_loop_impl.hpp"
#include "java/util.hpp"
#include "bitmap_factory.hpp"
#include "file_source.hpp"
#include "geometry/lat_lng_bounds.hpp"
#include "java/util.hpp"
#include "jni.hpp"
#include "map/camera_position.hpp"
#include "map/image.hpp"
#include "map/image.hpp"
#include "map_renderer.hpp"
#include "run_loop_impl.hpp"
#include "style/light.hpp"
#include "bitmap_factory.hpp"

namespace mbgl {
namespace android {
Expand Down Expand Up @@ -1050,6 +1050,14 @@ jni::jboolean NativeMapView::getPrefetchTiles(JNIEnv&) {
return jni::jboolean(map->getPrefetchZoomDelta() > 0);
}

void NativeMapView::setPrefetchZoomDelta(JNIEnv&, jni::jint delta) {
map->setPrefetchZoomDelta(uint8_t(abs(delta)));
pengdev marked this conversation as resolved.
Show resolved Hide resolved
}

jni::jint NativeMapView::getPrefetchZoomDelta(JNIEnv&) {
return jni::jint(map->getPrefetchZoomDelta());
}

mbgl::Map& NativeMapView::getMap() {
return *map;
}
Expand All @@ -1063,90 +1071,99 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)

// Register the peer
jni::RegisterNativePeer<NativeMapView>(env, javaClass, "nativePtr",
jni::MakePeer<NativeMapView, const jni::Object<NativeMapView>&, const jni::Object<FileSource>&, const jni::Object<MapRenderer>&, jni::jfloat, jni::jboolean>,
"nativeInitialize",
"nativeDestroy",
METHOD(&NativeMapView::resizeView, "nativeResizeView"),
METHOD(&NativeMapView::getStyleUrl, "nativeGetStyleUrl"),
METHOD(&NativeMapView::setStyleUrl, "nativeSetStyleUrl"),
METHOD(&NativeMapView::getStyleJson, "nativeGetStyleJson"),
METHOD(&NativeMapView::setStyleJson, "nativeSetStyleJson"),
METHOD(&NativeMapView::cancelTransitions, "nativeCancelTransitions"),
METHOD(&NativeMapView::setGestureInProgress, "nativeSetGestureInProgress"),
METHOD(&NativeMapView::moveBy, "nativeMoveBy"),
METHOD(&NativeMapView::jumpTo, "nativeJumpTo"),
METHOD(&NativeMapView::easeTo, "nativeEaseTo"),
METHOD(&NativeMapView::flyTo, "nativeFlyTo"),
METHOD(&NativeMapView::getLatLng, "nativeGetLatLng"),
METHOD(&NativeMapView::setLatLng, "nativeSetLatLng"),
METHOD(&NativeMapView::getCameraForLatLngBounds, "nativeGetCameraForLatLngBounds"),
METHOD(&NativeMapView::getCameraForGeometry, "nativeGetCameraForGeometry"),
METHOD(&NativeMapView::setReachability, "nativeSetReachability"),
METHOD(&NativeMapView::resetPosition, "nativeResetPosition"),
METHOD(&NativeMapView::getPitch, "nativeGetPitch"),
METHOD(&NativeMapView::setPitch, "nativeSetPitch"),
METHOD(&NativeMapView::getZoom, "nativeGetZoom"),
METHOD(&NativeMapView::setZoom, "nativeSetZoom"),
METHOD(&NativeMapView::resetZoom, "nativeResetZoom"),
METHOD(&NativeMapView::setMinZoom, "nativeSetMinZoom"),
METHOD(&NativeMapView::getMinZoom, "nativeGetMinZoom"),
METHOD(&NativeMapView::setMaxZoom, "nativeSetMaxZoom"),
METHOD(&NativeMapView::getMaxZoom, "nativeGetMaxZoom"),
METHOD(&NativeMapView::rotateBy, "nativeRotateBy"),
METHOD(&NativeMapView::setBearing, "nativeSetBearing"),
METHOD(&NativeMapView::setBearingXY, "nativeSetBearingXY"),
METHOD(&NativeMapView::getBearing, "nativeGetBearing"),
METHOD(&NativeMapView::resetNorth, "nativeResetNorth"),
METHOD(&NativeMapView::setVisibleCoordinateBounds, "nativeSetVisibleCoordinateBounds"),
METHOD(&NativeMapView::scheduleSnapshot, "nativeTakeSnapshot"),
METHOD(&NativeMapView::getCameraPosition, "nativeGetCameraPosition"),
METHOD(&NativeMapView::updateMarker, "nativeUpdateMarker"),
METHOD(&NativeMapView::addMarkers, "nativeAddMarkers"),
METHOD(&NativeMapView::setDebug, "nativeSetDebug"),
METHOD(&NativeMapView::cycleDebugOptions, "nativeCycleDebugOptions"),
METHOD(&NativeMapView::getDebug, "nativeGetDebug"),
METHOD(&NativeMapView::isFullyLoaded, "nativeIsFullyLoaded"),
METHOD(&NativeMapView::onLowMemory, "nativeOnLowMemory"),
METHOD(&NativeMapView::getMetersPerPixelAtLatitude, "nativeGetMetersPerPixelAtLatitude"),
METHOD(&NativeMapView::projectedMetersForLatLng, "nativeProjectedMetersForLatLng"),
METHOD(&NativeMapView::pixelForLatLng, "nativePixelForLatLng"),
METHOD(&NativeMapView::latLngForProjectedMeters, "nativeLatLngForProjectedMeters"),
METHOD(&NativeMapView::latLngForPixel, "nativeLatLngForPixel"),
METHOD(&NativeMapView::addPolylines, "nativeAddPolylines"),
METHOD(&NativeMapView::addPolygons, "nativeAddPolygons"),
METHOD(&NativeMapView::updatePolyline, "nativeUpdatePolyline"),
METHOD(&NativeMapView::updatePolygon, "nativeUpdatePolygon"),
METHOD(&NativeMapView::removeAnnotations, "nativeRemoveAnnotations"),
METHOD(&NativeMapView::addAnnotationIcon, "nativeAddAnnotationIcon"),
METHOD(&NativeMapView::removeAnnotationIcon, "nativeRemoveAnnotationIcon"),
METHOD(&NativeMapView::getTopOffsetPixelsForAnnotationSymbol, "nativeGetTopOffsetPixelsForAnnotationSymbol"),
METHOD(&NativeMapView::getTransitionOptions, "nativeGetTransitionOptions"),
METHOD(&NativeMapView::setTransitionOptions, "nativeSetTransitionOptions"),
METHOD(&NativeMapView::queryPointAnnotations, "nativeQueryPointAnnotations"),
METHOD(&NativeMapView::queryShapeAnnotations, "nativeQueryShapeAnnotations"),
METHOD(&NativeMapView::queryRenderedFeaturesForPoint, "nativeQueryRenderedFeaturesForPoint"),
METHOD(&NativeMapView::queryRenderedFeaturesForBox, "nativeQueryRenderedFeaturesForBox"),
METHOD(&NativeMapView::getLight, "nativeGetLight"),
METHOD(&NativeMapView::getLayers, "nativeGetLayers"),
METHOD(&NativeMapView::getLayer, "nativeGetLayer"),
METHOD(&NativeMapView::addLayer, "nativeAddLayer"),
METHOD(&NativeMapView::addLayerAbove, "nativeAddLayerAbove"),
METHOD(&NativeMapView::addLayerAt, "nativeAddLayerAt"),
METHOD(&NativeMapView::removeLayerAt, "nativeRemoveLayerAt"),
METHOD(&NativeMapView::removeLayer, "nativeRemoveLayer"),
METHOD(&NativeMapView::getSources, "nativeGetSources"),
METHOD(&NativeMapView::getSource, "nativeGetSource"),
METHOD(&NativeMapView::addSource, "nativeAddSource"),
METHOD(&NativeMapView::removeSource, "nativeRemoveSource"),
METHOD(&NativeMapView::addImage, "nativeAddImage"),
METHOD(&NativeMapView::addImages, "nativeAddImages"),
METHOD(&NativeMapView::removeImage, "nativeRemoveImage"),
METHOD(&NativeMapView::getImage, "nativeGetImage"),
METHOD(&NativeMapView::setLatLngBounds, "nativeSetLatLngBounds"),
METHOD(&NativeMapView::setPrefetchTiles, "nativeSetPrefetchTiles"),
METHOD(&NativeMapView::getPrefetchTiles, "nativeGetPrefetchTiles")
);
jni::RegisterNativePeer<NativeMapView>(
env,
javaClass,
"nativePtr",
jni::MakePeer<NativeMapView,
const jni::Object<NativeMapView>&,
const jni::Object<FileSource>&,
const jni::Object<MapRenderer>&,
jni::jfloat,
jni::jboolean>,
"nativeInitialize",
"nativeDestroy",
METHOD(&NativeMapView::resizeView, "nativeResizeView"),
METHOD(&NativeMapView::getStyleUrl, "nativeGetStyleUrl"),
METHOD(&NativeMapView::setStyleUrl, "nativeSetStyleUrl"),
METHOD(&NativeMapView::getStyleJson, "nativeGetStyleJson"),
METHOD(&NativeMapView::setStyleJson, "nativeSetStyleJson"),
METHOD(&NativeMapView::cancelTransitions, "nativeCancelTransitions"),
METHOD(&NativeMapView::setGestureInProgress, "nativeSetGestureInProgress"),
METHOD(&NativeMapView::moveBy, "nativeMoveBy"),
METHOD(&NativeMapView::jumpTo, "nativeJumpTo"),
METHOD(&NativeMapView::easeTo, "nativeEaseTo"),
METHOD(&NativeMapView::flyTo, "nativeFlyTo"),
METHOD(&NativeMapView::getLatLng, "nativeGetLatLng"),
METHOD(&NativeMapView::setLatLng, "nativeSetLatLng"),
METHOD(&NativeMapView::getCameraForLatLngBounds, "nativeGetCameraForLatLngBounds"),
METHOD(&NativeMapView::getCameraForGeometry, "nativeGetCameraForGeometry"),
METHOD(&NativeMapView::setReachability, "nativeSetReachability"),
METHOD(&NativeMapView::resetPosition, "nativeResetPosition"),
METHOD(&NativeMapView::getPitch, "nativeGetPitch"),
METHOD(&NativeMapView::setPitch, "nativeSetPitch"),
METHOD(&NativeMapView::getZoom, "nativeGetZoom"),
METHOD(&NativeMapView::setZoom, "nativeSetZoom"),
METHOD(&NativeMapView::resetZoom, "nativeResetZoom"),
METHOD(&NativeMapView::setMinZoom, "nativeSetMinZoom"),
METHOD(&NativeMapView::getMinZoom, "nativeGetMinZoom"),
METHOD(&NativeMapView::setMaxZoom, "nativeSetMaxZoom"),
METHOD(&NativeMapView::getMaxZoom, "nativeGetMaxZoom"),
METHOD(&NativeMapView::rotateBy, "nativeRotateBy"),
METHOD(&NativeMapView::setBearing, "nativeSetBearing"),
METHOD(&NativeMapView::setBearingXY, "nativeSetBearingXY"),
METHOD(&NativeMapView::getBearing, "nativeGetBearing"),
METHOD(&NativeMapView::resetNorth, "nativeResetNorth"),
METHOD(&NativeMapView::setVisibleCoordinateBounds, "nativeSetVisibleCoordinateBounds"),
METHOD(&NativeMapView::scheduleSnapshot, "nativeTakeSnapshot"),
METHOD(&NativeMapView::getCameraPosition, "nativeGetCameraPosition"),
METHOD(&NativeMapView::updateMarker, "nativeUpdateMarker"),
METHOD(&NativeMapView::addMarkers, "nativeAddMarkers"),
METHOD(&NativeMapView::setDebug, "nativeSetDebug"),
METHOD(&NativeMapView::cycleDebugOptions, "nativeCycleDebugOptions"),
METHOD(&NativeMapView::getDebug, "nativeGetDebug"),
METHOD(&NativeMapView::isFullyLoaded, "nativeIsFullyLoaded"),
METHOD(&NativeMapView::onLowMemory, "nativeOnLowMemory"),
METHOD(&NativeMapView::getMetersPerPixelAtLatitude, "nativeGetMetersPerPixelAtLatitude"),
METHOD(&NativeMapView::projectedMetersForLatLng, "nativeProjectedMetersForLatLng"),
METHOD(&NativeMapView::pixelForLatLng, "nativePixelForLatLng"),
METHOD(&NativeMapView::latLngForProjectedMeters, "nativeLatLngForProjectedMeters"),
METHOD(&NativeMapView::latLngForPixel, "nativeLatLngForPixel"),
METHOD(&NativeMapView::addPolylines, "nativeAddPolylines"),
METHOD(&NativeMapView::addPolygons, "nativeAddPolygons"),
METHOD(&NativeMapView::updatePolyline, "nativeUpdatePolyline"),
METHOD(&NativeMapView::updatePolygon, "nativeUpdatePolygon"),
METHOD(&NativeMapView::removeAnnotations, "nativeRemoveAnnotations"),
METHOD(&NativeMapView::addAnnotationIcon, "nativeAddAnnotationIcon"),
METHOD(&NativeMapView::removeAnnotationIcon, "nativeRemoveAnnotationIcon"),
METHOD(&NativeMapView::getTopOffsetPixelsForAnnotationSymbol, "nativeGetTopOffsetPixelsForAnnotationSymbol"),
METHOD(&NativeMapView::getTransitionOptions, "nativeGetTransitionOptions"),
METHOD(&NativeMapView::setTransitionOptions, "nativeSetTransitionOptions"),
METHOD(&NativeMapView::queryPointAnnotations, "nativeQueryPointAnnotations"),
METHOD(&NativeMapView::queryShapeAnnotations, "nativeQueryShapeAnnotations"),
METHOD(&NativeMapView::queryRenderedFeaturesForPoint, "nativeQueryRenderedFeaturesForPoint"),
METHOD(&NativeMapView::queryRenderedFeaturesForBox, "nativeQueryRenderedFeaturesForBox"),
METHOD(&NativeMapView::getLight, "nativeGetLight"),
METHOD(&NativeMapView::getLayers, "nativeGetLayers"),
METHOD(&NativeMapView::getLayer, "nativeGetLayer"),
METHOD(&NativeMapView::addLayer, "nativeAddLayer"),
METHOD(&NativeMapView::addLayerAbove, "nativeAddLayerAbove"),
METHOD(&NativeMapView::addLayerAt, "nativeAddLayerAt"),
METHOD(&NativeMapView::removeLayerAt, "nativeRemoveLayerAt"),
METHOD(&NativeMapView::removeLayer, "nativeRemoveLayer"),
METHOD(&NativeMapView::getSources, "nativeGetSources"),
METHOD(&NativeMapView::getSource, "nativeGetSource"),
METHOD(&NativeMapView::addSource, "nativeAddSource"),
METHOD(&NativeMapView::removeSource, "nativeRemoveSource"),
METHOD(&NativeMapView::addImage, "nativeAddImage"),
METHOD(&NativeMapView::addImages, "nativeAddImages"),
METHOD(&NativeMapView::removeImage, "nativeRemoveImage"),
METHOD(&NativeMapView::getImage, "nativeGetImage"),
METHOD(&NativeMapView::setLatLngBounds, "nativeSetLatLngBounds"),
METHOD(&NativeMapView::setPrefetchTiles, "nativeSetPrefetchTiles"),
METHOD(&NativeMapView::getPrefetchTiles, "nativeGetPrefetchTiles"),
METHOD(&NativeMapView::setPrefetchZoomDelta, "nativeSetPrefetchZoomDelta"),
METHOD(&NativeMapView::getPrefetchZoomDelta, "nativeGetPrefetchZoomDelta"));
}

} // namespace android
Expand Down
4 changes: 4 additions & 0 deletions platform/android/src/native_map_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ class NativeMapView : public MapObserver {

jni::jboolean getPrefetchTiles(JNIEnv&);

void setPrefetchZoomDelta(JNIEnv&, jni::jint);

jni::jint getPrefetchZoomDelta(JNIEnv&);

mbgl::Map& getMap();

private:
Expand Down