Add set and get api for volatile and minimumTileUpdateInterval in Source (#355)
* Add set and get api for Volatile and minimumTileUpdateInterval in Source * Format codes.
This commit is contained in:
@@ -180,6 +180,22 @@ static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,
|
||||
return ownedSource != nullptr;
|
||||
}
|
||||
|
||||
jni::Local<jni::Boolean> Source::isVolatile(jni::JNIEnv& env) {
|
||||
return jni::Box(env, jni::jboolean(source.isVolatile()));
|
||||
}
|
||||
|
||||
void Source::setVolatile(JNIEnv& env, jni::Boolean& value) {
|
||||
source.setVolatile(jni::Unbox(env, value));
|
||||
}
|
||||
|
||||
void Source::setMinimumTileUpdateInterval(JNIEnv& env, jni::Long& interval) {
|
||||
source.setMinimumTileUpdateInterval(Milliseconds(jni::Unbox(env, interval)));
|
||||
}
|
||||
|
||||
jni::Local<jni::Long> Source::getMinimumTileUpdateInterval(JNIEnv& env) {
|
||||
return jni::Box(env, jni::jlong(source.getMinimumTileUpdateInterval().count() / 1000000));
|
||||
}
|
||||
|
||||
void Source::releaseJavaPeer() {
|
||||
// We can't release the peer if the source was not removed from the map
|
||||
if (!ownedSource) {
|
||||
@@ -214,7 +230,12 @@ static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,
|
||||
METHOD(&Source::setPrefetchZoomDelta, "nativeSetPrefetchZoomDelta"),
|
||||
METHOD(&Source::getPrefetchZoomDelta, "nativeGetPrefetchZoomDelta"),
|
||||
METHOD(&Source::setMaxOverscaleFactorForParentTiles, "nativeSetMaxOverscaleFactorForParentTiles"),
|
||||
METHOD(&Source::getMaxOverscaleFactorForParentTiles, "nativeGetMaxOverscaleFactorForParentTiles"));
|
||||
METHOD(&Source::getMaxOverscaleFactorForParentTiles, "nativeGetMaxOverscaleFactorForParentTiles"),
|
||||
METHOD(&Source::isVolatile, "nativeIsVolatile"),
|
||||
METHOD(&Source::setVolatile, "nativeSetVolatile"),
|
||||
METHOD(&Source::setMinimumTileUpdateInterval, "nativeSetMinimumTileUpdateInterval"),
|
||||
METHOD(&Source::getMinimumTileUpdateInterval, "nativeGetMinimumTileUpdateInterval"));
|
||||
|
||||
|
||||
// Register subclasses
|
||||
GeoJSONSource::registerNative(env);
|
||||
@@ -225,6 +246,5 @@ static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,
|
||||
CustomGeometrySource::registerNative(env);
|
||||
RasterDEMSource::registerNative(env);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -54,6 +54,14 @@ public:
|
||||
|
||||
void addToStyle(JNIEnv& env, const jni::Object<Source>& obj, mbgl::style::Style& style);
|
||||
|
||||
jni::Local<jni::Boolean > isVolatile(JNIEnv&);
|
||||
|
||||
void setVolatile(JNIEnv&, jni::Boolean&);
|
||||
|
||||
void setMinimumTileUpdateInterval(JNIEnv&, jni::Long &);
|
||||
|
||||
jni::Local<jni::Long> getMinimumTileUpdateInterval(JNIEnv&);
|
||||
|
||||
protected:
|
||||
// Set on newly created sources until added to the map.
|
||||
std::unique_ptr<mbgl::style::Source> ownedSource;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.mapbox.mapboxsdk.style.sources;
|
||||
|
||||
import com.mapbox.mapboxsdk.LibraryLoader;
|
||||
import com.mapbox.mapboxsdk.utils.ThreadUtils;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mapbox.mapboxsdk.LibraryLoader;
|
||||
import com.mapbox.mapboxsdk.utils.ThreadUtils;
|
||||
|
||||
/**
|
||||
* Base Peer class for sources. see source.hpp for the other half of the peer.
|
||||
*/
|
||||
@@ -115,6 +115,44 @@ public abstract class Source {
|
||||
return nativeGetMaxOverscaleFactorForParentTiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether or not the fetched tiles for the given source should be stored in the local cache
|
||||
*
|
||||
@return true if tiles are volatile, false if they will be stored in local cache. Default value is false.
|
||||
*/
|
||||
@NonNull
|
||||
public Boolean isVolatile() {
|
||||
return nativeIsVolatile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a flag defining whether or not the fetched tiles for the given source should be stored in the local cache
|
||||
*
|
||||
* @param value current setting for volatile.
|
||||
*/
|
||||
public void setVolatile(Boolean value) {
|
||||
nativeSetVolatile(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum tile update interval, which is used to throttle the tile update network requests.
|
||||
*
|
||||
* @param interval the update interval in milliseconds.
|
||||
*/
|
||||
public void setMinimumTileUpdateInterval(Long interval) {
|
||||
nativeSetMinimumTileUpdateInterval(interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the minimum tile update interval, which is used to throttle the tile update network requests.
|
||||
*
|
||||
* @return the update interval in milliseconds, default valuse is 0.
|
||||
*/
|
||||
@NonNull
|
||||
public Long getMinimumTileUpdateInterval() {
|
||||
return nativeGetMinimumTileUpdateInterval();
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use
|
||||
*
|
||||
@@ -148,6 +186,22 @@ public abstract class Source {
|
||||
@Keep
|
||||
protected native Integer nativeGetMaxOverscaleFactorForParentTiles();
|
||||
|
||||
@NonNull
|
||||
@Keep
|
||||
protected native Boolean nativeIsVolatile();
|
||||
|
||||
@NonNull
|
||||
@Keep
|
||||
protected native void nativeSetVolatile(Boolean value);
|
||||
|
||||
@NonNull
|
||||
@Keep
|
||||
protected native void nativeSetMinimumTileUpdateInterval(Long interval);
|
||||
|
||||
@NonNull
|
||||
@Keep
|
||||
protected native Long nativeGetMinimumTileUpdateInterval();
|
||||
|
||||
public void setDetached() {
|
||||
detached = true;
|
||||
}
|
||||
|
||||
@@ -83,4 +83,28 @@ class CustomGeometrySourceTest : BaseTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isVolatileTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.style!!.getSource(ID_GRID_SOURCE)!!.let {
|
||||
assertFalse(it.isVolatile)
|
||||
it.isVolatile = true
|
||||
assertTrue(it.isVolatile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun minimumTileUpdateIntervalTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.style!!.getSource(ID_GRID_SOURCE)!!.let {
|
||||
assertEquals(0, it.minimumTileUpdateInterval)
|
||||
it.minimumTileUpdateInterval = 1000
|
||||
assertEquals(1000, it.minimumTileUpdateInterval)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user