diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK')
32 files changed, 4419 insertions, 181 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index ce886b1001..70c98f534a 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -1,27 +1,20 @@ apply plugin: 'com.android.library' dependencies { - compile rootProject.ext.dep.supportAnnotations - compile rootProject.ext.dep.supportFragmentV4 - compile rootProject.ext.dep.timber - compile rootProject.ext.dep.okhttp3 - provided(rootProject.ext.dep.lost) { - exclude group: 'com.android.support' - } - testCompile rootProject.ext.dep.junit - testCompile rootProject.ext.dep.mockito - testCompile rootProject.ext.dep.robolectric - - // Mapbox Android Services (GeoJSON support) - compile(rootProject.ext.dep.mapboxJavaGeoJSON) { - transitive = true - } - - // Mapbox Android Services (Telemetry support) - compile(rootProject.ext.dep.mapboxAndroidTelemetry) { - transitive = true + api rootProject.ext.dep.mapboxAndroidTelemetry + api rootProject.ext.dep.mapboxJavaGeoJSON + implementation rootProject.ext.dep.supportAnnotations + implementation rootProject.ext.dep.supportFragmentV4 + implementation rootProject.ext.dep.timber + implementation rootProject.ext.dep.okhttp3 + compileOnly(rootProject.ext.dep.lost) { + exclude group: 'com.google.guava' exclude group: 'com.android.support' } + testImplementation rootProject.ext.dep.lost + testImplementation rootProject.ext.dep.junit + testImplementation rootProject.ext.dep.mockito + testImplementation rootProject.ext.dep.robolectric } android { @@ -120,7 +113,7 @@ android { } lintOptions { - disable 'MissingTranslation', 'TypographyQuotes' + disable 'MissingTranslation', 'TypographyQuotes', 'ObsoleteLintCustomCheck', 'MissingPermission' baseline file("lint-baseline-local.xml") checkAllWarnings true warningsAsErrors false diff --git a/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle b/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle index e0bc076d3d..420ccb473a 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle +++ b/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle @@ -16,6 +16,7 @@ task checkstyle(type: Checkstyle) { exclude '**/style/layers/PropertyFactory.java' exclude '**/style/layers/*Layer.java' exclude '**/style/light/Light.java' + exclude '**/Expression.java' // allowing single character signature as e() classpath = files() ignoreFailures = false } diff --git a/platform/android/MapboxGLAndroidSDK/gradle-javadoc.gradle b/platform/android/MapboxGLAndroidSDK/gradle-javadoc.gradle index eeb5e9b4d6..39372b4378 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle-javadoc.gradle +++ b/platform/android/MapboxGLAndroidSDK/gradle-javadoc.gradle @@ -10,7 +10,7 @@ android.libraryVariants.all { variant -> options.windowTitle("Mapbox Android SDK $VERSION_NAME Reference") options.docTitle("Mapbox Android SDK $VERSION_NAME") options.header("Mapbox Android SDK $VERSION_NAME Reference") - options.bottom("© 2015–2017 Mapbox. All rights reserved.") + options.bottom("© 2015–2018 Mapbox. All rights reserved.") options.links("http://docs.oracle.com/javase/7/docs/api/") options.linksOffline("http://d.android.com/reference/", "$System.env.ANDROID_HOME/docs/reference") options.overview("src/main/java/overview.html") diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties index f1257f346e..f00eb1d77f 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle.properties +++ b/platform/android/MapboxGLAndroidSDK/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.mapbox.mapboxsdk -VERSION_NAME=5.3.0-SNAPSHOT +VERSION_NAME=6.0.0-SNAPSHOT POM_DESCRIPTION=Mapbox GL Android SDK POM_URL=https://github.com/mapbox/mapbox-gl-native diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java index a024f0ab70..6633d5d952 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java @@ -3,18 +3,46 @@ package com.mapbox.mapboxsdk; import timber.log.Timber; /** - * Centralises the knowledge about "mapbox-gl" library loading. + * Loads the mapbox-gl shared library + * <p> + * By default uses the {@link System#loadLibrary(String)}, + * use {@link #setLibraryLoader(LibraryLoader)} to provide an alternative library loading hook. + * </p> */ -public class LibraryLoader { +public abstract class LibraryLoader { + + private static final LibraryLoader DEFAULT = new LibraryLoader() { + @Override + public void load(String name) { + System.loadLibrary(name); + } + }; + + private static volatile LibraryLoader loader = DEFAULT; + + /** + * Set the library loader that loads the shared library. + * + * @param libraryLoader the library loader + */ + public static void setLibraryLoader(LibraryLoader libraryLoader) { + loader = libraryLoader; + } /** * Loads "libmapbox-gl.so" native shared library. + * <p> + * Catches UnsatisfiedLinkErrors and prints a warning to logcat. + * </p> */ public static void load() { try { - System.loadLibrary("mapbox-gl"); + loader.load("mapbox-gl"); } catch (UnsatisfiedLinkError error) { Timber.e(error, "Failed to load native shared library."); } } + + public abstract void load(String name); } + 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 357bcd5f99..b67b6e96f2 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 @@ -12,10 +12,10 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException; import com.mapbox.mapboxsdk.location.LocationSource; import com.mapbox.mapboxsdk.net.ConnectivityReceiver; +import com.mapbox.services.android.telemetry.MapboxTelemetry; import com.mapbox.services.android.telemetry.location.LocationEngine; import com.mapbox.services.android.telemetry.location.LocationEnginePriority; import com.mapbox.services.android.telemetry.location.LocationEngineProvider; -import com.mapbox.services.android.telemetry.MapboxTelemetry; import timber.log.Timber; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/GeometryConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/GeometryConstants.java new file mode 100644 index 0000000000..1a7544d33a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/GeometryConstants.java @@ -0,0 +1,63 @@ +package com.mapbox.mapboxsdk.constants; + +/** + * Contains constants used throughout the sdk classes. + * + * @since 6.0.0 + */ +public class GeometryConstants { + + /** + * The <a href='http://en.wikipedia.org/wiki/Earth_radius#Equatorial_radius'>equatorial radius</a> + * value in meters + * + * @since 6.0.0 + */ + public static final int RADIUS_EARTH_METERS = 6378137; + + /** + * This constant represents the lowest longitude value available to represent a geolocation. + * + * @since 6.0.0 + */ + public static final double MIN_LONGITUDE = -180; + + /** + * This constant represents the highest longitude value available to represent a geolocation. + * + * @since 6.0.0 + */ + public static final double MAX_LONGITUDE = 180; + + /** + * This constant represents the lowest latitude value available to represent a geolocation. + * + * @since 6.0.0 + */ + public static final double MIN_LATITUDE = -90; + + /** + * This constant represents the highest latitude value available to represent a geolocation. + * + * @since 6.0.0 + */ + public static final double MAX_LATITUDE = 90; + + /** + * Maximum latitude value in Mercator projection. + * + * @since 6.0.0 + */ + public static final double MAX_MERCATOR_LATITUDE = 85.05112877980659; + + /** + * Minimum latitude value in Mercator projection. + * + * @since 6.0.0 + */ + public static final double MIN_MERCATOR_LATITUDE = -85.05112877980659; + + private GeometryConstants() { + // Private constructor to prevent initializing of this class. + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java index eb57241196..79023e2fd9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java @@ -5,8 +5,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.FloatRange; -import com.mapbox.services.android.telemetry.constants.GeoConstants; -import com.mapbox.services.android.telemetry.utils.MathUtils; +import com.mapbox.mapboxsdk.constants.GeometryConstants; + /** * A geographical location which contains a single latitude, longitude pair, with @@ -105,20 +105,20 @@ public class LatLng implements ILatLng, Parcelable { /** * Set the latitude, in degrees. * <p> - * This value is in the range of [-85.05112878, 85.05112878], see {@link GeoConstants#MIN_LATITUDE} and - * {@link GeoConstants#MAX_LATITUDE} + * This value is in the range of [-90, 90], see {@link GeometryConstants#MIN_LATITUDE} and + * {@link GeometryConstants#MAX_LATITUDE} * </p> * * @param latitude the latitude value in degrees - * @see GeoConstants#MIN_LATITUDE - * @see GeoConstants#MAX_LATITUDE + * @see GeometryConstants#MIN_LATITUDE + * @see GeometryConstants#MAX_LATITUDE */ public void setLatitude( - @FloatRange(from = GeoConstants.MIN_LATITUDE, to = GeoConstants.MAX_LATITUDE) double latitude) { + @FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latitude) { if (Double.isNaN(latitude)) { throw new IllegalArgumentException("latitude must not be NaN"); } - if (Math.abs(latitude) > 90.0) { + if (Math.abs(latitude) > GeometryConstants.MAX_LATITUDE) { throw new IllegalArgumentException("latitude must be between -90 and 90"); } this.latitude = latitude; @@ -127,13 +127,13 @@ public class LatLng implements ILatLng, Parcelable { /** * Get the latitude, in degrees. * <p> - * This value is in the range of [-85.05112878, 85.05112878], see {@link GeoConstants#MIN_LATITUDE} and - * {@link GeoConstants#MAX_LATITUDE} + * This value is in the range of [-90, 90], see {@link GeometryConstants#MIN_LATITUDE} and + * {@link GeometryConstants#MAX_LATITUDE} * </p> * * @return the latitude value in degrees - * @see GeoConstants#MIN_LATITUDE - * @see GeoConstants#MAX_LATITUDE + * @see GeometryConstants#MIN_LATITUDE + * @see GeometryConstants#MAX_LATITUDE */ @Override public double getLatitude() { @@ -143,15 +143,15 @@ public class LatLng implements ILatLng, Parcelable { /** * Set the longitude, in degrees. * <p> - * This value is in the range of [-180, 180], see {@link GeoConstants#MIN_LONGITUDE} and - * {@link GeoConstants#MAX_LONGITUDE} + * This value is in the range of [-180, 180], see {@link GeometryConstants#MIN_LONGITUDE} and + * {@link GeometryConstants#MAX_LONGITUDE} * </p> * * @param longitude the longitude value in degrees - * @see GeoConstants#MIN_LONGITUDE - * @see GeoConstants#MAX_LONGITUDE + * @see GeometryConstants#MIN_LONGITUDE + * @see GeometryConstants#MAX_LONGITUDE */ - public void setLongitude(@FloatRange(from = GeoConstants.MIN_LONGITUDE, to = GeoConstants.MAX_LONGITUDE) + public void setLongitude(@FloatRange(from = GeometryConstants.MIN_LONGITUDE, to = GeometryConstants.MAX_LONGITUDE) double longitude) { if (Double.isNaN(longitude)) { throw new IllegalArgumentException("longitude must not be NaN"); @@ -165,13 +165,13 @@ public class LatLng implements ILatLng, Parcelable { /** * Get the longitude, in degrees. * <p> - * This value is in the range of [-180, 180], see {@link GeoConstants#MIN_LONGITUDE} and - * {@link GeoConstants#MAX_LONGITUDE} + * This value is in the range of [-180, 180], see {@link GeometryConstants#MIN_LONGITUDE} and + * {@link GeometryConstants#MAX_LONGITUDE} * </p> * * @return the longitude value in degrees - * @see GeoConstants#MIN_LONGITUDE - * @see GeoConstants#MAX_LONGITUDE + * @see GeometryConstants#MIN_LONGITUDE + * @see GeometryConstants#MAX_LONGITUDE */ @Override public double getLongitude() { @@ -204,8 +204,33 @@ public class LatLng implements ILatLng, Parcelable { * @return new LatLng object with wrapped Longitude */ public LatLng wrap() { - longitude = MathUtils.wrap(longitude, GeoConstants.MIN_LONGITUDE, GeoConstants.MAX_LONGITUDE); - return this; + return new LatLng(latitude, wrap(longitude, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE)); + } + + + /** + * Constrains value to the given range (including min & max) via modular arithmetic. + * <p> + * Same formula as used in Core GL (wrap.hpp) + * std::fmod((std::fmod((value - min), d) + d), d) + min; + * + * Multiples of max value will be wrapped to max. + * + * @param value Value to wrap + * @param min Minimum value + * @param max Maximum value + * @return Wrapped value + */ + static double wrap(double value, double min, double max) { + double delta = max - min; + + double firstMod = (value - min) % delta; + double secondMod = (firstMod + delta) % delta; + + if (value >= max && secondMod == 0) { + return max; + } + return secondMod + min; } /** @@ -305,6 +330,6 @@ public class LatLng implements ILatLng, Parcelable { final double t3 = Math.sin(a1) * Math.sin(b1); final double tt = Math.acos(t1 + t2 + t3); - return GeoConstants.RADIUS_EARTH_METERS * tt; + return GeometryConstants.RADIUS_EARTH_METERS * tt; } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java index 4fcb91033c..6d027a0cef 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java @@ -5,8 +5,8 @@ import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.mapbox.mapboxsdk.constants.GeometryConstants; import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException; -import com.mapbox.services.android.telemetry.constants.GeoConstants; import java.util.ArrayList; import java.util.List; @@ -48,8 +48,8 @@ public class LatLngBounds implements Parcelable { */ public static LatLngBounds world() { return new LatLngBounds.Builder() - .include(new LatLng(GeoConstants.MAX_LATITUDE, GeoConstants.MAX_LONGITUDE)) - .include(new LatLng(GeoConstants.MIN_LATITUDE, GeoConstants.MIN_LONGITUDE)) + .include(new LatLng(GeometryConstants.MAX_LATITUDE, GeometryConstants.MAX_LONGITUDE)) + .include(new LatLng(GeometryConstants.MIN_LATITUDE, GeometryConstants.MIN_LONGITUDE)) .build(); } @@ -194,10 +194,10 @@ public class LatLngBounds implements Parcelable { * @return LatLngBounds */ static LatLngBounds fromLatLngs(final List<? extends ILatLng> latLngs) { - double minLat = 90; - double minLon = 180; - double maxLat = -90; - double maxLon = -180; + double minLat = GeometryConstants.MAX_LATITUDE; + double minLon = GeometryConstants.MAX_LONGITUDE; + double maxLat = GeometryConstants.MIN_LATITUDE; + double maxLon = GeometryConstants.MIN_LONGITUDE; for (final ILatLng gp : latLngs) { final double latitude = gp.getLatitude(); @@ -231,6 +231,30 @@ public class LatLngBounds implements Parcelable { return new LatLngBounds(latNorth, lonEast, latSouth, lonWest); } + private static double lat_(int z, int y) { + double n = Math.PI - 2.0 * Math.PI * y / Math.pow(2.0, z); + return Math.toDegrees(Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))); + } + + private static double lon_(int z, int x) { + return x / Math.pow(2.0, z) * 360.0 - GeometryConstants.MAX_LONGITUDE; + } + + /** + * Constructs a LatLngBounds from a Tile identifier. + * + * Returned bounds will have latitude in the range of Mercator projection. + * @see GeometryConstants#MIN_MERCATOR_LATITUDE + * @see GeometryConstants#MAX_MERCATOR_LATITUDE + * + * @param z Tile zoom level. + * @param x Tile X coordinate. + * @param y Tile Y coordinate. + */ + public static LatLngBounds from(int z, int x, int y) { + return new LatLngBounds(lat_(z, y), lon_(z, x + 1), lat_(z, y + 1), lon_(z, x)); + } + /** * Constructs a LatLngBounds from current bounds with an additional latitude-longitude pair. * @@ -305,17 +329,17 @@ public class LatLngBounds implements Parcelable { * Returns a new LatLngBounds that stretches to include another LatLngBounds, * given by corner points. * - * @param lonNorth Northern Longitude - * @param latEast Eastern Latitude - * @param lonSouth Southern Longitude - * @param latWest Western Longitude + * @param latNorth Northern Latitude + * @param lonEast Eastern Longitude + * @param latSouth Southern Latitude + * @param lonWest Western Longitude * @return BoundingBox */ - public LatLngBounds union(final double lonNorth, final double latEast, final double lonSouth, final double latWest) { - return new LatLngBounds((this.latitudeNorth < lonNorth) ? lonNorth : this.latitudeNorth, - (this.longitudeEast < latEast) ? latEast : this.longitudeEast, - (this.latitudeSouth > lonSouth) ? lonSouth : this.latitudeSouth, - (this.longitudeWest > latWest) ? latWest : this.longitudeWest); + public LatLngBounds union(final double latNorth, final double lonEast, final double latSouth, final double lonWest) { + return new LatLngBounds((this.latitudeNorth < latNorth) ? latNorth : this.latitudeNorth, + (this.longitudeEast < lonEast) ? lonEast : this.longitudeEast, + (this.latitudeSouth > latSouth) ? latSouth : this.latitudeSouth, + (this.longitudeWest > lonWest) ? lonWest : this.longitudeWest); } /** @@ -326,13 +350,13 @@ public class LatLngBounds implements Parcelable { */ @Nullable public LatLngBounds intersect(LatLngBounds box) { - double minLatWest = Math.max(getLonWest(), box.getLonWest()); - double maxLatEast = Math.min(getLonEast(), box.getLonEast()); - if (maxLatEast > minLatWest) { - double minLonSouth = Math.max(getLatSouth(), box.getLatSouth()); - double maxLonNorth = Math.min(getLatNorth(), box.getLatNorth()); - if (maxLonNorth > minLonSouth) { - return new LatLngBounds(maxLonNorth, maxLatEast, minLonSouth, minLatWest); + double minLonWest = Math.max(getLonWest(), box.getLonWest()); + double maxLonEast = Math.min(getLonEast(), box.getLonEast()); + if (maxLonEast > minLonWest) { + double minLatSouth = Math.max(getLatSouth(), box.getLatSouth()); + double maxLatNorth = Math.min(getLatNorth(), box.getLatNorth()); + if (maxLatNorth > minLatSouth) { + return new LatLngBounds(maxLatNorth, maxLonEast, minLatSouth, minLonWest); } } return null; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java index 605c8912e2..69a43d4d3e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java @@ -127,16 +127,43 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M idle = false; moveStartedReason = reason; handler.post(onCameraMoveStartedRunnable); + + // new API + if (!onCameraMoveStarted.isEmpty()) { + for (OnCameraMoveStartedListener cameraMoveStartedListener : onCameraMoveStarted) { + cameraMoveStartedListener.onCameraMoveStarted(reason); + } + } } @Override public void onCameraMove() { handler.post(onCameraMoveRunnable); + if (onCameraMoveListener != null && !idle) { + onCameraMoveListener.onCameraMove(); + } + + // new API + if (!onCameraMove.isEmpty() && !idle) { + for (OnCameraMoveListener cameraMoveListener : onCameraMove) { + cameraMoveListener.onCameraMove(); + } + } } @Override public void onCameraMoveCanceled() { handler.post(onCameraMoveCancelRunnable); + if (onCameraMoveCanceledListener != null && !idle) { + onCameraMoveCanceledListener.onCameraMoveCanceled(); + } + + // new API + if (!onCameraMoveCanceled.isEmpty() && !idle) { + for (OnCameraMoveCanceledListener cameraMoveCanceledListener : onCameraMoveCanceled) { + cameraMoveCanceledListener.onCameraMoveCanceled(); + } + } } @Override @@ -144,6 +171,16 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M if (!idle) { idle = true; handler.post(onCameraIdleRunnable); + if (onCameraIdleListener != null) { + onCameraIdleListener.onCameraIdle(); + } + + // new API + if (!onCameraIdle.isEmpty()) { + for (OnCameraIdleListener cameraIdleListener : onCameraIdle) { + cameraIdleListener.onCameraIdle(); + } + } } } 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 77d2ac0e28..256f49ef52 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 @@ -22,7 +22,6 @@ import android.view.ViewTreeObserver; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ZoomButtonsController; - import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.MarkerViewManager; @@ -37,7 +36,10 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings; import com.mapbox.mapboxsdk.net.ConnectivityReceiver; import com.mapbox.mapboxsdk.storage.FileSource; import com.mapbox.services.android.telemetry.MapboxTelemetry; +import timber.log.Timber; +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; @@ -45,11 +47,6 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; - -import timber.log.Timber; - import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION; import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE; @@ -273,7 +270,7 @@ public class MapView extends FrameLayout { /** * <p> * You must call this method from the parent's Activity#onCreate(Bundle)} or - * Fragment#onCreate(Bundle). + * Fragment#onViewCreated(View, Bundle). * </p> * You must set a valid access token with {@link com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)} * before you call this method or an exception will be thrown. @@ -296,51 +293,43 @@ public class MapView extends FrameLayout { mapRenderer = new TextureViewMapRenderer(getContext(), textureView, options.getLocalIdeographFontFamily()) { @Override protected void onSurfaceCreated(GL10 gl, EGLConfig config) { - MapView.this.post(new Runnable() { - @Override - public void run() { - // Initialise only once - if (mapboxMap == null) { - initialiseMap(); - mapboxMap.onStart(); - } - } - }); - + initRenderSurface(); super.onSurfaceCreated(gl, config); } }; + addView(textureView, 0); } else { GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView); glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); - mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, options.getLocalIdeographFontFamily()) { @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { - MapView.this.post(new Runnable() { - @Override - public void run() { - // Initialise only once - if (mapboxMap == null) { - initialiseMap(); - mapboxMap.onStart(); - } - } - }); - + initRenderSurface(); super.onSurfaceCreated(gl, config); } }; glSurfaceView.setVisibility(View.VISIBLE); - } nativeMapView = new NativeMapView(this, mapRenderer); nativeMapView.resizeView(getMeasuredWidth(), getMeasuredHeight()); } + private void initRenderSurface() { + post(new Runnable() { + @Override + public void run() { + // Initialise only when not destroyed and only once + if (!destroyed && mapboxMap == null) { + initialiseMap(); + mapboxMap.onStart(); + } + } + }); + } + /** * You must call this method from the parent's Activity#onSaveInstanceState(Bundle) * or Fragment#onSaveInstanceState(Bundle). 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 4da2f63eeb..9525d48820 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 @@ -564,7 +564,7 @@ public final class MapboxMap { * * @return the TrackingSettings asssociated with this map * @deprecated use location layer plugin from - * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead. + * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead. */ @Deprecated public TrackingSettings getTrackingSettings() { @@ -580,7 +580,7 @@ public final class MapboxMap { * * @return the MyLocationViewSettings associated with this map * @deprecated use location layer plugin from - * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead. + * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead. */ @Deprecated public MyLocationViewSettings getMyLocationViewSettings() { @@ -2092,7 +2092,7 @@ public final class MapboxMap { * * @return True if the my-location layer is enabled, false otherwise. * @deprecated use location layer plugin from - * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead. + * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead. */ @Deprecated public boolean isMyLocationEnabled() { @@ -2110,7 +2110,7 @@ public final class MapboxMap { * * @param enabled True to enable; false to disable. * @deprecated use location layer plugin from - * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead. + * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead. */ @Deprecated public void setMyLocationEnabled(boolean enabled) { @@ -2122,7 +2122,7 @@ public final class MapboxMap { * * @return The currently displayed user location. * @deprecated use location layer plugin from - * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead. + * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead. */ @Nullable @Deprecated @@ -2137,7 +2137,7 @@ public final class MapboxMap { * @param listener The callback that's invoked when the user clicks on a marker. * To unset the callback, use null. * @deprecated use location layer plugin from - * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead. + * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead. */ @Deprecated public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener @@ -2150,7 +2150,7 @@ public final class MapboxMap { * * @param locationSource A {@link LocationEngine} location source to use in the my-location layer. * @deprecated use location layer plugin from - * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead. + * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead. */ @Deprecated public void setLocationSource(@Nullable LocationEngine locationSource) { @@ -2163,7 +2163,7 @@ public final class MapboxMap { * @param listener The callback that's invoked when the location tracking mode changes. * To unset the callback, use null. * @deprecated use location layer plugin from - * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead. + * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead. */ @Deprecated public void setOnMyLocationTrackingModeChangeListener( @@ -2177,7 +2177,7 @@ public final class MapboxMap { * @param listener The callback that's invoked when the bearing tracking mode changes. * To unset the callback, use null. * @deprecated use location layer plugin from - * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead. + * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead. */ @Deprecated public void setOnMyBearingTrackingModeChangeListener(@Nullable OnMyBearingTrackingModeChangeListener listener) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index e8eb7e8718..f1635c898f 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -733,7 +733,7 @@ final class NativeMapView { if (isDestroyedOn("addSource")) { return; } - nativeAddSource(source.getNativePtr()); + nativeAddSource(source, source.getNativePtr()); } @Nullable @@ -741,14 +741,15 @@ final class NativeMapView { if (isDestroyedOn("removeSource")) { return null; } - return nativeRemoveSourceById(sourceId); + Source source = getSource(sourceId); + return removeSource(source); } public Source removeSource(@NonNull Source source) { if (isDestroyedOn("removeSource")) { return null; } - nativeRemoveSource(source.getNativePtr()); + nativeRemoveSource(source, source.getNativePtr()); return source; } @@ -1027,11 +1028,9 @@ final class NativeMapView { private native Source nativeGetSource(String sourceId); - private native void nativeAddSource(long nativeSourcePtr) throws CannotAddSourceException; + private native void nativeAddSource(Source source, long sourcePtr) throws CannotAddSourceException; - private native Source nativeRemoveSourceById(String sourceId); - - private native void nativeRemoveSource(long sourcePtr); + private native void nativeRemoveSource(Source source, long sourcePtr); private native void nativeAddImage(String name, int width, int height, float pixelRatio, byte[] array); 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 new file mode 100644 index 0000000000..4d09fcaac6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -0,0 +1,1761 @@ +package com.mapbox.mapboxsdk.style.expressions; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.Size; + +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * The value for any layout property, paint property, or filter may be specified as an expression. + * An expression defines a formula for computing the value of the property using the operators described below. + * The set of expression operators provided by Mapbox GL includes: + * <p> + * <ul> + * <li>Element</li> + * <li>Mathematical operators for performing arithmetic and other operations on numeric values</li> + * <li>Logical operators for manipulating boolean values and making conditional decisions</li> + * <li>String operators for manipulating strings</li> + * <li>Data operators, providing access to the properties of source features</li> + * <li>Camera operators, providing access to the parameters defining the current map view</li> + * </ul> + * </p> + * <p> + * Expressions are represented as JSON arrays. + * The first element of an expression array is a string naming the expression operator, + * e.g. "*"or "case". Subsequent elements (if any) are the arguments to the expression. + * Each argument is either a literal value (a string, number, boolean, or null), or another expression array. + * </p> + * <p> + * Data expression: a data expression is any expression that access feature data -- that is, + * any expression that uses one of the data operators:get,has,id,geometry-type, or properties. + * Data expressions allow a feature's properties to determine its appearance. + * They can be used to differentiate features within the same layer and to create data visualizations. + * </p> + * <p> + * Camera expression: a camera expression is any expression that uses the zoom operator. + * Such expressions allow the the appearance of a layer to change with the map's zoom level. + * Camera expressions can be used to create the appearance of depth and to control data density. + * </p> + * <p> + * Composition: a single expression may use a mix of data operators, camera operators, and other operators. + * Such composite expressions allows a layer's appearance to be determined by + * a combination of the zoom level and individual feature properties. + * </p> + * + * @param <T> the type of the expression + */ +public class Expression<T> { + + private final String operator; + private final Expression[] arguments; + + /** + * Creates an empty expression for expression literals + */ + Expression() { + operator = null; + arguments = null; + } + + /** + * Creates an expression from its operator and varargs expressions. + * + * @param operator the expression operator + * @param arguments expressions input + */ + public Expression(@NonNull String operator, @Nullable Expression... arguments) { + this.operator = operator; + this.arguments = arguments; + } + + /** + * Converts the expression to Object array representation. + * <p> + * The output will later be converted to a JSON Object array. + * </p> + * + * @return the converted object array expression + */ + @NonNull + public Object[] toArray() { + List<Object> array = new ArrayList<>(); + array.add(operator); + if (arguments != null) { + for (Expression argument : arguments) { + if (argument instanceof Expression.ExpressionLiteral) { + array.add(toValue((ExpressionLiteral) argument)); + } else { + array.add(argument.toArray()); + } + } + } + return array.toArray(); + } + + /** + * 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 Expression.Color) { + return ((Expression.Color) value).convertColor(); + } else if (value instanceof Expression.ExpressionLiteral) { + return toValue((ExpressionLiteral) value); + } else if (value instanceof Expression) { + return ((Expression) value).toArray(); + } + return value; + } + + /** + * ExpressionLiteral wraps an object to be used as a literal in an expression. + * <p> + * ExpressionLiteral is created with {@link #literal(Number)}, {@link #literal(boolean)}, + * {@link #literal(String)} and {@link #literal(Object)}. + * </p> + * + * @param <T> + */ + private static class ExpressionLiteral<T> extends Expression<T> { + + protected T object; + + /** + * Create an ExpressionValue wrapper. + * + * @param object the object to be wrapped + */ + ExpressionLiteral(@NonNull T object) { + this.object = object; + } + + /** + * Get the wrapped object. + * + * @return the wrapped object + */ + Object toValue() { + return object; + } + } + + // + // Types + // + + /** + * Expression interpolator type. + * <p> + * Is used for first parameter of {@link #interpolate(Expression, Expression, Stop...)}. + * </p> + */ + private static class Interpolator { + } + + /** + * Expression color type. + */ + public static class Color { + + private int color; + + /** + * Creates a color color type from a color int. + * + * @param color the int color + */ + public Color(@ColorInt int color) { + this.color = color; + } + + /** + * Converts the int color to rgba(d, d, d, d) string representation + * + * @return + */ + public String convertColor() { + return PropertyFactory.colorToRgbaString(color); + } + } + + /** + * Expression array type. + */ + public static class Array { + } + + /** + * Expression stop type. + * <p> + * Can be used for {@link #stop(Object, Object)} as part of varargs parameter in + * {@link #step(Number, Expression, Stop...)} or {@link #interpolate(Expression, Expression, Stop...)}. + * </p> + */ + public static class Stop { + + private Object value; + private Object output; + + public Stop(Object value, Object output) { + this.value = value; + this.output = output; + } + } + + // + // Literals + // + + /** + * Create a literal number expression. + * + * @param number the number + * @return the expression + */ + public static Expression<Number> literal(@NonNull Number number) { + return new ExpressionLiteral<>(number); + } + + /** + * Create a literal string expression. + * + * @param string the string + * @return the expression + */ + public static Expression<String> literal(@NonNull String string) { + return new ExpressionLiteral<>(string); + } + + /** + * Create a literal boolean expression. + * + * @param bool the boolean + * @return the expression + */ + public static Expression<Boolean> literal(boolean bool) { + return new ExpressionLiteral<>(bool); + } + + /** + * Create a literal object expression + * + * @param object the object + * @return the expression + */ + public static Expression<Object> literal(@NonNull Object object) { + return new ExpressionLiteral<>(object); + } + + // + // Color + // + + /** + * Expression literal utility method to convert a color int to an color expression + * + * @param color the int color + * @return the color expression + */ + public static Expression<Color> color(@ColorInt int color) { + return new ExpressionLiteral<>(new Color(color)); + } + + /** + * Creates a color value from red, green, and blue components, which must range between 0 and 255, + * and an alpha component of 1. + * <p> + * If any component is out of range, the expression is an error. + * </p> + * + * @param red red color expression + * @param green green color expression + * @param blue blue color expression + * @return expression + */ + public static Expression<Color> rgb(@NonNull Expression<Number> red, @NonNull Expression<Number> green, + @NonNull Expression<Number> blue) { + return new Expression<>("rgb", red, green, blue); + } + + /** + * Creates a color value from red, green, and blue components, which must range between 0 and 255, + * and an alpha component of 1. + * <p> + * If any component is out of range, the expression is an error. + * </p> + * + * @param red red color value + * @param green green color value + * @param blue blue color value + * @return expression + */ + public static Expression<Color> rgb(@NonNull Number red, @NonNull Number green, @NonNull Number blue) { + return rgb(literal(red), literal(green), literal(blue)); + } + + /** + * Creates a color value from red, green, blue components, which must range between 0 and 255, + * and an alpha component which must range between 0 and 1. + * <p> + * If any component is out of range, the expression is an error. + * </p> + * + * @param red red color value + * @param green green color value + * @param blue blue color value + * @param alpha alpha color value + * @return expression + */ + public static Expression<Color> rgba(@NonNull Expression<Number> red, @NonNull Expression<Number> green, + @NonNull Expression<Number> blue, @NonNull Expression<Number> alpha) { + return new Expression<>("rgba", red, green, blue, alpha); + } + + /** + * Creates a color value from red, green, blue components, which must range between 0 and 255, + * and an alpha component which must range between 0 and 1. + * <p> + * If any component is out of range, the expression is an error. + * </p> + * + * @param red red color value + * @param green green color value + * @param blue blue color value + * @param alpha alpha color value + * @return expression + */ + public static Expression<Color> rgba(@NonNull Number red, @NonNull Number green, @NonNull Number blue, @NonNull Number alpha) { + return rgba(literal(red), literal(green), literal(blue), literal(alpha)); + } + + /** + * Returns a four-element array containing the input color's red, green, blue, and alpha components, in that order. + * + * @param expression an expression to convert to a color + * @return expression + */ + public static Expression<Array> toRgba(@NonNull Expression<Color> expression) { + return new Expression<>("to-rgba", expression); + } + + // + // Decision + // + + /** + * Returns true if the input values are equal, false otherwise. + * The inputs must be numbers, strings, or booleans, and both of the same type. + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @return expression + */ + public static Expression<Boolean> eq(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression<>("==", compareOne, compareTwo); + } + + /** + * Returns true if the input values are equal, false otherwise. + * + * @param compareOne the first boolean + * @param compareTwo the second boolean + * @return expression + */ + public static Expression<Boolean> eq(boolean compareOne, boolean compareTwo) { + return eq(literal(compareOne), literal(compareTwo)); + } + + /** + * Returns true if the input values are equal, false otherwise. + * + * @param compareOne the first number + * @param compareTwo the second number + * @return expression + */ + public static Expression<Boolean> eq(@NonNull String compareOne, @NonNull String compareTwo) { + return eq(literal(compareOne), literal(compareTwo)); + } + + /** + * Returns true if the input values are equal, false otherwise. + * + * @param compareOne the first number + * @param compareTwo the second number + * @return expression + */ + public static Expression<Boolean> eq(@NonNull Number compareOne, @NonNull Number compareTwo) { + return eq(literal(compareOne), literal(compareTwo)); + } + + /** + * 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. + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @return expression + */ + public static Expression<Boolean> neq(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression<>("!=", compareOne, compareTwo); + } + + /** + * Returns true if the input values are equal, false otherwise. + * + * @param compareOne the first boolean + * @param compareTwo the second boolean + * @return expression + */ + public static Expression<Boolean> neq(boolean compareOne, boolean compareTwo) { + return new Expression<>("!=", literal(compareOne), literal(compareTwo)); + } + + /** + * Returns `true` if the input values are not equal, `false` otherwise. + * + * @param compareOne the first string + * @param compareTwo the second string + * @return expression + */ + public static Expression<Boolean> neq(@NonNull String compareOne, @NonNull String compareTwo) { + return new Expression<>("!=", literal(compareOne), literal(compareTwo)); + } + + /** + * Returns `true` if the input values are not equal, `false` otherwise. + * + * @param compareOne the first number + * @param compareTwo the second number + * @return expression + */ + public static Expression<Boolean> neq(@NonNull Number compareOne, @NonNull Number compareTwo) { + return new Expression<>("!=", literal(compareOne), literal(compareTwo)); + } + + /** + * 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. + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @return expression + */ + public static Expression<Boolean> gt(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression<>(">", compareOne, compareTwo); + } + + /** + * Returns true if the first input is strictly greater than the second, false otherwise. + * + * @param compareOne the first number + * @param compareTwo the second number + * @return expression + */ + public static Expression<Boolean> gt(@NonNull Number compareOne, @NonNull Number compareTwo) { + return new Expression<>(">", literal(compareOne), literal(compareTwo)); + } + + /** + * Returns true if the first input is strictly greater than the second, false otherwise. + * + * @param compareOne the first string + * @param compareTwo the second string + * @return expression + */ + public static Expression<Boolean> gt(@NonNull String compareOne, @NonNull String compareTwo) { + return new Expression<>(">", literal(compareOne), literal(compareTwo)); + } + + /** + * 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. + * + * @param compareOne the first number + * @param compareTwo the second number + * @return expression + */ + public static Expression<Boolean> lt(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression<>("<", compareOne, compareTwo); + } + + /** + * Returns true if the first input is strictly less than the second, false otherwise. + * + * @param compareOne the first number + * @param compareTwo the second number + * @return expression + */ + public static Expression<Boolean> lt(@NonNull Number compareOne, @NonNull Number compareTwo) { + return new Expression<>("<", literal(compareOne), literal(compareTwo)); + } + + /** + * Returns true if the first input is strictly less than the second, false otherwise. + * + * @param compareOne the first string + * @param compareTwo the second string + * @return expression + */ + public static Expression<Boolean> lt(@NonNull String compareOne, @NonNull String compareTwo) { + return new Expression<>("<", literal(compareOne), literal(compareTwo)); + } + + /** + * 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. + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @return expression + */ + public static Expression<Boolean> gte(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression<>(">=", compareOne, compareTwo); + } + + /** + * Returns true if the first input is greater than or equal to the second, false otherwise. + * + * @param compareOne the first number + * @param compareTwo the second number + * @return expression + */ + public static Expression<Boolean> gte(@NonNull Number compareOne, @NonNull Number compareTwo) { + return new Expression<>(">=", literal(compareOne), literal(compareTwo)); + } + + /** + * Returns true if the first input is greater than or equal to the second, false otherwise. + * + * @param compareOne the first string + * @param compareTwo the second string + * @return expression + */ + public static Expression<Boolean> gte(@NonNull String compareOne, @NonNull String compareTwo) { + return new Expression<>(">=", literal(compareOne), literal(compareTwo)); + } + + /** + * 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. + * + * @param compareOne the first expression + * @param compareTwo the second expression + * @return expression + */ + public static Expression<Boolean> lte(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression<>("<=", compareOne, compareTwo); + } + + /** + * Returns true if the first input is less than or equal to the second, false otherwise. + * + * @param compareOne the first number + * @param compareTwo the second number + * @return expression + */ + public static Expression<Boolean> lte(@NonNull Number compareOne, @NonNull Number compareTwo) { + return new Expression<>("<=", literal(compareOne), literal(compareTwo)); + } + + /** + * Returns true if the first input is less than or equal to the second, false otherwise. + * + * @param compareOne the first string + * @param compareTwo the second string + * @return expression + */ + public static Expression<Boolean> lte(@NonNull String compareOne, @NonNull String compareTwo) { + return new Expression<>("<=", literal(compareOne), literal(compareTwo)); + } + + /** + * Returns `true` if all the inputs are `true`, `false` otherwise. + * <p> + * The inputs are evaluated in order, and evaluation is short-circuiting: + * once an input expression evaluates to `false`, + * the result is `false` and no further input expressions are evaluated. + * </p> + * + * @param input expression input + * @return expression + */ + public static Expression<Boolean> all(@NonNull Expression<Boolean>... input) { + return new Expression<>("all", input); + } + + /** + * Returns `true` if any of the inputs are `true`, `false` otherwise. + * <p> + * The inputs are evaluated in order, and evaluation is short-circuiting: + * once an input expression evaluates to `true`, + * the result is `true` and no further input expressions are evaluated. + * </p> + * + * @param input expression input + * @return expression + */ + public static Expression<Boolean> any(@NonNull Expression<Boolean>... input) { + return new Expression<>("any", input); + } + + /** + * Logical negation. Returns `true` if the input is `false`, and `false` if the input is `true`. + * + * @param input expression input + * @return expression + */ + public static Expression<Boolean> not(@NonNull Expression<Boolean> input) { + return new Expression<>("!", input); + } + + /** + * Logical negation. Returns `true` if the input is `false`, and `false` if the input is `true`. + * + * @param input boolean input + * @return expression + */ + public static Expression<Boolean> not(boolean input) { + return not(literal(input)); + } + + /** + * Selects the first output whose corresponding test condition evaluates to true. + * + * @param input expression input + * @return expression + */ + public static Expression switchCase(@NonNull @Size(min = 1) Expression... input) { + return new Expression("case", input); + } + + /** + * Selects the output whose label value matches the input value, or the fallback value if no match is found. + * The `input` can be any string or number expression. + * Each label can either be a single literal value or an array of values. + * + * @param input expression input + * @return expression + */ + public static Expression match(@NonNull @Size(min = 2) Expression... input) { + return new Expression("match", input); + } + + /** + * Selects the output whose label value matches the input value, or the fallback value if no match is found. + * The `input` can be any string or number expression. + * Each label can either be a single literal value or an array of values. + * + * @param input expression input + * @return expression + */ + public static Expression match(@NonNull Expression input, @NonNull Stop... stops) { + Expression[] expressions = new Expression[stops.length * 2]; + for (int i = 0; i < stops.length; i++) { + expressions[i * 2] = literal(stops[i].value); + expressions[i * 2 + 1] = literal(stops[i].output); + } + return match(join(new Expression[] {input}, expressions)); + } + + /** + * Evaluates each expression in turn until the first non-null value is obtained, and returns that value. + * + * @param input expression input + * @return expression + */ + public static Expression coalesce(@NonNull Expression... input) { + return new Expression("coalesce", input); + } + + // + // FeatureData + // + + /** + * Gets the feature properties object. + * <p> + * Note that in some cases, it may be more efficient to use {@link #get(Expression)}} instead. + * </p> + * + * @return expression + */ + public static Expression<Object> properties() { + return new Expression<>("properties"); + } + + /** + * Gets the feature's geometry type: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon. + * + * @return expression + */ + public static Expression<String> geometryType() { + return new Expression<>("geometry-type"); + } + + /** + * Gets the feature's id, if it has one. + * + * @return expression + */ + public static Expression<Number> id() { + return new Expression<>("id"); + } + + // + // Heatmap + // + + /** + * Gets the kernel density estimation of a pixel in a heatmap layer, + * which is a relative measure of how many data points are crowded around a particular pixel. + * Can only be used in the `heatmap-color` property. + * + * @return expression + */ + public static Expression<Number> heatmapDensity() { + return new Expression<>("heatmap-density"); + } + + // + // Lookup + // + + /** + * Retrieves an item from an array. + * + * @param number the index expression + * @param expression the array expression + * @return expression + */ + public static Expression<Object> at(@NonNull Expression<Number> number, @NonNull Expression expression) { + return new Expression<>("at", number, expression); + } + + /** + * Retrieves an item from an array. + * + * @param number the index expression + * @param expression the array expression + * @return expression + */ + public static Expression<Object> at(@NonNull Number number, @NonNull Expression expression) { + return at(literal(number), expression); + } + + /** + * Retrieves a property value from the current feature's properties, + * or from another object if a second argument is provided. + * Returns null if the requested property is missing. + * + * @param input expression input + * @return expression + */ + public static Expression get(@NonNull Expression<String> input) { + return new Expression<>("get", input); + } + + /** + * Retrieves a property value from the current feature's properties, + * or from another object if a second argument is provided. + * Returns null if the requested property is missing. + * + * @param input string input + * @return expression + */ + public static Expression get(@NonNull String input) { + return get(literal(input)); + } + + /** + * Retrieves a property value from another object. + * Returns null if the requested property is missing. + * + * @param key a property value key + * @param object an expression object + * @return expression + */ + public static Expression get(@NonNull Expression<String> key, @NonNull Expression<Object> object) { + return new Expression<>("get", key, object); + } + + /** + * Retrieves a property value from another object. + * Returns null if the requested property is missing. + * + * @param key a property value key + * @param object an expression object + * @return expression + */ + public static Expression get(@NonNull String key, @NonNull Expression<Object> object) { + return get(literal(key), object); + } + + /** + * Tests for the presence of an property value in the current feature's properties. + * + * @param key the expression property value key + * @return expression + */ + public static Expression<Boolean> has(@NonNull Expression<String> key) { + return new Expression<>("has", key); + } + + /** + * Tests for the presence of an property value in the current feature's properties. + * + * @param key the property value key + * @return expression + */ + public static Expression<Boolean> has(@NonNull String key) { + return has(literal(key)); + } + + /** + * Tests for the presence of an property value from another object. + * + * @param key the expression property value key + * @param object an expression object + * @return expression + */ + public static Expression<Boolean> has(@NonNull Expression<String> key, @NonNull Expression<Object> object) { + return new Expression<>("has", key, object); + } + + /** + * Tests for the presence of an property value from another object. + * + * @param key the property value key + * @param object an expression object + * @return expression + */ + public static Expression<Boolean> has(@NonNull String key, @NonNull Expression<Object> object) { + return has(literal(key), object); + } + + /** + * Gets the length of an array or string. + * + * @param expression an expression object or expression string + * @return expression + */ + public static Expression<Number> length(@NonNull Expression<?> expression) { + return new Expression<>("length", expression); + } + + /** + * Gets the length of an array or string. + * + * @param input a string + * @return expression + */ + public static Expression<Number> length(@NonNull String input) { + return length(literal(input)); + } + + // + // Math + // + + /** + * Returns mathematical constant ln(2). + * + * @return expression + */ + public static Expression<Number> ln2() { + return new Expression<>("ln2"); + } + + /** + * Returns the mathematical constant pi. + * + * @return expression + */ + public static Expression<Number> pi() { + return new Expression<>("pi"); + } + + /** + * Returns the mathematical constant e. + * + * @return expression + */ + public static Expression<Number> e() { + return new Expression<>("e"); + } + + /** + * Returns the sum of the inputs. + * + * @param numbers the numbers to calculate the sum for + * @return expression + */ + public static Expression<Number> sum(@Size(min = 2) Expression<Number>... numbers) { + return new Expression<>("+", numbers); + } + + /** + * Returns the sum of the inputs. + * + * @param numbers the numbers to calculate the sum for + * @return expression + */ + @SuppressWarnings("unchecked") + public static Expression<Number> sum(@Size(min = 2) Number... numbers) { + Expression<Number>[] numberExpression = (Expression<Number>[]) new Expression<?>[numbers.length]; + for (int i = 0; i < numbers.length; i++) { + numberExpression[i] = literal(numbers[i]); + } + return sum(numberExpression); + } + + /** + * Returns the product of the inputs. + * + * @param numbers the numbers to calculate the product for + * @return expression + */ + public static Expression<Number> product(@Size(min = 2) Expression<Number>... numbers) { + return new Expression<>("*", numbers); + } + + /** + * Returns the product of the inputs. + * + * @param numbers the numbers to calculate the product for + * @return expression + */ + @SuppressWarnings("unchecked") + public static Expression<Number> product(@Size(min = 2) Number... numbers) { + Expression<Number>[] numberExpression = (Expression<Number>[]) new Expression<?>[numbers.length]; + for (int i = 0; i < numbers.length; i++) { + numberExpression[i] = literal(numbers[i]); + } + return product(numberExpression); + } + + /** + * Returns the result of subtracting a number from 0. + * + * @param number the number subtract from 0 + * @return expression + */ + public static Expression<Number> subtract(@NonNull Expression<Number> number) { + return new Expression<>("-", number); + } + + /** + * Returns the result of subtracting a number from 0. + * + * @param number the number subtract from 0 + * @return expression + */ + public static Expression<Number> subtract(@NonNull Number number) { + return subtract(literal(number)); + } + + /** + * Returns the result of subtracting the second input from the first. + * + * @param first the first number + * @param second the second number + * @return expression + */ + public static Expression<Number> subtract(@NonNull Expression<Number> first, @NonNull Expression<Number> second) { + return new Expression<>("-", first, second); + } + + /** + * Returns the result of subtracting the second input from the first. + * + * @param first the first number + * @param second the second number + * @return expression + */ + public static Expression<Number> subtract(@NonNull Number first, @NonNull Number second) { + return subtract(literal(first), literal(second)); + } + + /** + * Returns the result of floating point division of the first input by the second. + * + * @param first the first number + * @param second the second number + * @return expression + */ + public static Expression<Number> division(@NonNull Expression<Number> first, @NonNull Expression<Number> second) { + return new Expression<>("/", first, second); + } + + /** + * Returns the result of floating point division of the first input by the second. + * + * @param first the first number + * @param second the second number + * @return expression + */ + public static Expression<Number> division(@NonNull Number first, @NonNull Number second) { + return division(literal(first), literal(second)); + } + + /** + * Returns the remainder after integer division of the first input by the second. + * + * @param first the first number + * @param second the second number + * @return expression + */ + public static Expression<Number> mod(@NonNull Expression<Number> first, @NonNull Expression<Number> second) { + return new Expression<>("%", first, second); + } + + /** + * Returns the remainder after integer division of the first input by the second. + * + * @param first the first number + * @param second the second number + * @return expression + */ + public static Expression<Number> mod(@NonNull Number first, @NonNull Number second) { + return mod(literal(first), literal(second)); + } + + /** + * Returns the result of raising the first input to the power specified by the second. + * + * @param first the first number + * @param second the second number + * @return expression + */ + public static Expression<Number> pow(@NonNull Expression<Number> first, @NonNull Expression<Number> second) { + return new Expression<>("^", first, second); + } + + /** + * Returns the result of raising the first input to the power specified by the second. + * + * @param first the first number + * @param second the second number + * @return expression + */ + public static Expression<Number> pow(@NonNull Number first, @NonNull Number second) { + return pow(literal(first), literal(second)); + } + + /** + * Returns the square root of the input + * + * @param number the number to take the square root from + * @return expression + */ + public static Expression<Number> sqrt(@NonNull Expression<Number> number) { + return new Expression<>("sqrt", number); + } + + /** + * Returns the square root of the input + * + * @param number the number to take the square root from + * @return expression + */ + public static Expression<Number> sqrt(@NonNull Number number) { + return sqrt(literal(number)); + } + + /** + * Returns the base-ten logarithm of the input. + * + * @param number the number to take base-ten logarithm from + * @return expression + */ + public static Expression<Number> log10(@NonNull Expression<Number> number) { + return new Expression<>("log10", number); + } + + /** + * Returns the base-ten logarithm of the input. + * + * @param number the number to take base-ten logarithm from + * @return expression + */ + public static Expression<Number> log10(@NonNull Number number) { + return log10(literal(number)); + } + + /** + * Returns the natural logarithm of the input. + * + * @param number the number to take natural logarithm from + * @return expression + */ + public static Expression<Number> ln(Expression<Number> number) { + return new Expression<>("ln", number); + } + + /** + * Returns the natural logarithm of the input. + * + * @param number the number to take natural logarithm from + * @return expression + */ + public static Expression<Number> ln(Number number) { + return ln(literal(number)); + } + + /** + * Returns the base-two logarithm of the input. + * + * @param number the number to take base-two logarithm from + * @return expression + */ + public static Expression<Number> log2(@NonNull Expression<Number> number) { + return new Expression<>("log2", number); + } + + /** + * Returns the base-two logarithm of the input. + * + * @param number the number to take base-two logarithm from + * @return expression + */ + public static Expression<Number> log2(@NonNull Number number) { + return log2(literal(number)); + } + + /** + * Returns the sine of the input. + * + * @param number the number to calculate the sine for + * @return expression + */ + public static Expression<Number> sin(@NonNull Expression<Number> number) { + return new Expression<>("sin", number); + } + + /** + * Returns the sine of the input. + * + * @param number the number to calculate the sine for + * @return expression + */ + public static Expression<Number> sin(@NonNull Number number) { + return sin(literal(number)); + } + + /** + * Returns the cosine of the input. + * + * @param number the number to calculate the cosine for + * @return expression + */ + public static Expression<Number> cos(@NonNull Expression<Number> number) { + return new Expression<>("cos", number); + } + + /** + * Returns the cosine of the input. + * + * @param number the number to calculate the cosine for + * @return expression + */ + public static Expression<Number> cos(@NonNull Number number) { + return new Expression<>("cos", literal(number)); + } + + /** + * Returns the tangent of the input. + * + * @param number the number to calculate the tangent for + * @return expression + */ + public static Expression<Number> tan(@NonNull Expression<Number> number) { + return new Expression<>("tan", number); + } + + /** + * Returns the tangent of the input. + * + * @param number the number to calculate the tangent for + * @return expression + */ + public static Expression<Number> tan(@NonNull Number number) { + return new Expression<>("tan", literal(number)); + } + + /** + * Returns the arcsine of the input. + * + * @param number the number to calculate the arcsine for + * @return expression + */ + public static Expression<Number> asin(@NonNull Expression<Number> number) { + return new Expression<>("asin", number); + } + + /** + * Returns the arcsine of the input. + * + * @param number the number to calculate the arcsine for + * @return expression + */ + public static Expression<Number> asin(@NonNull Number number) { + return asin(literal(number)); + } + + /** + * Returns the arccosine of the input. + * + * @param number the number to calculate the arccosine for + * @return expression + */ + public static Expression<Number> acos(@NonNull Expression<Number> number) { + return new Expression<>("acos", number); + } + + /** + * Returns the arccosine of the input. + * + * @param number the number to calculate the arccosine for + * @return expression + */ + public static Expression<Number> acos(@NonNull Number number) { + return acos(literal(number)); + } + + /** + * Returns the arctangent of the input. + * + * @param number the number to calculate the arctangent for + * @return expression + */ + public static Expression<Number> atan(@NonNull Expression<Number> number) { + return new Expression("atan", number); + } + + /** + * Returns the arctangent of the input. + * + * @param number the number to calculate the arctangent for + * @return expression + */ + public static Expression<Number> atan(@NonNull Number number) { + return atan(literal(number)); + } + + /** + * Returns the minimum value of the inputs. + * + * @param numbers varargs of numbers to get the minimum from + * @return expression + */ + public static Expression<Number> min(@Size(min = 1) Expression<Number>... numbers) { + return new Expression<>("min", numbers); + } + + /** + * Returns the minimum value of the inputs. + * + * @param numbers varargs of numbers to get the minimum from + * @return expression + */ + @SuppressWarnings("unchecked") + public static Expression<Number> min(@Size(min = 1) Number... numbers) { + Expression<Number>[] numberExpression = (Expression<Number>[]) new Expression<?>[numbers.length]; + for (int i = 0; i < numbers.length; i++) { + numberExpression[i] = literal(numbers[i]); + } + return min(numberExpression); + } + + /** + * Returns the maximum value of the inputs. + * + * @param numbers varargs of numbers to get the maximum from + * @return expression + */ + public static Expression<Number> max(@Size(min = 1) Expression<Number>... numbers) { + return new Expression<>("max", numbers); + } + + /** + * Returns the maximum value of the inputs. + * + * @param numbers varargs of numbers to get the maximum from + * @return expression + */ + @SuppressWarnings("unchecked") + public static Expression<Number> max(@Size(min = 1) Number... numbers) { + Expression<Number>[] numberExpression = (Expression<Number>[]) new Expression<?>[numbers.length]; + for (int i = 0; i < numbers.length; i++) { + numberExpression[i] = literal(numbers[i]); + } + return max(numberExpression); + } + + // + // String + // + + /** + * Returns the input string converted to uppercase. + * <p> + * Follows the Unicode Default Case Conversion algorithm + * and the locale-insensitive case mappings in the Unicode Character Database. + * </p> + * + * @param string the string to upcase + * @return expression + */ + public static Expression<String> upcase(@NonNull Expression<String> string) { + return new Expression<>("upcase", string); + } + + /** + * Returns the input string converted to uppercase. + * <p> + * Follows the Unicode Default Case Conversion algorithm + * and the locale-insensitive case mappings in the Unicode Character Database. + * </p> + * + * @param string string to upcase + * @return expression + */ + public static Expression<String> upcase(@NonNull String string) { + return upcase(literal(string)); + } + + /** + * Returns the input string converted to lowercase. + * <p> + * Follows the Unicode Default Case Conversion algorithm + * and the locale-insensitive case mappings in the Unicode Character Database. + * </p> + * + * @param input expression input + * @return expression + */ + public static Expression<String> downcase(@NonNull Expression<String> input) { + return new Expression<>("downcase", input); + } + + /** + * Returns the input string converted to lowercase. + * <p> + * Follows the Unicode Default Case Conversion algorithm + * and the locale-insensitive case mappings in the Unicode Character Database. + * </p> + * + * @param input string to downcase + * @return expression + */ + public static Expression<String> downcase(@NonNull String input) { + return downcase(literal(input)); + } + + /** + * Returns a string consisting of the concatenation of the inputs. + * + * @param input expression input + * @return expression + */ + public static Expression<String> concat(@NonNull Expression<String>... input) { + return new Expression<>("concat", input); + } + + /** + * Returns a string consisting of the concatenation of the inputs. + * + * @param input expression input + * @return expression + */ + @SuppressWarnings("unchecked") + public static Expression<String> concat(@NonNull String... input) { + Expression<String>[] stringExpression = (Expression<String>[]) new Expression<?>[input.length]; + for (int i = 0; i < input.length; i++) { + stringExpression[i] = literal(input[i]); + } + return concat(stringExpression); + } + + // + // Types + // + + /** + * Asserts that the input is an array (optionally with a specific item type and length). + * If, when the input expression is evaluated, it is not of the asserted type, + * then this assertion will cause the whole expression to be aborted. + * + * @param input expression input + * @return expression + */ + public static Expression<Boolean> array(@NonNull Expression input) { + return new Expression<>("array", input); + } + + /** + * Returns a string describing the type of the given value. + * + * @param input expression input + * @return expression + */ + public static Expression<String> typeOf(@NonNull Expression input) { + return new Expression<>("typeof", input); + } + + /** + * Asserts that the input value is a string. + * If multiple values are provided, each one is evaluated in order until a string value is obtained. + * If none of the inputs are strings, the expression is an error. + * + * @param input expression input + * @return expression + */ + public static Expression<Boolean> string(@NonNull Expression input) { + return new Expression<>("string", input); + } + + /** + * Asserts that the input value is a number. + * If multiple values are provided, each one is evaluated in order until a number value is obtained. + * If none of the inputs are numbers, the expression is an error. + * + * @param input expression input + * @return expression + */ + public static Expression<Boolean> number(@NonNull Expression input) { + return new Expression<>("number", input); + } + + /** + * Asserts that the input value is a boolean. + * If multiple values are provided, each one is evaluated in order until a boolean value is obtained. + * If none of the inputs are booleans, the expression is an error. + * + * @param input expression input + * @return expression + */ + public static Expression<Boolean> bool(@NonNull Expression input) { + return new Expression<>("boolean", input); + } + + /** + * Asserts that the input value is an object. If it is not, the expression is an error + * + * @param input expression input + * @return expression + */ + public static Expression<Boolean> object(@NonNull Expression input) { + return new Expression<>("object", input); + } + + /** + * Converts the input value to a string. + * If the input is null, the result is null. + * If the input is a boolean, the result is true or false. + * If the input is a number, it is converted to a string by NumberToString in the ECMAScript Language Specification. + * If the input is a color, it is converted to a string of the form "rgba(r,g,b,a)", + * where `r`, `g`, and `b` are numerals ranging from 0 to 255, and `a` ranges from 0 to 1. + * Otherwise, the input is converted to a string in the format specified by the JSON.stringify in the ECMAScript + * Language Specification. + * + * @param input expression input + * @return expression + */ + public static Expression<String> toString(@NonNull Expression input) { + return new Expression<>("to-string", input); + } + + /** + * Converts the input value to a number, if possible. + * If the input is null or false, the result is 0. + * If the input is true, the result is 1. + * If the input is a string, it is converted to a number as specified by the ECMAScript Language Specification. + * If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained. + * If none of the inputs can be converted, the expression is an error. + * + * @param input expression input + * @return expression + */ + public static Expression<Number> toNumber(@NonNull Expression input) { + return new Expression<>("to-number", input); + } + + /** + * "Converts the input value to a boolean. The result is `false` when then input is an empty string, 0, false, + * null, or NaN; otherwise it is true. + * + * @param input expression input + * @return expression + */ + public static Expression<Boolean> toBool(@NonNull Expression input) { + return new Expression<>("to-boolean", input); + } + + /** + * Converts the input value to a color. If multiple values are provided, + * each one is evaluated in order until the first successful conversion is obtained. + * If none of the inputs can be converted, the expression is an error. + * + * @param input expression input + * @return expression + */ + public static Expression<Color> toColor(@NonNull Expression input) { + return new Expression<>("to-color", input); + } + + // + // Variable binding + // + + /** + * Binds input to named variables, + * which can then be referenced in the result expression using {@link #var(String)} or {@link #var(Expression)}. + * + * @param input expression input + * @return expression + */ + public static Expression let(@Size(min = 1) Expression... input) { + return new Expression<>("let", input); + } + + /** + * References variable bound using let. + * + * @param expression the variable naming expression that was bound with using let + * @return expression + */ + public static Expression<Object> var(@NonNull Expression<String> expression) { + return new Expression<>("var", expression); + } + + /** + * References variable bound using let. + * + * @param variableName the variable naming that was bound with using let + * @return expression + */ + public static Expression var(@NonNull String variableName) { + return var(literal(variableName)); + } + + // + // Zoom + // + + /** + * Gets the current zoom level. + * <p> + * Note that in style layout and paint properties, + * zoom may only appear as the input to a top-level step or interpolate expression. + * </p> + * + * @return expression + */ + public static Expression<Number> zoom() { + return new Expression<>("zoom"); + } + + // + // Ramps, scales, curves + // + + public static Stop stop(@NonNull Object stop, @NonNull Object value) { + return new Stop(stop, value); + } + + /** + * Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of + * input and output values (\"stops\"). The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * Returns the output value of the stop just less than the input, + * or the first input if the input is less than the first stop. + * + * @param input the input value + * @param stops pair of input and output values + * @return expression + */ + public static Expression step(@NonNull Number input, @NonNull Expression expression, Expression... stops) { + return step(literal(input), expression, stops); + } + + /** + * Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of + * input and output values (\"stops\"). The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * Returns the output value of the stop just less than the input, + * or the first input if the input is less than the first stop. + * + * @param expression the input expression + * @param stops pair of input and output values + * @return expression + */ + public static Expression step(@NonNull Expression<Number> input, @NonNull Expression expression, Expression... stops) { + return new Expression("step", join(new Expression[] {input, expression}, stops)); + } + + /** + * Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of + * input and output values (\"stops\"). The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * Returns the output value of the stop just less than the input, + * or the first input if the input is less than the first stop. + * + * @param input the input value + * @param stops pair of input and output values + * @return expression + */ + public static Expression step(@NonNull Number input, @NonNull Expression expression, Stop... stops) { + Expression[] expressions = new Expression[stops.length * 2]; + for (int i = 0; i < stops.length; i++) { + expressions[i * 2] = literal(stops[i].value); + expressions[i * 2 + 1] = literal(stops[i].output); + } + return step(literal(input), expression, expressions); + } + + /** + * Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of + * input and output values (\"stops\"). The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * Returns the output value of the stop just less than the input, + * or the first input if the input is less than the first stop. + * + * @param input the input value + * @param stops pair of input and output values + * @return expression + */ + public static Expression step(@NonNull Expression<Number> input, @NonNull Expression expression, Stop... stops) { + Expression[] expressions = new Expression[stops.length * 2]; + for (int i = 0; i < stops.length; i++) { + expressions[i * 2] = literal(stops[i].value); + expressions[i * 2 + 1] = literal(stops[i].output); + } + return step(input, expression, expressions); + } + + /** + * Produces continuous, smooth results by interpolating between pairs of input and output values (\"stops\"). + * The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * The output type must be `number`, `array<number>`, or `color`. + * + * @param interpolation type of interpolation + * @param number the input expression + * @param stops pair of input and output values + * @return expression + */ + public static Expression interpolate(@NonNull Expression<Interpolator> interpolation, + @NonNull Expression<Number> number, Expression... stops) { + return new Expression("interpolate", join(new Expression[] {interpolation, number}, stops)); + } + + /** + * Produces continuous, smooth results by interpolating between pairs of input and output values (\"stops\"). + * The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * The output type must be `number`, `array<number>`, or `color`. + * + * @param interpolation type of interpolation + * @param number the input expression + * @param stops pair of input and output values + * @return expression + */ + public static Expression interpolate(@NonNull Expression<Interpolator> interpolation, + @NonNull Expression<Number> number, Stop... stops) { + Expression[] expressions = new Expression[stops.length * 2]; + for (int i = 0; i < stops.length; i++) { + expressions[i * 2] = literal(stops[i].value); + expressions[i * 2 + 1] = literal(stops[i].output); + } + return interpolate(interpolation, number, expressions); + } + + /** + * interpolates linearly between the pair of stops just less than and just greater than the input. + * + * @return expression + */ + public static Expression<Interpolator> linear() { + return new Expression<>("linear"); + } + + /** + * Interpolates exponentially between the stops just less than and just greater than the input. + * `base` controls the rate at which the output increases: + * higher values make the output increase more towards the high end of the range. + * With values close to 1 the output increases linearly. + * + * @param base value controlling the route at which the output increases + * @return expression + */ + public static Expression<Interpolator> exponential(@NonNull Number base) { + return exponential(literal(base)); + } + + /** + * Interpolates exponentially between the stops just less than and just greater than the input. + * The parameter controls the rate at which the output increases: + * higher values make the output increase more towards the high end of the range. + * With values close to 1 the output increases linearly. + * + * @param expression base number expression + * @return expression + */ + public static Expression<Interpolator> exponential(@NonNull Expression<Number> expression) { + return new Expression<>("exponential", expression); + } + + /** + * Interpolates using the cubic bezier curve defined by the given control points. + * + * @param x1 x value of the first point of a cubic bezier, ranges from 0 to 1 + * @param y1 y value of the first point of a cubic bezier, ranges from 0 to 1 + * @param x2 x value of the second point of a cubic bezier, ranges from 0 to 1 + * @param y2 y value fo the second point of a cubic bezier, ranges from 0 to 1 + * @return expression + */ + public static Expression<Interpolator> cubicBezier(@NonNull Expression<Number> x1, @NonNull Expression<Number> y1, + @NonNull Expression<Number> x2, @NonNull Expression<Number> y2) { + return new Expression<>("cubic-bezier", x1, y1, x2, y2); + } + + /** + * Interpolates using the cubic bezier curve defined by the given control points. + * + * @param x1 x value of the first point of a cubic bezier, ranges from 0 to 1 + * @param y1 y value of the first point of a cubic bezier, ranges from 0 to 1 + * @param x2 x value of the second point of a cubic bezier, ranges from 0 to 1 + * @param y2 y value fo the second point of a cubic bezier, ranges from 0 to 1 + * @return expression + */ + public static Expression<Interpolator> cubicBezier(@NonNull Number x1, @NonNull Number y1, + @NonNull Number x2, @NonNull Number y2) { + return cubicBezier(literal(x1), literal(y1), literal(x2), literal(y2)); + } + + /** + * Joins two expressions arrays. + * <p> + * This flattens the object array output of an expression from a nested expression hierarchy. + * </p> + * + * @param left the left part of an expression + * @param right the right part of an expression + * @return the joined expression + */ + private static Expression[] join(Expression[] left, Expression[] right) { + Expression[] output = new Expression[left.length + right.length]; + System.arraycopy(left, 0, output, 0, left.length); + System.arraycopy(right, 0, output, left.length, right.length); + return output; + } + +}
\ No newline at end of file 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 978fa29ef8..324b845dda 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 @@ -8,8 +8,6 @@ import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; -import com.mapbox.mapboxsdk.style.layers.TransitionOptions; - /** * The background color or pattern of the map. * 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 10663142b5..ea96e4e9c3 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 @@ -8,8 +8,6 @@ import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; -import com.mapbox.mapboxsdk.style.layers.TransitionOptions; - /** * A filled circle. * 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 6772da73b1..d4cdb2a425 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 @@ -8,8 +8,6 @@ import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; -import com.mapbox.mapboxsdk.style.layers.TransitionOptions; - /** * An extruded (3D) polygon. * 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 3719ae9e1b..e639823ee1 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 @@ -8,8 +8,6 @@ import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; -import com.mapbox.mapboxsdk.style.layers.TransitionOptions; - /** * A filled polygon with an optional stroked border. * 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 5015dd009d..5400e04589 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 @@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.NonNull; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.functions.Function; /** @@ -88,6 +89,14 @@ public abstract class Layer { } private Object convertValue(Object value) { - return value != null && value instanceof Function ? ((Function) value).toValueObject() : value; + if (value != null) { + if (value instanceof Function) { + return ((Function) value).toValueObject(); + } else if (value instanceof Expression) { + return ((Expression) value).toArray(); + } + } + return value; } -} + +}
\ No newline at end of file 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 ca106cc106..bbcfb98f07 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 @@ -8,8 +8,6 @@ import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; -import com.mapbox.mapboxsdk.style.layers.TransitionOptions; - /** * A stroked line. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java index 8d5858217b..8d6c7dd055 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java @@ -402,7 +402,7 @@ public final class Property { @Retention(RetentionPolicy.SOURCE) public @interface TEXT_TRANSFORM {} - // FILL_TRANSLATE_ANCHOR: Controls the translation reference point. + // FILL_TRANSLATE_ANCHOR: Controls the frame of reference for `fill-translate`. /** * The fill is translated relative to the map. @@ -414,7 +414,7 @@ public final class Property { public static final String FILL_TRANSLATE_ANCHOR_VIEWPORT = "viewport"; /** - * Controls the translation reference point. + * Controls the frame of reference for `fill-translate`. */ @StringDef({ FILL_TRANSLATE_ANCHOR_MAP, @@ -423,7 +423,7 @@ public final class Property { @Retention(RetentionPolicy.SOURCE) public @interface FILL_TRANSLATE_ANCHOR {} - // LINE_TRANSLATE_ANCHOR: Controls the translation reference point. + // LINE_TRANSLATE_ANCHOR: Controls the frame of reference for `line-translate`. /** * The line is translated relative to the map. @@ -435,7 +435,7 @@ public final class Property { public static final String LINE_TRANSLATE_ANCHOR_VIEWPORT = "viewport"; /** - * Controls the translation reference point. + * Controls the frame of reference for `line-translate`. */ @StringDef({ LINE_TRANSLATE_ANCHOR_MAP, @@ -444,7 +444,7 @@ public final class Property { @Retention(RetentionPolicy.SOURCE) public @interface LINE_TRANSLATE_ANCHOR {} - // ICON_TRANSLATE_ANCHOR: Controls the translation reference point. + // ICON_TRANSLATE_ANCHOR: Controls the frame of reference for `icon-translate`. /** * Icons are translated relative to the map. @@ -456,7 +456,7 @@ public final class Property { public static final String ICON_TRANSLATE_ANCHOR_VIEWPORT = "viewport"; /** - * Controls the translation reference point. + * Controls the frame of reference for `icon-translate`. */ @StringDef({ ICON_TRANSLATE_ANCHOR_MAP, @@ -465,7 +465,7 @@ public final class Property { @Retention(RetentionPolicy.SOURCE) public @interface ICON_TRANSLATE_ANCHOR {} - // TEXT_TRANSLATE_ANCHOR: Controls the translation reference point. + // TEXT_TRANSLATE_ANCHOR: Controls the frame of reference for `text-translate`. /** * The text is translated relative to the map. @@ -477,7 +477,7 @@ public final class Property { public static final String TEXT_TRANSLATE_ANCHOR_VIEWPORT = "viewport"; /** - * Controls the translation reference point. + * Controls the frame of reference for `text-translate`. */ @StringDef({ TEXT_TRANSLATE_ANCHOR_MAP, @@ -486,7 +486,7 @@ public final class Property { @Retention(RetentionPolicy.SOURCE) public @interface TEXT_TRANSLATE_ANCHOR {} - // CIRCLE_TRANSLATE_ANCHOR: Controls the translation reference point. + // CIRCLE_TRANSLATE_ANCHOR: Controls the frame of reference for `circle-translate`. /** * The circle is translated relative to the map. @@ -498,7 +498,7 @@ public final class Property { public static final String CIRCLE_TRANSLATE_ANCHOR_VIEWPORT = "viewport"; /** - * Controls the translation reference point. + * Controls the frame of reference for `circle-translate`. */ @StringDef({ CIRCLE_TRANSLATE_ANCHOR_MAP, @@ -549,7 +549,7 @@ public final class Property { @Retention(RetentionPolicy.SOURCE) public @interface CIRCLE_PITCH_ALIGNMENT {} - // FILL_EXTRUSION_TRANSLATE_ANCHOR: Controls the translation reference point. + // FILL_EXTRUSION_TRANSLATE_ANCHOR: Controls the frame of reference for `fill-extrusion-translate`. /** * The fill extrusion is translated relative to the map. @@ -561,7 +561,7 @@ public final class Property { public static final String FILL_EXTRUSION_TRANSLATE_ANCHOR_VIEWPORT = "viewport"; /** - * Controls the translation reference point. + * Controls the frame of reference for `fill-extrusion-translate`. */ @StringDef({ FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP, 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 d4ddbe48ef..fe164343b5 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 @@ -5,8 +5,11 @@ package com.mapbox.mapboxsdk.style.layers; import android.annotation.SuppressLint; import android.support.annotation.ColorInt; -import com.mapbox.mapboxsdk.style.functions.Function; import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.functions.Function; + +import java.util.Locale; /** * Constructs paint/layout properties for Layers @@ -32,6 +35,7 @@ public class PropertyFactory { * @param function the visibility function * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> visibility(Function<T, String> function) { return new LayoutPropertyValue<>("visibility", function); } @@ -46,6 +50,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-antialias", value); } + /** + * Whether or not the fill should be antialiased. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillAntialias(Expression expression) { + return new PaintPropertyValue<>("fill-antialias", expression); + } + /** * Whether or not the fill should be antialiased. @@ -54,6 +68,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> fillAntialias(CameraFunction<Z, Boolean> function) { return new PaintPropertyValue<>("fill-antialias", function); } @@ -68,6 +83,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-opacity", value); } + /** + * The opacity of the entire fill layer. In contrast to the {@link PropertyFactory#fillColor}, this value will also affect the 1px stroke around the fill, if the stroke is used. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillOpacity(Expression expression) { + return new PaintPropertyValue<>("fill-opacity", expression); + } + /** * The opacity of the entire fill layer. In contrast to the {@link PropertyFactory#fillColor}, this value will also affect the 1px stroke around the fill, if the stroke is used. @@ -76,6 +101,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> fillOpacity(Function<T, Float> function) { return new PaintPropertyValue<>("fill-opacity", function); } @@ -100,6 +126,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-color", value); } + /** + * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillColor(Expression expression) { + return new PaintPropertyValue<>("fill-color", expression); + } + /** * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. @@ -108,6 +144,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> fillColor(Function<T, String> function) { return new PaintPropertyValue<>("fill-color", function); } @@ -132,6 +169,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-outline-color", value); } + /** + * The outline color of the fill. Matches the value of {@link PropertyFactory#fillColor} if unspecified. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillOutlineColor(Expression expression) { + return new PaintPropertyValue<>("fill-outline-color", expression); + } + /** * The outline color of the fill. Matches the value of {@link PropertyFactory#fillColor} if unspecified. @@ -140,6 +187,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> fillOutlineColor(Function<T, String> function) { return new PaintPropertyValue<>("fill-outline-color", function); } @@ -154,6 +202,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-translate", value); } + /** + * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillTranslate(Expression expression) { + return new PaintPropertyValue<>("fill-translate", expression); + } + /** * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. @@ -162,12 +220,13 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> fillTranslate(CameraFunction<Z, Float[]> function) { return new PaintPropertyValue<>("fill-translate", function); } /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#fillTranslate}. * * @param value a String value * @return property wrapper around String @@ -176,14 +235,25 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-translate-anchor", value); } + /** + * Controls the frame of reference for {@link PropertyFactory#fillTranslate}. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillTranslateAnchor(Expression expression) { + return new PaintPropertyValue<>("fill-translate-anchor", expression); + } + /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#fillTranslate}. * * @param <Z> the zoom parameter type * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> fillTranslateAnchor(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("fill-translate-anchor", function); } @@ -198,6 +268,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-pattern", value); } + /** + * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillPattern(Expression expression) { + return new PaintPropertyValue<>("fill-pattern", expression); + } + /** * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). @@ -206,6 +286,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> fillPattern(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("fill-pattern", function); } @@ -220,6 +301,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-opacity", value); } + /** + * The opacity at which the line will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> lineOpacity(Expression expression) { + return new PaintPropertyValue<>("line-opacity", expression); + } + /** * The opacity at which the line will be drawn. @@ -228,6 +319,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> lineOpacity(Function<T, Float> function) { return new PaintPropertyValue<>("line-opacity", function); } @@ -252,6 +344,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-color", value); } + /** + * The color with which the line will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> lineColor(Expression expression) { + return new PaintPropertyValue<>("line-color", expression); + } + /** * The color with which the line will be drawn. @@ -260,6 +362,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> lineColor(Function<T, String> function) { return new PaintPropertyValue<>("line-color", function); } @@ -274,6 +377,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-translate", value); } + /** + * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> lineTranslate(Expression expression) { + return new PaintPropertyValue<>("line-translate", expression); + } + /** * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. @@ -282,12 +395,13 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> lineTranslate(CameraFunction<Z, Float[]> function) { return new PaintPropertyValue<>("line-translate", function); } /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#lineTranslate}. * * @param value a String value * @return property wrapper around String @@ -296,14 +410,25 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-translate-anchor", value); } + /** + * Controls the frame of reference for {@link PropertyFactory#lineTranslate}. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> lineTranslateAnchor(Expression expression) { + return new PaintPropertyValue<>("line-translate-anchor", expression); + } + /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#lineTranslate}. * * @param <Z> the zoom parameter type * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> lineTranslateAnchor(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("line-translate-anchor", function); } @@ -318,6 +443,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-width", value); } + /** + * Stroke thickness. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> lineWidth(Expression expression) { + return new PaintPropertyValue<>("line-width", expression); + } + /** * Stroke thickness. @@ -326,6 +461,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> lineWidth(Function<T, Float> function) { return new PaintPropertyValue<>("line-width", function); } @@ -340,6 +476,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-gap-width", value); } + /** + * Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> lineGapWidth(Expression expression) { + return new PaintPropertyValue<>("line-gap-width", expression); + } + /** * Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap. @@ -348,6 +494,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> lineGapWidth(Function<T, Float> function) { return new PaintPropertyValue<>("line-gap-width", function); } @@ -362,6 +509,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-offset", value); } + /** + * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> lineOffset(Expression expression) { + return new PaintPropertyValue<>("line-offset", expression); + } + /** * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. @@ -370,6 +527,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> lineOffset(Function<T, Float> function) { return new PaintPropertyValue<>("line-offset", function); } @@ -384,6 +542,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-blur", value); } + /** + * Blur applied to the line, in density-independent pixels. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> lineBlur(Expression expression) { + return new PaintPropertyValue<>("line-blur", expression); + } + /** * Blur applied to the line, in density-independent pixels. @@ -392,6 +560,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> lineBlur(Function<T, Float> function) { return new PaintPropertyValue<>("line-blur", function); } @@ -406,6 +575,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-dasharray", value); } + /** + * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to density-independent pixels, multiply the length by the current line width. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> lineDasharray(Expression expression) { + return new PaintPropertyValue<>("line-dasharray", expression); + } + /** * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to density-independent pixels, multiply the length by the current line width. @@ -414,6 +593,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> lineDasharray(CameraFunction<Z, Float[]> function) { return new PaintPropertyValue<>("line-dasharray", function); } @@ -428,6 +608,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-pattern", value); } + /** + * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> linePattern(Expression expression) { + return new PaintPropertyValue<>("line-pattern", expression); + } + /** * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). @@ -436,6 +626,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> linePattern(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("line-pattern", function); } @@ -450,6 +641,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-opacity", value); } + /** + * The opacity at which the icon will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> iconOpacity(Expression expression) { + return new PaintPropertyValue<>("icon-opacity", expression); + } + /** * The opacity at which the icon will be drawn. @@ -458,6 +659,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> iconOpacity(Function<T, Float> function) { return new PaintPropertyValue<>("icon-opacity", function); } @@ -482,6 +684,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-color", value); } + /** + * The color of the icon. This can only be used with sdf icons. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> iconColor(Expression expression) { + return new PaintPropertyValue<>("icon-color", expression); + } + /** * The color of the icon. This can only be used with sdf icons. @@ -490,6 +702,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> iconColor(Function<T, String> function) { return new PaintPropertyValue<>("icon-color", function); } @@ -514,6 +727,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-halo-color", value); } + /** + * The color of the icon's halo. Icon halos can only be used with SDF icons. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> iconHaloColor(Expression expression) { + return new PaintPropertyValue<>("icon-halo-color", expression); + } + /** * The color of the icon's halo. Icon halos can only be used with SDF icons. @@ -522,6 +745,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> iconHaloColor(Function<T, String> function) { return new PaintPropertyValue<>("icon-halo-color", function); } @@ -536,6 +760,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-halo-width", value); } + /** + * Distance of halo to the icon outline. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> iconHaloWidth(Expression expression) { + return new PaintPropertyValue<>("icon-halo-width", expression); + } + /** * Distance of halo to the icon outline. @@ -544,6 +778,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> iconHaloWidth(Function<T, Float> function) { return new PaintPropertyValue<>("icon-halo-width", function); } @@ -558,6 +793,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-halo-blur", value); } + /** + * Fade out the halo towards the outside. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> iconHaloBlur(Expression expression) { + return new PaintPropertyValue<>("icon-halo-blur", expression); + } + /** * Fade out the halo towards the outside. @@ -566,6 +811,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> iconHaloBlur(Function<T, Float> function) { return new PaintPropertyValue<>("icon-halo-blur", function); } @@ -580,6 +826,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-translate", value); } + /** + * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> iconTranslate(Expression expression) { + return new PaintPropertyValue<>("icon-translate", expression); + } + /** * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. @@ -588,12 +844,13 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> iconTranslate(CameraFunction<Z, Float[]> function) { return new PaintPropertyValue<>("icon-translate", function); } /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#iconTranslate}. * * @param value a String value * @return property wrapper around String @@ -602,14 +859,25 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-translate-anchor", value); } + /** + * Controls the frame of reference for {@link PropertyFactory#iconTranslate}. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> iconTranslateAnchor(Expression expression) { + return new PaintPropertyValue<>("icon-translate-anchor", expression); + } + /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#iconTranslate}. * * @param <Z> the zoom parameter type * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> iconTranslateAnchor(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("icon-translate-anchor", function); } @@ -624,6 +892,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-opacity", value); } + /** + * The opacity at which the text will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> textOpacity(Expression expression) { + return new PaintPropertyValue<>("text-opacity", expression); + } + /** * The opacity at which the text will be drawn. @@ -632,6 +910,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> textOpacity(Function<T, Float> function) { return new PaintPropertyValue<>("text-opacity", function); } @@ -656,6 +935,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-color", value); } + /** + * The color with which the text will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> textColor(Expression expression) { + return new PaintPropertyValue<>("text-color", expression); + } + /** * The color with which the text will be drawn. @@ -664,6 +953,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> textColor(Function<T, String> function) { return new PaintPropertyValue<>("text-color", function); } @@ -688,6 +978,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-halo-color", value); } + /** + * The color of the text's halo, which helps it stand out from backgrounds. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> textHaloColor(Expression expression) { + return new PaintPropertyValue<>("text-halo-color", expression); + } + /** * The color of the text's halo, which helps it stand out from backgrounds. @@ -696,6 +996,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> textHaloColor(Function<T, String> function) { return new PaintPropertyValue<>("text-halo-color", function); } @@ -710,6 +1011,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-halo-width", value); } + /** + * Distance of halo to the font outline. Max text halo width is 1/4 of the font-size. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> textHaloWidth(Expression expression) { + return new PaintPropertyValue<>("text-halo-width", expression); + } + /** * Distance of halo to the font outline. Max text halo width is 1/4 of the font-size. @@ -718,6 +1029,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> textHaloWidth(Function<T, Float> function) { return new PaintPropertyValue<>("text-halo-width", function); } @@ -732,6 +1044,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-halo-blur", value); } + /** + * The halo's fadeout distance towards the outside. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> textHaloBlur(Expression expression) { + return new PaintPropertyValue<>("text-halo-blur", expression); + } + /** * The halo's fadeout distance towards the outside. @@ -740,6 +1062,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> textHaloBlur(Function<T, Float> function) { return new PaintPropertyValue<>("text-halo-blur", function); } @@ -754,6 +1077,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-translate", value); } + /** + * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> textTranslate(Expression expression) { + return new PaintPropertyValue<>("text-translate", expression); + } + /** * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. @@ -762,12 +1095,13 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> textTranslate(CameraFunction<Z, Float[]> function) { return new PaintPropertyValue<>("text-translate", function); } /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#textTranslate}. * * @param value a String value * @return property wrapper around String @@ -776,14 +1110,25 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-translate-anchor", value); } + /** + * Controls the frame of reference for {@link PropertyFactory#textTranslate}. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> textTranslateAnchor(Expression expression) { + return new PaintPropertyValue<>("text-translate-anchor", expression); + } + /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#textTranslate}. * * @param <Z> the zoom parameter type * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> textTranslateAnchor(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("text-translate-anchor", function); } @@ -798,6 +1143,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-radius", value); } + /** + * Circle radius. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circleRadius(Expression expression) { + return new PaintPropertyValue<>("circle-radius", expression); + } + /** * Circle radius. @@ -806,6 +1161,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> circleRadius(Function<T, Float> function) { return new PaintPropertyValue<>("circle-radius", function); } @@ -830,6 +1186,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-color", value); } + /** + * The fill color of the circle. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circleColor(Expression expression) { + return new PaintPropertyValue<>("circle-color", expression); + } + /** * The fill color of the circle. @@ -838,6 +1204,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> circleColor(Function<T, String> function) { return new PaintPropertyValue<>("circle-color", function); } @@ -852,6 +1219,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-blur", value); } + /** + * Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circleBlur(Expression expression) { + return new PaintPropertyValue<>("circle-blur", expression); + } + /** * Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. @@ -860,6 +1237,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> circleBlur(Function<T, Float> function) { return new PaintPropertyValue<>("circle-blur", function); } @@ -874,6 +1252,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-opacity", value); } + /** + * The opacity at which the circle will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circleOpacity(Expression expression) { + return new PaintPropertyValue<>("circle-opacity", expression); + } + /** * The opacity at which the circle will be drawn. @@ -882,6 +1270,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> circleOpacity(Function<T, Float> function) { return new PaintPropertyValue<>("circle-opacity", function); } @@ -896,6 +1285,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-translate", value); } + /** + * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circleTranslate(Expression expression) { + return new PaintPropertyValue<>("circle-translate", expression); + } + /** * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. @@ -904,12 +1303,13 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> circleTranslate(CameraFunction<Z, Float[]> function) { return new PaintPropertyValue<>("circle-translate", function); } /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#circleTranslate}. * * @param value a String value * @return property wrapper around String @@ -918,14 +1318,25 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-translate-anchor", value); } + /** + * Controls the frame of reference for {@link PropertyFactory#circleTranslate}. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circleTranslateAnchor(Expression expression) { + return new PaintPropertyValue<>("circle-translate-anchor", expression); + } + /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#circleTranslate}. * * @param <Z> the zoom parameter type * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> circleTranslateAnchor(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("circle-translate-anchor", function); } @@ -940,6 +1351,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-pitch-scale", value); } + /** + * Controls the scaling behavior of the circle when the map is pitched. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circlePitchScale(Expression expression) { + return new PaintPropertyValue<>("circle-pitch-scale", expression); + } + /** * Controls the scaling behavior of the circle when the map is pitched. @@ -948,6 +1369,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> circlePitchScale(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("circle-pitch-scale", function); } @@ -962,6 +1384,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-pitch-alignment", value); } + /** + * Orientation of circle when map is pitched. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circlePitchAlignment(Expression expression) { + return new PaintPropertyValue<>("circle-pitch-alignment", expression); + } + /** * Orientation of circle when map is pitched. @@ -970,6 +1402,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> circlePitchAlignment(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("circle-pitch-alignment", function); } @@ -984,6 +1417,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-stroke-width", value); } + /** + * The width of the circle's stroke. Strokes are placed outside of the {@link PropertyFactory#circleRadius}. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circleStrokeWidth(Expression expression) { + return new PaintPropertyValue<>("circle-stroke-width", expression); + } + /** * The width of the circle's stroke. Strokes are placed outside of the {@link PropertyFactory#circleRadius}. @@ -992,6 +1435,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> circleStrokeWidth(Function<T, Float> function) { return new PaintPropertyValue<>("circle-stroke-width", function); } @@ -1016,6 +1460,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-stroke-color", value); } + /** + * The stroke color of the circle. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circleStrokeColor(Expression expression) { + return new PaintPropertyValue<>("circle-stroke-color", expression); + } + /** * The stroke color of the circle. @@ -1024,6 +1478,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> circleStrokeColor(Function<T, String> function) { return new PaintPropertyValue<>("circle-stroke-color", function); } @@ -1038,6 +1493,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-stroke-opacity", value); } + /** + * The opacity of the circle's stroke. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> circleStrokeOpacity(Expression expression) { + return new PaintPropertyValue<>("circle-stroke-opacity", expression); + } + /** * The opacity of the circle's stroke. @@ -1046,6 +1511,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> circleStrokeOpacity(Function<T, Float> function) { return new PaintPropertyValue<>("circle-stroke-opacity", function); } @@ -1060,6 +1526,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-opacity", value); } + /** + * The opacity of the entire fill extrusion layer. This is rendered on a per-layer, not per-feature, basis, and data-driven styling is not available. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillExtrusionOpacity(Expression expression) { + return new PaintPropertyValue<>("fill-extrusion-opacity", expression); + } + /** * The opacity of the entire fill extrusion layer. This is rendered on a per-layer, not per-feature, basis, and data-driven styling is not available. @@ -1068,6 +1544,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> fillExtrusionOpacity(CameraFunction<Z, Float> function) { return new PaintPropertyValue<>("fill-extrusion-opacity", function); } @@ -1092,6 +1569,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-color", value); } + /** + * The base color of the extruded fill. The extrusion's surfaces will be shaded differently based on this color in combination with the root `light` settings. If this color is specified as `rgba` with an alpha component, the alpha component will be ignored; use {@link PropertyFactory#fillExtrusionOpacity} to set layer opacity. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillExtrusionColor(Expression expression) { + return new PaintPropertyValue<>("fill-extrusion-color", expression); + } + /** * The base color of the extruded fill. The extrusion's surfaces will be shaded differently based on this color in combination with the root `light` settings. If this color is specified as `rgba` with an alpha component, the alpha component will be ignored; use {@link PropertyFactory#fillExtrusionOpacity} to set layer opacity. @@ -1100,6 +1587,7 @@ public class PropertyFactory { * @param function a wrapper function for String * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> fillExtrusionColor(Function<T, String> function) { return new PaintPropertyValue<>("fill-extrusion-color", function); } @@ -1114,6 +1602,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-translate", value); } + /** + * The geometry's offset. Values are [x, y] where negatives indicate left and up (on the flat plane), respectively. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillExtrusionTranslate(Expression expression) { + return new PaintPropertyValue<>("fill-extrusion-translate", expression); + } + /** * The geometry's offset. Values are [x, y] where negatives indicate left and up (on the flat plane), respectively. @@ -1122,12 +1620,13 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> fillExtrusionTranslate(CameraFunction<Z, Float[]> function) { return new PaintPropertyValue<>("fill-extrusion-translate", function); } /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#fillExtrusionTranslate}. * * @param value a String value * @return property wrapper around String @@ -1136,14 +1635,25 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-translate-anchor", value); } + /** + * Controls the frame of reference for {@link PropertyFactory#fillExtrusionTranslate}. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillExtrusionTranslateAnchor(Expression expression) { + return new PaintPropertyValue<>("fill-extrusion-translate-anchor", expression); + } + /** - * Controls the translation reference point. + * Controls the frame of reference for {@link PropertyFactory#fillExtrusionTranslate}. * * @param <Z> the zoom parameter type * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> fillExtrusionTranslateAnchor(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("fill-extrusion-translate-anchor", function); } @@ -1158,6 +1668,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-pattern", value); } + /** + * Name of image in sprite to use for drawing images on extruded fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillExtrusionPattern(Expression expression) { + return new PaintPropertyValue<>("fill-extrusion-pattern", expression); + } + /** * Name of image in sprite to use for drawing images on extruded fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). @@ -1166,6 +1686,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> fillExtrusionPattern(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("fill-extrusion-pattern", function); } @@ -1180,6 +1701,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-height", value); } + /** + * The height with which to extrude this layer. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillExtrusionHeight(Expression expression) { + return new PaintPropertyValue<>("fill-extrusion-height", expression); + } + /** * The height with which to extrude this layer. @@ -1188,6 +1719,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> fillExtrusionHeight(Function<T, Float> function) { return new PaintPropertyValue<>("fill-extrusion-height", function); } @@ -1202,6 +1734,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-base", value); } + /** + * The height with which to extrude the base of this layer. Must be less than or equal to {@link PropertyFactory#fillExtrusionHeight}. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> fillExtrusionBase(Expression expression) { + return new PaintPropertyValue<>("fill-extrusion-base", expression); + } + /** * The height with which to extrude the base of this layer. Must be less than or equal to {@link PropertyFactory#fillExtrusionHeight}. @@ -1210,6 +1752,7 @@ public class PropertyFactory { * @param function a wrapper function for Float * @return property wrapper around a Float function */ + @Deprecated public static <T> PropertyValue<Function<T, Float>> fillExtrusionBase(Function<T, Float> function) { return new PaintPropertyValue<>("fill-extrusion-base", function); } @@ -1224,6 +1767,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-opacity", value); } + /** + * The opacity at which the image will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> rasterOpacity(Expression expression) { + return new PaintPropertyValue<>("raster-opacity", expression); + } + /** * The opacity at which the image will be drawn. @@ -1232,6 +1785,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterOpacity(CameraFunction<Z, Float> function) { return new PaintPropertyValue<>("raster-opacity", function); } @@ -1246,6 +1800,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-hue-rotate", value); } + /** + * Rotates hues around the color wheel. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> rasterHueRotate(Expression expression) { + return new PaintPropertyValue<>("raster-hue-rotate", expression); + } + /** * Rotates hues around the color wheel. @@ -1254,6 +1818,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterHueRotate(CameraFunction<Z, Float> function) { return new PaintPropertyValue<>("raster-hue-rotate", function); } @@ -1268,6 +1833,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-brightness-min", value); } + /** + * Increase or reduce the brightness of the image. The value is the minimum brightness. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> rasterBrightnessMin(Expression expression) { + return new PaintPropertyValue<>("raster-brightness-min", expression); + } + /** * Increase or reduce the brightness of the image. The value is the minimum brightness. @@ -1276,6 +1851,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterBrightnessMin(CameraFunction<Z, Float> function) { return new PaintPropertyValue<>("raster-brightness-min", function); } @@ -1290,6 +1866,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-brightness-max", value); } + /** + * Increase or reduce the brightness of the image. The value is the maximum brightness. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> rasterBrightnessMax(Expression expression) { + return new PaintPropertyValue<>("raster-brightness-max", expression); + } + /** * Increase or reduce the brightness of the image. The value is the maximum brightness. @@ -1298,6 +1884,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterBrightnessMax(CameraFunction<Z, Float> function) { return new PaintPropertyValue<>("raster-brightness-max", function); } @@ -1312,6 +1899,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-saturation", value); } + /** + * Increase or reduce the saturation of the image. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> rasterSaturation(Expression expression) { + return new PaintPropertyValue<>("raster-saturation", expression); + } + /** * Increase or reduce the saturation of the image. @@ -1320,6 +1917,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterSaturation(CameraFunction<Z, Float> function) { return new PaintPropertyValue<>("raster-saturation", function); } @@ -1334,6 +1932,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-contrast", value); } + /** + * Increase or reduce the contrast of the image. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> rasterContrast(Expression expression) { + return new PaintPropertyValue<>("raster-contrast", expression); + } + /** * Increase or reduce the contrast of the image. @@ -1342,6 +1950,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterContrast(CameraFunction<Z, Float> function) { return new PaintPropertyValue<>("raster-contrast", function); } @@ -1356,6 +1965,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-fade-duration", value); } + /** + * Fade duration when a new tile is added. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> rasterFadeDuration(Expression expression) { + return new PaintPropertyValue<>("raster-fade-duration", expression); + } + /** * Fade duration when a new tile is added. @@ -1364,6 +1983,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterFadeDuration(CameraFunction<Z, Float> function) { return new PaintPropertyValue<>("raster-fade-duration", function); } @@ -1388,6 +2008,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("background-color", value); } + /** + * The color with which the background will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> backgroundColor(Expression expression) { + return new PaintPropertyValue<>("background-color", expression); + } + /** * The color with which the background will be drawn. @@ -1396,6 +2026,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> backgroundColor(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("background-color", function); } @@ -1410,6 +2041,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("background-pattern", value); } + /** + * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> backgroundPattern(Expression expression) { + return new PaintPropertyValue<>("background-pattern", expression); + } + /** * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). @@ -1418,6 +2059,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> backgroundPattern(CameraFunction<Z, String> function) { return new PaintPropertyValue<>("background-pattern", function); } @@ -1432,6 +2074,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("background-opacity", value); } + /** + * The opacity at which the background will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> backgroundOpacity(Expression expression) { + return new PaintPropertyValue<>("background-opacity", expression); + } + /** * The opacity at which the background will be drawn. @@ -1440,6 +2092,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> backgroundOpacity(CameraFunction<Z, Float> function) { return new PaintPropertyValue<>("background-opacity", function); } @@ -1454,6 +2107,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("line-cap", value); } + /** + * The display of line endings. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> lineCap(Expression value) { + return new LayoutPropertyValue<>("line-cap", value); + } /** @@ -1477,6 +2139,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("line-join", value); } + /** + * The display of lines when joining. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> lineJoin(Expression value) { + return new LayoutPropertyValue<>("line-join", value); + } /** @@ -1500,6 +2171,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("line-miter-limit", value); } + /** + * Used to automatically convert miter joins to bevel joins for sharp angles. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> lineMiterLimit(Expression value) { + return new LayoutPropertyValue<>("line-miter-limit", value); + } /** @@ -1523,6 +2203,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("line-round-limit", value); } + /** + * Used to automatically convert round joins to miter joins for shallow angles. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> lineRoundLimit(Expression value) { + return new LayoutPropertyValue<>("line-round-limit", value); + } /** @@ -1546,6 +2235,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("symbol-placement", value); } + /** + * Label placement relative to its geometry. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> symbolPlacement(Expression value) { + return new LayoutPropertyValue<>("symbol-placement", value); + } /** @@ -1569,6 +2267,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("symbol-spacing", value); } + /** + * Distance between two symbol anchors. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> symbolSpacing(Expression value) { + return new LayoutPropertyValue<>("symbol-spacing", value); + } /** @@ -1592,6 +2299,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("symbol-avoid-edges", value); } + /** + * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. + * + * @param value a Boolean value + * @return property wrapper around Boolean + */ + public static PropertyValue<Expression> symbolAvoidEdges(Expression value) { + return new LayoutPropertyValue<>("symbol-avoid-edges", value); + } /** @@ -1615,6 +2331,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-allow-overlap", value); } + /** + * If true, the icon will be visible even if it collides with other previously drawn symbols. + * + * @param value a Boolean value + * @return property wrapper around Boolean + */ + public static PropertyValue<Expression> iconAllowOverlap(Expression value) { + return new LayoutPropertyValue<>("icon-allow-overlap", value); + } /** @@ -1638,6 +2363,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-ignore-placement", value); } + /** + * If true, other symbols can be visible even if they collide with the icon. + * + * @param value a Boolean value + * @return property wrapper around Boolean + */ + public static PropertyValue<Expression> iconIgnorePlacement(Expression value) { + return new LayoutPropertyValue<>("icon-ignore-placement", value); + } /** @@ -1661,6 +2395,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-optional", value); } + /** + * If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not. + * + * @param value a Boolean value + * @return property wrapper around Boolean + */ + public static PropertyValue<Expression> iconOptional(Expression value) { + return new LayoutPropertyValue<>("icon-optional", value); + } /** @@ -1684,6 +2427,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-rotation-alignment", value); } + /** + * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of icons. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> iconRotationAlignment(Expression value) { + return new LayoutPropertyValue<>("icon-rotation-alignment", value); + } /** @@ -1707,6 +2459,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-size", value); } + /** + * Scales the original size of the icon by the provided factor. The new pixel size of the image will be the original pixel size multiplied by {@link PropertyFactory#iconSize}. 1 is the original size; 3 triples the size of the image. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> iconSize(Expression value) { + return new LayoutPropertyValue<>("icon-size", value); + } /** @@ -1730,6 +2491,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-text-fit", value); } + /** + * Scales the icon to fit around the associated text. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> iconTextFit(Expression value) { + return new LayoutPropertyValue<>("icon-text-fit", value); + } /** @@ -1753,6 +2523,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-text-fit-padding", value); } + /** + * Size of the additional area added to dimensions determined by {@link Property.ICON_TEXT_FIT}, in clockwise order: top, right, bottom, left. + * + * @param value a Float[] value + * @return property wrapper around Float[] + */ + public static PropertyValue<Expression> iconTextFitPadding(Expression value) { + return new LayoutPropertyValue<>("icon-text-fit-padding", value); + } /** @@ -1767,7 +2546,7 @@ public class PropertyFactory { } /** - * Name of image in sprite to use for drawing an image background. A string with {tokens} replaced, referencing the data property to pull from. + * Name of image in sprite to use for drawing an image background. A string with `{tokens}` replaced, referencing the data property to pull from. (`{token}` replacement is only supported for literal {@link PropertyFactory#iconImage} values; not for property functions.) * * @param value a String value * @return property wrapper around String @@ -1776,10 +2555,19 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-image", value); } + /** + * Name of image in sprite to use for drawing an image background. A string with `{tokens}` replaced, referencing the data property to pull from. (`{token}` replacement is only supported for literal {@link PropertyFactory#iconImage} values; not for property functions.) + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> iconImage(Expression value) { + return new LayoutPropertyValue<>("icon-image", value); + } /** - * Name of image in sprite to use for drawing an image background. A string with {tokens} replaced, referencing the data property to pull from. + * Name of image in sprite to use for drawing an image background. A string with `{tokens}` replaced, referencing the data property to pull from. (`{token}` replacement is only supported for literal {@link PropertyFactory#iconImage} values; not for property functions.) * * @param <T> the function input type * @param function a wrapper function for String @@ -1799,6 +2587,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-rotate", value); } + /** + * Rotates the icon clockwise. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> iconRotate(Expression value) { + return new LayoutPropertyValue<>("icon-rotate", value); + } /** @@ -1822,6 +2619,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-padding", value); } + /** + * Size of the additional area around the icon bounding box used for detecting symbol collisions. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> iconPadding(Expression value) { + return new LayoutPropertyValue<>("icon-padding", value); + } /** @@ -1845,6 +2651,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-keep-upright", value); } + /** + * If true, the icon may be flipped to prevent it from being rendered upside-down. + * + * @param value a Boolean value + * @return property wrapper around Boolean + */ + public static PropertyValue<Expression> iconKeepUpright(Expression value) { + return new LayoutPropertyValue<>("icon-keep-upright", value); + } /** @@ -1868,6 +2683,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-offset", value); } + /** + * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. When combined with {@link PropertyFactory#iconRotate} the offset will be as if the rotated direction was up. + * + * @param value a Float[] value + * @return property wrapper around Float[] + */ + public static PropertyValue<Expression> iconOffset(Expression value) { + return new LayoutPropertyValue<>("icon-offset", value); + } /** @@ -1891,6 +2715,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-anchor", value); } + /** + * Part of the icon placed closest to the anchor. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> iconAnchor(Expression value) { + return new LayoutPropertyValue<>("icon-anchor", value); + } /** @@ -1914,6 +2747,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-pitch-alignment", value); } + /** + * Orientation of icon when map is pitched. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> iconPitchAlignment(Expression value) { + return new LayoutPropertyValue<>("icon-pitch-alignment", value); + } /** @@ -1937,6 +2779,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-pitch-alignment", value); } + /** + * Orientation of text when map is pitched. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> textPitchAlignment(Expression value) { + return new LayoutPropertyValue<>("text-pitch-alignment", value); + } /** @@ -1960,6 +2811,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-rotation-alignment", value); } + /** + * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of the individual glyphs forming the text. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> textRotationAlignment(Expression value) { + return new LayoutPropertyValue<>("text-rotation-alignment", value); + } /** @@ -1974,7 +2834,7 @@ public class PropertyFactory { } /** - * Value to use for a text label. Feature properties are specified using tokens like {field_name}. (Token replacement is only supported for literal {@link PropertyFactory#textField} values--not for property functions.) + * Value to use for a text label. Feature properties are specified using tokens like `{field_name}`. (`{token}` replacement is only supported for literal {@link PropertyFactory#textField} values; not for property functions.) * * @param value a String value * @return property wrapper around String @@ -1983,10 +2843,19 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-field", value); } + /** + * Value to use for a text label. Feature properties are specified using tokens like `{field_name}`. (`{token}` replacement is only supported for literal {@link PropertyFactory#textField} values; not for property functions.) + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> textField(Expression value) { + return new LayoutPropertyValue<>("text-field", value); + } /** - * Value to use for a text label. Feature properties are specified using tokens like {field_name}. (Token replacement is only supported for literal {@link PropertyFactory#textField} values--not for property functions.) + * Value to use for a text label. Feature properties are specified using tokens like `{field_name}`. (`{token}` replacement is only supported for literal {@link PropertyFactory#textField} values; not for property functions.) * * @param <T> the function input type * @param function a wrapper function for String @@ -2006,16 +2875,25 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-font", value); } + /** + * Font stack to use for displaying text. + * + * @param value a String[] value + * @return property wrapper around String[] + */ + public static PropertyValue<Expression> textFont(Expression value) { + return new LayoutPropertyValue<>("text-font", value); + } /** * Font stack to use for displaying text. * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String[] + * @param <T> the function input type + * @param function a wrapper function for String[] * @return property wrapper around a String[] function */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, String[]>> textFont(CameraFunction<Z, String[]> function) { + public static <T> PropertyValue<Function<T, String[]>> textFont(Function<T, String[]> function) { return new LayoutPropertyValue<>("text-font", function); } @@ -2029,6 +2907,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-size", value); } + /** + * Font size. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> textSize(Expression value) { + return new LayoutPropertyValue<>("text-size", value); + } /** @@ -2052,6 +2939,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-max-width", value); } + /** + * The maximum line width for text wrapping. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> textMaxWidth(Expression value) { + return new LayoutPropertyValue<>("text-max-width", value); + } /** @@ -2075,6 +2971,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-line-height", value); } + /** + * Text leading value for multi-line text. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> textLineHeight(Expression value) { + return new LayoutPropertyValue<>("text-line-height", value); + } /** @@ -2098,6 +3003,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-letter-spacing", value); } + /** + * Text tracking amount. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> textLetterSpacing(Expression value) { + return new LayoutPropertyValue<>("text-letter-spacing", value); + } /** @@ -2121,6 +3035,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-justify", value); } + /** + * Text justification options. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> textJustify(Expression value) { + return new LayoutPropertyValue<>("text-justify", value); + } /** @@ -2144,6 +3067,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-anchor", value); } + /** + * Part of the text placed closest to the anchor. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> textAnchor(Expression value) { + return new LayoutPropertyValue<>("text-anchor", value); + } /** @@ -2167,6 +3099,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-max-angle", value); } + /** + * Maximum angle change between adjacent characters. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> textMaxAngle(Expression value) { + return new LayoutPropertyValue<>("text-max-angle", value); + } /** @@ -2190,6 +3131,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-rotate", value); } + /** + * Rotates the text clockwise. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> textRotate(Expression value) { + return new LayoutPropertyValue<>("text-rotate", value); + } /** @@ -2213,6 +3163,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-padding", value); } + /** + * Size of the additional area around the text bounding box used for detecting symbol collisions. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> textPadding(Expression value) { + return new LayoutPropertyValue<>("text-padding", value); + } /** @@ -2236,6 +3195,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-keep-upright", value); } + /** + * If true, the text may be flipped vertically to prevent it from being rendered upside-down. + * + * @param value a Boolean value + * @return property wrapper around Boolean + */ + public static PropertyValue<Expression> textKeepUpright(Expression value) { + return new LayoutPropertyValue<>("text-keep-upright", value); + } /** @@ -2259,6 +3227,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-transform", value); } + /** + * Specifies how to capitalize text, similar to the CSS {@link PropertyFactory#textTransform} property. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<Expression> textTransform(Expression value) { + return new LayoutPropertyValue<>("text-transform", value); + } /** @@ -2282,6 +3259,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-offset", value); } + /** + * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. + * + * @param value a Float[] value + * @return property wrapper around Float[] + */ + public static PropertyValue<Expression> textOffset(Expression value) { + return new LayoutPropertyValue<>("text-offset", value); + } /** @@ -2305,6 +3291,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-allow-overlap", value); } + /** + * If true, the text will be visible even if it collides with other previously drawn symbols. + * + * @param value a Boolean value + * @return property wrapper around Boolean + */ + public static PropertyValue<Expression> textAllowOverlap(Expression value) { + return new LayoutPropertyValue<>("text-allow-overlap", value); + } /** @@ -2328,6 +3323,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-ignore-placement", value); } + /** + * If true, other symbols can be visible even if they collide with the text. + * + * @param value a Boolean value + * @return property wrapper around Boolean + */ + public static PropertyValue<Expression> textIgnorePlacement(Expression value) { + return new LayoutPropertyValue<>("text-ignore-placement", value); + } /** @@ -2351,7 +3355,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-optional", value); } - + /** + * If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. + * + * @param value a Boolean value + * @return property wrapper around Boolean + */ + public static PropertyValue<Expression> textOptional(Expression value) { + return new LayoutPropertyValue<>("text-optional", value); + } /** * If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. @@ -2364,9 +3376,9 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-optional", function); } - @SuppressLint("DefaultLocale") public static String colorToRgbaString(@ColorInt int value) { - return String.format("rgba(%d, %d, %d, %d)", (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF, (value >> 24) & 0xFF); + return String.format(Locale.US,"rgba(%d, %d, %d, %d)", + (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF, (value >> 24) & 0xFF); } } 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 e67e71b61d..0a056d8fac 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 @@ -2,14 +2,9 @@ package com.mapbox.mapboxsdk.style.layers; -import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.UiThread; -import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; - -import com.mapbox.mapboxsdk.style.layers.TransitionOptions; - /** * Raster map textures such as satellite imagery. * 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 d0fb82dce5..3d2c3881b2 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 @@ -8,8 +8,6 @@ import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; -import com.mapbox.mapboxsdk.style.layers.TransitionOptions; - /** * An icon or a text label. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs index 2d3421d1d9..ed138e557a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs @@ -11,6 +11,7 @@ import android.support.annotation.ColorInt; import com.mapbox.mapboxsdk.style.functions.Function; import com.mapbox.mapboxsdk.style.functions.CameraFunction; +import com.mapbox.mapboxsdk.style.expressions.Expression; /** * Constructs paint/layout properties for Layers @@ -36,6 +37,7 @@ public class PropertyFactory { * @param function the visibility function * @return property wrapper around a String function */ + @Deprecated public static <T> PropertyValue<Function<T, String>> visibility(Function<T, String> function) { return new LayoutPropertyValue<>("visibility", function); } @@ -63,6 +65,16 @@ public class PropertyFactory { return new PaintPropertyValue<>("<%- property.name %>", value); } + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> <%- camelizeWithLeadingLowercase(property.name) %>(Expression expression) { + return new PaintPropertyValue<>("<%- property.name %>", expression); + } + <% if (supportsPropertyFunction(property)) { -%> /** @@ -72,6 +84,7 @@ public class PropertyFactory { * @param function a wrapper function for <%- propertyType(property) %> * @return property wrapper around a <%- propertyType(property) %> function */ + @Deprecated public static <T> PropertyValue<Function<T, <%- propertyType(property) %>>> <%- camelizeWithLeadingLowercase(property.name) %>(Function<T, <%- propertyType(property) %>> function) { return new PaintPropertyValue<>("<%- property.name %>", function); } @@ -85,6 +98,7 @@ public class PropertyFactory { * @param function a wrapper {@link CameraFunction} for <%- propertyType(property) %> * @return property wrapper around a <%- propertyType(property) %> function */ + @Deprecated public static <Z extends Number> PropertyValue<CameraFunction<Z, <%- propertyType(property) %>>> <%- camelizeWithLeadingLowercase(property.name) %>(CameraFunction<Z, <%- propertyType(property) %>> function) { return new PaintPropertyValue<>("<%- property.name %>", function); } @@ -102,6 +116,15 @@ public class PropertyFactory { return new LayoutPropertyValue<>("<%- property.name %>", value); } + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param value a <%- propertyType(property) %> value + * @return property wrapper around <%- propertyType(property) %> + */ + public static PropertyValue<Expression> <%- camelizeWithLeadingLowercase(property.name) %>(Expression value) { + return new LayoutPropertyValue<>("<%- property.name %>", value); + } <% if (supportsPropertyFunction(property)) { -%> 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 new file mode 100644 index 0000000000..62f1719ddf --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java @@ -0,0 +1,203 @@ +package com.mapbox.mapboxsdk.style.sources; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.UiThread; +import android.support.annotation.WorkerThread; + +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.style.layers.Filter; +import com.mapbox.services.commons.geojson.Feature; +import com.mapbox.services.commons.geojson.FeatureCollection; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Custom Vector Source, allows using FeatureCollections. + * + */ +@UiThread +public class CustomGeometrySource extends Source { + private ExecutorService executor; + private GeometryTileProvider provider; + private final Map<TileID, AtomicBoolean> cancelledTileRequests = new ConcurrentHashMap<>(); + + /** + * Create a CustomGeometrySource + * + * @param id The source id. + * @param provider The tile provider that returns geometry data for this source. + */ + public CustomGeometrySource(String id, GeometryTileProvider provider) { + this(id, provider, new GeoJsonOptions()); + } + + /** + * Create a CustomGeometrySource with non-default GeoJsonOptions. + * <p>Supported options are minZoom, maxZoom, buffer, and tolerance.</p> + * + * @param id The source id. + * @param provider The tile provider that returns geometry data for this source. + * @param options GeoJsonOptions. + */ + public CustomGeometrySource(String id, GeometryTileProvider provider, GeoJsonOptions options) { + 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. + * + * @param bounds The region in which features should be invalidated at all zoom levels + */ + public void invalidateRegion(LatLngBounds bounds) { + nativeInvalidateBounds(bounds); + } + + /** + * Invalidate the geometry contents of a specific tile. Invoking this method will result + * in new requests to `GeometryTileProvider` for visible tiles. + * + * @param zoomLevel Tile zoom level. + * @param x Tile X coordinate. + * @param y Tile Y coordinate. + */ + public void invalidateTile(int zoomLevel, int x, int y) { + nativeInvalidateTile(zoomLevel, x, y); + } + + /** + * Set or update geometry contents of a specific tile. Use this method to update tiles + * for which `GeometryTileProvider` was previously invoked. This method can be called from + * background threads. + * + * @param zoomLevel Tile zoom level. + * @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) { + nativeSetTileData(zoomLevel, x, y, data); + } + + /** + * Queries the source for features. + * + * @param filter an optional filter statement to filter the returned Features + * @return the features + */ + @NonNull + public List<Feature> querySourceFeatures(@Nullable Filter.Statement filter) { + Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null); + return features != null ? Arrays.asList(features) : new ArrayList<Feature>(); + } + + protected native void initialize(String sourceId, Object options); + + private native Feature[] querySourceFeatures(Object[] filter); + + private native void nativeSetTileData(int z, int x, int y, FeatureCollection data); + + private native void nativeInvalidateTile(int z, int x, int y); + + private native void nativeInvalidateBounds(LatLngBounds bounds); + + @Override + protected native void finalize() throws Throwable; + + private void setTileData(TileID tileId, FeatureCollection data) { + cancelledTileRequests.remove(tileId); + nativeSetTileData(tileId.z, tileId.x, tileId.y, data); + } + + @WorkerThread + private void fetchTile(int z, int x, int y) { + AtomicBoolean cancelFlag = new AtomicBoolean(false); + TileID tileID = new TileID(z, x, y); + cancelledTileRequests.put(tileID, cancelFlag); + GeometryTileRequest request = new GeometryTileRequest(tileID, provider, this, cancelFlag); + executor.execute(request); + } + + @WorkerThread + private void cancelTile(int z, int x, int y) { + AtomicBoolean cancelFlag = cancelledTileRequests.get(new TileID(z, x, y)); + if (cancelFlag != null) { + cancelFlag.compareAndSet(false, true); + } + } + + private static class TileID { + public int z; + public int x; + public int y; + + public TileID(int _z, int _x, int _y) { + z = _z; + x = _x; + y = _y; + } + + public int hashCode() { + return Arrays.hashCode(new int[]{z, x, y}); + } + + public boolean equals(Object object) { + if (object == this) { + return true; + } + + if (object == null || getClass() != object.getClass()) { + return false; + } + + if (object instanceof TileID) { + TileID other = (TileID)object; + return this.z == other.z && this.x == other.x && this.y == other.y; + } + return false; + } + } + + private static class GeometryTileRequest implements Runnable { + private TileID id; + private GeometryTileProvider provider; + private WeakReference<CustomGeometrySource> sourceRef; + private AtomicBoolean cancelled; + + public GeometryTileRequest(TileID _id, GeometryTileProvider p, + CustomGeometrySource _source, AtomicBoolean _cancelled) { + id = _id; + provider = p; + sourceRef = new WeakReference<>(_source); + cancelled = _cancelled; + } + + public void run() { + if (isCancelled()) { + return; + } + + FeatureCollection data = provider.getFeaturesForBounds(LatLngBounds.from(id.z, id.x, id.y), id.z); + CustomGeometrySource source = sourceRef.get(); + if (!isCancelled() && source != null && data != null) { + source.setTileData(id, data); + } + } + + private Boolean isCancelled() { + return cancelled.get(); + } + } +} 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 1a1711e547..81f7255b86 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 @@ -16,6 +16,17 @@ public class GeoJsonOptions extends HashMap<String, Object> { * @param maxZoom the maximum zoom - Defaults to 18. * @return the current instance for chaining */ + public GeoJsonOptions withMinZoom(int minZoom) { + this.put("minzoom", minZoom); + return this; + } + + /** + * 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. + * @return the current instance for chaining + */ public GeoJsonOptions withMaxZoom(int maxZoom) { this.put("maxzoom", maxZoom); return this; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeometryTileProvider.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeometryTileProvider.java new file mode 100644 index 0000000000..3f1eb315d3 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeometryTileProvider.java @@ -0,0 +1,22 @@ +package com.mapbox.mapboxsdk.style.sources; + +import android.support.annotation.WorkerThread; + +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.services.commons.geojson.FeatureCollection; + +/** + * Interface that defines methods for working with {@link CustomGeometrySource}. + */ +public interface GeometryTileProvider { + + /*** + * Interface method called by {@link CustomGeometrySource} to request features for a tile. + * + * @param bounds {@link LatLngBounds} of the tile. + * @param zoomLevel Tile zoom level. + * @return Return a @{link FeatureCollection} to be displayed in the requested tile. + */ + @WorkerThread + FeatureCollection getFeaturesForBounds(LatLngBounds bounds, int zoomLevel); +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java index 765ca431dd..78503f9dfe 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java @@ -54,13 +54,25 @@ public class BitmapUtils { /** * Extract an underlying bitmap from a drawable - * @param drawable The source drawable + * + * @param sourceDrawable The source drawable * @return The underlying bitmap */ - public static Bitmap getBitmapFromDrawable(Drawable drawable) { - if (drawable instanceof BitmapDrawable) { - return ((BitmapDrawable) drawable).getBitmap(); + public static Bitmap getBitmapFromDrawable(Drawable sourceDrawable) { + if (sourceDrawable == null) { + return null; + } + + if (sourceDrawable instanceof BitmapDrawable) { + return ((BitmapDrawable) sourceDrawable).getBitmap(); } else { + //copying drawable object to not manipulate on the same reference + Drawable.ConstantState constantState = sourceDrawable.getConstantState(); + if (constantState == null) { + return null; + } + Drawable drawable = constantState.newDrawable().mutate(); + Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); @@ -72,6 +84,7 @@ public class BitmapUtils { /** * Create a byte array out of drawable + * * @param drawable The source drawable * @return The byte array of source drawable */ @@ -79,7 +92,11 @@ public class BitmapUtils { if (drawable == null) { return null; } + Bitmap bitmap = getBitmapFromDrawable(drawable); + if (bitmap == null) { + return null; + } ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); return stream.toByteArray(); @@ -87,8 +104,9 @@ public class BitmapUtils { /** * Decode byte array to drawable object + * * @param context Context to obtain {@link android.content.res.Resources} - * @param array The source byte array + * @param array The source byte array * @return The drawable created from source byte array */ public static Drawable getDrawableFromByteArray(Context context, byte[] array) { diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java index bb96c9939d..c3d13f0c66 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java @@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.geometry; import android.os.Parcelable; +import com.mapbox.mapboxsdk.constants.GeometryConstants; import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException; import com.mapbox.mapboxsdk.utils.MockParcel; @@ -272,4 +273,20 @@ public class LatLngBoundsTest { Parcelable parcel = MockParcel.obtain(latLngBounds); assertEquals("Parcel should match original object", parcel, latLngBounds); } + + @Test + public void fromTileID() { + LatLngBounds bounds = LatLngBounds.from(0, 0, 0); + assertEquals(GeometryConstants.MIN_LONGITUDE, bounds.getLonWest(), DELTA); + assertEquals(GeometryConstants.MIN_MERCATOR_LATITUDE, bounds.getLatSouth(), DELTA); + assertEquals(GeometryConstants.MAX_LONGITUDE, bounds.getLonEast(), DELTA); + assertEquals(GeometryConstants.MAX_MERCATOR_LATITUDE, bounds.getLatNorth(), DELTA); + + bounds = LatLngBounds.from(10, 288, 385); + assertEquals(-78.75, bounds.getLonWest(), DELTA); + assertEquals(40.446947059600497, bounds.getLatSouth(), DELTA); + assertEquals(-78.3984375, bounds.getLonEast(), DELTA); + assertEquals(40.713955826286039, bounds.getLatNorth(), DELTA); + + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java index 06e93b9d2f..8e47f069c3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java @@ -12,6 +12,7 @@ import org.junit.rules.ExpectedException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -255,8 +256,17 @@ public class LatLngTest { @Test public void testWrapped() { - LatLng latLng = new LatLng(45.0, -185.0).wrap(); - assertEquals("longitude wrapped value", latLng.getLongitude(), 175.0, DELTA); + LatLng originalLatLng = new LatLng(45.0, -185.0); + LatLng newLatlng = originalLatLng.wrap(); + assertNotSame(" new wrapped LatLng is created", originalLatLng, newLatlng); + assertEquals("longitude wrapped value", originalLatLng.getLongitude(), -185.0, DELTA); + assertEquals("longitude wrapped value", newLatlng.getLongitude(), 175.0, DELTA); + + newLatlng = new LatLng(45.0, 180.0).wrap(); + assertEquals("longitude wrapped max value", newLatlng.getLongitude(), 180.0, DELTA); + + newLatlng = new LatLng(45.0, -180.0).wrap(); + assertEquals("longitude wrapped min value", newLatlng.getLongitude(), -180.0, DELTA); } @Test diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java new file mode 100644 index 0000000000..eb1ce8bfaa --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java @@ -0,0 +1,1010 @@ +package com.mapbox.mapboxsdk.style.expressions; + +import android.graphics.Color; + +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; + +import org.junit.Test; + +import java.util.Arrays; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.acos; +import static com.mapbox.mapboxsdk.style.expressions.Expression.all; +import static com.mapbox.mapboxsdk.style.expressions.Expression.any; +import static com.mapbox.mapboxsdk.style.expressions.Expression.array; +import static com.mapbox.mapboxsdk.style.expressions.Expression.asin; +import static com.mapbox.mapboxsdk.style.expressions.Expression.at; +import static com.mapbox.mapboxsdk.style.expressions.Expression.atan; +import static com.mapbox.mapboxsdk.style.expressions.Expression.bool; +import static com.mapbox.mapboxsdk.style.expressions.Expression.coalesce; +import static com.mapbox.mapboxsdk.style.expressions.Expression.color; +import static com.mapbox.mapboxsdk.style.expressions.Expression.concat; +import static com.mapbox.mapboxsdk.style.expressions.Expression.cos; +import static com.mapbox.mapboxsdk.style.expressions.Expression.cubicBezier; +import static com.mapbox.mapboxsdk.style.expressions.Expression.division; +import static com.mapbox.mapboxsdk.style.expressions.Expression.downcase; +import static com.mapbox.mapboxsdk.style.expressions.Expression.e; +import static com.mapbox.mapboxsdk.style.expressions.Expression.eq; +import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.geometryType; +import static com.mapbox.mapboxsdk.style.expressions.Expression.get; +import static com.mapbox.mapboxsdk.style.expressions.Expression.gt; +import static com.mapbox.mapboxsdk.style.expressions.Expression.gte; +import static com.mapbox.mapboxsdk.style.expressions.Expression.has; +import static com.mapbox.mapboxsdk.style.expressions.Expression.heatmapDensity; +import static com.mapbox.mapboxsdk.style.expressions.Expression.id; +import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; +import static com.mapbox.mapboxsdk.style.expressions.Expression.length; +import static com.mapbox.mapboxsdk.style.expressions.Expression.let; +import static com.mapbox.mapboxsdk.style.expressions.Expression.linear; +import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; +import static com.mapbox.mapboxsdk.style.expressions.Expression.ln; +import static com.mapbox.mapboxsdk.style.expressions.Expression.ln2; +import static com.mapbox.mapboxsdk.style.expressions.Expression.log10; +import static com.mapbox.mapboxsdk.style.expressions.Expression.log2; +import static com.mapbox.mapboxsdk.style.expressions.Expression.lt; +import static com.mapbox.mapboxsdk.style.expressions.Expression.lte; +import static com.mapbox.mapboxsdk.style.expressions.Expression.match; +import static com.mapbox.mapboxsdk.style.expressions.Expression.max; +import static com.mapbox.mapboxsdk.style.expressions.Expression.min; +import static com.mapbox.mapboxsdk.style.expressions.Expression.mod; +import static com.mapbox.mapboxsdk.style.expressions.Expression.neq; +import static com.mapbox.mapboxsdk.style.expressions.Expression.not; +import static com.mapbox.mapboxsdk.style.expressions.Expression.number; +import static com.mapbox.mapboxsdk.style.expressions.Expression.object; +import static com.mapbox.mapboxsdk.style.expressions.Expression.pi; +import static com.mapbox.mapboxsdk.style.expressions.Expression.pow; +import static com.mapbox.mapboxsdk.style.expressions.Expression.product; +import static com.mapbox.mapboxsdk.style.expressions.Expression.properties; +import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb; +import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba; +import static com.mapbox.mapboxsdk.style.expressions.Expression.sin; +import static com.mapbox.mapboxsdk.style.expressions.Expression.sqrt; +import static com.mapbox.mapboxsdk.style.expressions.Expression.step; +import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; +import static com.mapbox.mapboxsdk.style.expressions.Expression.string; +import static com.mapbox.mapboxsdk.style.expressions.Expression.subtract; +import static com.mapbox.mapboxsdk.style.expressions.Expression.sum; +import static com.mapbox.mapboxsdk.style.expressions.Expression.switchCase; +import static com.mapbox.mapboxsdk.style.expressions.Expression.tan; +import static com.mapbox.mapboxsdk.style.expressions.Expression.toBool; +import static com.mapbox.mapboxsdk.style.expressions.Expression.toColor; +import static com.mapbox.mapboxsdk.style.expressions.Expression.toNumber; +import static com.mapbox.mapboxsdk.style.expressions.Expression.toRgba; +import static com.mapbox.mapboxsdk.style.expressions.Expression.typeOf; +import static com.mapbox.mapboxsdk.style.expressions.Expression.upcase; +import static com.mapbox.mapboxsdk.style.expressions.Expression.var; +import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; +import static junit.framework.Assert.assertTrue; + +/** + * Expression unit tests that validate the expression output with the expected Object[]array representation. + */ +public class ExpressionTest { + + @Test + public void testRgb() throws Exception { + Object[] expected = new Object[] {"rgb", 0, 0, 0}; + Object[] actual = rgb(literal(0), literal(0), literal(0)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testRgbLiteral() throws Exception { + Object[] expected = new Object[] {"rgb", 0, 0, 0}; + Object[] actual = rgb(0, 0, 0).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testRgba() throws Exception { + Object[] expected = new Object[] {"rgba", 0, 0, 0, 1}; + Object[] actual = rgba(literal(0), literal(0), literal(0), literal(1)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testRgbaLiteral() throws Exception { + Object[] expected = new Object[] {"rgba", 0, 0, 0, 1}; + Object[] actual = rgba(0, 0, 0, 1).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testToRgba() throws Exception { + Object[] expected = new Object[] {"to-rgba", PropertyFactory.colorToRgbaString(Color.RED)}; + Object[] actual = toRgba(color(Color.RED)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testEq() throws Exception { + Object[] expected = new Object[] {"==", 1, 1}; + Object[] actual = eq(literal(1), literal(1)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testEqLiteral() throws Exception { + Object[] expected = new Object[] {"==", 1, 1}; + Object[] actual = eq(1, 1).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testNeq() throws Exception { + Object[] expected = new Object[] {"!=", 0, 1}; + Object[] actual = neq(literal(0), literal(1)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testNeqLiteral() throws Exception { + Object[] expected = new Object[] {"!=", 0, 1}; + Object[] actual = neq(0, 1).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testGt() throws Exception { + Object[] expected = new Object[] {">", 0, 1}; + Object[] actual = gt(literal(0), literal(1)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testGtLiteral() throws Exception { + Object[] expected = new Object[] {">", 0, 1}; + Object[] actual = gt(0, 1).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLt() throws Exception { + Object[] expected = new Object[] {"<", 1, 0}; + Object[] actual = lt(literal(1), literal(0)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLtLiteral() throws Exception { + Object[] expected = new Object[] {"<", 1, 0}; + Object[] actual = lt(1, 0).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testGte() throws Exception { + Object[] expected = new Object[] {">=", 1, 1}; + Object[] actual = gte(literal(1), literal(1)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testGteLiteral() throws Exception { + Object[] expected = new Object[] {">=", 1, 1}; + Object[] actual = gte(1, 1).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLte() throws Exception { + Object[] expected = new Object[] {"<=", 1, 1}; + Object[] actual = lte(literal(1), literal(1)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLteLiteral() throws Exception { + Object[] expected = new Object[] {"<=", 1, 1}; + Object[] actual = lte(1, 1).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAll() throws Exception { + Object[] expected = new Object[] {"all", true, true, true}; + Object[] actual = all(literal(true), literal(true), literal(true)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAny() throws Exception { + Object[] expected = new Object[] {"any", true, false, false}; + Object[] actual = any(literal(true), literal(false), literal(false)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testNot() throws Exception { + Object[] expected = new Object[] {"!", false}; + Object[] actual = not(literal(false)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testNotLiteral() throws Exception { + Object[] expected = new Object[] {"!", false}; + Object[] actual = not(false).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSwitchCase() throws Exception { + Object[] expectedCaseOneGet = new Object[] {"get", "key1"}; + Object[] expectedCaseOne = new Object[] {"==", expectedCaseOneGet, "value1"}; + Object[] expectedCaseTwoGet = new Object[] {"get", "key2"}; + Object[] expectedCaseTwo = new Object[] {"!=", expectedCaseTwoGet, "value2"}; + Object[] expected = new Object[] {"case", expectedCaseOne, expectedCaseTwo}; + + Object[] actual = switchCase( + eq(get(literal("key1")), literal("value1")), + neq(get(literal("key2")), literal("value2")) + ).toArray(); + + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSwitchCaseLiteral() throws Exception { + Object[] expectedCaseOneGet = new Object[] {"get", "key1"}; + Object[] expectedCaseOne = new Object[] {"==", expectedCaseOneGet, "value1"}; + Object[] expectedCaseTwoGet = new Object[] {"get", "key2"}; + Object[] expectedCaseTwo = new Object[] {"!=", expectedCaseTwoGet, "value2"}; + Object[] expected = new Object[] {"case", expectedCaseOne, expectedCaseTwo}; + + Object[] actual = switchCase( + eq(get("key1"), literal("value1")), + neq(get("key2"), literal("value2")) + ).toArray(); + + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testMatch() throws Exception { + Object[] labelZero = new Object[] {"a", "output"}; + Object[] labelOne = new Object[] {"b", "output2"}; + Object[] labelTwo = new Object[] {"c", "output3"}; + + Object[] expected = new Object[] {"match", labelZero, labelOne, labelTwo}; + Object[] actual = match(literal(labelZero), literal(labelOne), literal(labelTwo)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCoalesce() throws Exception { + Object[] expectedGetOne = new Object[] {"get", "invalidKey"}; + Object[] expectedGetTwo = new Object[] {"get", "validKey"}; + Object[] expected = new Object[] {"coalesce", expectedGetOne, expectedGetTwo}; + + Object[] actual = coalesce( + get(literal("invalidKey")), + get(literal("validKey")) + ).toArray(); + + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCoalesceLiteral() throws Exception { + Object[] expectedGetOne = new Object[] {"get", "invalidKey"}; + Object[] expectedGetTwo = new Object[] {"get", "validKey"}; + Object[] expected = new Object[] {"coalesce", expectedGetOne, expectedGetTwo}; + + Object[] actual = coalesce( + get("invalidKey"), + get("validKey") + ).toArray(); + + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testProperties() throws Exception { + Object[] expected = new Object[] {"properties"}; + Object[] actual = properties().toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testGeometryType() throws Exception { + Object[] expected = new Object[] {"geometry-type"}; + Object[] actual = geometryType().toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testId() throws Exception { + Object[] expected = new Object[] {"id"}; + Object[] actual = id().toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testHeatmapDensity() throws Exception { + Object[] expected = new Object[] {"heatmap-density"}; + Object[] actual = heatmapDensity().toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAt() throws Exception { + Object[] expected = new Object[] {"at", 3, new Object[] {"one", "two"}}; + Object[] actual = at(literal(3), literal(new Object[] {"one", "two"})).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAtLiteral() throws Exception { + Object[] expected = new Object[] {"at", 3, new Object[] {"one", "two"}}; + Object[] actual = at(3, literal(new Object[] {"one", "two"})).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAtExpression() throws Exception { + Object[] expected = new Object[] {"at", 3, new Object[] {"properties"}}; + Object[] actual = at(literal(3), properties()).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testGet() throws Exception { + Object[] expected = new Object[] {"get", "key"}; + Object[] actual = get(literal("key")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testGetLiteral() throws Exception { + Object[] expected = new Object[] {"get", "key"}; + Object[] actual = get("key").toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testGetObject() throws Exception { + Object[] expected = new Object[] {"get", "key", new Object[] {"properties"}}; + Object[] actual = get(literal("key"), properties()).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testGetObjectLiteral() throws Exception { + Object[] expected = new Object[] {"get", "key", new Object[] {"properties"}}; + Object[] actual = get("key", properties()).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testHas() throws Exception { + Object[] expected = new Object[] {"has", "key"}; + Object[] actual = has(literal("key")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testHasLiteral() throws Exception { + Object[] expected = new Object[] {"has", "key"}; + Object[] actual = has("key").toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testHasObject() throws Exception { + Object[] expected = new Object[] {"has", "key", new Object[] {"properties"}}; + Object[] actual = has(literal("key"), properties()).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testHasObjectLiteral() throws Exception { + Object[] expected = new Object[] {"has", "key", new Object[] {"properties"}}; + Object[] actual = has("key", properties()).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testHasExpression() throws Exception { + Object[] expected = new Object[] {"has", new Object[] {"get", "key"}, new Object[] {"properties"}}; + Object[] actual = has(get(literal("key")), properties()).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testHasExpressionLiteral() throws Exception { + Object[] expected = new Object[] {"has", new Object[] {"get", "key"}, new Object[] {"properties"}}; + Object[] actual = has(get("key"), properties()).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLength() throws Exception { + Object[] expected = new Object[] {"length", "key"}; + Object[] actual = length(literal("key")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLengthLiteral() throws Exception { + Object[] expected = new Object[] {"length", "key"}; + Object[] actual = length("key").toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLengthExpression() throws Exception { + Object[] expected = new Object[] {"length", new Object[] {"get", "key"}}; + Object[] actual = length(get(literal("key"))).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLn2() throws Exception { + Object[] expected = new Object[] {"ln2"}; + Object[] actual = ln2().toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testPi() throws Exception { + Object[] expected = new Object[] {"pi"}; + Object[] actual = pi().toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testE() throws Exception { + Object[] expected = new Object[] {"e"}; + Object[] actual = e().toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSum() throws Exception { + Object[] expected = new Object[] {"+", 1, 2}; + Object[] actual = sum(literal(1), literal(2)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSumLiteral() throws Exception { + Object[] expected = new Object[] {"+", 1, 2}; + Object[] actual = sum(1, 2).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testProduct() throws Exception { + Object[] expected = new Object[] {"*", 1, 2}; + Object[] actual = product(literal(1), literal(2)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testProductLiteral() throws Exception { + Object[] expected = new Object[] {"*", 1, 2}; + Object[] actual = product(1, 2).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSubtract() throws Exception { + Object[] expected = new Object[] {"-", 2, 1}; + Object[] actual = subtract(literal(2), literal(1)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSubtractLiteral() throws Exception { + Object[] expected = new Object[] {"-", 2, 1}; + Object[] actual = subtract(2, 1).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testDivision() throws Exception { + Object[] expected = new Object[] {"/", 2, 1}; + Object[] actual = division(literal(2), literal(1)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testDivisionLiteral() throws Exception { + Object[] expected = new Object[] {"/", 2, 1}; + Object[] actual = division(2, 1).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testDivisionWithNestedGet() throws Exception { + Object nestedGet = new Object[] {"get", "key"}; + Object[] expected = new Object[] {"/", 2, nestedGet}; + Object[] actual = division(literal(2), get(literal("key"))).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testMod() throws Exception { + Object[] expected = new Object[] {"%", 1, 3}; + Object[] actual = mod(literal(1), literal(3)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testModLiteral() throws Exception { + Object[] expected = new Object[] {"%", 1, 3}; + Object[] actual = mod(1, 3).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testPow() throws Exception { + Object[] expected = new Object[] {"^", 2, 3}; + Object[] actual = pow(literal(2), literal(3)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testPowLiteral() throws Exception { + Object[] expected = new Object[] {"^", 2, 3}; + Object[] actual = pow(2, 3).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSqrt() throws Exception { + Object[] expected = new Object[] {"sqrt", 4}; + Object[] actual = sqrt(literal(4)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSqrtLiteral() throws Exception { + Object[] expected = new Object[] {"sqrt", 4}; + Object[] actual = sqrt(4).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLog10() throws Exception { + Object[] expected = new Object[] {"log10", 10}; + Object[] actual = log10(literal(10)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLog10Literal() throws Exception { + Object[] expected = new Object[] {"log10", 10}; + Object[] actual = log10(10).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLn() throws Exception { + Object[] expected = new Object[] {"ln", 2}; + Object[] actual = ln(literal(2)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLnLiteral() throws Exception { + Object[] expected = new Object[] {"ln", 2}; + Object[] actual = ln(2).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLog2() throws Exception { + Object[] expected = new Object[] {"log2", 16}; + Object[] actual = log2(literal(16)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLog2Literal() throws Exception { + Object[] expected = new Object[] {"log2", 16}; + Object[] actual = log2(16).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSin() throws Exception { + Object[] expected = new Object[] {"sin", 45}; + Object[] actual = sin(literal(45)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testSinLiteral() throws Exception { + Object[] expected = new Object[] {"sin", 45}; + Object[] actual = sin(45).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCos() throws Exception { + Object[] expected = new Object[] {"cos", 45}; + Object[] actual = cos(literal(45)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCosLiteral() throws Exception { + Object[] expected = new Object[] {"cos", 45}; + Object[] actual = cos(45).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testTan() throws Exception { + Object[] expected = new Object[] {"tan", 45}; + Object[] actual = tan(literal(45)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testTanLiteral() throws Exception { + Object[] expected = new Object[] {"tan", 45}; + Object[] actual = tan(45).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAsin() throws Exception { + Object[] expected = new Object[] {"asin", 45}; + Object[] actual = asin(literal(45)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAsinLiteral() throws Exception { + Object[] expected = new Object[] {"asin", 45}; + Object[] actual = asin(45).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAcos() throws Exception { + Object[] expected = new Object[] {"acos", 45}; + Object[] actual = acos(literal(45)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAcosLiteral() throws Exception { + Object[] expected = new Object[] {"acos", 45}; + Object[] actual = acos(45).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAtan() throws Exception { + Object[] expected = new Object[] {"atan", 45}; + Object[] actual = atan(literal(45)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testAtanLiteral() throws Exception { + Object[] expected = new Object[] {"atan", 45}; + Object[] actual = atan(45).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testMin() throws Exception { + Object[] expected = new Object[] {"min", 0, 1, 2, 3}; + Object[] actual = min(literal(0), literal(1), literal(2), literal(3)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testMinLiteral() throws Exception { + Object[] expected = new Object[] {"min", 0, 1, 2, 3}; + Object[] actual = min(0, 1, 2, 3).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testMax() throws Exception { + Object[] expected = new Object[] {"max", 0, 1, 2, 3}; + Object[] actual = max(literal(0), literal(1), literal(2), literal(3)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testMaxLiteral() throws Exception { + Object[] expected = new Object[] {"max", 0, 1, 2, 3}; + Object[] actual = max(0, 1, 2, 3).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testUpcase() throws Exception { + Object[] expected = new Object[] {"upcase", "string"}; + Object[] actual = upcase(literal("string")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testUpcaseLiteral() throws Exception { + Object[] expected = new Object[] {"upcase", "string"}; + Object[] actual = upcase("string").toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testDowncase() throws Exception { + Object[] expected = new Object[] {"downcase", "string"}; + Object[] actual = downcase(literal("string")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testDowncaseLiteral() throws Exception { + Object[] expected = new Object[] {"downcase", "string"}; + Object[] actual = downcase("string").toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testConcat() throws Exception { + Object[] expected = new Object[] {"concat", "foo", "bar"}; + Object[] actual = concat(literal("foo"), literal("bar")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testConcatLiteral() throws Exception { + Object[] expected = new Object[] {"concat", "foo", "bar"}; + Object[] actual = concat("foo", "bar").toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testArray() throws Exception { + Object[] get = new Object[] {"get", "keyToArray"}; + Object[] expected = new Object[] {"array", get}; + Object[] actual = array(get(literal("keyToArray"))).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testArrayLiteral() throws Exception { + Object[] get = new Object[] {"get", "keyToArray"}; + Object[] expected = new Object[] {"array", get}; + Object[] actual = array(get("keyToArray")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testTypeOf() throws Exception { + Object[] expected = new Object[] {"typeof", "value"}; + Object[] actual = typeOf(literal("value")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testString() throws Exception { + Object[] expected = new Object[] {"string", "value"}; + Object[] actual = string(literal("value")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testNumber() throws Exception { + Object[] expected = new Object[] {"number", 1}; + Object[] actual = number(literal(1)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testBool() throws Exception { + Object[] expected = new Object[] {"boolean", true}; + Object[] actual = bool(literal(true)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testObject() throws Exception { + Object object = new Object(); + Object[] expected = new Object[] {"object", object}; + Object[] actual = object(literal(object)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testToString() throws Exception { + Object[] expected = new Object[] {"to-string", 3}; + Object[] actual = Expression.toString(literal(3)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testToNumber() throws Exception { + Object[] expected = new Object[] {"to-number", "3"}; + Object[] actual = toNumber(literal("3")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testToBool() throws Exception { + Object[] expected = new Object[] {"to-boolean", "true"}; + Object[] actual = toBool(literal("true")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testToColor() throws Exception { + Object[] expected = new Object[] {"to-color", "value"}; + Object[] actual = toColor(literal("value")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLet() throws Exception { + Object[] expected = new Object[] {"let", "letName", "value"}; + Object[] actual = let(literal("letName"), literal("value")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testVar() throws Exception { + Object[] expected = new Object[] {"var", "letName"}; + Object[] actual = var(literal("letName")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testVarLiteral() throws Exception { + Object[] expected = new Object[] {"var", "letName"}; + Object[] actual = var("letName").toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testVarExpression() throws Exception { + Object[] expected = new Object[] {"var", new Object[] {"get", "letName"}}; + Object[] actual = var(get(literal("letName"))).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testVarExpressionLiteral() throws Exception { + Object[] expected = new Object[] {"var", new Object[] {"get", "letName"}}; + Object[] actual = var(get("letName")).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testZoom() throws Exception { + Object[] expected = new Object[] {"zoom"}; + Object[] actual = zoom().toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testStepBasic() throws Exception { + Object[] expected = new Object[] {"step", 12, 11, 0, 111, 1, 1111}; + Object[] actual = step(literal(12), literal(11), literal(0), literal(111), literal(1), literal(1111)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testStepBasicLiteral() throws Exception { + Object[] expected = new Object[] {"step", new Object[] {"get", "line-width"}, 11, 0, 111, 1, 1111}; + Object[] actual = step(get("line-width"), literal(11), stop(0, 111), stop(1, 1111)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testStepExpression() throws Exception { + Object[] input = new Object[] {"get", "key"}; + Object[] number = new Object[] {"to-number", input}; + Object[] expected = new Object[] {"step", number, 11, 0, 111, 1, 1111}; + Object[] actual = step(toNumber(get(literal("key"))), + literal(11), literal(0), literal(111), literal(1), literal(1111)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testStepExpressionLiteral() throws Exception { + Object[] input = new Object[] {"get", "key"}; + Object[] number = new Object[] {"to-number", input}; + Object[] expected = new Object[] {"step", number, 11, 0, 111, 1, 1111}; + Object[] actual = step(toNumber(get("key")), literal(11), stop(0, 111), stop(1, 1111)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLinear() throws Exception { + Object[] stopZero = new Object[] {0, 1}; + Object[] stopOne = new Object[] {1, 2}; + Object[] stopTwo = new Object[] {2, 3}; + Object[] expected = new Object[] {"interpolate", new Object[] {"linear"}, 12, stopZero, stopOne, stopTwo}; + Object[] actual = interpolate(linear(), literal(12), + literal(stopZero), literal(stopOne), literal(stopTwo)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testLinearStops() throws Exception { + Object[] expected = new Object[] {"interpolate", new Object[] {"linear"}, 12, 0, 1, 1, 2, 2, 3}; + Object[] actual = interpolate(linear(), literal(12), stop(0, 1), stop(1, 2), stop(2, 3)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testExponential() throws Exception { + Object[] exponential = new Object[] {"exponential", 12}; + Object[] get = new Object[] {"get", "x"}; + Object[] expected = new Object[] {"interpolate", exponential, get, 0, 100, 200}; + Object[] actual = interpolate(exponential(literal(12)), + get(literal("x")), literal(0), literal(100), literal(200)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testExponentialLiteral() throws Exception { + Object[] exponential = new Object[] {"exponential", 12}; + Object[] get = new Object[] {"get", "x"}; + Object[] expected = new Object[] {"interpolate", exponential, get, 0, 100, 100, 200}; + Object[] actual = interpolate(exponential(12), get("x"), stop(0, 100), stop(100, 200)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testExponentialExpressionLiteral() throws Exception { + Object[] getX = new Object[] {"get", "x"}; + Object[] exponential = new Object[] {"exponential", getX}; + Object[] getY = new Object[] {"get", "y"}; + Object[] expected = new Object[] {"interpolate", exponential, getY, 0, 100, 100, 200}; + Object[] actual = interpolate(exponential(get("x")), get("y"), stop(0, 100), stop(100, 200)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCubicBezier() throws Exception { + Object[] cubicBezier = new Object[] {"cubic-bezier", 1, 1, 1, 1}; + Object[] get = new Object[] {"get", "x"}; + Object[] expected = new Object[] {"interpolate", cubicBezier, get, 0, 100, 100, 200}; + Object[] actual = interpolate(cubicBezier(literal(1), literal(1), literal(1), literal(1)), + get(literal("x")), literal(0), literal(100), literal(100), literal(200)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCubicBezierLiteral() throws Exception { + Object[] cubicBezier = new Object[] {"cubic-bezier", 1, 1, 1, 1}; + Object[] get = new Object[] {"get", "x"}; + Object[] expected = new Object[] {"interpolate", cubicBezier, get, 0, 100, 100, 200}; + Object[] actual = interpolate(cubicBezier(1, 1, 1, 1), get("x"), stop(0, 100), stop(100, 200)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCubicBezierExpression() throws Exception { + Object[] getX = new Object[] {"get", "x"}; + Object[] getY = new Object[] {"get", "y"}; + Object[] getZ = new Object[] {"get", "z"}; + Object[] cubicBezier = new Object[] {"cubic-bezier", getZ, 1, getY, 1}; + Object[] expected = new Object[] {"interpolate", cubicBezier, getX, 0, 100, 200}; + Object[] actual = interpolate(cubicBezier(get(literal("z")), literal(1), + get(literal("y")), literal(1)), get(literal("x")), literal(0), literal(100), literal(200)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } + + @Test + public void testCubicBezierExpressionLiteral() throws Exception { + Object[] getX = new Object[] {"get", "x"}; + Object[] getY = new Object[] {"get", "y"}; + Object[] getZ = new Object[] {"get", "z"}; + Object[] cubicBezier = new Object[] {"cubic-bezier", getZ, 1, getY, 1}; + Object[] expected = new Object[] {"interpolate", cubicBezier, getX, 0, 100, 100, 200}; + Object[] actual = interpolate(cubicBezier(get("z"), literal(1), get("y"), + literal(1)), get("x"), stop(0, 100), stop(100, 200)).toArray(); + assertTrue("expression should match", Arrays.deepEquals(expected, actual)); + } +}
\ No newline at end of file |