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

* [android] Expose pre-fetching zoom delta.

* [android] Fix Clang format.

* [android] Add MapboxMap unit test.

* [android] Add prefetching zoom delta into MapboxMapOptions.

* [android] Deprecate setPrefetchesTiles to migrate to setPrefetchZoomDelta.

* [android] Deprecate getPrefetchesTiles() and migrate to setPrefetchZoomDelta().

* [android] Add unit test to NativeMapViewTest.

* [android] Add IntRange annotation to getPrefetchZoomDelta.
This commit is contained in:
Peng Liu
2019-10-08 16:21:46 +03:00
committed by GitHub
parent 4eaaa9046e
commit 7139abdbf5
11 changed files with 262 additions and 96 deletions

205
platform/android/src/native_map_view.cpp Executable file → Normal file
View File

@@ -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 "geometry/lat_lng_bounds.hpp"
#include "map/camera_position.hpp"
#include "map/image.hpp"
#include "style/light.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_renderer.hpp"
#include "run_loop_impl.hpp"
#include "style/light.hpp"
namespace mbgl {
namespace android {
@@ -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(delta));
}
jni::jint NativeMapView::getPrefetchZoomDelta(JNIEnv&) {
return jni::jint(map->getPrefetchZoomDelta());
}
mbgl::Map& NativeMapView::getMap() {
return *map;
}
@@ -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