Experimental API to toggle tile cache in map view (#2590)

This commit is contained in:
Alex Cristici
2024-07-16 01:31:11 +03:00
committed by GitHub
parent 9119afc5a3
commit 1ae14a55d0
21 changed files with 93 additions and 4 deletions

View File

@@ -86,6 +86,10 @@ const TaggedScheduler& AndroidRendererFrontend::getThreadPool() const {
return mapRenderer.getThreadPool();
}
void AndroidRendererFrontend::setTileCacheEnabled(bool enabled) {
mapRenderer.actor().invoke(&Renderer::setTileCacheEnabled, enabled);
}
void AndroidRendererFrontend::reduceMemoryUse() {
mapRenderer.actor().invoke(&Renderer::reduceMemoryUse);
}

View File

@@ -54,6 +54,7 @@ public:
const std::optional<std::map<std::string, mbgl::Value>>& args) const;
// Memory
void setTileCacheEnabled(bool);
void reduceMemoryUse();
private:

View File

@@ -676,6 +676,10 @@ 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();
}
@@ -1284,6 +1288,7 @@ 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"),

View File

@@ -192,6 +192,8 @@ 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);

View File

@@ -2504,4 +2504,18 @@ 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,6 +33,8 @@ interface NativeMap {
void resizeView(int width, int height);
void setTileCacheEnabled(boolean enabled);
void onLowMemory();
void destroy();

View File

@@ -619,6 +619,14 @@ 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")) {
@@ -1332,6 +1340,9 @@ 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();