Add Tile LOD controls (#2958)

Co-authored-by: Bart Louwers <bart@emeel.net>
Co-authored-by: Adrian Cojocaru <adrian.cojocaru92@yahoo.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
alasram
2025-06-04 05:49:41 -07:00
committed by GitHub
parent 2e4541c441
commit b11134a301
43 changed files with 1066 additions and 114 deletions

View File

@@ -1269,6 +1269,38 @@ jni::jboolean NativeMapView::getTileCacheEnabled(JNIEnv&) {
return jni::jboolean(rendererFrontend->getTileCacheEnabled());
}
void NativeMapView::setTileLodMinRadius(JNIEnv&, jni::jdouble radius) {
map->setTileLodMinRadius(radius);
}
jni::jdouble NativeMapView::getTileLodMinRadius(JNIEnv&) {
return jni::jdouble(map->getTileLodMinRadius());
}
void NativeMapView::setTileLodScale(JNIEnv&, jni::jdouble scale) {
map->setTileLodScale(scale);
}
jni::jdouble NativeMapView::getTileLodScale(JNIEnv&) {
return jni::jdouble(map->getTileLodScale());
}
void NativeMapView::setTileLodPitchThreshold(JNIEnv&, jni::jdouble threshold) {
map->setTileLodPitchThreshold(threshold);
}
jni::jdouble NativeMapView::getTileLodPitchThreshold(JNIEnv&) {
return jni::jdouble(map->getTileLodPitchThreshold());
}
void NativeMapView::setTileLodZoomShift(JNIEnv&, jni::jdouble shift) {
map->setTileLodZoomShift(shift);
}
jni::jdouble NativeMapView::getTileLodZoomShift(JNIEnv&) {
return jni::jdouble(map->getTileLodZoomShift());
}
mbgl::Map& NativeMapView::getMap() {
return *map;
}
@@ -1400,6 +1432,14 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
METHOD(&NativeMapView::getPrefetchZoomDelta, "nativeGetPrefetchZoomDelta"),
METHOD(&NativeMapView::setTileCacheEnabled, "nativeSetTileCacheEnabled"),
METHOD(&NativeMapView::getTileCacheEnabled, "nativeGetTileCacheEnabled"),
METHOD(&NativeMapView::setTileLodMinRadius, "nativeSetTileLodMinRadius"),
METHOD(&NativeMapView::getTileLodMinRadius, "nativeGetTileLodMinRadius"),
METHOD(&NativeMapView::setTileLodScale, "nativeSetTileLodScale"),
METHOD(&NativeMapView::getTileLodScale, "nativeGetTileLodScale"),
METHOD(&NativeMapView::setTileLodPitchThreshold, "nativeSetTileLodPitchThreshold"),
METHOD(&NativeMapView::getTileLodPitchThreshold, "nativeGetTileLodPitchThreshold"),
METHOD(&NativeMapView::setTileLodZoomShift, "nativeSetTileLodZoomShift"),
METHOD(&NativeMapView::getTileLodZoomShift, "nativeGetTileLodZoomShift"),
METHOD(&NativeMapView::triggerRepaint, "nativeTriggerRepaint"),
METHOD(&NativeMapView::isRenderingStatsViewEnabled, "nativeIsRenderingStatsViewEnabled"),
METHOD(&NativeMapView::enableRenderingStatsView, "nativeEnableRenderingStatsView"));

View File

@@ -302,6 +302,22 @@ public:
jni::jboolean getTileCacheEnabled(JNIEnv&);
void setTileLodMinRadius(JNIEnv&, jni::jdouble);
jni::jdouble getTileLodMinRadius(JNIEnv&);
void setTileLodScale(JNIEnv&, jni::jdouble);
jni::jdouble getTileLodScale(JNIEnv&);
void setTileLodPitchThreshold(JNIEnv&, jni::jdouble);
jni::jdouble getTileLodPitchThreshold(JNIEnv&);
void setTileLodZoomShift(JNIEnv&, jni::jdouble);
jni::jdouble getTileLodZoomShift(JNIEnv&);
mbgl::Map& getMap();
void triggerRepaint(JNIEnv&);

View File

