diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src')
47 files changed, 6061 insertions, 702 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java deleted file mode 100644 index 8ea7e61eee..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.mapbox.mapboxsdk; - - -import android.location.Location; -import android.support.annotation.Nullable; - -import com.mapbox.mapboxsdk.location.LocationSource; -import com.mapbox.services.android.telemetry.location.LocationEngine; -import com.mapbox.services.android.telemetry.location.LocationEngineListener; - -class EmptyLocationSource extends LocationSource { - - /** - * Activate the location engine which will connect whichever location provider you are using. You'll need to call - * this before requesting user location updates using {@link LocationEngine#requestLocationUpdates()}. - */ - @Override - public void activate() { - // Intentionally left empty - } - - /** - * Disconnect the location engine which is useful when you no longer need location updates or requesting the users - * {@link LocationEngine#getLastLocation()}. Before deactivating, you'll need to stop request user location updates - * using {@link LocationEngine#removeLocationUpdates()}. - */ - @Override - public void deactivate() { - // Intentionally left empty - } - - /** - * Check if your location provider has been activated/connected. This is mainly used internally but is also useful in - * the rare case when you'd like to know if your location engine is connected or not. - * - * @return boolean true if the location engine has been activated/connected, else false. - */ - @Override - public boolean isConnected() { - return false; - } - - /** - * Returns the Last known location is the location provider is connected and location permissions are granted. - * - * @return the last known location - */ - @Override - @Nullable - public Location getLastLocation() { - return null; - } - - /** - * Request location updates to the location provider. - */ - @Override - public void requestLocationUpdates() { - // Intentionally left empty - } - - /** - * Dismiss ongoing location update to the location provider. - */ - @Override - public void removeLocationUpdates() { - // Intentionally left empty - } - - /** - * Invoked when the Location has changed. - * - * @param location the new location - */ - @Override - public void onLocationChanged(Location location) { - // Intentionally left empty - } - - /** - * Useful when you'd like to add a location listener to handle location connections and update events. It is important - * to note, that the callback will continue getting called even when your application isn't in the foreground. - * Therefore, it is a good idea to use {@link LocationEngine#removeLocationEngineListener(LocationEngineListener)} - * inside your activities {@code onStop()} method. - * - * @param listener A {@link LocationEngineListener} which you'd like to add to your location engine. - * @since 2.0.0 - */ - @Override - public void addLocationEngineListener(LocationEngineListener listener) { - // Intentionally left empty - } - - /** - * If you no longer need your {@link LocationEngineListener} to be invoked with every location update, use this - * method to remove it. It's also important to remove your listeners before the activity is destroyed to prevent any - * potential memory leaks. - * - * @param listener the {@link LocationEngineListener} you'd like to remove from this {@link LocationEngine}. - * @return true. - * @since 2.0.0 - */ - @Override - public boolean removeLocationEngineListener(LocationEngineListener listener) { - return true; - } -} 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..853ea1c11b 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 @@ -8,16 +8,12 @@ import android.support.annotation.NonNull; import android.support.annotation.UiThread; import android.text.TextUtils; +import com.mapbox.android.core.location.LocationEngine; +import com.mapbox.android.core.location.LocationEnginePriority; +import com.mapbox.android.core.location.LocationEngineProvider; 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.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; /** * The entry point to initialize the Mapbox Android SDK. @@ -56,15 +52,9 @@ public final class Mapbox { INSTANCE = new Mapbox(appContext, accessToken, locationEngine); locationEngine.setPriority(LocationEnginePriority.NO_POWER); - try { - MapboxTelemetry.getInstance().initialize( - appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine); - } catch (Exception exception) { - Timber.e(exception, "Unable to instantiate Mapbox telemetry"); - } - ConnectivityReceiver.instance(appContext); } + return INSTANCE; } @@ -146,22 +136,11 @@ public final class Mapbox { } /** - * Returns a location source instance with empty methods. - * - * @return an empty location source implementation - * @deprecated Replaced by {@link Mapbox#getLocationEngine()} - */ - @Deprecated - public static LocationSource getLocationSource() { - return new EmptyLocationSource(); - } - - - /** * Returns the location engine used by the SDK. * * @return the location engine configured */ + // TODO Do we need to expose this? public static LocationEngine getLocationEngine() { return INSTANCE.locationEngine; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java index c2f19072db..e732b2525f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java @@ -8,7 +8,7 @@ import android.support.annotation.FloatRange; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.services.android.telemetry.utils.MathUtils; +import com.mapbox.mapboxsdk.utils.MathUtils; /** * Resembles the position, angle, zoom and tilt of the user's viewpoint. 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..7a17e500ca --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/GeometryConstants.java @@ -0,0 +1,77 @@ +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 latitude span when representing a geolocation. + * + * @since 6.0.0 + */ + public static final double LATITUDE_SPAN = 180; + + /** + * This constant represents the longitude span when representing a geolocation. + * + * @since 6.0.0 + */ + public static final double LONGITUDE_SPAN = 360; + + /** + * 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..fc8d2ec8f0 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 @@ -2,11 +2,12 @@ package com.mapbox.mapboxsdk.geometry; import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.FloatRange; 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; @@ -28,6 +29,10 @@ public class LatLngBounds implements Parcelable { * Construct a new LatLngBounds based on its corners, given in NESW * order. * + * If eastern longitude is smaller than the western one, bounds will include antimeridian. + * For example, if the NE point is (10, -170) and the SW point is (-10, 170), then bounds will span over 20 degrees + * and cross the antimeridian. + * * @param northLatitude Northern Latitude * @param eastLongitude Eastern Longitude * @param southLatitude Southern Latitude @@ -47,10 +52,9 @@ public class LatLngBounds implements Parcelable { * @return the bounds representing the world */ 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)) - .build(); + return LatLngBounds.from( + GeometryConstants.MAX_LATITUDE, GeometryConstants.MAX_LONGITUDE, + GeometryConstants.MIN_LATITUDE, GeometryConstants.MIN_LONGITUDE); } /** @@ -60,8 +64,21 @@ public class LatLngBounds implements Parcelable { * @return LatLng center of this LatLngBounds */ public LatLng getCenter() { - return new LatLng((this.latitudeNorth + this.latitudeSouth) / 2, - (this.longitudeEast + this.longitudeWest) / 2); + double latCenter = (this.latitudeNorth + this.latitudeSouth) / 2.0; + double longCenter; + + if (this.longitudeEast > this.longitudeWest) { + longCenter = (this.longitudeEast + this.longitudeWest) / 2; + } else { + double halfSpan = (GeometryConstants.LONGITUDE_SPAN + this.longitudeEast - this.longitudeWest) / 2.0; + longCenter = this.longitudeWest + halfSpan; + if (longCenter >= GeometryConstants.MAX_LONGITUDE) { + longCenter = this.longitudeEast - halfSpan; + } + return new LatLng(latCenter, longCenter); + } + + return new LatLng(latCenter, longCenter); } /** @@ -162,10 +179,26 @@ public class LatLngBounds implements Parcelable { * @return Span distance */ public double getLongitudeSpan() { - return Math.abs(this.longitudeEast - this.longitudeWest); + double longSpan = Math.abs(this.longitudeEast - this.longitudeWest); + if (this.longitudeEast > this.longitudeWest) { + return longSpan; + } + + // shortest span contains antimeridian + return GeometryConstants.LONGITUDE_SPAN - longSpan; } + static double getLongitudeSpan(final double longEast, final double longWest) { + double longSpan = Math.abs(longEast - longWest); + if (longEast > longWest) { + return longSpan; + } + + // shortest span contains antimeridian + return GeometryConstants.LONGITUDE_SPAN - longSpan; + } + /** * Validate if LatLngBounds is empty, determined if absolute distance is * @@ -194,22 +227,45 @@ 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 maxLat = GeometryConstants.MIN_LATITUDE; + + double eastLon = latLngs.get(0).getLongitude(); + double westLon = latLngs.get(1).getLongitude(); + double lonSpan = Math.abs(eastLon - westLon); + if (lonSpan < GeometryConstants.LONGITUDE_SPAN / 2) { + if (eastLon < westLon) { + double temp = eastLon; + eastLon = westLon; + westLon = temp; + } + } else { + lonSpan = GeometryConstants.LONGITUDE_SPAN - lonSpan; + if (westLon < eastLon) { + double temp = eastLon; + eastLon = westLon; + westLon = temp; + } + } for (final ILatLng gp : latLngs) { final double latitude = gp.getLatitude(); - final double longitude = gp.getLongitude(); - minLat = Math.min(minLat, latitude); - minLon = Math.min(minLon, longitude); maxLat = Math.max(maxLat, latitude); - maxLon = Math.max(maxLon, longitude); + + final double longitude = gp.getLongitude(); + if (!containsLongitude(eastLon, westLon, longitude)) { + final double eastSpan = getLongitudeSpan(longitude, westLon); + final double westSpan = getLongitudeSpan(eastLon, longitude); + if (eastSpan <= westSpan) { + eastLon = longitude; + } else { + westLon = longitude; + } + } } - return new LatLngBounds(maxLat, maxLon, minLat, minLon); + return new LatLngBounds(maxLat, eastLon, minLat, westLon); } /** @@ -223,14 +279,69 @@ public class LatLngBounds implements Parcelable { /** * Constructs a LatLngBounds from doubles representing a LatLng pair. + * + * This values of latNorth and latSouth should be in the range of [-90, 90], + * see {@link GeometryConstants#MIN_LATITUDE} and {@link GeometryConstants#MAX_LATITUDE}, + * otherwise IllegalArgumentException will be thrown. * <p> * This method doesn't recalculate most east or most west boundaries. + * Note that lonEast and lonWest will be wrapped to be in the range of [-180, 180], + * see {@link GeometryConstants#MIN_LONGITUDE} and {@link GeometryConstants#MAX_LONGITUDE} * </p> */ - public static LatLngBounds from(double latNorth, double lonEast, double latSouth, double lonWest) { + public static LatLngBounds from( + @FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latNorth, + double lonEast, + @FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latSouth, + double lonWest) { + + if (Double.isNaN(latNorth) || Double.isNaN(latSouth)) { + throw new IllegalArgumentException("latitude must not be NaN"); + } + + if (Double.isNaN(lonEast) || Double.isNaN(lonWest)) { + throw new IllegalArgumentException("longitude must not be NaN"); + } + + if (Double.isInfinite(lonEast) || Double.isInfinite(lonWest)) { + throw new IllegalArgumentException("longitude must not be infinite"); + } + + if (latNorth > GeometryConstants.MAX_LATITUDE || latNorth < GeometryConstants.MIN_LATITUDE + || latSouth > GeometryConstants.MAX_LATITUDE || latSouth < GeometryConstants.MIN_LATITUDE) { + throw new IllegalArgumentException("latitude must be between -90 and 90"); + } + + lonEast = LatLng.wrap(lonEast, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE); + lonWest = LatLng.wrap(lonWest, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE); + 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. * @@ -266,6 +377,24 @@ public class LatLngBounds implements Parcelable { return false; } + + private boolean containsLatitude(final double latitude) { + return (latitude <= this.latitudeNorth) + && (latitude >= this.latitudeSouth); + } + + private boolean containsLongitude(final double longitude) { + return containsLongitude(this.longitudeEast, this.longitudeWest, longitude); + } + + static boolean containsLongitude(final double eastLon, final double westLon, final double longitude) { + if (eastLon > westLon) { + return (longitude <= eastLon) + && (longitude >= westLon); + } + return (longitude < eastLon) || (longitude > westLon); + } + /** * Determines whether this LatLngBounds contains a point. * @@ -273,12 +402,8 @@ public class LatLngBounds implements Parcelable { * @return true, if the point is contained within the bounds */ public boolean contains(final ILatLng latLng) { - final double latitude = latLng.getLatitude(); - final double longitude = latLng.getLongitude(); - return ((latitude <= this.latitudeNorth) - && (latitude >= this.latitudeSouth)) - && ((longitude <= this.longitudeEast) - && (longitude >= this.longitudeWest)); + return containsLatitude(latLng.getLatitude()) + && containsLongitude(latLng.getLongitude()); } /** @@ -288,7 +413,8 @@ public class LatLngBounds implements Parcelable { * @return true, if the bounds is contained within the bounds */ public boolean contains(final LatLngBounds other) { - return contains(other.getNorthEast()) && contains(other.getSouthWest()); + return contains(other.getNorthEast()) + && contains(other.getSouthWest()); } /** @@ -305,17 +431,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 +452,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/location/LocationSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java deleted file mode 100644 index 1313587158..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.mapbox.mapboxsdk.location; - -import android.content.Context; -import android.location.Location; -import android.support.annotation.Nullable; - -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.services.android.telemetry.location.LocationEngine; -import com.mapbox.services.android.telemetry.location.LocationEngineListener; -import com.mapbox.services.android.telemetry.location.LocationEnginePriority; -import com.mapzen.android.lost.api.LocationListener; -import com.mapzen.android.lost.api.LocationRequest; -import com.mapzen.android.lost.api.LocationServices; -import com.mapzen.android.lost.api.LostApiClient; - -/** - * LocationEngine using the Open Source Lost library - * Manages locational updates. Contains methods to register and unregister location listeners. - * <ul> - * <li>You can register a LocationEngineListener with LocationSource#addLocationEngineListener(LocationEngineListener) - * to receive location updates.</li> - * <li> You can unregister a LocationEngineListener with - * LocationEngine#removeLocationEngineListener(LocationEngineListener)} to stop receiving location updates.</li> - * </ul> - * <p> - * Note: If registering a listener in your Activity.onStart() implementation, you should unregister it in - * Activity.onStop(). (You won't receive location updates when paused, and this will cut down on unnecessary system - * overhead). Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back - * in the history stack. - * </p> - * - * @deprecated Use a {@link Mapbox#getLocationEngine()} instead. - */ -@Deprecated -public class LocationSource extends LocationEngine implements LostApiClient.ConnectionCallbacks, LocationListener { - - private Context context; - private LostApiClient lostApiClient; - - /** - * Constructs a location source instance. - * - * @param context the context from which the Application context will be derived. - */ - public LocationSource(Context context) { - super(); - this.context = context.getApplicationContext(); - lostApiClient = new LostApiClient.Builder(this.context) - .addConnectionCallbacks(this) - .build(); - } - - /** - * Constructs a location source instance. - * Needed to create empty location source implementations. - */ - public LocationSource() { - } - - /** - * Activate the location engine which will connect whichever location provider you are using. You'll need to call - * this before requesting user location updates using {@link LocationEngine#requestLocationUpdates()}. - */ - @Override - public void activate() { - connect(); - } - - /** - * Disconnect the location engine which is useful when you no longer need location updates or requesting the users - * {@link LocationEngine#getLastLocation()}. Before deactivating, you'll need to stop request user location updates - * using {@link LocationEngine#removeLocationUpdates()}. - */ - @Override - public void deactivate() { - if (lostApiClient != null && lostApiClient.isConnected()) { - lostApiClient.disconnect(); - } - } - - /** - * Check if your location provider has been activated/connected. This is mainly used internally but is also useful in - * the rare case when you'd like to know if your location engine is connected or not. - * - * @return boolean true if the location engine has been activated/connected, else false. - */ - @Override - public boolean isConnected() { - return lostApiClient.isConnected(); - } - - /** - * Invoked when the location provider has connected. - */ - @Override - public void onConnected() { - for (LocationEngineListener listener : locationListeners) { - listener.onConnected(); - } - } - - /** - * Invoked when the location provider connection has been suspended. - */ - @Override - public void onConnectionSuspended() { - // Empty - } - - /** - * Returns the Last known location is the location provider is connected and location permissions are granted. - * - * @return the last known location - */ - @Override - @Nullable - public Location getLastLocation() { - if (lostApiClient.isConnected()) { - //noinspection MissingPermission - return LocationServices.FusedLocationApi.getLastLocation(lostApiClient); - } - return null; - } - - /** - * Request location updates to the location provider. - */ - @Override - public void requestLocationUpdates() { - LocationRequest request = LocationRequest.create(); - - if (interval != null) { - request.setInterval(interval); - } - if (fastestInterval != null) { - request.setFastestInterval(fastestInterval); - } - if (smallestDisplacement != null) { - request.setSmallestDisplacement(smallestDisplacement); - } - - if (priority == LocationEnginePriority.NO_POWER) { - request.setPriority(LocationRequest.PRIORITY_NO_POWER); - } else if (priority == LocationEnginePriority.LOW_POWER) { - request.setPriority(LocationRequest.PRIORITY_LOW_POWER); - } else if (priority == LocationEnginePriority.BALANCED_POWER_ACCURACY) { - request.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); - } else if (priority == LocationEnginePriority.HIGH_ACCURACY) { - request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); - } - - if (lostApiClient.isConnected()) { - //noinspection MissingPermission - LocationServices.FusedLocationApi.requestLocationUpdates(lostApiClient, request, this); - } - } - - /** - * Dismiss ongoing location update to the location provider. - */ - @Override - public void removeLocationUpdates() { - if (lostApiClient.isConnected()) { - LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient, this); - } - } - - /** - * Returns the location engine type. - * - * @return Lost type - */ - @Override - public Type obtainType() { - return Type.LOST; - } - - /** - * Invoked when the Location has changed. - * - * @param location the new location - */ - @Override - public void onLocationChanged(Location location) { - for (LocationEngineListener listener : locationListeners) { - listener.onLocationChanged(location); - } - } - - private void connect() { - if (lostApiClient != null) { - if (lostApiClient.isConnected()) { - onConnected(); - } else { - lostApiClient.connect(); - } - } - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/package-info.java deleted file mode 100644 index b27559e95e..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains the Mapbox Maps Android Location API classes. - */ -package com.mapbox.mapboxsdk.location;
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java index 2956d864e6..2bcbd5ce40 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java @@ -10,12 +10,12 @@ import android.support.annotation.NonNull; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Toast; + import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.attribution.Attribution; import com.mapbox.mapboxsdk.attribution.AttributionParser; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.style.sources.Source; -import com.mapbox.services.android.telemetry.MapboxTelemetry; import java.util.ArrayList; import java.util.List; @@ -30,17 +30,16 @@ import java.util.Set; * Additionally an telemetry option item is shown to configure telemetry settings. * </p> */ -class AttributionDialogManager implements View.OnClickListener, DialogInterface.OnClickListener { +public class AttributionDialogManager implements View.OnClickListener, DialogInterface.OnClickListener { private static final String MAP_FEEDBACK_URL = "https://www.mapbox.com/map-feedback"; private static final String MAP_FEEDBACK_LOCATION_FORMAT = MAP_FEEDBACK_URL + "/#/%f/%f/%d"; private final Context context; private final MapboxMap mapboxMap; - private String[] attributionTitles; private Set<Attribution> attributionSet; - AttributionDialogManager(@NonNull Context context, @NonNull MapboxMap mapboxMap) { + public AttributionDialogManager(@NonNull Context context, @NonNull MapboxMap mapboxMap) { this.context = context; this.mapboxMap = mapboxMap; } @@ -49,11 +48,10 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface. @Override public void onClick(View view) { attributionSet = new AttributionBuilder(mapboxMap).build(); - showAttributionDialog(); + showAttributionDialog(getAttributionTitles()); } - private void showAttributionDialog() { - attributionTitles = getAttributionTitles(); + protected void showAttributionDialog(String[] attributionTitles) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.mapbox_attributionsDialogTitle); builder.setAdapter(new ArrayAdapter<>(context, R.layout.mapbox_attribution_list_item, attributionTitles), this); @@ -79,7 +77,7 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface. } private boolean isLatestEntry(int attributionKeyIndex) { - return attributionKeyIndex == attributionTitles.length - 1; + return attributionKeyIndex == getAttributionTitles().length - 1; } private void showTelemetryDialog() { @@ -89,7 +87,7 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface. builder.setPositiveButton(R.string.mapbox_attributionTelemetryPositive, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - MapboxTelemetry.getInstance().setTelemetryEnabled(true); + Events.obtainTelemetry().enable(); dialog.cancel(); } }); @@ -103,7 +101,7 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface. builder.setNegativeButton(R.string.mapbox_attributionTelemetryNegative, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - MapboxTelemetry.getInstance().setTelemetryEnabled(false); + Events.obtainTelemetry().disable(); dialog.cancel(); } }); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Events.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Events.java new file mode 100644 index 0000000000..a68d4763ac --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Events.java @@ -0,0 +1,36 @@ +package com.mapbox.mapboxsdk.maps; + + +import com.mapbox.android.telemetry.MapboxTelemetry; +import com.mapbox.android.telemetry.TelemetryEnabler; +import com.mapbox.mapboxsdk.BuildConfig; +import com.mapbox.mapboxsdk.Mapbox; + +class Events { + static final String TWO_FINGER_TAP = "TwoFingerTap"; + static final String DOUBLE_TAP = "DoubleTap"; + static final String SINGLE_TAP = "SingleTap"; + static final String PAN = "Pan"; + static final String PINCH = "Pinch"; + static final String ROTATION = "Rotation"; + static final String PITCH = "Pitch"; + private MapboxTelemetry telemetry; + + private Events() { + telemetry = new MapboxTelemetry(Mapbox.getApplicationContext(), Mapbox.getAccessToken(), + BuildConfig.MAPBOX_EVENTS_USER_AGENT); + TelemetryEnabler.State telemetryState = TelemetryEnabler.retrieveTelemetryStateFromPreferences(); + if (TelemetryEnabler.State.NOT_INITIALIZED.equals(telemetryState) + || TelemetryEnabler.State.ENABLED.equals(telemetryState)) { + telemetry.enable(); + } + } + + private static class EventsHolder { + private static final Events INSTANCE = new Events(); + } + + static MapboxTelemetry obtainTelemetry() { + return EventsHolder.INSTANCE.telemetry; + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index 1788cb4428..8047e19809 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -5,7 +5,6 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.PointF; -import android.location.Location; import android.support.annotation.Nullable; import android.support.v4.view.GestureDetectorCompat; import android.support.v4.view.ScaleGestureDetectorCompat; @@ -19,12 +18,12 @@ import android.view.ViewConfiguration; import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector; import com.almeros.android.multitouch.gesturedetectors.ShoveGestureDetector; import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector; +import com.mapbox.android.telemetry.Event; +import com.mapbox.android.telemetry.MapEventFactory; +import com.mapbox.android.telemetry.MapState; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.services.android.telemetry.MapboxEvent; -import com.mapbox.services.android.telemetry.MapboxTelemetry; -import com.mapbox.services.android.telemetry.utils.MathUtils; -import com.mapbox.services.android.telemetry.utils.TelemetryUtils; +import com.mapbox.mapboxsdk.utils.MathUtils; import java.util.concurrent.CopyOnWriteArrayList; @@ -145,19 +144,6 @@ final class MapGestureDetector { } /** - * Given coordinates from a gesture, use the current projection to translate it into - * a Location object. - * - * @param x coordinate - * @param y coordinate - * @return location - */ - private Location getLocationFromGesture(float x, float y) { - LatLng latLng = projection.fromScreenLocation(new PointF(x, y)); - return TelemetryUtils.buildLocation(latLng.getLongitude(), latLng.getLatitude()); - } - - /** * Called when user touches the screen, all positions are absolute. * <p> * Forwards event to the related gesture detectors. @@ -202,9 +188,13 @@ final class MapGestureDetector { && uiSettings.isZoomGesturesEnabled(); if (twoTap) { // Confirmed 2nd Finger Down - MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( - getLocationFromGesture(event.getX(), event.getY()), - MapboxEvent.GESTURE_TWO_FINGER_SINGLETAP, transform)); + if (isZoomValid(transform)) { + MapEventFactory mapEventFactory = new MapEventFactory(); + LatLng latLng = projection.fromScreenLocation(new PointF(event.getX(), event.getY())); + MapState twoFingerTap = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom()); + twoFingerTap.setGesture(Events.TWO_FINGER_TAP); + Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, twoFingerTap)); + } } break; @@ -233,8 +223,12 @@ final class MapGestureDetector { // Scroll / Pan Has Stopped if (scrollGestureOccurred) { - MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapDragEndEvent( - getLocationFromGesture(event.getX(), event.getY()), transform)); + if (isZoomValid(transform)) { + MapEventFactory mapEventFactory = new MapEventFactory(); + LatLng latLng = projection.fromScreenLocation(new PointF(event.getX(), event.getY())); + MapState dragend = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom()); + Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_DRAGEND, dragend)); + } scrollGestureOccurred = false; if (!scaleAnimating && !rotateAnimating) { @@ -350,9 +344,13 @@ final class MapGestureDetector { // Zoom in on gesture transform.zoom(true, new PointF(e.getX(), e.getY())); } - MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( - getLocationFromGesture(e.getX(), e.getY()), - MapboxEvent.GESTURE_DOUBLETAP, transform)); + if (isZoomValid(transform)) { + MapEventFactory mapEventFactory = new MapEventFactory(); + LatLng latLng = projection.fromScreenLocation(new PointF(e.getX(), e.getY())); + MapState doubleTap = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom()); + doubleTap.setGesture(Events.DOUBLE_TAP); + Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, doubleTap)); + } break; } @@ -380,9 +378,13 @@ final class MapGestureDetector { notifyOnMapClickListeners(tapPoint); } - MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( - getLocationFromGesture(motionEvent.getX(), motionEvent.getY()), - MapboxEvent.GESTURE_SINGLETAP, transform)); + if (isZoomValid(transform)) { + MapEventFactory mapEventFactory = new MapEventFactory(); + LatLng latLng = projection.fromScreenLocation(new PointF(motionEvent.getX(), motionEvent.getY())); + MapState singleTap = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom()); + singleTap.setGesture(Events.SINGLE_TAP); + Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, singleTap)); + } return true; } @@ -456,9 +458,13 @@ final class MapGestureDetector { cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE); } - MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( - getLocationFromGesture(e1.getX(), e1.getY()), - MapboxEvent.GESTURE_PAN_START, transform)); + if (isZoomValid(transform)) { + MapEventFactory mapEventFactory = new MapEventFactory(); + LatLng latLng = projection.fromScreenLocation(new PointF(e1.getX(), e1.getY())); + MapState pan = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom()); + pan.setGesture(Events.PAN); + Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, pan)); + } } // reset tracking if needed @@ -541,9 +547,13 @@ final class MapGestureDetector { recentScaleGestureOccurred = true; scalePointBegin = new PointF(detector.getFocusX(), detector.getFocusY()); scaleBeginTime = detector.getEventTime(); - MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( - getLocationFromGesture(detector.getFocusX(), detector.getFocusY()), - MapboxEvent.GESTURE_PINCH_START, transform)); + if (isZoomValid(transform)) { + MapEventFactory mapEventFactory = new MapEventFactory(); + LatLng latLng = projection.fromScreenLocation(new PointF(detector.getFocusX(), detector.getFocusY())); + MapState pinch = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom()); + pinch.setGesture(Events.PINCH); + Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, pinch)); + } return true; } @@ -724,9 +734,13 @@ final class MapGestureDetector { // Also is zoom already started, don't rotate float angle = detector.getRotationDegreesDelta(); if (Math.abs(angle) >= ROTATE_INVOKE_ANGLE) { - MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( - getLocationFromGesture(detector.getFocusX(), detector.getFocusY()), - MapboxEvent.GESTURE_ROTATION_START, transform)); + if (isZoomValid(transform)) { + MapEventFactory mapEventFactory = new MapEventFactory(); + LatLng latLng = projection.fromScreenLocation(new PointF(detector.getFocusX(), detector.getFocusY())); + MapState rotation = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom()); + rotation.setGesture(Events.ROTATION); + Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, rotation)); + } started = true; } @@ -895,9 +909,13 @@ final class MapGestureDetector { if (!tiltGestureOccurred && ((totalDelta > 10.0f) || (totalDelta < -10.0f))) { tiltGestureOccurred = true; beginTime = detector.getEventTime(); - MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( - getLocationFromGesture(detector.getFocusX(), detector.getFocusY()), - MapboxEvent.GESTURE_PITCH_START, transform)); + if (isZoomValid(transform)) { + MapEventFactory mapEventFactory = new MapEventFactory(); + LatLng latLng = projection.fromScreenLocation(new PointF(detector.getFocusX(), detector.getFocusY())); + MapState pitch = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom()); + pitch.setGesture(Events.PITCH); + Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, pitch)); + } } if (!tiltGestureOccurred) { @@ -962,4 +980,15 @@ final class MapGestureDetector { void removeOnScrollListener(MapboxMap.OnScrollListener onScrollListener) { onScrollListenerList.remove(onScrollListener); } + + private boolean isZoomValid(Transform transform) { + if (transform == null) { + return false; + } + double mapZoom = transform.getZoom(); + if (mapZoom < MapboxConstants.MINIMUM_ZOOM || mapZoom > MapboxConstants.MAXIMUM_ZOOM) { + return false; + } + return true; + } } 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 a8e065c45e..990c56cb51 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,6 +22,12 @@ import android.view.ViewTreeObserver; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ZoomButtonsController; + +import com.mapbox.android.telemetry.AppUserTurnstile; +import com.mapbox.android.telemetry.Event; +import com.mapbox.android.telemetry.MapEventFactory; +import com.mapbox.android.telemetry.MapboxTelemetry; +import com.mapbox.mapboxsdk.BuildConfig; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.MarkerViewManager; @@ -35,8 +41,6 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; 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; @@ -48,6 +52,8 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +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; @@ -192,7 +198,7 @@ public class MapView extends FrameLayout { compassView.setOnClickListener(createCompassClickListener(cameraChangeDispatcher)); // inject widgets with MapboxMap myLocationView.setMapboxMap(mapboxMap); - attrView.setOnClickListener(new AttributionDialogManager(context, mapboxMap)); + attrView.setOnClickListener(new AttributionClickListener(context, mapboxMap)); // Ensure this view is interactable setClickable(true); @@ -262,7 +268,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. @@ -273,7 +279,12 @@ public class MapView extends FrameLayout { @UiThread public void onCreate(@Nullable Bundle savedInstanceState) { if (savedInstanceState == null) { - MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapLoadEvent()); + MapboxTelemetry telemetry = Events.obtainTelemetry(); + AppUserTurnstile turnstileEvent = new AppUserTurnstile(BuildConfig.MAPBOX_SDK_IDENTIFIER, + BuildConfig.MAPBOX_SDK_VERSION); + telemetry.push(turnstileEvent); + MapEventFactory mapEventFactory = new MapEventFactory(); + telemetry.push(mapEventFactory.createMapLoadEvent(Event.Type.MAP_LOAD)); } else if (savedInstanceState.getBoolean(MapboxConstants.STATE_HAS_SAVED_STATE)) { this.savedInstanceState = savedInstanceState; } @@ -285,7 +296,7 @@ public class MapView extends FrameLayout { mapRenderer = new TextureViewMapRenderer(getContext(), textureView, options.getLocalIdeographFontFamily()) { @Override protected void onSurfaceCreated(GL10 gl, EGLConfig config) { - initRenderSurface(); + MapView.this.onSurfaceCreated(); super.onSurfaceCreated(gl, config); } }; @@ -297,7 +308,7 @@ public class MapView extends FrameLayout { mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, options.getLocalIdeographFontFamily()) { @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { - initRenderSurface(); + MapView.this.onSurfaceCreated(); super.onSurfaceCreated(gl, config); } }; @@ -309,16 +320,13 @@ public class MapView extends FrameLayout { nativeMapView.resizeView(getMeasuredWidth(), getMeasuredHeight()); } - private void initRenderSurface() { + private void onSurfaceCreated() { hasSurface = true; - post(new Runnable() { - @Override - public void run() { - // Initialise only when not destroyed and only once - if (!destroyed && mapboxMap == null) { - initialiseMap(); - mapboxMap.onStart(); - } + post(() -> { + // Initialise only when not destroyed and only once + if (!destroyed && mapboxMap == null) { + initialiseMap(); + mapboxMap.onStart(); } }); } @@ -1089,4 +1097,28 @@ public class MapView extends FrameLayout { onMapReadyCallbackList.clear(); } } + + /** + * Click event hook for providing a custom attribution dialog manager. + */ + private static class AttributionClickListener implements OnClickListener { + + private final AttributionDialogManager defaultDialogManager; + private UiSettings uiSettings; + + private AttributionClickListener(Context context, MapboxMap mapboxMap) { + this.defaultDialogManager = new AttributionDialogManager(context, mapboxMap); + this.uiSettings = mapboxMap.getUiSettings(); + } + + @Override + public void onClick(View v) { + AttributionDialogManager customDialogManager = uiSettings.getAttributionDialogManager(); + if (customDialogManager != null) { + uiSettings.getAttributionDialogManager().onClick(v); + } else { + defaultDialogManager.onClick(v); + } + } + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxEventWrapper.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxEventWrapper.java deleted file mode 100644 index 6730278d79..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxEventWrapper.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.mapbox.mapboxsdk.maps; - -import android.location.Location; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.services.android.telemetry.MapboxEvent; - -import java.util.Hashtable; - -/** - * Wrapper class for MapboxEvent - * <p> - * Provides facility methods to use Transform and handle the case that the zoom, required for a telemetry event, - * isn't available yet. - * </p> - */ -class MapboxEventWrapper { - - @Nullable - static Hashtable<String, Object> buildMapClickEvent( - @NonNull Location location, @NonNull String gestureId, Transform transform) { - try { - double mapZoom = transform.getZoom(); - if (mapZoom >= MapboxConstants.MINIMUM_ZOOM && mapZoom <= MapboxConstants.MAXIMUM_ZOOM) { - // validate zoom #8057 - return MapboxEvent.buildMapClickEvent(location, gestureId, transform.getZoom()); - } - } catch (NullPointerException exception) { - // Map/Transform is not ready yet #8650 - // returning null is valid, event is ignored. - } - return null; - } - - @Nullable - static Hashtable<String, Object> buildMapDragEndEvent( - @NonNull Location location, Transform transform) { - try { - double mapZoom = transform.getZoom(); - if (mapZoom >= MapboxConstants.MINIMUM_ZOOM && mapZoom <= MapboxConstants.MAXIMUM_ZOOM) { - // validate zoom #8057 - return MapboxEvent.buildMapDragEndEvent(location, transform.getZoom()); - } - } catch (NullPointerException exception) { - // Map/Transform is not ready yet #8650 - // returning null is valid, event is ignored. - } - return null; - } - - @Nullable - static Hashtable<String, Object> buildMapLoadEvent() { - return MapboxEvent.buildMapLoadEvent(); - } -} 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 ba116e1278..2fd9a9010c 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 @@ -16,6 +16,8 @@ import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.Geometry; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions; @@ -41,9 +43,7 @@ import com.mapbox.mapboxsdk.style.layers.Filter; import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.light.Light; import com.mapbox.mapboxsdk.style.sources.Source; -import com.mapbox.services.android.telemetry.location.LocationEngine; -import com.mapbox.services.commons.geojson.Feature; -import com.mapbox.services.commons.geojson.Geometry; +import com.mapbox.android.core.location.LocationEngine; import java.lang.reflect.ParameterizedType; import java.util.HashMap; @@ -563,7 +563,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() { @@ -579,7 +579,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() { @@ -2077,7 +2077,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() { @@ -2095,7 +2095,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) { @@ -2107,7 +2107,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 @@ -2122,7 +2122,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 @@ -2135,7 +2135,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) { @@ -2148,7 +2148,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( @@ -2162,7 +2162,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..785b045779 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 @@ -11,6 +11,8 @@ import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.DisplayMetrics; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.Geometry; import com.mapbox.mapboxsdk.LibraryLoader; import com.mapbox.mapboxsdk.annotations.Icon; import com.mapbox.mapboxsdk.annotations.Marker; @@ -29,8 +31,6 @@ import com.mapbox.mapboxsdk.style.light.Light; import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException; import com.mapbox.mapboxsdk.style.sources.Source; import com.mapbox.mapboxsdk.utils.BitmapUtils; -import com.mapbox.services.commons.geojson.Feature; -import com.mapbox.services.commons.geojson.Geometry; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -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/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java index 16c73b1ca5..ae559189ad 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java @@ -104,11 +104,12 @@ public class Projection { LatLng bottomLeft = fromScreenLocation(new PointF(left, bottom)); return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight, - LatLngBounds.from( - topRight.getLatitude(), - topRight.getLongitude(), - bottomLeft.getLatitude(), - bottomLeft.getLongitude()) + new LatLngBounds.Builder() + .include(topRight) + .include(bottomLeft) + .include(bottomRight) + .include(topLeft) + .build() ); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java index 81fd091c90..3743096824 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java @@ -12,9 +12,9 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.constants.MyBearingTracking; import com.mapbox.mapboxsdk.constants.MyLocationTracking; import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; -import com.mapbox.services.android.telemetry.location.LocationEngine; -import com.mapbox.services.android.telemetry.location.LocationEngineListener; -import com.mapbox.services.android.telemetry.permissions.PermissionsManager; +import com.mapbox.android.core.location.LocationEngine; +import com.mapbox.android.core.location.LocationEngineListener; +import com.mapbox.android.core.permissions.PermissionsManager; import timber.log.Timber; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java index 3fd3e1220a..12d8dfe85b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java @@ -37,6 +37,7 @@ public final class UiSettings { private final ImageView attributionsView; private final int[] attributionsMargins = new int[4]; + private AttributionDialogManager attributionDialogManager; private final View logoView; private final int[] logoMargins = new int[4]; @@ -535,6 +536,28 @@ public final class UiSettings { return attributionsView.getVisibility() == View.VISIBLE; } + + /** + * Set a custom attribution dialog manager. + * <p> + * Set to null to reset to default behaviour. + * </p> + * + * @param attributionDialogManager the manager class used for showing attribution + */ + public void setAttributionDialogManager(AttributionDialogManager attributionDialogManager) { + this.attributionDialogManager = attributionDialogManager; + } + + /** + * Get the custom attribution dialog manager. + * + * @return the active manager class used for showing attribution + */ + public AttributionDialogManager getAttributionDialogManager() { + return attributionDialogManager; + } + /** * <p> * Sets the gravity of the attribution. diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java index 1e604c9bef..45f72af1c5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java @@ -6,10 +6,10 @@ import android.support.annotation.NonNull; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPropertyAnimatorCompat; import android.support.v4.view.ViewPropertyAnimatorListenerAdapter; +import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import com.mapbox.mapboxsdk.maps.MapboxMap; @@ -22,7 +22,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; * use {@link com.mapbox.mapboxsdk.maps.UiSettings}. * </p> */ -public final class CompassView extends ImageView implements Runnable { +public final class CompassView extends AppCompatImageView implements Runnable { public static final long TIME_WAIT_IDLE = 500; public static final long TIME_MAP_NORTH_ANIMATION = 150; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java index 1cdd91028d..3f37da99d5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java @@ -35,9 +35,9 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.Projection; -import com.mapbox.services.android.telemetry.location.LocationEngine; -import com.mapbox.services.android.telemetry.location.LocationEngineListener; -import com.mapbox.services.android.telemetry.location.LocationEnginePriority; +import com.mapbox.android.core.location.LocationEngine; +import com.mapbox.android.core.location.LocationEngineListener; +import com.mapbox.android.core.location.LocationEnginePriority; import java.lang.ref.WeakReference; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java index 987756876b..090e9576ee 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java @@ -250,12 +250,9 @@ public class OfflineRegion { @Override public void onStatusChanged(final OfflineRegionStatus status) { if (deliverMessages()) { - handler.post(new Runnable() { - @Override - public void run() { - if (observer != null) { - observer.onStatusChanged(status); - } + handler.post(() -> { + if (observer != null) { + observer.onStatusChanged(status); } }); } @@ -264,12 +261,9 @@ public class OfflineRegion { @Override public void onError(final OfflineRegionError error) { if (deliverMessages()) { - handler.post(new Runnable() { - @Override - public void run() { - if (observer != null) { - observer.onError(error); - } + handler.post(() -> { + if (observer != null) { + observer.onError(error); } }); } @@ -278,12 +272,9 @@ public class OfflineRegion { @Override public void mapboxTileCountLimitExceeded(final long limit) { if (deliverMessages()) { - handler.post(new Runnable() { - @Override - public void run() { - if (observer != null) { - observer.mapboxTileCountLimitExceeded(limit); - } + handler.post(() -> { + if (observer != null) { + observer.mapboxTileCountLimitExceeded(limit); } }); } @@ -322,23 +313,17 @@ public class OfflineRegion { getOfflineRegionStatus(new OfflineRegionStatusCallback() { @Override public void onStatus(final OfflineRegionStatus status) { - handler.post(new Runnable() { - @Override - public void run() { - callback.onStatus(status); - FileSource.getInstance(Mapbox.getApplicationContext()).deactivate(); - } + handler.post(() -> { + callback.onStatus(status); + FileSource.getInstance(Mapbox.getApplicationContext()).deactivate(); }); } @Override public void onError(final String error) { - handler.post(new Runnable() { - @Override - public void run() { - callback.onError(error); - FileSource.getInstance(Mapbox.getApplicationContext()).deactivate(); - } + handler.post(() -> { + callback.onError(error); + FileSource.getInstance(Mapbox.getApplicationContext()).deactivate(); }); } }); @@ -368,25 +353,19 @@ public class OfflineRegion { deleteOfflineRegion(new OfflineRegionDeleteCallback() { @Override public void onDelete() { - handler.post(new Runnable() { - @Override - public void run() { - callback.onDelete(); - FileSource.getInstance(Mapbox.getApplicationContext()).deactivate(); - OfflineRegion.this.finalize(); - } + handler.post((Runnable) () -> { + callback.onDelete(); + FileSource.getInstance(Mapbox.getApplicationContext()).deactivate(); + OfflineRegion.this.finalize(); }); } @Override public void onError(final String error) { - handler.post(new Runnable() { - @Override - public void run() { - isDeleted = false; - FileSource.getInstance(Mapbox.getApplicationContext()).deactivate(); - callback.onError(error); - } + handler.post(() -> { + isDeleted = false; + FileSource.getInstance(Mapbox.getApplicationContext()).deactivate(); + callback.onError(error); }); } }); @@ -407,23 +386,15 @@ public class OfflineRegion { updateOfflineRegionMetadata(bytes, new OfflineRegionUpdateMetadataCallback() { @Override public void onUpdate(final byte[] metadata) { - handler.post(new Runnable() { - @Override - public void run() { - OfflineRegion.this.metadata = metadata; - callback.onUpdate(metadata); - } + handler.post(() -> { + OfflineRegion.this.metadata = metadata; + callback.onUpdate(metadata); }); } @Override public void onError(final String error) { - handler.post(new Runnable() { - @Override - public void run() { - callback.onError(error); - } - }); + handler.post(() -> callback.onError(error)); } }); } 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..7b841a2580 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -0,0 +1,1797 @@ +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 + */ + @SafeVarargs + 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> + */ + public 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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<Object> 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<Object> 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SuppressWarnings("unchecked") + 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 + */ + @SuppressWarnings("unchecked") + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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 + */ + @SafeVarargs + 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; + } + + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("[\"").append(operator).append("\""); + if (arguments != null) { + for (Expression argument : arguments) { + builder.append(", "); + if (argument instanceof ExpressionLiteral) { + builder.append(((ExpressionLiteral) argument).toValue()); + } else { + builder.append(argument.toString()); + } + } + } + builder.append("]"); + return builder.toString(); + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java new file mode 100644 index 0000000000..6b8fd65def --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java @@ -0,0 +1,221 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +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; + +/** + * A heatmap. + * + * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layers-heatmap">The online documentation</a> + */ +@UiThread +public class HeatmapLayer extends Layer { + + /** + * Creates a HeatmapLayer. + * + * @param nativePtr pointer used by core + */ + public HeatmapLayer(long nativePtr) { + super(nativePtr); + } + + /** + * Creates a HeatmapLayer. + * + * @param layerId the id of the layer + * @param sourceId the id of the source + */ + public HeatmapLayer(String layerId, String sourceId) { + initialize(layerId, sourceId); + } + + protected native void initialize(String layerId, String sourceId); + + /** + * Set the source layer. + * + * @param sourceLayer the source layer to set + */ + public void setSourceLayer(String sourceLayer) { + nativeSetSourceLayer(sourceLayer); + } + + /** + * Set the source Layer. + * + * @param sourceLayer the source layer to set + * @return This + */ + public HeatmapLayer withSourceLayer(String sourceLayer) { + setSourceLayer(sourceLayer); + return this; + } + + /** + * Get the source layer. + * + * @return sourceLayer the source layer to get + */ + public String getSourceLayer() { + return nativeGetSourceLayer(); + } + + /** + * Set a single filter. + * + * @param filter the filter to set + */ + public void setFilter(Filter.Statement filter) { + nativeSetFilter(filter.toArray()); + } + + /** + * Set a single filter. + * + * @param filter the filter to set + * @return This + */ + public HeatmapLayer withFilter(Filter.Statement filter) { + setFilter(filter); + return this; + } + + /** + * Set a property or properties. + * + * @param properties the var-args properties + * @return This + */ + public HeatmapLayer withProperties(@NonNull PropertyValue<?>... properties) { + setProperties(properties); + return this; + } + + // Property getters + + /** + * Get the HeatmapRadius property + * + * @return property wrapper value around Float + */ + @SuppressWarnings("unchecked") + public PropertyValue<Float> getHeatmapRadius() { + return (PropertyValue<Float>) new PropertyValue("heatmap-radius", nativeGetHeatmapRadius()); + } + + /** + * Get the HeatmapRadius property transition options + * + * @return transition options for Float + */ + public TransitionOptions getHeatmapRadiusTransition() { + return nativeGetHeatmapRadiusTransition(); + } + + /** + * Set the HeatmapRadius property transition options + * + * @param options transition options for Float + */ + public void setHeatmapRadiusTransition(TransitionOptions options) { + nativeSetHeatmapRadiusTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the HeatmapWeight property + * + * @return property wrapper value around Float + */ + @SuppressWarnings("unchecked") + public PropertyValue<Float> getHeatmapWeight() { + return (PropertyValue<Float>) new PropertyValue("heatmap-weight", nativeGetHeatmapWeight()); + } + + /** + * Get the HeatmapIntensity property + * + * @return property wrapper value around Float + */ + @SuppressWarnings("unchecked") + public PropertyValue<Float> getHeatmapIntensity() { + return (PropertyValue<Float>) new PropertyValue("heatmap-intensity", nativeGetHeatmapIntensity()); + } + + /** + * Get the HeatmapIntensity property transition options + * + * @return transition options for Float + */ + public TransitionOptions getHeatmapIntensityTransition() { + return nativeGetHeatmapIntensityTransition(); + } + + /** + * Set the HeatmapIntensity property transition options + * + * @param options transition options for Float + */ + public void setHeatmapIntensityTransition(TransitionOptions options) { + nativeSetHeatmapIntensityTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the HeatmapOpacity property + * + * @return property wrapper value around Float + */ + @SuppressWarnings("unchecked") + public PropertyValue<Float> getHeatmapOpacity() { + return (PropertyValue<Float>) new PropertyValue("heatmap-opacity", nativeGetHeatmapOpacity()); + } + + /** + * Get the HeatmapOpacity property transition options + * + * @return transition options for Float + */ + public TransitionOptions getHeatmapOpacityTransition() { + return nativeGetHeatmapOpacityTransition(); + } + + /** + * Set the HeatmapOpacity property transition options + * + * @param options transition options for Float + */ + public void setHeatmapOpacityTransition(TransitionOptions options) { + nativeSetHeatmapOpacityTransition(options.getDuration(), options.getDelay()); + } + + private native Object nativeGetHeatmapRadius(); + + private native TransitionOptions nativeGetHeatmapRadiusTransition(); + + private native void nativeSetHeatmapRadiusTransition(long duration, long delay); + + private native Object nativeGetHeatmapWeight(); + + private native Object nativeGetHeatmapIntensity(); + + private native TransitionOptions nativeGetHeatmapIntensityTransition(); + + private native void nativeSetHeatmapIntensityTransition(long duration, long delay); + + private native Object nativeGetHeatmapOpacity(); + + private native TransitionOptions nativeGetHeatmapOpacityTransition(); + + private native void nativeSetHeatmapOpacityTransition(long duration, long delay); + + @Override + protected native void finalize() throws Throwable; + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java new file mode 100644 index 0000000000..7e3d3a7779 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java @@ -0,0 +1,286 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +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; + +/** + * Client-side hillshading visualization based on DEM data. Currently, the implementation only supports Mapbox Terrain RGB and Mapzen Terrarium tiles. + * + * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layers-hillshade">The online documentation</a> + */ +@UiThread +public class HillshadeLayer extends Layer { + + /** + * Creates a HillshadeLayer. + * + * @param nativePtr pointer used by core + */ + public HillshadeLayer(long nativePtr) { + super(nativePtr); + } + + /** + * Creates a HillshadeLayer. + * + * @param layerId the id of the layer + * @param sourceId the id of the source + */ + public HillshadeLayer(String layerId, String sourceId) { + initialize(layerId, sourceId); + } + + protected native void initialize(String layerId, String sourceId); + + /** + * Set the source layer. + * + * @param sourceLayer the source layer to set + */ + public void setSourceLayer(String sourceLayer) { + nativeSetSourceLayer(sourceLayer); + } + + /** + * Set the source Layer. + * + * @param sourceLayer the source layer to set + * @return This + */ + public HillshadeLayer withSourceLayer(String sourceLayer) { + setSourceLayer(sourceLayer); + return this; + } + + /** + * Set a property or properties. + * + * @param properties the var-args properties + * @return This + */ + public HillshadeLayer withProperties(@NonNull PropertyValue<?>... properties) { + setProperties(properties); + return this; + } + + // Property getters + + /** + * Get the HillshadeIlluminationDirection property + * + * @return property wrapper value around Float + */ + @SuppressWarnings("unchecked") + public PropertyValue<Float> getHillshadeIlluminationDirection() { + return (PropertyValue<Float>) new PropertyValue("hillshade-illumination-direction", nativeGetHillshadeIlluminationDirection()); + } + + /** + * Get the HillshadeIlluminationAnchor property + * + * @return property wrapper value around String + */ + @SuppressWarnings("unchecked") + public PropertyValue<String> getHillshadeIlluminationAnchor() { + return (PropertyValue<String>) new PropertyValue("hillshade-illumination-anchor", nativeGetHillshadeIlluminationAnchor()); + } + + /** + * Get the HillshadeExaggeration property + * + * @return property wrapper value around Float + */ + @SuppressWarnings("unchecked") + public PropertyValue<Float> getHillshadeExaggeration() { + return (PropertyValue<Float>) new PropertyValue("hillshade-exaggeration", nativeGetHillshadeExaggeration()); + } + + /** + * Get the HillshadeExaggeration property transition options + * + * @return transition options for Float + */ + public TransitionOptions getHillshadeExaggerationTransition() { + return nativeGetHillshadeExaggerationTransition(); + } + + /** + * Set the HillshadeExaggeration property transition options + * + * @param options transition options for Float + */ + public void setHillshadeExaggerationTransition(TransitionOptions options) { + nativeSetHillshadeExaggerationTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the HillshadeShadowColor property + * + * @return property wrapper value around String + */ + @SuppressWarnings("unchecked") + public PropertyValue<String> getHillshadeShadowColor() { + return (PropertyValue<String>) new PropertyValue("hillshade-shadow-color", nativeGetHillshadeShadowColor()); + } + + /** + * The shading color of areas that face away from the light source. + * + * @return int representation of a rgba string color + * @throws RuntimeException thrown if property isn't a value + */ + @ColorInt + public int getHillshadeShadowColorAsInt() { + PropertyValue<String> value = getHillshadeShadowColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("hillshade-shadow-color was set as a Function"); + } + } + + /** + * Get the HillshadeShadowColor property transition options + * + * @return transition options for String + */ + public TransitionOptions getHillshadeShadowColorTransition() { + return nativeGetHillshadeShadowColorTransition(); + } + + /** + * Set the HillshadeShadowColor property transition options + * + * @param options transition options for String + */ + public void setHillshadeShadowColorTransition(TransitionOptions options) { + nativeSetHillshadeShadowColorTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the HillshadeHighlightColor property + * + * @return property wrapper value around String + */ + @SuppressWarnings("unchecked") + public PropertyValue<String> getHillshadeHighlightColor() { + return (PropertyValue<String>) new PropertyValue("hillshade-highlight-color", nativeGetHillshadeHighlightColor()); + } + + /** + * The shading color of areas that faces towards the light source. + * + * @return int representation of a rgba string color + * @throws RuntimeException thrown if property isn't a value + */ + @ColorInt + public int getHillshadeHighlightColorAsInt() { + PropertyValue<String> value = getHillshadeHighlightColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("hillshade-highlight-color was set as a Function"); + } + } + + /** + * Get the HillshadeHighlightColor property transition options + * + * @return transition options for String + */ + public TransitionOptions getHillshadeHighlightColorTransition() { + return nativeGetHillshadeHighlightColorTransition(); + } + + /** + * Set the HillshadeHighlightColor property transition options + * + * @param options transition options for String + */ + public void setHillshadeHighlightColorTransition(TransitionOptions options) { + nativeSetHillshadeHighlightColorTransition(options.getDuration(), options.getDelay()); + } + + /** + * Get the HillshadeAccentColor property + * + * @return property wrapper value around String + */ + @SuppressWarnings("unchecked") + public PropertyValue<String> getHillshadeAccentColor() { + return (PropertyValue<String>) new PropertyValue("hillshade-accent-color", nativeGetHillshadeAccentColor()); + } + + /** + * The shading color used to accentuate rugged terrain like sharp cliffs and gorges. + * + * @return int representation of a rgba string color + * @throws RuntimeException thrown if property isn't a value + */ + @ColorInt + public int getHillshadeAccentColorAsInt() { + PropertyValue<String> value = getHillshadeAccentColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("hillshade-accent-color was set as a Function"); + } + } + + /** + * Get the HillshadeAccentColor property transition options + * + * @return transition options for String + */ + public TransitionOptions getHillshadeAccentColorTransition() { + return nativeGetHillshadeAccentColorTransition(); + } + + /** + * Set the HillshadeAccentColor property transition options + * + * @param options transition options for String + */ + public void setHillshadeAccentColorTransition(TransitionOptions options) { + nativeSetHillshadeAccentColorTransition(options.getDuration(), options.getDelay()); + } + + private native Object nativeGetHillshadeIlluminationDirection(); + + private native Object nativeGetHillshadeIlluminationAnchor(); + + private native Object nativeGetHillshadeExaggeration(); + + private native TransitionOptions nativeGetHillshadeExaggerationTransition(); + + private native void nativeSetHillshadeExaggerationTransition(long duration, long delay); + + private native Object nativeGetHillshadeShadowColor(); + + private native TransitionOptions nativeGetHillshadeShadowColorTransition(); + + private native void nativeSetHillshadeShadowColorTransition(long duration, long delay); + + private native Object nativeGetHillshadeHighlightColor(); + + private native TransitionOptions nativeGetHillshadeHighlightColorTransition(); + + private native void nativeSetHillshadeHighlightColorTransition(long duration, long delay); + + private native Object nativeGetHillshadeAccentColor(); + + private native TransitionOptions nativeGetHillshadeAccentColorTransition(); + + private native void nativeSetHillshadeAccentColorTransition(long duration, long delay); + + @Override + protected native void finalize() throws Throwable; + +} 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/Property.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java index 8d5858217b..e52474c35b 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, @@ -570,6 +570,27 @@ public final class Property { @Retention(RetentionPolicy.SOURCE) public @interface FILL_EXTRUSION_TRANSLATE_ANCHOR {} + // HILLSHADE_ILLUMINATION_ANCHOR: Direction of light source when map is rotated. + + /** + * The hillshade illumination is relative to the north direction. + */ + public static final String HILLSHADE_ILLUMINATION_ANCHOR_MAP = "map"; + /** + * The hillshade illumination is relative to the top of the viewport. + */ + public static final String HILLSHADE_ILLUMINATION_ANCHOR_VIEWPORT = "viewport"; + + /** + * Direction of light source when map is rotated. + */ + @StringDef({ + HILLSHADE_ILLUMINATION_ANCHOR_MAP, + HILLSHADE_ILLUMINATION_ANCHOR_VIEWPORT, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface HILLSHADE_ILLUMINATION_ANCHOR {} + // ANCHOR: Whether extruded geometries are lit relative to the map or viewport. /** 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 c43977aec6..18ee05e63b 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 @@ -2,11 +2,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; @@ -34,6 +34,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); } @@ -48,6 +49,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. @@ -56,6 +67,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); } @@ -70,6 +82,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. @@ -78,6 +100,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); } @@ -102,6 +125,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. @@ -110,6 +143,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); } @@ -134,6 +168,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. @@ -142,6 +186,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); } @@ -156,6 +201,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. @@ -164,12 +219,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 @@ -178,14 +234,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); } @@ -200,6 +267,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). @@ -208,6 +285,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); } @@ -222,6 +300,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. @@ -230,6 +318,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); } @@ -254,6 +343,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. @@ -262,6 +361,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); } @@ -276,6 +376,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. @@ -284,12 +394,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 @@ -298,14 +409,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); } @@ -320,6 +442,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. @@ -328,6 +460,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); } @@ -342,6 +475,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. @@ -350,6 +493,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); } @@ -364,6 +508,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. @@ -372,6 +526,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); } @@ -386,6 +541,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. @@ -394,6 +559,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); } @@ -408,6 +574,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. @@ -416,6 +592,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); } @@ -430,6 +607,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). @@ -438,6 +625,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); } @@ -452,6 +640,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. @@ -460,6 +658,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); } @@ -484,6 +683,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. @@ -492,6 +701,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); } @@ -516,6 +726,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. @@ -524,6 +744,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); } @@ -538,6 +759,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. @@ -546,6 +777,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); } @@ -560,6 +792,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. @@ -568,6 +810,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); } @@ -582,6 +825,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. @@ -590,12 +843,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 @@ -604,14 +858,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); } @@ -626,6 +891,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. @@ -634,6 +909,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); } @@ -658,6 +934,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. @@ -666,6 +952,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); } @@ -690,6 +977,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. @@ -698,6 +995,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); } @@ -712,6 +1010,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. @@ -720,6 +1028,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); } @@ -734,6 +1043,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. @@ -742,6 +1061,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); } @@ -756,6 +1076,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. @@ -764,12 +1094,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 @@ -778,14 +1109,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); } @@ -800,6 +1142,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. @@ -808,6 +1160,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); } @@ -832,6 +1185,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. @@ -840,6 +1203,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); } @@ -854,6 +1218,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. @@ -862,6 +1236,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); } @@ -876,6 +1251,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. @@ -884,6 +1269,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); } @@ -898,6 +1284,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. @@ -906,12 +1302,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 @@ -920,14 +1317,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); } @@ -942,6 +1350,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. @@ -950,6 +1368,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); } @@ -964,6 +1383,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. @@ -972,6 +1401,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); } @@ -986,6 +1416,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}. @@ -994,6 +1434,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); } @@ -1018,6 +1459,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. @@ -1026,6 +1477,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); } @@ -1040,6 +1492,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. @@ -1048,11 +1510,144 @@ 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); } /** + * Radius of influence of one heatmap point in density-independent pixels. Increasing the value makes the heatmap smoother, but less detailed. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Float> heatmapRadius(Float value) { + return new PaintPropertyValue<>("heatmap-radius", value); + } + + /** + * Radius of influence of one heatmap point in density-independent pixels. Increasing the value makes the heatmap smoother, but less detailed. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> heatmapRadius(Expression expression) { + return new PaintPropertyValue<>("heatmap-radius", expression); + } + + + /** + * Radius of influence of one heatmap point in density-independent pixels. Increasing the value makes the heatmap smoother, but less detailed. + * + * @param <T> the function input type + * @param function a wrapper function for Float + * @return property wrapper around a Float function + */ + @Deprecated + public static <T> PropertyValue<Function<T, Float>> heatmapRadius(Function<T, Float> function) { + return new PaintPropertyValue<>("heatmap-radius", function); + } + + /** + * A measure of how much an individual point contributes to the heatmap. A value of 10 would be equivalent to having 10 points of weight 1 in the same spot. Especially useful when combined with clustering. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Float> heatmapWeight(Float value) { + return new PaintPropertyValue<>("heatmap-weight", value); + } + + /** + * A measure of how much an individual point contributes to the heatmap. A value of 10 would be equivalent to having 10 points of weight 1 in the same spot. Especially useful when combined with clustering. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> heatmapWeight(Expression expression) { + return new PaintPropertyValue<>("heatmap-weight", expression); + } + + + /** + * A measure of how much an individual point contributes to the heatmap. A value of 10 would be equivalent to having 10 points of weight 1 in the same spot. Especially useful when combined with clustering. + * + * @param <T> the function input type + * @param function a wrapper function for Float + * @return property wrapper around a Float function + */ + @Deprecated + public static <T> PropertyValue<Function<T, Float>> heatmapWeight(Function<T, Float> function) { + return new PaintPropertyValue<>("heatmap-weight", function); + } + + /** + * Similar to {@link PropertyFactory#heatmapWeight} but controls the intensity of the heatmap globally. Primarily used for adjusting the heatmap based on zoom level. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Float> heatmapIntensity(Float value) { + return new PaintPropertyValue<>("heatmap-intensity", value); + } + + /** + * Similar to {@link PropertyFactory#heatmapWeight} but controls the intensity of the heatmap globally. Primarily used for adjusting the heatmap based on zoom level. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> heatmapIntensity(Expression expression) { + return new PaintPropertyValue<>("heatmap-intensity", expression); + } + + + /** + * Similar to {@link PropertyFactory#heatmapWeight} but controls the intensity of the heatmap globally. Primarily used for adjusting the heatmap based on zoom level. + * + * @param <Z> the zoom parameter type + * @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>> heatmapIntensity(CameraFunction<Z, Float> function) { + return new PaintPropertyValue<>("heatmap-intensity", function); + } + + /** + * The global opacity at which the heatmap layer will be drawn. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Float> heatmapOpacity(Float value) { + return new PaintPropertyValue<>("heatmap-opacity", value); + } + + /** + * The global opacity at which the heatmap layer will be drawn. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> heatmapOpacity(Expression expression) { + return new PaintPropertyValue<>("heatmap-opacity", expression); + } + + + /** + * The global opacity at which the heatmap layer will be drawn. + * + * @param <Z> the zoom parameter type + * @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>> heatmapOpacity(CameraFunction<Z, Float> function) { + return new PaintPropertyValue<>("heatmap-opacity", function); + } + + /** * 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 value a Float value @@ -1062,6 +1657,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. @@ -1070,6 +1675,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); } @@ -1094,6 +1700,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. @@ -1102,6 +1718,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); } @@ -1116,6 +1733,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. @@ -1124,12 +1751,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 @@ -1138,14 +1766,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); } @@ -1160,6 +1799,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). @@ -1168,6 +1817,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); } @@ -1182,6 +1832,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. @@ -1190,6 +1850,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); } @@ -1204,6 +1865,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}. @@ -1212,6 +1883,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); } @@ -1226,6 +1898,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. @@ -1234,6 +1916,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); } @@ -1248,6 +1931,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. @@ -1256,6 +1949,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); } @@ -1270,6 +1964,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. @@ -1278,6 +1982,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); } @@ -1292,6 +1997,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. @@ -1300,6 +2015,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); } @@ -1314,6 +2030,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. @@ -1322,6 +2048,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); } @@ -1336,6 +2063,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. @@ -1344,6 +2081,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); } @@ -1358,6 +2096,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. @@ -1366,11 +2114,240 @@ 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); } /** + * The direction of the light source used to generate the hillshading with 0 as the top of the viewport if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `viewport` and due north if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `map`. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Float> hillshadeIlluminationDirection(Float value) { + return new PaintPropertyValue<>("hillshade-illumination-direction", value); + } + + /** + * The direction of the light source used to generate the hillshading with 0 as the top of the viewport if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `viewport` and due north if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `map`. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> hillshadeIlluminationDirection(Expression expression) { + return new PaintPropertyValue<>("hillshade-illumination-direction", expression); + } + + + /** + * The direction of the light source used to generate the hillshading with 0 as the top of the viewport if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `viewport` and due north if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `map`. + * + * @param <Z> the zoom parameter type + * @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>> hillshadeIlluminationDirection(CameraFunction<Z, Float> function) { + return new PaintPropertyValue<>("hillshade-illumination-direction", function); + } + + /** + * Direction of light source when map is rotated. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<String> hillshadeIlluminationAnchor(@Property.HILLSHADE_ILLUMINATION_ANCHOR String value) { + return new PaintPropertyValue<>("hillshade-illumination-anchor", value); + } + + /** + * Direction of light source when map is rotated. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> hillshadeIlluminationAnchor(Expression expression) { + return new PaintPropertyValue<>("hillshade-illumination-anchor", expression); + } + + + /** + * Direction of light source when map is rotated. + * + * @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>> hillshadeIlluminationAnchor(CameraFunction<Z, String> function) { + return new PaintPropertyValue<>("hillshade-illumination-anchor", function); + } + + /** + * Intensity of the hillshade + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Float> hillshadeExaggeration(Float value) { + return new PaintPropertyValue<>("hillshade-exaggeration", value); + } + + /** + * Intensity of the hillshade + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> hillshadeExaggeration(Expression expression) { + return new PaintPropertyValue<>("hillshade-exaggeration", expression); + } + + + /** + * Intensity of the hillshade + * + * @param <Z> the zoom parameter type + * @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>> hillshadeExaggeration(CameraFunction<Z, Float> function) { + return new PaintPropertyValue<>("hillshade-exaggeration", function); + } + + /** + * The shading color of areas that face away from the light source. + * + * @param value a int color value + * @return property wrapper around String color + */ + public static PropertyValue<String> hillshadeShadowColor(@ColorInt int value) { + return new PaintPropertyValue<>("hillshade-shadow-color", colorToRgbaString(value)); + } + + /** + * The shading color of areas that face away from the light source. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<String> hillshadeShadowColor(String value) { + return new PaintPropertyValue<>("hillshade-shadow-color", value); + } + + /** + * The shading color of areas that face away from the light source. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> hillshadeShadowColor(Expression expression) { + return new PaintPropertyValue<>("hillshade-shadow-color", expression); + } + + + /** + * The shading color of areas that face away from the light source. + * + * @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>> hillshadeShadowColor(CameraFunction<Z, String> function) { + return new PaintPropertyValue<>("hillshade-shadow-color", function); + } + + /** + * The shading color of areas that faces towards the light source. + * + * @param value a int color value + * @return property wrapper around String color + */ + public static PropertyValue<String> hillshadeHighlightColor(@ColorInt int value) { + return new PaintPropertyValue<>("hillshade-highlight-color", colorToRgbaString(value)); + } + + /** + * The shading color of areas that faces towards the light source. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<String> hillshadeHighlightColor(String value) { + return new PaintPropertyValue<>("hillshade-highlight-color", value); + } + + /** + * The shading color of areas that faces towards the light source. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> hillshadeHighlightColor(Expression expression) { + return new PaintPropertyValue<>("hillshade-highlight-color", expression); + } + + + /** + * The shading color of areas that faces towards the light source. + * + * @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>> hillshadeHighlightColor(CameraFunction<Z, String> function) { + return new PaintPropertyValue<>("hillshade-highlight-color", function); + } + + /** + * The shading color used to accentuate rugged terrain like sharp cliffs and gorges. + * + * @param value a int color value + * @return property wrapper around String color + */ + public static PropertyValue<String> hillshadeAccentColor(@ColorInt int value) { + return new PaintPropertyValue<>("hillshade-accent-color", colorToRgbaString(value)); + } + + /** + * The shading color used to accentuate rugged terrain like sharp cliffs and gorges. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<String> hillshadeAccentColor(String value) { + return new PaintPropertyValue<>("hillshade-accent-color", value); + } + + /** + * The shading color used to accentuate rugged terrain like sharp cliffs and gorges. + * + * @param expression an expression statement + * @return property wrapper around an expression statement + */ + public static PropertyValue<Expression> hillshadeAccentColor(Expression expression) { + return new PaintPropertyValue<>("hillshade-accent-color", expression); + } + + + /** + * The shading color used to accentuate rugged terrain like sharp cliffs and gorges. + * + * @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>> hillshadeAccentColor(CameraFunction<Z, String> function) { + return new PaintPropertyValue<>("hillshade-accent-color", function); + } + + /** * The color with which the background will be drawn. * * @param value a int color value @@ -1390,6 +2367,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. @@ -1398,6 +2385,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); } @@ -1412,6 +2400,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). @@ -1420,6 +2418,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); } @@ -1434,6 +2433,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. @@ -1442,6 +2451,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); } @@ -1456,6 +2466,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); + } /** @@ -1479,6 +2498,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); + } /** @@ -1502,6 +2530,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); + } /** @@ -1525,6 +2562,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); + } /** @@ -1548,6 +2594,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); + } /** @@ -1571,6 +2626,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); + } /** @@ -1594,6 +2658,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); + } /** @@ -1617,6 +2690,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); + } /** @@ -1640,6 +2722,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); + } /** @@ -1663,6 +2754,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); + } /** @@ -1686,6 +2786,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); + } /** @@ -1709,6 +2818,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); + } /** @@ -1732,6 +2850,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); + } /** @@ -1755,6 +2882,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); + } /** @@ -1769,7 +2905,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. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. * * @param value a String value * @return property wrapper around String @@ -1778,10 +2914,19 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-image", value); } + /** + * Name of image in sprite to use for drawing an image background. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * + * @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. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. * * @param <T> the function input type * @param function a wrapper function for String @@ -1801,6 +2946,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); + } /** @@ -1824,6 +2978,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); + } /** @@ -1847,6 +3010,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); + } /** @@ -1861,7 +3033,7 @@ public class PropertyFactory { } /** - * 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. + * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of {@link PropertyFactory#iconSize} to obtain the final offset in density-independent pixels. 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[] @@ -1870,10 +3042,19 @@ 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. Each component is multiplied by the value of {@link PropertyFactory#iconSize} to obtain the final offset in density-independent pixels. 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); + } /** - * 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. + * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of {@link PropertyFactory#iconSize} to obtain the final offset in density-independent pixels. When combined with {@link PropertyFactory#iconRotate} the offset will be as if the rotated direction was up. * * @param <T> the function input type * @param function a wrapper function for Float[] @@ -1893,6 +3074,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); + } /** @@ -1916,6 +3106,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); + } /** @@ -1939,6 +3138,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); + } /** @@ -1962,6 +3170,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); + } /** @@ -1976,7 +3193,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. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. * * @param value a String value * @return property wrapper around String @@ -1985,10 +3202,19 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-field", value); } + /** + * Value to use for a text label. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * + * @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. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. * * @param <T> the function input type * @param function a wrapper function for String @@ -2008,16 +3234,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); } @@ -2031,6 +3266,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); + } /** @@ -2054,6 +3298,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); + } /** @@ -2077,6 +3330,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); + } /** @@ -2100,6 +3362,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); + } /** @@ -2123,6 +3394,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); + } /** @@ -2146,6 +3426,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); + } /** @@ -2169,6 +3458,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); + } /** @@ -2192,6 +3490,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); + } /** @@ -2215,6 +3522,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); + } /** @@ -2238,6 +3554,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); + } /** @@ -2261,6 +3586,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); + } /** @@ -2284,6 +3618,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); + } /** @@ -2307,6 +3650,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); + } /** @@ -2330,6 +3682,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); + } /** @@ -2353,6 +3714,16 @@ 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. 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..a0f45535f6 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 @@ -250,24 +250,6 @@ public class RasterLayer extends Layer { return (PropertyValue<Float>) new PropertyValue("raster-fade-duration", nativeGetRasterFadeDuration()); } - /** - * Get the RasterFadeDuration property transition options - * - * @return transition options for Float - */ - public TransitionOptions getRasterFadeDurationTransition() { - return nativeGetRasterFadeDurationTransition(); - } - - /** - * Set the RasterFadeDuration property transition options - * - * @param options transition options for Float - */ - public void setRasterFadeDurationTransition(TransitionOptions options) { - nativeSetRasterFadeDurationTransition(options.getDuration(), options.getDelay()); - } - private native Object nativeGetRasterOpacity(); private native TransitionOptions nativeGetRasterOpacityTransition(); @@ -306,10 +288,6 @@ public class RasterLayer extends Layer { private native Object nativeGetRasterFadeDuration(); - private native TransitionOptions nativeGetRasterFadeDurationTransition(); - - private native void nativeSetRasterFadeDurationTransition(long duration, long delay); - @Override protected native void finalize() throws Throwable; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs index 56e0af8b45..77fa11808e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs @@ -78,7 +78,7 @@ public class <%- camelize(type) %>Layer extends Layer { } <% } -%> -<% if (type !== 'background' && type !== 'raster') { -%> +<% if (type !== 'background' && type !== 'raster' && type !== 'hillshade') { -%> /** * Get the source layer. * 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..283d4e4189 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 @@ -6,11 +6,13 @@ 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 @@ -36,6 +38,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 +66,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 +85,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 +99,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 +117,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)) { -%> @@ -131,9 +155,9 @@ public class PropertyFactory { <% } -%> <% } -%> - @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/sources/CustomGeometrySource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java new file mode 100644 index 0000000000..1b0999ae2e --- /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.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.style.layers.Filter; + +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 CustomGeometrySourceOptions()); + } + + /** + * Create a CustomGeometrySource with non-default CustomGeometrySourceOptions. + * <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 CustomGeometrySourceOptions. + */ + public CustomGeometrySource(String id, GeometryTileProvider provider, CustomGeometrySourceOptions 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/CustomGeometrySourceOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySourceOptions.java new file mode 100644 index 0000000000..4ada38c238 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySourceOptions.java @@ -0,0 +1,31 @@ +package com.mapbox.mapboxsdk.style.sources; + +/** + * Builder class for composing CustomGeometrySource objects. + */ +public class CustomGeometrySourceOptions extends GeoJsonOptions { + + /** + * If the data includes wrapped coordinates, setting this to true unwraps the coordinates. + * + * @param wrap defaults to false + * @return the current instance for chaining + */ + public CustomGeometrySourceOptions withWrap(boolean wrap) { + this.put("wrap", wrap); + return this; + } + + /** + * If the data includes geometry outside the tile boundaries, setting this to true clips the geometry + * to the tile boundaries. + * + * @param clip defaults to false + * @return the current instance for chaining + */ + public CustomGeometrySourceOptions withClip(boolean clip) { + this.put("clip", clip); + return this; + } + +} 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..79cde7429c 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 @@ -13,6 +13,17 @@ public class GeoJsonOptions extends HashMap<String, Object> { /** * Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels). * + * @param minZoom 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 */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java index 10ecb945ad..5c740554cd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java @@ -4,10 +4,10 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.UiThread; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.geojson.Geometry; import com.mapbox.mapboxsdk.style.layers.Filter; -import com.mapbox.services.commons.geojson.Feature; -import com.mapbox.services.commons.geojson.FeatureCollection; -import com.mapbox.services.commons.geojson.Geometry; import java.net.URL; import java.util.ArrayList; 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..17e7f0f5e4 --- /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.geojson.FeatureCollection; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; + +/** + * 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/style/sources/RasterDemSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java new file mode 100644 index 0000000000..ee6fc5d7b7 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java @@ -0,0 +1,93 @@ +package com.mapbox.mapboxsdk.style.sources; + +import android.support.annotation.Nullable; +import android.support.annotation.UiThread; + +import java.net.URL; + +/** + * A raster DEM source. Currently only supports Mapbox Terrain RGB (mapbox://mapbox.terrain-rgb) + * + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#sources-raster-dem">The style specification</a> + */ +@UiThread +public class RasterDemSource extends Source { + public static final int DEFAULT_TILE_SIZE = 512; + + /** + * Internal use + * + * @param nativePtr - pointer to native peer + */ + private RasterDemSource(long nativePtr) { + super(nativePtr); + } + + /** + * Create the raster dem source from an URL + * + * @param id the source id + * @param url the source url + */ + public RasterDemSource(String id, URL url) { + this(id, url.toExternalForm()); + } + + /** + * Create the raster dem source from an URL + * + * @param id the source id + * @param url the source url + */ + public RasterDemSource(String id, String url) { + initialize(id, url, DEFAULT_TILE_SIZE); + } + + /** + * Create the raster source from an URL with a specific tile size + * + * @param id the source id + * @param url the source url + * @param tileSize the tile size + */ + public RasterDemSource(String id, String url, int tileSize) { + initialize(id, url, tileSize); + } + + /** + * Create the raster dem source from a {@link TileSet} + * + * @param id the source id + * @param tileSet the {@link TileSet} + */ + public RasterDemSource(String id, TileSet tileSet) { + initialize(id, tileSet.toValueObject(), DEFAULT_TILE_SIZE); + } + + /** + * Create the raster source from a {@link TileSet} with a specific tile size + * + * @param id the source id + * @param tileSet the {@link TileSet} + * @param tileSize tje tile size + */ + public RasterDemSource(String id, TileSet tileSet, int tileSize) { + initialize(id, tileSet.toValueObject(), tileSize); + } + + /** + * @return The url or null + */ + @Nullable + public String getUrl() { + return nativeGetUrl(); + } + + protected native void initialize(String layerId, Object payload, int tileSize); + + @Override + protected native void finalize() throws Throwable; + + protected native String nativeGetUrl(); + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java index 9b59cf8967..62b08a90ed 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java @@ -5,8 +5,8 @@ import android.support.annotation.Nullable; import android.support.annotation.Size; import android.support.annotation.UiThread; +import com.mapbox.geojson.Feature; import com.mapbox.mapboxsdk.style.layers.Filter; -import com.mapbox.services.commons.geojson.Feature; import java.net.URL; import java.util.ArrayList; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java new file mode 100644 index 0000000000..0c90e4b244 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java @@ -0,0 +1,49 @@ +package com.mapbox.mapboxsdk.utils; + +// TODO Remove this class if we finally include it within MAS 3.x (GeoJSON) +public class MathUtils { + + /** + * Test a value in specified range, returning minimum if it's below, and maximum if it's above + * + * @param value Value to test + * @param min Minimum value of range + * @param max Maximum value of range + * @return value if it's between min and max, min if it's below, max if it's above + */ + public static double clamp(double value, double min, double max) { + return Math.max(min, Math.min(max, value)); + } + + /** + * Test a value in specified range, returning minimum if it's below, and maximum if it's above + * + * @param value Value to test + * @param min Minimum value of range + * @param max Maximum value of range + * @return value if it's between min and max, min if it's below, max if it's above + */ + public static float clamp(float value, float min, float max) { + return Math.max(min, Math.min(max, value)); + } + + /** + * Constrains value to the given range (including min, excluding max) via modular arithmetic. + * <p> + * Same formula as used in Core GL (wrap.hpp) + * std::fmod((std::fmod((value - min), d) + d), d) + min; + * + * @param value Value to wrap + * @param min Minimum value + * @param max Maximum value + * @return Wrapped value + */ + public static double wrap(double value, double min, double max) { + double delta = max - min; + + double firstMod = (value - min) % delta; + double secondMod = (firstMod + delta) % delta; + + return secondMod + min; + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml index 48d90c3324..9548bf9b3d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml @@ -1,15 +1,16 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <string name="mapbox_compassContentDescription">Boussole. Activer pour rétablir l\'orientation de la carte vers le nord.</string> - <string name="mapbox_attributionsIconContentDescription">Icone d\'attribution. Activer pour montrer le dialogue d\'attribution.</string> + <string name="mapbox_compassContentDescription">Boussole. Activer pour rétablir l’orientation de la carte vers le nord.</string> + <string name="mapbox_attributionsIconContentDescription">Icône d’attribution. Activer pour afficher le dialogue d’attribution.</string> <string name="mapbox_myLocationViewContentDescription">Vue de géolocalisation. Ceci affiche votre localisation sur la carte.</string> - <string name="mapbox_mapActionDescription">Affichage d\'une carte créée avec Mapbox. Faites la glisser en traînant deux doigts. Zoomez ou dézoomez en écartant ou rapprochant deux doigts.</string> - <string name="mapbox_attributionsDialogTitle">SDK Mapbox pour Android</string> + <string name="mapbox_mapActionDescription">Affichage d’une carte créée avec Mapbox. Faites la glisser en traînant deux doigts. Zoomez ou dézoomez en écartant ou rapprochant deux doigts.</string> + <string name="mapbox_attributionsDialogTitle">SDK Mapbox Maps pour Android</string> <string name="mapbox_attributionTelemetryTitle">Faire de meilleures cartes Mapbox</string> <string name="mapbox_attributionTelemetryMessage">Vous aidez à améliorer les cartes OpenStreetMap et Mapbox en contribuant des données d\'utilisation anonymes.</string> - <string name="mapbox_attributionTelemetryPositive">D\'accord</string> - <string name="mapbox_attributionTelemetryNegative">Pas d\'accord</string> - <string name="mapbox_attributionTelemetryNeutral">Plus d\'informations</string> + <string name="mapbox_attributionTelemetryPositive">D’accord</string> + <string name="mapbox_attributionTelemetryNegative">Pas d’accord</string> + <string name="mapbox_attributionTelemetryNeutral">Plus d’informations</string> + <string name="mapbox_attributionErrorNoBrowser">Aucun navigateur web installé sur l’appareil, impossible d’ouvrir une page web.</string> <string name="mapbox_offline_error_region_definition_invalid">Le cadre OfflineRegionDefinition pour définir la région de navigation ne tient pas dans les limites du monde : %s</string> - + <string name="mapbox_telemetrySettings">Paramètres de télémétrie</string> </resources> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-iw/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-iw/strings.xml new file mode 100644 index 0000000000..11b20f5dc5 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-iw/strings.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="mapbox_compassContentDescription">מצפן. הפעל בכדי לקבע את כיוון המפה צפונה.</string> + <string name="mapbox_attributionsIconContentDescription">סמל שיוך. הפעל כדי להציג תיבת דו-שיח של שיוך.</string> + <string name="mapbox_myLocationViewContentDescription">סמן מיקום. מציג את המיקום הנוכחי שלך על המפה.</string> + <string name="mapbox_mapActionDescription">מציג מפה שנוצרה עם Mapbox. גלול באמצעות גרירה עם שתי אצבעות, זום באמצעות צביטה עם שתי אצבעות.</string> + <string name="mapbox_attributionsDialogTitle">Mapbox Maps SDK for Android</string> + <string name="mapbox_attributionTelemetryTitle">שפר את המפות של Mapbox </string> + <string name="mapbox_attributionTelemetryMessage">אתם מסייעים לשפר את המפות של OpenStreetMap ו Mapbox באמצעות שיתוף אנונימי של נתוני השימוש.</string> + <string name="mapbox_attributionTelemetryPositive">מסכים/מה</string> + <string name="mapbox_attributionTelemetryNegative">לא מסכים/מה</string> + <string name="mapbox_attributionTelemetryNeutral">מידע נוסף</string> + <string name="mapbox_attributionErrorNoBrowser">לא מותקן דפדפן אינטרנט במכשיר, לא ניתן לפתוח את דף האינטרנט.</string> + <string name="mapbox_offline_error_region_definition_invalid">בתנאי ש- OfflineRegionDefinition אינו מתאים לגבולות העולם: %s</string> + <string name="mapbox_telemetrySettings">הגדרות טלמטריות</string> + </resources> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-sv/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-sv/strings.xml index c9474fa473..9537299a72 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values-sv/strings.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-sv/strings.xml @@ -4,12 +4,13 @@ <string name="mapbox_attributionsIconContentDescription">Tillskrivningsikon. Aktivera för att visa tillskrivningsdialog.</string> <string name="mapbox_myLocationViewContentDescription">Positionsvy. Denna visar din position på kartan.</string> <string name="mapbox_mapActionDescription">Visar en karta skapad med Mapbox. Scrolla genom att dra med två fingrar. Zooma genom att nypa med två fingrar.</string> - <string name="mapbox_attributionsDialogTitle">Mapbox Android SDK</string> + <string name="mapbox_attributionsDialogTitle">Mapbox Maps SDK for Android</string> <string name="mapbox_attributionTelemetryTitle">Gör Mapbox kartor bättre</string> <string name="mapbox_attributionTelemetryMessage">Du hjälper till att göra OpenStreetMap och Mapbox karttjänster bättre genom att bidra med anonymiserad användningsdata.</string> <string name="mapbox_attributionTelemetryPositive">Godkänn</string> <string name="mapbox_attributionTelemetryNegative">Avböj</string> <string name="mapbox_attributionTelemetryNeutral">Visa mer information</string> + <string name="mapbox_attributionErrorNoBrowser">Ingen webbläsare installerad på enheten. Kan inte visa sidan.</string> <string name="mapbox_offline_error_region_definition_invalid">Försedd OfflineRegionDefinition passar inte världens gränser: %s</string> - + <string name="mapbox_telemetrySettings">Telemetri-inställningar</string> </resources> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-uk/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-uk/strings.xml index 64c7e3efcc..17e13a1fe6 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values-uk/strings.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-uk/strings.xml @@ -4,12 +4,13 @@ <string name="mapbox_attributionsIconContentDescription">Значок атрибуції. Натисніть, щоб показати діалог атрибуції.</string> <string name="mapbox_myLocationViewContentDescription">Визначення положення. Показує ваше місцеположення на мапі.</string> <string name="mapbox_mapActionDescription">Показує мапи створені за допомоги Mapbox. Пересувайте мапу двома пальцями. Змінюйте масштаб стуляючи/розводячи два пальці.</string> - <string name="mapbox_attributionsDialogTitle">Mapbox Android SDK</string> + <string name="mapbox_attributionsDialogTitle">Mapbox Maps SDK для Android</string> <string name="mapbox_attributionTelemetryTitle">Допоможіть зробити мапи Mapbox краще</string> <string name="mapbox_attributionTelemetryMessage">Ви допомагаєте робити мапи OpenStreetMap та Mapbox краще пощирюючи анонімні дані про користування мапами.</string> <string name="mapbox_attributionTelemetryPositive">Погоджуюсь</string> <string name="mapbox_attributionTelemetryNegative">Не погоджуюсь</string> <string name="mapbox_attributionTelemetryNeutral">Додаткова інформація</string> + <string name="mapbox_attributionErrorNoBrowser">Веб-оглядач відсутній на цьому пристрої, неможливо відкрити веб-сторінку</string> <string name="mapbox_offline_error_region_definition_invalid">Межі ділянки для оффлайнового користування даними за межами світу: %s</string> - + <string name="mapbox_telemetrySettings">Налаштування телеметрії</string> </resources> diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java index 7a28d846ea..d9e3ae427d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java @@ -5,7 +5,7 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException; -import com.mapbox.services.android.telemetry.location.LocationEngine; +import com.mapbox.android.core.location.LocationEngine; import org.junit.Before; import org.junit.Test; 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..f03bbdb11c 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,11 +2,14 @@ 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; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.util.ArrayList; import java.util.List; @@ -68,6 +71,82 @@ public class LatLngBoundsTest { } @Test + public void dateLineSpanBuilder1() { + latLngBounds = new LatLngBounds.Builder() + .include(new LatLng(10, -170)) + .include(new LatLng(-10, 170)) + .build(); + + LatLngSpan latLngSpan = latLngBounds.getSpan(); + assertEquals("LatLngSpan should be shortest distance", new LatLngSpan(20, 20), + latLngSpan); + } + + @Test + public void dateLineSpanBuilder2() { + latLngBounds = new LatLngBounds.Builder() + .include(new LatLng(-10, -170)) + .include(new LatLng(10, 170)) + .build(); + + LatLngSpan latLngSpan = latLngBounds.getSpan(); + assertEquals("LatLngSpan should be shortest distance", new LatLngSpan(20, 20), + latLngSpan); + } + + @Test + public void dateLineSpanFrom1() { + latLngBounds = LatLngBounds.from(10, -170, -10, 170); + LatLngSpan latLngSpan = latLngBounds.getSpan(); + assertEquals("LatLngSpan should be shortest distance", new LatLngSpan(20, 20), + latLngSpan); + } + + @Test + public void dateLineSpanFrom2() { + latLngBounds = LatLngBounds.from(10, 170, -10, -170); + LatLngSpan latLngSpan = latLngBounds.getSpan(); + assertEquals("LatLngSpan should be shortest distance", new LatLngSpan(20, 340), + latLngSpan); + } + + @Test + public void nearDateLineCenter1() { + latLngBounds = LatLngBounds.from(10, -175, -10, 165); + LatLng center = latLngBounds.getCenter(); + assertEquals("Center should match", new LatLng(0, 175), center); + } + + @Test + public void nearDateLineCenter2() { + latLngBounds = LatLngBounds.from(10, -165, -10, 175); + LatLng center = latLngBounds.getCenter(); + assertEquals("Center should match", new LatLng(0, -175), center); + } + + @Test + public void nearDateLineCenter3() { + latLngBounds = LatLngBounds.from(10, -170, -10, 170); + LatLng center = latLngBounds.getCenter(); + assertEquals("Center should match", new LatLng(0, -180), center); + } + + @Test + public void nearDateLineCenter4() { + latLngBounds = LatLngBounds.from(10, -180, -10, 0); + LatLng center = latLngBounds.getCenter(); + assertEquals("Center should match", new LatLng(0, 90), center); + } + + @Test + public void nearDateLineCenter5() { + latLngBounds = LatLngBounds.from(10, 180, -10, 0); + LatLng center = latLngBounds.getCenter(); + assertEquals("Center should match", new LatLng(0, 90), center); + } + + + @Test public void center() { LatLng center = latLngBounds.getCenter(); assertEquals("Center should match", new LatLng(1, 1), center); @@ -118,6 +197,46 @@ public class LatLngBoundsTest { } @Test + public void includesOverDateline1() { + + LatLngBounds latLngBounds = new LatLngBounds.Builder() + .include(new LatLng(10, -170)) + .include(new LatLng(-10, -175)) + .include(new LatLng(0, 170)) + .build(); + + assertEquals("LatLngSpan should be the same", + new LatLngSpan(20, 20), latLngBounds.getSpan()); + } + + @Test + public void includesOverDateline2() { + + LatLngBounds latLngBounds = new LatLngBounds.Builder() + .include(new LatLng(10, 170)) + .include(new LatLng(-10, 175)) + .include(new LatLng(0, -170)) + .build(); + + assertEquals("LatLngSpan should be the same", + new LatLngSpan(20, 20), latLngBounds.getSpan()); + } + + @Test + public void includesOverDateline3() { + + LatLngBounds latLngBounds = new LatLngBounds.Builder() + .include(new LatLng(10, 170)) + .include(new LatLng(-10, -170)) + .include(new LatLng(0, -180)) + .include(new LatLng(5, 180)) + .build(); + + assertEquals("LatLngSpan should be the same", + new LatLngSpan(20, 20), latLngBounds.getSpan()); + } + + @Test public void containsNot() { assertFalse("LatLng should not be included", latLngBounds.contains(new LatLng(3, 1))); } @@ -128,6 +247,21 @@ public class LatLngBoundsTest { } @Test + public void worldSpan() { + assertEquals("LatLngBounds world span should be 180, 360", + GeometryConstants.LATITUDE_SPAN, LatLngBounds.world().getLatitudeSpan(), DELTA); + assertEquals("LatLngBounds world span should be 180, 360", + GeometryConstants.LONGITUDE_SPAN, LatLngBounds.world().getLongitudeSpan(), DELTA); + } + + @Test + public void emptySpan() { + LatLngBounds latLngBounds = LatLngBounds.from(GeometryConstants.MIN_LATITUDE, GeometryConstants.MAX_LONGITUDE, + GeometryConstants.MIN_LATITUDE, GeometryConstants.MAX_LONGITUDE); + assertTrue("LatLngBounds empty span", latLngBounds.isEmptySpan()); + } + + @Test public void containsBounds() { LatLngBounds inner = new LatLngBounds.Builder() .include(new LatLng(-5, -5)) @@ -272,4 +406,94 @@ 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); + + } + + @Rule + public final ExpectedException exception = ExpectedException.none(); + + @Test + public void testConstructorChecksNorthLatitudeNaN() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("latitude must not be NaN"); + LatLngBounds.from(Double.NaN, 0, -20, -20); + } + + @Test + public void testConstructorChecksEastLongitudeNaN() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("longitude must not be NaN"); + LatLngBounds.from(0, Double.NaN, -20, -20); + } + + @Test + public void testConstructorChecksNorthLatitudeGreaterThan90() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("latitude must be between -90 and 90"); + LatLngBounds.from(95, 0, -20, -20); + } + + @Test + public void testConstructorChecksNorthLatitudeLessThanThanNegative90() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("latitude must be between -90 and 90"); + LatLngBounds.from(-95, 0, -20, -20); + } + + @Test + public void testConstructorChecksEastLongitudeInfinity() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("longitude must not be infinite"); + LatLngBounds.from(0, Double.POSITIVE_INFINITY, -20, -20); + } + + + @Test + public void testConstructorChecksSouthLatitudeNaN() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("latitude must not be NaN"); + LatLngBounds.from(20, 20, Double.NaN, 0); + } + + @Test + public void testConstructorChecksWesttLongitudeNaN() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("longitude must not be NaN"); + LatLngBounds.from(20, 20, 0, Double.NaN); + } + + @Test + public void testConstructorChecksSouthLatitudeGreaterThan90() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("latitude must be between -90 and 90"); + LatLngBounds.from(20, 20,95, 0); + } + + @Test + public void testConstructorChecksSouthLatitudeLessThanThanNegative90() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("latitude must be between -90 and 90"); + LatLngBounds.from(20, 20, -95, 0); + } + + @Test + public void testConstructorChecksWestLongitudeInfinity() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("longitude must not be infinite"); + LatLngBounds.from(20, 20, 0, Double.POSITIVE_INFINITY); + } } 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..c0b7832727 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java @@ -0,0 +1,1033 @@ +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; +import static org.junit.Assert.assertEquals; + +/** + * 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)); + } + + @Test + public void testExpressionConcatToString() throws Exception { + String expected = "[\"concat\", foo, bar]"; + String actual = concat(literal("foo"), literal("bar")).toString(); + assertEquals("toString should match", expected, actual); + } + + @Test + public void testExpressionMinToString() throws Exception { + String expected = "[\"min\", 0, 1, 2, 3]"; + String actual = min(0, 1, 2, 3).toString(); + assertEquals("toString should match", expected, actual); + } + + @Test + public void testExpressionExponentialToString() throws Exception { + String expected = "[\"interpolate\", [\"cubic-bezier\", 1, 1, 1, 1], [\"get\", x], 0, 100, 100, 200]"; + String actual = interpolate(cubicBezier(literal(1), literal(1), literal(1), literal(1)), + get(literal("x")), literal(0), literal(100), literal(100), literal(200)).toString(); + assertEquals("toString should match", expected, actual); + } +}
\ No newline at end of file |