[android] add api to enable/disable tile prefetching

This commit is contained in:
Ivo van Dongen
2017-07-18 16:26:24 +02:00
committed by Ivo van Dongen
parent c0dd1103e0
commit c5300ebabf
8 changed files with 128 additions and 1 deletions

View File

@@ -99,6 +99,7 @@ public final class MapboxMap {
setDebugActive(options.getDebugActive());
setApiBaseUrl(options);
setStyleUrl(options);
setPrefetchesTiles(options);
}
/**
@@ -247,6 +248,38 @@ public final class MapboxMap {
nativeMapView.setTransitionDelay(delayMs);
}
/**
* Sets tile pre-fetching from MapboxOptions.
*
* @param options the options object
*/
private void setPrefetchesTiles(@NonNull MapboxMapOptions options) {
setPrefetchesTiles(options.getPrefetchesTiles());
}
/**
* Enable or disable tile pre-fetching. Pre-fetching makes sure that a low-resolution
* tile is rendered as soon as possible at the expense of a little bandwidth.
*
* @param enable true to enable
*/
@UiThread
public void setPrefetchesTiles(boolean enable) {
nativeMapView.setPrefetchesTiles(enable);
}
/**
* Check whether tile pre-fetching is enabled or not.
*
* @return true if enabled
*
* @see MapboxMap#setPrefetchesTiles(boolean)
*/
@UiThread
public boolean getPrefetchesTiles() {
return nativeMapView.getPrefetchesTiles();
}
/**
* Retrieve all the layers in the style
*

View File

@@ -80,6 +80,7 @@ public class MapboxMapOptions implements Parcelable {
private int myLocationAccuracyTintColor;
private int myLocationAccuracyAlpha;
private float myLocationAccuracyThreshold;
private boolean prefetchesTiles = true;
private String apiBaseUrl;
@@ -154,6 +155,7 @@ public class MapboxMapOptions implements Parcelable {
style = in.readString();
apiBaseUrl = in.readString();
textureMode = in.readByte() != 0;
prefetchesTiles = in.readByte() != 0;
}
static Bitmap getBitmapFromDrawable(Drawable drawable) {
@@ -297,6 +299,8 @@ public class MapboxMapOptions implements Parcelable {
typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyThreshold, 0));
mapboxMapOptions.textureMode(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false));
mapboxMapOptions.setPrefetchesTiles(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true));
} finally {
typedArray.recycle();
}
@@ -711,6 +715,30 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
/**
* Enable tile pre-fetching. Loads tiles at a lower zoom-level to pre-render
* a low resolution preview while more detailed tiles are loaded.
*
* Enabled by default
*
* @param enable true to enable
*
* @return This
*/
public MapboxMapOptions setPrefetchesTiles(boolean enable) {
this.prefetchesTiles = enable;
return this;
}
/**
* Check whether tile pre-fetching is enabled.
*
* @return true if enabled
*/
public boolean getPrefetchesTiles() {
return prefetchesTiles;
}
/**
* Get the current configured API endpoint base URL.
*
@@ -1094,6 +1122,7 @@ public class MapboxMapOptions implements Parcelable {
dest.writeString(style);
dest.writeString(apiBaseUrl);
dest.writeByte((byte) (textureMode ? 1 : 0));
dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
}
@Override
@@ -1217,6 +1246,9 @@ public class MapboxMapOptions implements Parcelable {
if (apiBaseUrl != null ? !apiBaseUrl.equals(options.apiBaseUrl) : options.apiBaseUrl != null) {
return false;
}
if (prefetchesTiles != options.prefetchesTiles) {
return false;
}
return false;
}
@@ -1263,6 +1295,7 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
result = 31 * result + (textureMode ? 1 : 0);
result = 31 * result + (style != null ? style.hashCode() : 0);
result = 31 * result + (prefetchesTiles ? 1 : 0);
return result;
}
}

View File

@@ -638,6 +638,20 @@ final class NativeMapView {
return nativeGetCameraPosition();
}
public void setPrefetchesTiles(boolean enable) {
if (isDestroyedOn("setPrefetchesTiles")) {
return;
}
nativeSetPrefetchesTiles(enable);
}
public boolean getPrefetchesTiles() {
if (isDestroyedOn("getPrefetchesTiles")) {
return false;
}
return nativeGetPrefetchesTiles();
}
// Runtime style Api
public long getTransitionDuration() {
@@ -1072,6 +1086,10 @@ final class NativeMapView {
private native Light nativeGetLight();
private native void nativeSetPrefetchesTiles(boolean enable);
private native boolean nativeGetPrefetchesTiles();
int getWidth() {
if (isDestroyedOn("")) {
return 0;