@@ -358,6 +358,101 @@ public final class MapLibreMap {
return nativeMapView.getTileCacheEnabled();
}
/**
* Camera based tile level of detail controls
*
* @param radius minimum radius around the view point in unit of tiles in which the fine
* grained zoom level tiles are always used when performing LOD
* radius must be greater than 1 (At least 1 fine detailed tile is present)
* A smaller radius value may improve performance at the cost of quality (tiles away from
* camera use lower Zoom levels)
*/
public void setTileLodMinRadius(@FloatRange(from = 1, fromInclusive = true) double radius) {
nativeMapView.setTileLodMinRadius(radius);
}
/**
* Camera based tile level of detail controls
*
* @return minimum radius around the view point in unit of tiles in which the fine grained
* zoom level tiles are always used when performing LOD
* @see MapLibreMap#setTileLodMinRadius(double)
*/
public double getTileLodMinRadius() {
return nativeMapView.getTileLodMinRadius();
}
/**
* Camera based tile level of detail controls
*
* @param scale factor for the distance to the camera view point
* A value larger than 1 increases the distance to the camera view point reducing LOD
* Larger values may improve performance at the cost of quality (tiles away from camera
* use lower Zoom levels)
*/
public void setTileLodScale(@FloatRange(from = 0, fromInclusive = false) double scale) {
nativeMapView.setTileLodScale(scale);
}
/**
* Camera based tile level of detail controls
*
* @return scale factor for the distance to the camera view point
* @see MapLibreMap#setTileLodScale(double)
*/
public double getTileLodScale() {
return nativeMapView.getTileLodScale();
}
/**
* Camera based tile level of detail controls
*
* @param threshold pitch angle in radians above which LOD calculation is performed
* A smaller radius value may improve performance at the cost of quality
*/
public void setTileLodPitchThreshold(@FloatRange(from = 0, to = Math.PI) double threshold) {
nativeMapView.setTileLodPitchThreshold(threshold);
}
/**
* Camera based tile level of detail controls
*
* @return pitch angle threshold in radians above which LOD calculation is performed
* @see MapLibreMap#setTileLodPitchThreshold(double)
*/
public double getTileLodPitchThreshold() {
return nativeMapView.getTileLodPitchThreshold();
}
/**
* Camera based tile level of detail controls
*
* @param shift shift applied to the Zoom level during LOD calculation
* A negative value shifts the Zoom level to a coarser level reducing quality but
* improving performance
* A positive value shifts the Zoom level to a finer level increasing details but
* negatively affecting performance
* A value of zero (default) does not apply any shift to the Zoom level
* It is not recommended to change the default value unless performance is critical
* and the loss of quality is acceptable. A value of -1 reduces the number of
* displayed tiles by a factor of 4 on average
* It is recommended to first configure the pixelRatio before adjusting
* TileLodZoomShift. {@link MapLibreMapOptions#pixelRatio(float)}
*/
public void setTileLodZoomShift(double shift) {
nativeMapView.setTileLodZoomShift(shift);
}
/**
* Camera based tile level of detail controls
*
* @return shift applied to the Zoom level during LOD calculation
* @see MapLibreMap#setTileLodZoomShift(double)
*/
public double getTileLodZoomShift() {
return nativeMapView.getTileLodZoomShift();
}
//
// MinZoom
//

View File

@@ -244,6 +244,22 @@ interface NativeMap {
boolean getTileCacheEnabled();
void setTileLodMinRadius(double radius);
double getTileLodMinRadius();
void setTileLodScale(double scale);
double getTileLodScale();
void setTileLodPitchThreshold(double threshold);
double getTileLodPitchThreshold();
void setTileLodZoomShift(double shift);
double getTileLodZoomShift();
void setGestureInProgress(boolean inProgress);
float getPixelRatio();

View File

@@ -855,6 +855,70 @@ final class NativeMapView implements NativeMap {
}
return nativeGetTileCacheEnabled();
}
@Override
public void setTileLodMinRadius(double radius) {
if (checkState("setTileLodMinRadius")) {
return;
}
nativeSetTileLodMinRadius(radius);
}
@Override
public double getTileLodMinRadius() {
if (checkState("getTileLodMinRadius")) {
return 0;
}
return nativeGetTileLodMinRadius();
}
@Override
public void setTileLodScale(double scale) {
if (checkState("setTileLodScale")) {
return;
}
nativeSetTileLodScale(scale);
}
@Override
public double getTileLodScale() {
if (checkState("getTileLodScale")) {
return 0;
}
return nativeGetTileLodScale();
}
@Override
public void setTileLodPitchThreshold(double threshold) {
if (checkState("setTileLodPitchThreshold")) {
return;
}
nativeSetTileLodPitchThreshold(threshold);
}
@Override
public double getTileLodPitchThreshold() {
if (checkState("getTileLodPitchThreshold")) {
return 0;
}
return nativeGetTileLodPitchThreshold();
}
@Override
public void setTileLodZoomShift(double shift) {
if (checkState("setTileLodZoomShift")) {
return;
}
nativeSetTileLodZoomShift(shift);
}
@Override
public double getTileLodZoomShift() {
if (checkState("getTileLodZoomShift")) {
return 0;
}
return nativeGetTileLodZoomShift();
}
// Runtime style Api
@Override
@@ -1644,6 +1708,30 @@ final class NativeMapView implements NativeMap {
@Keep
private native int nativeGetPrefetchZoomDelta();
@Keep
private native void nativeSetTileLodMinRadius(double radius);
@Keep
private native double nativeGetTileLodMinRadius();
@Keep
private native void nativeSetTileLodScale(double scale);
@Keep
private native double nativeGetTileLodScale();
@Keep
private native void nativeSetTileLodPitchThreshold(double threshold);
@Keep
private native double nativeGetTileLodPitchThreshold();
@Keep
private native void nativeSetTileLodZoomShift(double shift);
@Keep
private native double nativeGetTileLodZoomShift();
@Override
public long getNativePtr() {
return nativePtr;