diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com')
35 files changed, 1022 insertions, 117 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java index 6897cf66df..8c9cd362d3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java @@ -11,6 +11,9 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException; import com.mapbox.mapboxsdk.maps.Telemetry; import com.mapbox.mapboxsdk.net.ConnectivityReceiver; +import com.mapbox.mapboxsdk.storage.FileSource; +import com.mapbox.mapboxsdk.utils.ThreadUtils; + import timber.log.Timber; /** @@ -42,8 +45,10 @@ public final class Mapbox { */ @UiThread public static synchronized Mapbox getInstance(@NonNull Context context, @Nullable String accessToken) { + ThreadUtils.checkThread("Mapbox"); if (INSTANCE == null) { Context appContext = context.getApplicationContext(); + FileSource.initializeFileDirsPaths(appContext); INSTANCE = new Mapbox(appContext, accessToken); if (isAccessTokenValid(accessToken)) { initializeTelemetry(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java index 90bb23429f..3e75a34b4a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java @@ -1,10 +1,13 @@ package com.mapbox.mapboxsdk.attribution; +import android.content.Context; import android.text.Html; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.URLSpan; +import com.mapbox.mapboxsdk.R; +import java.lang.ref.WeakReference; import java.util.LinkedHashSet; import java.util.Set; @@ -17,6 +20,7 @@ import java.util.Set; */ public class AttributionParser { + private final WeakReference<Context> context; private final Set<Attribution> attributions = new LinkedHashSet<>(); private final String attributionData; private final boolean withImproveMap; @@ -24,8 +28,9 @@ public class AttributionParser { private final boolean withTelemetryAttribution; private final boolean withMapboxAttribution; - AttributionParser(String attributionData, boolean withImproveMap, boolean withCopyrightSign, - boolean withTelemetryAttribution, boolean withMapboxAttribution) { + AttributionParser(WeakReference<Context> context, String attributionData, boolean withImproveMap, + boolean withCopyrightSign, boolean withTelemetryAttribution, boolean withMapboxAttribution) { + this.context = context; this.attributionData = attributionData; this.withImproveMap = withImproveMap; this.withCopyrightSign = withCopyrightSign; @@ -167,7 +172,13 @@ public class AttributionParser { */ private void addAdditionalAttributions() { if (withTelemetryAttribution) { - attributions.add(new Attribution(Attribution.TELEMETRY, Attribution.TELEMETRY_URL)); + Context context = this.context.get(); + attributions.add( + new Attribution( + context != null ? context.getString(R.string.mapbox_telemetrySettings) : Attribution.TELEMETRY, + Attribution.TELEMETRY_URL + ) + ); } } @@ -196,6 +207,7 @@ public class AttributionParser { * </p> */ public static class Options { + private WeakReference<Context> context; private boolean withImproveMap = true; private boolean withCopyrightSign = true; private boolean withTelemetryAttribution = false; @@ -227,6 +239,11 @@ public class AttributionParser { return this; } + public Options withContext(Context context) { + this.context = new WeakReference<>(context); + return this; + } + public AttributionParser build() { if (attributionDataStringArray == null) { throw new IllegalStateException("Using builder without providing attribution data"); @@ -234,6 +251,7 @@ public class AttributionParser { String fullAttributionString = parseAttribution(attributionDataStringArray); AttributionParser attributionParser = new AttributionParser( + context, fullAttributionString, withImproveMap, withCopyrightSign, diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java index 546ee62804..c2114f458e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java @@ -17,10 +17,12 @@ import com.mapbox.mapboxsdk.attribution.AttributionParser; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.style.sources.Source; +import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.Set; +import java.util.Locale; /** * Responsible for managing attribution interactions on the map. @@ -47,7 +49,7 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt // Called when someone presses the attribution icon on the map @Override public void onClick(View view) { - attributionSet = new AttributionBuilder(mapboxMap).build(); + attributionSet = new AttributionBuilder(mapboxMap, view.getContext()).build(); boolean isActivityFinishing = false; if (context instanceof Activity) { @@ -148,12 +150,19 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt private static class AttributionBuilder { private final MapboxMap mapboxMap; + private final WeakReference<Context> context; - AttributionBuilder(MapboxMap mapboxMap) { + AttributionBuilder(MapboxMap mapboxMap, Context context) { this.mapboxMap = mapboxMap; + this.context = new WeakReference<>(context); } private Set<Attribution> build() { + Context context = this.context.get(); + if (context == null) { + return Collections.emptySet(); + } + List<String> attributions = new ArrayList<>(); for (Source source : mapboxMap.getSources()) { attributions.add(source.getAttribution()); @@ -162,6 +171,7 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt return new AttributionParser.Options() .withCopyrightSign(true) .withImproveMap(true) + .withContext(context) .withTelemetryAttribution(true) .withAttributionData(attributions.toArray(new String[attributions.size()])) .build().getAttributions(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index aaed71ddec..d480d28f26 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -37,11 +37,13 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.constants.Style; +import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.renderer.MapRenderer; import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer; import com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewMapRenderer; import com.mapbox.mapboxsdk.maps.widgets.CompassView; import com.mapbox.mapboxsdk.net.ConnectivityReceiver; +import com.mapbox.mapboxsdk.offline.OfflineGeometryRegionDefinition; import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition; import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition; import com.mapbox.mapboxsdk.storage.FileSource; @@ -567,22 +569,46 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { return; } - OfflineTilePyramidRegionDefinition regionDefinition = (OfflineTilePyramidRegionDefinition) definition; - setStyleUrl(regionDefinition.getStyleURL()); + if (definition instanceof OfflineTilePyramidRegionDefinition) { + setOfflineTilePyramidRegionDefinition((OfflineTilePyramidRegionDefinition) definition); + } else if (definition instanceof OfflineGeometryRegionDefinition) { + setOfflineGeometryRegionDefinition((OfflineGeometryRegionDefinition) definition); + } else { + throw new UnsupportedOperationException("OfflineRegionDefintion instance not supported"); + } + } + + private void setOfflineRegionDefinition(String styleUrl, LatLng cameraTarget, double minZoom, double maxZoom) { CameraPosition cameraPosition = new CameraPosition.Builder() - .target(regionDefinition.getBounds().getCenter()) - .zoom(regionDefinition.getMinZoom()) + .target(cameraTarget) + .zoom(minZoom) .build(); - + setStyleUrl(styleUrl); if (!isMapInitialized()) { mapboxMapOptions.camera(cameraPosition); - mapboxMapOptions.minZoomPreference(regionDefinition.getMinZoom()); - mapboxMapOptions.maxZoomPreference(regionDefinition.getMaxZoom()); + mapboxMapOptions.minZoomPreference(minZoom); + mapboxMapOptions.maxZoomPreference(maxZoom); return; } mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); - mapboxMap.setMinZoomPreference(regionDefinition.getMinZoom()); - mapboxMap.setMaxZoomPreference(regionDefinition.getMaxZoom()); + mapboxMap.setMinZoomPreference(minZoom); + mapboxMap.setMaxZoomPreference(maxZoom); + } + + private void setOfflineTilePyramidRegionDefinition(OfflineTilePyramidRegionDefinition regionDefinition) { + setOfflineRegionDefinition(regionDefinition.getStyleURL(), + regionDefinition.getBounds().getCenter(), + regionDefinition.getMinZoom(), + regionDefinition.getMaxZoom() + ); + } + + private void setOfflineGeometryRegionDefinition(OfflineGeometryRegionDefinition regionDefinition) { + setOfflineRegionDefinition(regionDefinition.getStyleURL(), + regionDefinition.getBounds().getCenter(), + regionDefinition.getMinZoom(), + regionDefinition.getMaxZoom() + ); } // diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 0719412b4c..45e54a3d14 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -95,6 +95,7 @@ public final class MapboxMap { setDebugActive(options.getDebugActive()); setApiBaseUrl(options); setStyleUrl(options); + setStyleJson(options); setPrefetchesTiles(options); } @@ -433,7 +434,7 @@ public final class MapboxMap { } /** - * Removes the source, preserving the reverence for re-use + * Removes the source, preserving the reference for re-use * * @param source the source to remove * @return the source @@ -1058,7 +1059,7 @@ public final class MapboxMap { * @param options the object containing the style url */ private void setStyleUrl(@NonNull MapboxMapOptions options) { - String style = options.getStyle(); + String style = options.getStyleUrl(); if (!TextUtils.isEmpty(style)) { setStyleUrl(style, null); } @@ -1087,6 +1088,18 @@ public final class MapboxMap { } /** + * Loads a new map style json from MapboxMapOptions if available. + * + * @param options the object containing the style json + */ + private void setStyleJson(@NonNull MapboxMapOptions options) { + String styleJson = options.getStyleJson(); + if (!TextUtils.isEmpty(styleJson)) { + setStyleJson(styleJson); + } + } + + /** * Returns the map style json currently displayed in the map view. * * @return The json of the map style @@ -1601,7 +1614,7 @@ public final class MapboxMap { public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds, @NonNull @Size(value = 4) int[] padding) { // we use current camera tilt/bearing value to provide expected transformations as #11993 - return getCameraForLatLngBounds(latLngBounds, padding, transform.getBearing(), transform.getTilt()); + return getCameraForLatLngBounds(latLngBounds, padding, transform.getRawBearing(), transform.getTilt()); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 0075199b1e..f48bd92327 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -77,7 +77,8 @@ public class MapboxMapOptions implements Parcelable { @ColorInt private int foregroundLoadColor; - private String style; + private String styleUrl; + private String styleJson; private float pixelRatio; @@ -120,7 +121,8 @@ public class MapboxMapOptions implements Parcelable { zoomGesturesEnabled = in.readByte() != 0; doubleTapGesturesEnabled = in.readByte() != 0; - style = in.readString(); + styleUrl = in.readString(); + styleJson = in.readString(); apiBaseUrl = in.readString(); textureMode = in.readByte() != 0; translucentTextureSurface = in.readByte() != 0; @@ -145,6 +147,7 @@ public class MapboxMapOptions implements Parcelable { try { mapboxMapOptions.camera(new CameraPosition.Builder(typedArray).build()); mapboxMapOptions.styleUrl(typedArray.getString(R.styleable.mapbox_MapView_mapbox_styleUrl)); + mapboxMapOptions.styleJson(typedArray.getString(R.styleable.mapbox_MapView_mapbox_styleJson)); mapboxMapOptions.apiBaseUrl(typedArray.getString(R.styleable.mapbox_MapView_mapbox_apiBaseUrl)); mapboxMapOptions.zoomGesturesEnabled( @@ -258,13 +261,24 @@ public class MapboxMapOptions implements Parcelable { } /** - * Specifies the style url associated with a map view. + * Specifies the styleUrl url associated with a map view. * - * @param styleUrl Url to be used to load a style + * @param styleUrl Url to be used to load a styleUrl * @return This */ public MapboxMapOptions styleUrl(String styleUrl) { - style = styleUrl; + this.styleUrl = styleUrl; + return this; + } + + /** + * Specifies the styleJson associated with a map view. + * + * @param styleJson json to used as style + * @return This + */ + public MapboxMapOptions styleJson(String styleJson) { + this.styleJson = styleJson; return this; } @@ -716,12 +730,21 @@ public class MapboxMapOptions implements Parcelable { } /** - * Get the current configured style url for a map view. + * Get the current configured styleUrl url for a map view. * * @return Style url to be used. */ - public String getStyle() { - return style; + public String getStyleUrl() { + return styleUrl; + } + + /** + * Get the current configured styleJson for a map view. + * + * @return Style json to be used. + */ + public String getStyleJson() { + return styleJson; } /** @@ -912,7 +935,8 @@ public class MapboxMapOptions implements Parcelable { dest.writeByte((byte) (zoomGesturesEnabled ? 1 : 0)); dest.writeByte((byte) (doubleTapGesturesEnabled ? 1 : 0)); - dest.writeString(style); + dest.writeString(styleUrl); + dest.writeString(styleJson); dest.writeString(apiBaseUrl); dest.writeByte((byte) (textureMode ? 1 : 0)); dest.writeByte((byte) (translucentTextureSurface ? 1 : 0)); @@ -1002,9 +1026,14 @@ public class MapboxMapOptions implements Parcelable { if (!Arrays.equals(attributionMargins, options.attributionMargins)) { return false; } - if (style != null ? !style.equals(options.style) : options.style != null) { + if (styleUrl != null ? !styleUrl.equals(options.styleUrl) : options.styleUrl != null) { return false; } + + if (styleJson != null ? !styleJson.equals(options.styleJson) : options.styleJson != null) { + return false; + } + if (apiBaseUrl != null ? !apiBaseUrl.equals(options.apiBaseUrl) : options.apiBaseUrl != null) { return false; } @@ -1055,7 +1084,8 @@ public class MapboxMapOptions implements Parcelable { result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0); result = 31 * result + (textureMode ? 1 : 0); result = 31 * result + (translucentTextureSurface ? 1 : 0); - result = 31 * result + (style != null ? style.hashCode() : 0); + result = 31 * result + (styleUrl != null ? styleUrl.hashCode() : 0); + result = 31 * result + (styleJson != null ? styleJson.hashCode() : 0); result = 31 * result + (prefetchesTiles ? 1 : 0); result = 31 * result + (zMediaOverlay ? 1 : 0); result = 31 * result + (localIdeographFontFamily != null ? localIdeographFontFamily.hashCode() : 0); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java index 1129b8000e..492f653dae 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java @@ -28,7 +28,7 @@ public abstract class MapRenderer implements MapRendererScheduler { public MapRenderer(Context context, String localIdeographFontFamily) { FileSource fileSource = FileSource.getInstance(context); float pixelRatio = context.getResources().getDisplayMetrics().density; - String programCacheDir = context.getCacheDir().getAbsolutePath(); + String programCacheDir = FileSource.getInternalCachePath(context); // Initialise native peer nativeInitialize(this, fileSource, pixelRatio, programCacheDir, localIdeographFontFamily); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineGeometryRegionDefinition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineGeometryRegionDefinition.java new file mode 100644 index 0000000000..0db3ee3202 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineGeometryRegionDefinition.java @@ -0,0 +1,128 @@ +package com.mapbox.mapboxsdk.offline; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.Geometry; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.turf.TurfMeasurement; + +/** + * An offline region defined by a style URL, geometry, zoom range, and + * device pixel ratio. + * <p> + * Both minZoom and maxZoom must be ≥ 0, and maxZoom must be ≥ minZoom. + * <p> + * maxZoom may be ∞, in which case for each tile source, the region will include + * tiles from minZoom up to the maximum zoom level provided by that source. + * <p> + * pixelRatio must be ≥ 0 and should typically be 1.0 or 2.0. + */ +public class OfflineGeometryRegionDefinition implements OfflineRegionDefinition, Parcelable { + + private String styleURL; + private Geometry geometry; + private double minZoom; + private double maxZoom; + private float pixelRatio; + + /** + * Constructor to create an OfflineGeometryRegionDefinition from parameters. + * + * @param styleURL the style + * @param geometry the geometry + * @param minZoom min zoom + * @param maxZoom max zoom + * @param pixelRatio pixel ratio of the device + */ + public OfflineGeometryRegionDefinition( + String styleURL, Geometry geometry, double minZoom, double maxZoom, float pixelRatio) { + // Note: Also used in JNI + this.styleURL = styleURL; + this.geometry = geometry; + this.minZoom = minZoom; + this.maxZoom = maxZoom; + this.pixelRatio = pixelRatio; + } + + /** + * Constructor to create an OfflineGeometryRegionDefinition from a Parcel. + * + * @param parcel the parcel to create the OfflineGeometryRegionDefinition from + */ + public OfflineGeometryRegionDefinition(Parcel parcel) { + this.styleURL = parcel.readString(); + this.geometry = Feature.fromJson(parcel.readString()).geometry(); + this.minZoom = parcel.readDouble(); + this.maxZoom = parcel.readDouble(); + this.pixelRatio = parcel.readFloat(); + } + + /* + * Getters + */ + + public String getStyleURL() { + return styleURL; + } + + public Geometry getGeometry() { + return geometry; + } + + /** + * Calculates the bounding box for the Geometry it contains + * to retain backwards compatibility + * @return the {@link LatLngBounds} or null + */ + @Override + public LatLngBounds getBounds() { + if (geometry == null) { + return null; + } + + double[] bbox = TurfMeasurement.bbox(geometry); + return LatLngBounds.from(bbox[3], bbox[2], bbox[1], bbox[0]); + } + + public double getMinZoom() { + return minZoom; + } + + public double getMaxZoom() { + return maxZoom; + } + + public float getPixelRatio() { + return pixelRatio; + } + + /* + * Parceable + */ + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(styleURL); + dest.writeString(Feature.fromGeometry(geometry).toJson()); + dest.writeDouble(minZoom); + dest.writeDouble(maxZoom); + dest.writeFloat(pixelRatio); + } + + public static final Creator CREATOR = new Creator() { + public OfflineGeometryRegionDefinition createFromParcel(Parcel in) { + return new OfflineGeometryRegionDefinition(in); + } + + public OfflineGeometryRegionDefinition[] newArray(int size) { + return new OfflineGeometryRegionDefinition[size]; + } + }; +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java index dbf425986d..f6dd7ff7a1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java @@ -109,7 +109,7 @@ public class OfflineManager { @Override public void run() { try { - String path = context.getCacheDir().getAbsolutePath() + File.separator + "mbgl-cache.db"; + String path = FileSource.getInternalCachePath(context) + File.separator + "mbgl-cache.db"; File file = new File(path); if (file.exists()) { file.delete(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java index 2aea565d8b..354a8fb6cd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java @@ -217,7 +217,7 @@ public class MapSnapshotter { checkThread(); this.context = context.getApplicationContext(); FileSource fileSource = FileSource.getInstance(context); - String programCacheDir = context.getCacheDir().getAbsolutePath(); + String programCacheDir = FileSource.getInternalCachePath(context); nativeInitialize(this, fileSource, options.pixelRatio, options.width, options.height, options.styleUrl, options.styleJson, options.region, options.cameraPosition, diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java index c8d02c05d9..495e425976 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.AssetManager; +import android.os.AsyncTask; import android.os.Environment; import android.support.annotation.Keep; import android.support.annotation.NonNull; @@ -11,6 +12,10 @@ import android.support.annotation.UiThread; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.constants.MapboxConstants; +import com.mapbox.mapboxsdk.utils.ThreadUtils; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; import timber.log.Timber; @@ -20,6 +25,11 @@ import timber.log.Timber; */ public class FileSource { + private static String resourcesCachePath; + private static String internalCachePath; + private static final Lock resourcesCachePathLoaderLock = new ReentrantLock(); + private static final Lock internalCachePathLoaderLock = new ReentrantLock(); + /** * This callback allows implementors to transform URLs before they are requested * from the internet. This can be used add or remove custom parameters, or reroute @@ -51,19 +61,20 @@ public class FileSource { @UiThread public static synchronized FileSource getInstance(Context context) { if (INSTANCE == null) { - String cachePath = getCachePath(context); - INSTANCE = new FileSource(cachePath, context.getResources().getAssets()); + INSTANCE = new FileSource(getResourcesCachePath(context), context.getResources().getAssets()); } return INSTANCE; } /** - * Get the cache path for a context. + * Get files directory path for a context. * - * @param context the context to derive the cache path from - * @return the cache path + * @param context the context to derive the files directory path from + * @return the files directory path + * @deprecated Use {@link #getResourcesCachePath(Context)} instead. */ + @Deprecated public static String getCachePath(Context context) { // Default value boolean setStorageExternal = MapboxConstants.DEFAULT_SET_STORAGE_EXTERNAL; @@ -122,6 +133,89 @@ public class FileSource { return false; } + /** + * Initializes file directories paths. + * + * @param context the context to derive paths from + */ + @UiThread + public static void initializeFileDirsPaths(Context context) { + ThreadUtils.checkThread("FileSource"); + lockPathLoaders(); + if (resourcesCachePath == null || internalCachePath == null) { + new FileDirsPathsTask().execute(context); + } + } + + private static class FileDirsPathsTask extends AsyncTask<Context, Void, String[]> { + + @Override + protected void onCancelled() { + unlockPathLoaders(); + } + + @Override + protected String[] doInBackground(Context... contexts) { + return new String[] { + getCachePath(contexts[0]), + contexts[0].getCacheDir().getAbsolutePath() + }; + } + + @Override + protected void onPostExecute(String[] paths) { + resourcesCachePath = paths[0]; + internalCachePath = paths[1]; + unlockPathLoaders(); + } + } + + /** + * Get files directory path for a context. + * + * @param context the context to derive the files directory path from + * @return the files directory path + */ + public static String getResourcesCachePath(Context context) { + resourcesCachePathLoaderLock.lock(); + try { + if (resourcesCachePath == null) { + resourcesCachePath = getCachePath(context); + } + return resourcesCachePath; + } finally { + resourcesCachePathLoaderLock.unlock(); + } + } + + /** + * Get internal cache path for a context. + * + * @param context the context to derive the internal cache path from + * @return the internal cache path + */ + public static String getInternalCachePath(Context context) { + internalCachePathLoaderLock.lock(); + try { + if (internalCachePath == null) { + internalCachePath = context.getCacheDir().getAbsolutePath(); + } + return internalCachePath; + } finally { + internalCachePathLoaderLock.unlock(); + } + } + + private static void lockPathLoaders() { + internalCachePathLoaderLock.lock(); + resourcesCachePathLoaderLock.lock(); + } + + private static void unlockPathLoaders() { + resourcesCachePathLoaderLock.unlock(); + internalCachePathLoaderLock.unlock(); + } + @Keep private long nativePtr; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java index 1aa0ce9093..bd4d5d7d4b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -4,17 +4,22 @@ import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.Size; + import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonNull; +import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; import com.mapbox.mapboxsdk.style.layers.PropertyValue; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Locale; +import java.util.Map; /** * The value for any layout property, paint property, or filter may be specified as an expression. @@ -345,7 +350,8 @@ public class Expression { * @return expression * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-rgba">Style specification</a> */ - public static Expression rgba(@NonNull Number red, @NonNull Number green, @NonNull Number blue, @NonNull Number alpha) { + public static Expression rgba(@NonNull Number red, @NonNull Number green, @NonNull Number blue, @NonNull Number + alpha) { return rgba(literal(red), literal(green), literal(blue), literal(alpha)); } @@ -386,6 +392,32 @@ public class Expression { /** * Returns true if the input values are equal, false otherwise. + * The inputs must be numbers, strings, or booleans, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * eq(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a> + */ + public static Expression eq(@NonNull Expression compareOne, @NonNull Expression compareTwo, + @NonNull Expression collator) { + return new Expression("==", compareOne, compareTwo, collator); + } + + /** + * Returns true if the input values are equal, false otherwise. * <p> * Example usage: * </p> @@ -432,6 +464,32 @@ public class Expression { /** * Returns true if the input values are equal, false otherwise. + * The inputs must be numbers, strings, or booleans, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * eq(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second String + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a> + */ + public static Expression eq(@NonNull Expression compareOne, @NonNull String compareTwo, + @NonNull Expression collator) { + return eq(compareOne, literal(compareTwo), collator); + } + + /** + * Returns true if the input values are equal, false otherwise. * <p> * Example usage: * </p> @@ -478,6 +536,32 @@ public class Expression { } /** + * Returns true if the input values are not equal, false otherwise. + * The inputs must be numbers, strings, or booleans, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * neq(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a> + */ + public static Expression neq(@NonNull Expression compareOne, @NonNull Expression compareTwo, + @NonNull Expression collator) { + return new Expression("!=", compareOne, compareTwo, collator); + } + + /** * Returns true if the input values are equal, false otherwise. * <p> * Example usage: @@ -524,6 +608,32 @@ public class Expression { } /** + * Returns true if the input values are not equal, false otherwise. + * The inputs must be numbers, strings, or booleans, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * neq(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second String + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a> + */ + public static Expression neq(@NonNull Expression compareOne, @NonNull String compareTwo, + @NonNull Expression collator) { + return new Expression("!=", compareOne, literal(compareTwo), collator); + } + + /** * Returns `true` if the input values are not equal, `false` otherwise. * <p> * Example usage: @@ -572,6 +682,32 @@ public class Expression { /** * Returns true if the first input is strictly greater than the second, false otherwise. + * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * gt(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E">Style specification</a> + */ + public static Expression gt(@NonNull Expression compareOne, @NonNull Expression compareTwo, + @NonNull Expression collator) { + return new Expression(">", compareOne, compareTwo, collator); + } + + /** + * Returns true if the first input is strictly greater than the second, false otherwise. * <p> * Example usage: * </p> @@ -617,6 +753,32 @@ public class Expression { } /** + * Returns true if the first input is strictly greater than the second, false otherwise. + * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * gt(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second String + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E">Style specification</a> + */ + public static Expression gt(@NonNull Expression compareOne, @NonNull String compareTwo, + @NonNull Expression collator) { + return new Expression(">", compareOne, literal(compareTwo), collator); + } + + /** * Returns true if the first input is strictly less than the second, false otherwise. * The inputs must be numbers or strings, and both of the same type. * <p> @@ -626,13 +788,13 @@ public class Expression { * {@code * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); * fillLayer.setFilter( - * lt(get("keyToValue"), get("keyToOtherValue")) + * lt(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) * ); * } * </pre> * * @param compareOne the first expression - * @param compareTwo the second number + * @param compareTwo the second expression * @return expression * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C">Style specification</a> */ @@ -642,6 +804,32 @@ public class Expression { /** * Returns true if the first input is strictly less than the second, false otherwise. + * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lt(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second number + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C">Style specification</a> + */ + public static Expression lt(@NonNull Expression compareOne, @NonNull Expression compareTwo, + @NonNull Expression collator) { + return new Expression("<", compareOne, compareTwo, collator); + } + + /** + * Returns true if the first input is strictly less than the second, false otherwise. * <p> * Example usage: * </p> @@ -687,6 +875,32 @@ public class Expression { } /** + * Returns true if the first input is strictly less than the second, false otherwise. + * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lt(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second String + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C">Style specification</a> + */ + public static Expression lt(@NonNull Expression compareOne, @NonNull String compareTwo, + @NonNull Expression collator) { + return new Expression("<", compareOne, literal(compareTwo), collator); + } + + /** * Returns true if the first input is greater than or equal to the second, false otherwise. * The inputs must be numbers or strings, and both of the same type. * <p> @@ -712,6 +926,32 @@ public class Expression { /** * Returns true if the first input is greater than or equal to the second, false otherwise. + * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * gte(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E%3D">Style specification</a> + */ + public static Expression gte(@NonNull Expression compareOne, @NonNull Expression compareTwo, + @NonNull Expression collator) { + return new Expression(">=", compareOne, compareTwo, collator); + } + + /** + * Returns true if the first input is greater than or equal to the second, false otherwise. * <p> * Example usage: * </p> @@ -757,6 +997,32 @@ public class Expression { } /** + * Returns true if the first input is greater than or equal to the second, false otherwise. + * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * gte(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second String + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E%3D">Style specification</a> + */ + public static Expression gte(@NonNull Expression compareOne, @NonNull String compareTwo, + @NonNull Expression collator) { + return new Expression(">=", compareOne, literal(compareTwo), collator); + } + + /** * Returns true if the first input is less than or equal to the second, false otherwise. * The inputs must be numbers or strings, and both of the same type. * <p> @@ -782,6 +1048,32 @@ public class Expression { /** * Returns true if the first input is less than or equal to the second, false otherwise. + * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lte(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C%3D">Style specification</a> + */ + public static Expression lte(@NonNull Expression compareOne, @NonNull Expression compareTwo, + @NonNull Expression collator) { + return new Expression("<=", compareOne, compareTwo, collator); + } + + /** + * Returns true if the first input is less than or equal to the second, false otherwise. * <p> * Example usage: * </p> @@ -827,6 +1119,32 @@ public class Expression { } /** + * Returns true if the first input is less than or equal to the second, false otherwise. + * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lte(get("keyToValue"), get("keyToOtherValue"), collator(true, false)) + * ); + * } + * </pre> + * + * @param compareOne the first expression + * @param compareTwo the second String + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C%3D">Style specification</a> + */ + public static Expression lte(@NonNull Expression compareOne, @NonNull String compareTwo, + @NonNull Expression collator) { + return new Expression("<=", compareOne, literal(compareTwo), collator); + } + + /** * Returns `true` if all the inputs are `true`, `false` otherwise. * <p> * The inputs are evaluated in order, and evaluation is short-circuiting: @@ -2479,6 +2797,32 @@ public class Expression { } /** + * Returns the IETF language tag of the locale being used by the provided collator. + * This can be used to determine the default system locale, + * or to determine if a requested locale was successfully loaded. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleColor(switchCase( + eq(literal("it"), resolvedLocale(collator(true, true, "it"))), literal(ColorUtils.colorToRgbaString(Color.GREEN)), + literal(ColorUtils.colorToRgbaString(Color.RED)))) + * ); + * } + * </pre> + * + * @param collator the collator expression + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-resolved-locale">Style specification</a> + */ + public static Expression resolvedLocale(Expression collator) { + return new Expression("resolved-locale", collator); + } + + /** * Returns the input string converted to uppercase. * <p> * Follows the Unicode Default Case Conversion algorithm @@ -2697,6 +3041,104 @@ public class Expression { } /** + * Returns a collator for use in locale-dependent comparison operations. + * The case-sensitive and diacritic-sensitive options default to false. + * The locale argument specifies the IETF language tag of the locale to use. + * If none is provided, the default locale is used. If the requested locale is not available, + * the collator will use a system-defined fallback locale. + * Use resolved-locale to test the results of locale fallback behavior. + * + * @param caseSensitive case sensitive flag + * @param diacriticSensitive diacritic sensitive flag + * @param locale locale + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-collator">Style specification</a> + */ + public static Expression collator(boolean caseSensitive, boolean diacriticSensitive, Locale locale) { + Map<String, Expression> map = new HashMap<>(); + map.put("case-sensitive", literal(caseSensitive)); + map.put("diacritic-sensitive", literal(diacriticSensitive)); + + StringBuilder localeStringBuilder = new StringBuilder(); + + String language = locale.getLanguage(); + if (language != null && !language.isEmpty()) { + localeStringBuilder.append(language); + } + + String country = locale.getCountry(); + if (country != null && !country.isEmpty()) { + localeStringBuilder.append("-"); + localeStringBuilder.append(country); + } + + map.put("locale", literal(localeStringBuilder.toString())); + return new Expression("collator", new ExpressionMap(map)); + } + + /** + * Returns a collator for use in locale-dependent comparison operations. + * The case-sensitive and diacritic-sensitive options default to false. + * The locale argument specifies the IETF language tag of the locale to use. + * If none is provided, the default locale is used. If the requested locale is not available, + * the collator will use a system-defined fallback locale. + * Use resolved-locale to test the results of locale fallback behavior. + * + * @param caseSensitive case sensitive flag + * @param diacriticSensitive diacritic sensitive flag + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-collator">Style specification</a> + */ + public static Expression collator(boolean caseSensitive, boolean diacriticSensitive) { + Map<String, Expression> map = new HashMap<>(); + map.put("case-sensitive", literal(caseSensitive)); + map.put("diacritic-sensitive", literal(diacriticSensitive)); + return new Expression("collator", new ExpressionMap(map)); + } + + /** + * Returns a collator for use in locale-dependent comparison operations. + * The case-sensitive and diacritic-sensitive options default to false. + * The locale argument specifies the IETF language tag of the locale to use. + * If none is provided, the default locale is used. If the requested locale is not available, + * the collator will use a system-defined fallback locale. + * Use resolved-locale to test the results of locale fallback behavior. + * + * @param caseSensitive case sensitive flag + * @param diacriticSensitive diacritic sensitive flag + * @param locale locale + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-collator">Style specification</a> + */ + public static Expression collator(Expression caseSensitive, Expression diacriticSensitive, Expression locale) { + Map<String, Expression> map = new HashMap<>(); + map.put("case-sensitive", caseSensitive); + map.put("diacritic-sensitive", diacriticSensitive); + map.put("locale", locale); + return new Expression("collator", new ExpressionMap(map)); + } + + /** + * Returns a collator for use in locale-dependent comparison operations. + * The case-sensitive and diacritic-sensitive options default to false. + * The locale argument specifies the IETF language tag of the locale to use. + * If none is provided, the default locale is used. If the requested locale is not available, + * the collator will use a system-defined fallback locale. + * Use resolved-locale to test the results of locale fallback behavior. + * + * @param caseSensitive case sensitive flag + * @param diacriticSensitive diacritic sensitive flag + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-collator">Style specification</a> + */ + public static Expression collator(Expression caseSensitive, Expression diacriticSensitive) { + Map<String, Expression> map = new HashMap<>(); + map.put("case-sensitive", caseSensitive); + map.put("diacritic-sensitive", diacriticSensitive); + return new Expression("collator", new ExpressionMap(map)); + } + + /** * Asserts that the input value is an object. If it is not, the expression is an error * The asserted input value is returned as result. * @@ -3422,8 +3864,8 @@ public class Expression { array.add(operator); if (arguments != null) { for (Expression argument : arguments) { - if (argument instanceof Expression.ExpressionLiteral) { - array.add(toValue((ExpressionLiteral) argument)); + if (argument instanceof ValueExpression) { + array.add(((ValueExpression) argument).toValue()); } else { array.add(argument.toArray()); } @@ -3433,22 +3875,6 @@ public class Expression { } /** - * Converts the expression value to an Object. - * - * @param expressionValue the expression value to convert - * @return the converted object expression - */ - private Object toValue(ExpressionLiteral expressionValue) { - Object value = expressionValue.toValue(); - if (value instanceof PropertyValue) { - throw new IllegalArgumentException("PropertyValue are not allowed as an expression literal, use value instead."); - } else if (value instanceof Expression.ExpressionLiteral) { - return toValue((ExpressionLiteral) value); - } - return value; - } - - /** * Returns a string representation of the object that matches the definition set in the style specification. * <p> * If this expression contains a coma (,) delimited literal, like 'rgba(r, g, b, a)`, @@ -3549,7 +3975,7 @@ public class Expression { * {@link #literal(String)} and {@link #literal(Object)}. * </p> */ - public static class ExpressionLiteral extends Expression { + public static class ExpressionLiteral extends Expression implements ValueExpression { protected Object literal; @@ -3572,7 +3998,14 @@ public class Expression { * * @return the literal object */ - Object toValue() { + @Override + public Object toValue() { + if (literal instanceof PropertyValue) { + throw new IllegalArgumentException( + "PropertyValue are not allowed as an expression literal, use value instead."); + } else if (literal instanceof Expression.ExpressionLiteral) { + return ((ExpressionLiteral) literal).toValue(); + } return literal; } @@ -3589,7 +4022,13 @@ public class Expression { */ @Override public String toString() { - return literal.toString(); + String string; + if (literal instanceof String) { + string = "\"" + literal + "\""; + } else { + string = literal.toString(); + } + return string; } /** @@ -3627,7 +4066,7 @@ public class Expression { return result; } - private String unwrapStringLiteral(String value) { + private static String unwrapStringLiteral(String value) { if (value.length() > 1 && value.charAt(0) == '\"' && value.charAt(value.length() - 1) == '\"') { return value.substring(1, value.length() - 1); @@ -3727,20 +4166,36 @@ public class Expression { JsonElement jsonElement; for (int i = 1; i < jsonArray.size(); i++) { jsonElement = jsonArray.get(i); - if (jsonElement instanceof JsonArray) { - arguments.add(convert((JsonArray) jsonElement)); - } else if (jsonElement instanceof JsonPrimitive) { - arguments.add(convert((JsonPrimitive) jsonElement)); - } else if (jsonElement instanceof JsonNull) { - arguments.add(new Expression.ExpressionLiteral("")); - } else { - throw new RuntimeException("Unsupported expression conversion for " + jsonElement.getClass()); - } + arguments.add(convert(jsonElement)); } return new Expression(operator, arguments.toArray(new Expression[arguments.size()])); } /** + * Converts a JsonElement to an expression + * + * @param jsonElement the json element to convert + * @return the expression + */ + private static Expression convert(@NonNull JsonElement jsonElement) { + if (jsonElement instanceof JsonArray) { + return convert((JsonArray) jsonElement); + } else if (jsonElement instanceof JsonPrimitive) { + return convert((JsonPrimitive) jsonElement); + } else if (jsonElement instanceof JsonNull) { + return new Expression.ExpressionLiteral(""); + } else if (jsonElement instanceof JsonObject) { + Map<String, Expression> map = new HashMap<>(); + for (String key : ((JsonObject) jsonElement).keySet()) { + map.put(key, convert(((JsonObject) jsonElement).get(key))); + } + return new ExpressionMap(map); + } else { + throw new RuntimeException("Unsupported expression conversion for " + jsonElement.getClass()); + } + } + + /** * Converts a JsonPrimitive to an expression literal * * @param jsonPrimitive the json primitive to convert @@ -3816,6 +4271,79 @@ public class Expression { } /** + * Wraps an expression value stored in a Map. + */ + private static class ExpressionMap extends Expression implements ValueExpression { + private Map<String, Expression> map; + + ExpressionMap(Map<String, Expression> map) { + this.map = map; + } + + @Override + public Object toValue() { + Map<String, Object> unwrappedMap = new HashMap<>(); + for (String key : map.keySet()) { + Expression expression = map.get(key); + if (expression instanceof Expression.ExpressionLiteral) { + unwrappedMap.put(key, ((ExpressionLiteral) expression).toValue()); + } else { + unwrappedMap.put(key, expression.toArray()); + } + } + + return unwrappedMap; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("{"); + for (String key : map.keySet()) { + builder.append("\"").append(key).append("\": "); + builder.append(map.get(key)); + builder.append(", "); + } + + if (map.size() > 0) { + builder.delete(builder.length() - 2, builder.length()); + } + + builder.append("}"); + return builder.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + ExpressionMap that = (ExpressionMap) o; + return map.equals(that.map); + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (map == null ? 0 : map.hashCode()); + return result; + } + } + + /** + * Interface used to describe expressions that hold a Java value. + */ + private interface ValueExpression { + Object toValue(); + } + + /** * Converts an object that is a primitive array to an Object[] * * @param object the object to convert to an object array diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java index ddb4d04fff..dd20a4b957 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java @@ -28,7 +28,7 @@ public class BackgroundLayer extends Layer { * @param nativePtr pointer used by core */ @Keep - public BackgroundLayer(long nativePtr) { + BackgroundLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java index 8abd78ace2..9d2b9d89a5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java @@ -28,7 +28,7 @@ public class CircleLayer extends Layer { * @param nativePtr pointer used by core */ @Keep - public CircleLayer(long nativePtr) { + CircleLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java index 79b68bbfc0..c03f8689fc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java @@ -16,7 +16,7 @@ public class CustomLayer extends Layer { } @Keep - public CustomLayer(long nativePtr) { + CustomLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java index 6efe04e39d..2de0de06d9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java @@ -28,7 +28,7 @@ public class FillExtrusionLayer extends Layer { * @param nativePtr pointer used by core */ @Keep - public FillExtrusionLayer(long nativePtr) { + FillExtrusionLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java index aaa20d6f3a..6e28900c26 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java @@ -28,7 +28,7 @@ public class FillLayer extends Layer { * @param nativePtr pointer used by core */ @Keep - public FillLayer(long nativePtr) { + FillLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java index 6d7cece124..f1076ecd96 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java @@ -28,7 +28,7 @@ public class HeatmapLayer extends Layer { * @param nativePtr pointer used by core */ @Keep - public HeatmapLayer(long nativePtr) { + HeatmapLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java index f906104e91..f706e5a234 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java @@ -28,7 +28,7 @@ public class HillshadeLayer extends Layer { * @param nativePtr pointer used by core */ @Keep - public HillshadeLayer(long nativePtr) { + HillshadeLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java index 92aa54e55f..605f883bdb 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java @@ -18,7 +18,7 @@ public abstract class Layer { private boolean invalidated; @Keep - public Layer(long nativePtr) { + protected Layer(long nativePtr) { checkThread(); this.nativePtr = nativePtr; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java index 4a742cd7a6..d6519c991f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java @@ -28,7 +28,7 @@ public class LineLayer extends Layer { * @param nativePtr pointer used by core */ @Keep - public LineLayer(long nativePtr) { + LineLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index 1cedf8c9ca..cd7bd473f3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -2055,7 +2055,7 @@ public class PropertyFactory { } /** - * Value to use for a text label. + * Value to use for a text label. If a plain `string` is provided, it will be treated as a `formatted` with default/inherited formatting options. * * @param value a String value * @return property wrapper around String @@ -2065,7 +2065,7 @@ public class PropertyFactory { } /** - * Value to use for a text label. + * Value to use for a text label. If a plain `string` is provided, it will be treated as a `formatted` with default/inherited formatting options. * * @param value a String value * @return property wrapper around String diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java index 83e228cba0..50837a97be 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java @@ -28,7 +28,7 @@ public class RasterLayer extends Layer { * @param nativePtr pointer used by core */ @Keep - public RasterLayer(long nativePtr) { + RasterLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java index f2ddb600a5..4389f6cb21 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java @@ -28,7 +28,7 @@ public class SymbolLayer extends Layer { * @param nativePtr pointer used by core */ @Keep - public SymbolLayer(long nativePtr) { + SymbolLayer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs index 2d4db2b55d..6ed58b1928 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs @@ -33,7 +33,7 @@ public class <%- camelize(type) %>Layer extends Layer { * @param nativePtr pointer used by core */ @Keep - public <%- camelize(type) %>Layer(long nativePtr) { + <%- camelize(type) %>Layer(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java index c0cf33e150..f3886d6cce 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java @@ -29,7 +29,7 @@ public class Light { * @param nativePtr pointer used by core */ @Keep - public Light(long nativePtr) { + Light(long nativePtr) { checkThread(); this.nativePtr = nativePtr; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs index 59b07d32d4..7c9893a3a4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs @@ -33,7 +33,7 @@ public class Light { * @param nativePtr pointer used by core */ @Keep - public Light(long nativePtr) { + Light(long nativePtr) { checkThread(); this.nativePtr = nativePtr; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java index 1f6029e2a2..6c0b76f00e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java @@ -15,18 +15,26 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; /** * Custom Vector Source, allows using FeatureCollections. - * */ @UiThread public class CustomGeometrySource extends Source { + public static final String THREAD_PREFIX = "CustomGeom"; + public static final int THREAD_POOL_LIMIT = 4; + private static final AtomicInteger poolCount = new AtomicInteger(); + private final Lock executorLock = new ReentrantLock(); private ExecutorService executor; private GeometryTileProvider provider; private final Map<TileID, AtomicBoolean> cancelledTileRequests = new ConcurrentHashMap<>(); @@ -34,7 +42,7 @@ public class CustomGeometrySource extends Source { /** * Create a CustomGeometrySource * - * @param id The source id. + * @param id The source id. * @param provider The tile provider that returns geometry data for this source. */ public CustomGeometrySource(String id, GeometryTileProvider provider) { @@ -45,21 +53,20 @@ public class CustomGeometrySource extends Source { * Create a CustomGeometrySource with non-default CustomGeometrySourceOptions. * <p>Supported options are minZoom, maxZoom, buffer, and tolerance.</p> * - * @param id The source id. + * @param id The source id. * @param provider The tile provider that returns geometry data for this source. - * @param options CustomGeometrySourceOptions. + * @param options CustomGeometrySourceOptions. */ public CustomGeometrySource(String id, GeometryTileProvider provider, CustomGeometrySourceOptions options) { super(); this.provider = provider; - executor = Executors.newFixedThreadPool(4); initialize(id, options); } /** - * Invalidate previously provided features within a given bounds at all zoom levels. - * Invoking this method will result in new requests to `GeometryTileProvider` for regions - * that contain, include, or intersect with the provided bounds. + * Invalidate previously provided features within a given bounds at all zoom levels. + * Invoking this method will result in new requests to `GeometryTileProvider` for regions + * that contain, include, or intersect with the provided bounds. * * @param bounds The region in which features should be invalidated at all zoom levels */ @@ -73,8 +80,8 @@ public class CustomGeometrySource extends Source { * in new requests to `GeometryTileProvider` for visible tiles. * * @param zoomLevel Tile zoom level. - * @param x Tile X coordinate. - * @param y Tile Y coordinate. + * @param x Tile X coordinate. + * @param y Tile Y coordinate. */ public void invalidateTile(int zoomLevel, int x, int y) { checkThread(); @@ -87,9 +94,9 @@ public class CustomGeometrySource extends Source { * background threads. * * @param zoomLevel Tile zoom level. - * @param x Tile X coordinate. - * @param y Tile Y coordinate. - * @param data Feature collection for the tile. + * @param x Tile X coordinate. + * @param y Tile Y coordinate. + * @param data Feature collection for the tile. */ public void setTileData(int zoomLevel, int x, int y, FeatureCollection data) { checkThread(); @@ -140,7 +147,15 @@ public class CustomGeometrySource extends Source { TileID tileID = new TileID(z, x, y); cancelledTileRequests.put(tileID, cancelFlag); GeometryTileRequest request = new GeometryTileRequest(tileID, provider, this, cancelFlag); - executor.execute(request); + + executorLock.lock(); + try { + if (executor != null && !executor.isShutdown()) { + executor.execute(request); + } + } finally { + executorLock.unlock(); + } } @WorkerThread @@ -152,6 +167,40 @@ public class CustomGeometrySource extends Source { } } + @Keep + private void startThreads() { + executorLock.lock(); + try { + if (executor != null && !executor.isShutdown()) { + executor.shutdownNow(); + } + + executor = Executors.newFixedThreadPool(THREAD_POOL_LIMIT, new ThreadFactory() { + final AtomicInteger threadCount = new AtomicInteger(); + final int poolId = poolCount.getAndIncrement(); + + @Override + public Thread newThread(@NonNull Runnable runnable) { + return new Thread( + runnable, + String.format(Locale.US, "%s-%d-%d", THREAD_PREFIX, poolId, threadCount.getAndIncrement())); + } + }); + } finally { + executorLock.unlock(); + } + } + + @Keep + private void releaseThreads() { + executorLock.lock(); + try { + executor.shutdownNow(); + } finally { + executorLock.unlock(); + } + } + private static class TileID { public int z; public int x; @@ -164,7 +213,7 @@ public class CustomGeometrySource extends Source { } public int hashCode() { - return Arrays.hashCode(new int[]{z, x, y}); + return Arrays.hashCode(new int[] {z, x, y}); } public boolean equals(Object object) { @@ -177,7 +226,7 @@ public class CustomGeometrySource extends Source { } if (object instanceof TileID) { - TileID other = (TileID)object; + TileID other = (TileID) object; return this.z == other.z && this.x == other.x && this.y == other.y; } return false; @@ -205,7 +254,7 @@ public class CustomGeometrySource extends Source { FeatureCollection data = provider.getFeaturesForBounds(LatLngBounds.from(id.z, id.x, id.y), id.z); CustomGeometrySource source = sourceRef.get(); - if (!isCancelled() && source != null && data != null) { + if (!isCancelled() && source != null && data != null) { source.setTileData(id, data); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java index 79cde7429c..6961027338 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java @@ -11,9 +11,9 @@ import java.util.HashMap; public class GeoJsonOptions extends HashMap<String, Object> { /** - * Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels). + * Minimum zoom level at which to create vector tiles (lower means more field of view detail at low zoom levels). * - * @param minZoom the maximum zoom - Defaults to 18. + * @param minZoom the minimum zoom - Defaults to 0. * @return the current instance for chaining */ public GeoJsonOptions withMinZoom(int minZoom) { @@ -24,7 +24,7 @@ public class GeoJsonOptions extends HashMap<String, Object> { /** * Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels). * - * @param maxZoom the maximum zoom - Defaults to 18. + * @param maxZoom the maximum zoom - Defaults to 25.5 * @return the current instance for chaining */ public GeoJsonOptions withMaxZoom(int maxZoom) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java index 33d8ba03ee..2d9b1c985a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java @@ -29,7 +29,7 @@ public class GeoJsonSource extends Source { * @param nativePtr - pointer to native peer */ @Keep - public GeoJsonSource(long nativePtr) { + GeoJsonSource(long nativePtr) { super(nativePtr); } @@ -188,7 +188,8 @@ public class GeoJsonSource extends Source { } /** - * Updates the GeoJson with a single feature + * Updates the GeoJson with a single feature. The update is performed asynchronously, + * so the data won't be immediately visible or available to query when this method returns. * * @param feature the GeoJSON {@link Feature} to set */ @@ -198,7 +199,8 @@ public class GeoJsonSource extends Source { } /** - * Updates the GeoJson with a single geometry + * Updates the GeoJson with a single geometry. The update is performed asynchronously, + * so the data won't be immediately visible or available to query when this method returns. * * @param geometry the GeoJSON {@link Geometry} to set */ @@ -208,7 +210,8 @@ public class GeoJsonSource extends Source { } /** - * Updates the GeoJson + * Updates the GeoJson. The update is performed asynchronously, + * so the data won't be immediately visible or available to query when this method returns. * * @param features the GeoJSON FeatureCollection */ @@ -218,7 +221,8 @@ public class GeoJsonSource extends Source { } /** - * Updates the GeoJson + * Updates the GeoJson. The update is performed asynchronously, + * so the data won't be immediately visible or available to query when this method returns. * * @param json the raw GeoJson FeatureCollection string */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/ImageSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/ImageSource.java index d84105a05c..d0ca5e050b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/ImageSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/ImageSource.java @@ -35,7 +35,7 @@ public class ImageSource extends Source { * @param nativePtr - pointer to native peer */ @Keep - public ImageSource(long nativePtr) { + ImageSource(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java index dc3635ca86..4c2b39375a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java @@ -21,7 +21,7 @@ public class RasterDemSource extends Source { * @param nativePtr - pointer to native peer */ @Keep - private RasterDemSource(long nativePtr) { + RasterDemSource(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java index 6bd0456e0c..dac9b02166 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java @@ -19,7 +19,7 @@ public class RasterSource extends Source { * @param nativePtr - pointer to native peer */ @Keep - public RasterSource(long nativePtr) { + RasterSource(long nativePtr) { super(nativePtr); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/Source.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/Source.java index 53c8148580..14d9ef1cc5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/Source.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/Source.java @@ -18,7 +18,7 @@ public abstract class Source { * @param nativePtr - pointer to native peer */ @Keep - public Source(long nativePtr) { + protected Source(long nativePtr) { checkThread(); this.nativePtr = nativePtr; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java index 393d8c2b81..5888eaa7e1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java @@ -28,7 +28,7 @@ public class VectorSource extends Source { * @param nativePtr - pointer to native peer */ @Keep - public VectorSource(long nativePtr) { + VectorSource(long nativePtr) { super(nativePtr); } |