Toggle tile cache final API (#2723)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
Alex Cristici
2024-08-21 00:28:00 +03:00
committed by GitHub
parent d544da140b
commit a4258ccbb8
21 changed files with 170 additions and 63 deletions

View File

@@ -92,6 +92,10 @@ void AndroidRendererFrontend::setTileCacheEnabled(bool enabled) {
mapRenderer.actor().invoke(&Renderer::setTileCacheEnabled, enabled);
}
bool AndroidRendererFrontend::getTileCacheEnabled() const {
return mapRenderer.actor().ask(&Renderer::getTileCacheEnabled).get();
}
void AndroidRendererFrontend::reduceMemoryUse() {
mapRenderer.actor().invoke(&Renderer::reduceMemoryUse);
}

View File

@@ -55,6 +55,7 @@ public:
// Memory
void setTileCacheEnabled(bool);
bool getTileCacheEnabled() const;
void reduceMemoryUse();
private:

View File

@@ -676,10 +676,6 @@ jni::Local<jni::Array<jni::jlong>> NativeMapView::addMarkers(jni::JNIEnv& env,
return result;
}
void NativeMapView::setTileCacheEnabled(JNIEnv&, jni::jboolean enabled) {
rendererFrontend->setTileCacheEnabled(enabled);
}
void NativeMapView::onLowMemory(JNIEnv&) {
rendererFrontend->reduceMemoryUse();
}
@@ -1215,6 +1211,14 @@ jni::jint NativeMapView::getPrefetchZoomDelta(JNIEnv&) {
return jni::jint(map->getPrefetchZoomDelta());
}
void NativeMapView::setTileCacheEnabled(JNIEnv&, jni::jboolean enabled) {
rendererFrontend->setTileCacheEnabled(enabled);
}
jni::jboolean NativeMapView::getTileCacheEnabled(JNIEnv&) {
return jni::jboolean(rendererFrontend->getTileCacheEnabled());
}
mbgl::Map& NativeMapView::getMap() {
return *map;
}
@@ -1288,7 +1292,6 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
METHOD(&NativeMapView::setDebug, "nativeSetDebug"),
METHOD(&NativeMapView::getDebug, "nativeGetDebug"),
METHOD(&NativeMapView::isFullyLoaded, "nativeIsFullyLoaded"),
METHOD(&NativeMapView::setTileCacheEnabled, "nativeSetTileCacheEnabled"),
METHOD(&NativeMapView::onLowMemory, "nativeOnLowMemory"),
METHOD(&NativeMapView::getMetersPerPixelAtLatitude, "nativeGetMetersPerPixelAtLatitude"),
METHOD(&NativeMapView::projectedMetersForLatLng, "nativeProjectedMetersForLatLng"),
@@ -1333,6 +1336,8 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
METHOD(&NativeMapView::getPrefetchTiles, "nativeGetPrefetchTiles"),
METHOD(&NativeMapView::setPrefetchZoomDelta, "nativeSetPrefetchZoomDelta"),
METHOD(&NativeMapView::getPrefetchZoomDelta, "nativeGetPrefetchZoomDelta"),
METHOD(&NativeMapView::setTileCacheEnabled, "nativeSetTileCacheEnabled"),
METHOD(&NativeMapView::getTileCacheEnabled, "nativeGetTileCacheEnabled"),
METHOD(&NativeMapView::triggerRepaint, "nativeTriggerRepaint"));
}

View File

@@ -192,8 +192,6 @@ public:
jni::Local<jni::Array<jni::jlong>> addMarkers(jni::JNIEnv&, const jni::Array<jni::Object<Marker>>&);
void setTileCacheEnabled(JNIEnv&, jni::jboolean);
void onLowMemory(JNIEnv& env);
void setDebug(JNIEnv&, jni::jboolean);
@@ -292,6 +290,10 @@ public:
jni::jint getPrefetchZoomDelta(JNIEnv&);
void setTileCacheEnabled(JNIEnv&, jni::jboolean);
jni::jboolean getTileCacheEnabled(JNIEnv&);
mbgl::Map& getMap();
void triggerRepaint(JNIEnv&);

View File

@@ -324,6 +324,26 @@ public final class MapLibreMap {
return nativeMapView.getPrefetchZoomDelta();
}
/**
* Indicating whether the map may cache tiles for different zoom levels or not.
*
* @param enabled true causes the map view to consume more memory and have a smoother user
* experience when zoom in/out. The default value of this property is `true`.
*/
public void setTileCacheEnabled(boolean enabled) {
nativeMapView.setTileCacheEnabled(enabled);
}
/**
* Check whether tile cache is enabled or not.
*
* @return true if enabled
* @see MapLibreMap#setTileCacheEnabled(boolean)
*/
public boolean getTileCacheEnabled() {
return nativeMapView.getTileCacheEnabled();
}
//
// MinZoom
//
@@ -2504,18 +2524,4 @@ public final class MapLibreMap {
listener.onDeveloperAnimationStarted();
}
}
//
// Tile cache
//
/**
* Indicating whether the map may cache tiles for different zoom levels or not.
*
* @param enabled true causes the map view to consume more memory and have a smoother user
* experience when zoom in/out. The default value of this property is `true`.
*/
public void experimental_setTileCacheEnabled(boolean enabled) {
nativeMapView.setTileCacheEnabled(enabled);
}
}

View File

@@ -33,8 +33,6 @@ interface NativeMap {
void resizeView(int width, int height);
void setTileCacheEnabled(boolean enabled);
void onLowMemory();
void destroy();
@@ -235,6 +233,10 @@ interface NativeMap {
@IntRange(from = 0)
int getPrefetchZoomDelta();
void setTileCacheEnabled(boolean enabled);
boolean getTileCacheEnabled();
void setGestureInProgress(boolean inProgress);
float getPixelRatio();

View File

@@ -619,14 +619,6 @@ final class NativeMapView implements NativeMap {
nativeSetVisibleCoordinateBounds(coordinates, padding, direction, duration);
}
@Override
public void setTileCacheEnabled(boolean enabled) {
if (checkState("setTileCacheEnabled")) {
return;
}
nativeSetTileCacheEnabled(enabled);
}
@Override
public void onLowMemory() {
if (checkState("onLowMemory")) {
@@ -815,6 +807,21 @@ final class NativeMapView implements NativeMap {
return nativeGetPrefetchZoomDelta();
}
@Override
public void setTileCacheEnabled(boolean enabled) {
if (checkState("setTileCacheEnabled")) {
return;
}
nativeSetTileCacheEnabled(enabled);
}
@Override
public boolean getTileCacheEnabled() {
if (checkState("getTileCacheEnabled")) {
return false;
}
return nativeGetTileCacheEnabled();
}
// Runtime style Api
@Override
@@ -1340,9 +1347,6 @@ final class NativeMapView implements NativeMap {
private native void nativeSetVisibleCoordinateBounds(LatLng[] coordinates, RectF padding,
double direction, long duration);
@Keep
private native void nativeSetTileCacheEnabled(boolean enabled);
@Keep
private native void nativeOnLowMemory();
@@ -1510,6 +1514,12 @@ final class NativeMapView implements NativeMap {
@Keep
private native void nativeSetPrefetchZoomDelta(int delta);
@Keep
private native void nativeSetTileCacheEnabled(boolean enabled);
@Keep
private native boolean nativeGetTileCacheEnabled();
@Keep
private native int nativeGetPrefetchZoomDelta();