diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src')
10 files changed, 147 insertions, 71 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/annotation.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/annotation.java.ejs index cf62963a78..60bdd1ffa1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/annotation.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/annotation.java.ejs @@ -21,7 +21,9 @@ import java.util.List; public class <%- camelize(type) %> { public static final String ID_KEY = "id-<%- type %>"; - +<% if (type === "symbol") { -%> + public static final String Z_INDEX = "z-index"; +<% } -%> private final <%- camelize(type) %>Manager <%- type %>Manager; private final JsonObject jsonObject = new JsonObject(); private Geometry geometry; @@ -35,6 +37,9 @@ public class <%- camelize(type) %> { <%- camelize(type) %>(<%- camelize(type) %>Manager manager, long id) { this.<%- type %>Manager = manager; this.jsonObject.addProperty(ID_KEY, id); +<% if (type === "symbol") { -%> + this.jsonObject.addProperty(Z_INDEX, 0); +<% } -%> } /** @@ -112,6 +117,33 @@ public class <%- camelize(type) %> { fillManager.updateSource(); } <% } -%> +<% if (type === "symbol") { -%> + + /** + * Set the z-index of a symbol. + * <p> + * If a symbol z-index is higher as another symbol it will be rendered above it. + * </p> + * <p> + * Default value is 0. + * </p> + * + * @param index the z-index value + */ + public void setZIndex(int index) { + jsonObject.addProperty(Z_INDEX, index); + symbolManager.updateSource(); + } + + /** + * Get the z-index of a symbol. + * + * @return the z-index value, 0 if not set + */ + public int getZIndex() { + return jsonObject.get(Z_INDEX).getAsInt(); + } +<% } -%> // Property accessors <% for (const property of properties) { -%> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/annotationManager.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/annotationManager.java.ejs index ad69520cf3..6aa8ddd771 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/annotationManager.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/annotationManager.java.ejs @@ -23,10 +23,13 @@ import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import static com.mapbox.mapboxsdk.style.expressions.Expression.get; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; +import static com.mapbox.mapboxsdk.annotations.symbol.Symbol.Z_INDEX; /** * The <%- type %> manager allows to add <%- type %>s to a map. @@ -49,6 +52,10 @@ public class <%- camelize(type) %>Manager { private final LongSparseArray<<%- camelize(type) %>> <%- type %>s = new LongSparseArray<>(); private final List<Feature> features = new ArrayList<>(); private long currentId; +<% if (type === "symbol") { -%> + + private final SymbolComparator symbolComparator = new SymbolComparator(); +<% } -%> /** * Create a <%- type %> manager, used to manage <%- type %>s. @@ -171,6 +178,9 @@ public class <%- camelize(type) %>Manager { <%- type %> = <%- type %>s.valueAt(i); features.add(Feature.fromGeometry(<%- type %>.getGeometry(), <%- type %>.getFeature())); } +<% if (type === "symbol") { -%> + Collections.sort(features, symbolComparator); +<% } -%> geoJsonSource.setGeoJson(FeatureCollection.fromFeatures(features)); } @@ -200,14 +210,17 @@ public class <%- camelize(type) %>Manager { return new PropertyValue[]{ <% for (const property of properties) { -%> <% if (supportsPropertyFunction(property) && property.name !== "fill-pattern" && property.name !== "line-pattern") { -%> - <%- camelizeWithLeadingLowercase(property.name) %>(get("<%- property.name %>")), + <%- camelizeWithLeadingLowercase(property.name) %>(get("<%- property.name %>")), <% } -%><% } -%> +<% if (type === "symbol") { -%> + symbolZOrder(Property.SYMBOL_Z_ORDER_SOURCE) +<% } -%> }; } // Property accessors <% for (const property of properties) { -%> -<% if (!supportsPropertyFunction(property) && property.name !== "line-gradient") { -%> +<% if (!supportsPropertyFunction(property) && property.name !== "line-gradient" && property.name !== "symbol-z-order") { -%> /** * Get the <%- camelize(property.name) %> property * @@ -259,5 +272,13 @@ public class <%- camelize(type) %>Manager { } } } +<% if (type === "symbol") { -%> + private class SymbolComparator implements Comparator<Feature> { + @Override + public int compare(Feature left, Feature right) { + return right.getProperty(Z_INDEX).getAsInt() - left.getProperty(Z_INDEX).getAsInt(); + } + } +<% } -%> } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/circle/Circle.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/circle/Circle.java index 354790ff57..19d97b714a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/circle/Circle.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/circle/Circle.java @@ -16,7 +16,6 @@ import java.util.List; public class Circle { public static final String ID_KEY = "id-circle"; - private final CircleManager circleManager; private final JsonObject jsonObject = new JsonObject(); private Geometry geometry; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/circle/CircleManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/circle/CircleManager.java index 5cc1af7d0f..e780fd7062 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/circle/CircleManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/circle/CircleManager.java @@ -18,10 +18,13 @@ import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import static com.mapbox.mapboxsdk.style.expressions.Expression.get; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; +import static com.mapbox.mapboxsdk.annotations.symbol.Symbol.Z_INDEX; /** * The circle manager allows to add circles to a map. @@ -159,13 +162,13 @@ public class CircleManager { private static PropertyValue<?>[] getLayerDefinition() { return new PropertyValue[]{ - circleRadius(get("circle-radius")), - circleColor(get("circle-color")), - circleBlur(get("circle-blur")), - circleOpacity(get("circle-opacity")), - circleStrokeWidth(get("circle-stroke-width")), - circleStrokeColor(get("circle-stroke-color")), - circleStrokeOpacity(get("circle-stroke-opacity")), + circleRadius(get("circle-radius")), + circleColor(get("circle-color")), + circleBlur(get("circle-blur")), + circleOpacity(get("circle-opacity")), + circleStrokeWidth(get("circle-stroke-width")), + circleStrokeColor(get("circle-stroke-color")), + circleStrokeOpacity(get("circle-stroke-opacity")), }; } @@ -276,5 +279,4 @@ public class CircleManager { } } } - } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/fill/Fill.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/fill/Fill.java index 1fb1d767f0..1686deb180 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/fill/Fill.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/fill/Fill.java @@ -16,7 +16,6 @@ import java.util.List; public class Fill { public static final String ID_KEY = "id-fill"; - private final FillManager fillManager; private final JsonObject jsonObject = new JsonObject(); private Geometry geometry; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/fill/FillManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/fill/FillManager.java index c3cd03a691..ffcaefb7e6 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/fill/FillManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/fill/FillManager.java @@ -18,10 +18,13 @@ import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import static com.mapbox.mapboxsdk.style.expressions.Expression.get; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; +import static com.mapbox.mapboxsdk.annotations.symbol.Symbol.Z_INDEX; /** * The fill manager allows to add fills to a map. @@ -159,9 +162,9 @@ public class FillManager { private static PropertyValue<?>[] getLayerDefinition() { return new PropertyValue[]{ - fillOpacity(get("fill-opacity")), - fillColor(get("fill-color")), - fillOutlineColor(get("fill-outline-color")), + fillOpacity(get("fill-opacity")), + fillColor(get("fill-color")), + fillOutlineColor(get("fill-outline-color")), }; } @@ -253,5 +256,4 @@ public class FillManager { } } } - } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/line/Line.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/line/Line.java index 2dca2b6bf3..d7c62dfe92 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/line/Line.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/line/Line.java @@ -16,7 +16,6 @@ import java.util.List; public class Line { public static final String ID_KEY = "id-line"; - private final LineManager lineManager; private final JsonObject jsonObject = new JsonObject(); private Geometry geometry; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/line/LineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/line/LineManager.java index 3e285bdd8d..c326fd95dd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/line/LineManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/line/LineManager.java @@ -18,10 +18,13 @@ import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import static com.mapbox.mapboxsdk.style.expressions.Expression.get; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; +import static com.mapbox.mapboxsdk.annotations.symbol.Symbol.Z_INDEX; /** * The line manager allows to add lines to a map. @@ -159,13 +162,13 @@ public class LineManager { private static PropertyValue<?>[] getLayerDefinition() { return new PropertyValue[]{ - lineJoin(get("line-join")), - lineOpacity(get("line-opacity")), - lineColor(get("line-color")), - lineWidth(get("line-width")), - lineGapWidth(get("line-gap-width")), - lineOffset(get("line-offset")), - lineBlur(get("line-blur")), + lineJoin(get("line-join")), + lineOpacity(get("line-opacity")), + lineColor(get("line-color")), + lineWidth(get("line-width")), + lineGapWidth(get("line-gap-width")), + lineOffset(get("line-offset")), + lineBlur(get("line-blur")), }; } @@ -314,5 +317,4 @@ public class LineManager { } } } - } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/symbol/Symbol.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/symbol/Symbol.java index dec408225e..a2e17defdc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/symbol/Symbol.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/symbol/Symbol.java @@ -16,7 +16,7 @@ import java.util.List; public class Symbol { public static final String ID_KEY = "id-symbol"; - + public static final String Z_INDEX = "z-index"; private final SymbolManager symbolManager; private final JsonObject jsonObject = new JsonObject(); private Geometry geometry; @@ -30,6 +30,7 @@ public class Symbol { Symbol(SymbolManager manager, long id) { this.symbolManager = manager; this.jsonObject.addProperty(ID_KEY, id); + this.jsonObject.addProperty(Z_INDEX, 0); } /** @@ -72,6 +73,31 @@ public class Symbol { symbolManager.updateSource(); } + /** + * Set the z-index of a symbol. + * <p> + * If a symbol z-index is higher as another symbol it will be rendered above it. + * </p> + * <p> + * Default value is 0. + * </p> + * + * @param index the z-index value + */ + public void setZIndex(int index) { + jsonObject.addProperty(Z_INDEX, index); + symbolManager.updateSource(); + } + + /** + * Get the z-index of a symbol. + * + * @return the z-index value, 0 if not set + */ + public int getZIndex() { + return jsonObject.get(Z_INDEX).getAsInt(); + } + // Property accessors /** * Get the IconSize property diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/symbol/SymbolManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/symbol/SymbolManager.java index a81200a55f..bbe89e847a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/symbol/SymbolManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/symbol/SymbolManager.java @@ -18,10 +18,13 @@ import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import static com.mapbox.mapboxsdk.style.expressions.Expression.get; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; +import static com.mapbox.mapboxsdk.annotations.symbol.Symbol.Z_INDEX; /** * The symbol manager allows to add symbols to a map. @@ -45,6 +48,8 @@ public class SymbolManager { private final List<Feature> features = new ArrayList<>(); private long currentId; + private final SymbolComparator symbolComparator = new SymbolComparator(); + /** * Create a symbol manager, used to manage symbols. * @@ -132,6 +137,7 @@ public class SymbolManager { symbol = symbols.valueAt(i); features.add(Feature.fromGeometry(symbol.getGeometry(), symbol.getFeature())); } + Collections.sort(features, symbolComparator); geoJsonSource.setGeoJson(FeatureCollection.fromFeatures(features)); } @@ -159,31 +165,32 @@ public class SymbolManager { private static PropertyValue<?>[] getLayerDefinition() { return new PropertyValue[]{ - iconSize(get("icon-size")), - iconImage(get("icon-image")), - iconRotate(get("icon-rotate")), - iconOffset(get("icon-offset")), - iconAnchor(get("icon-anchor")), - textField(get("text-field")), - textFont(get("text-font")), - textSize(get("text-size")), - textMaxWidth(get("text-max-width")), - textLetterSpacing(get("text-letter-spacing")), - textJustify(get("text-justify")), - textAnchor(get("text-anchor")), - textRotate(get("text-rotate")), - textTransform(get("text-transform")), - textOffset(get("text-offset")), - iconOpacity(get("icon-opacity")), - iconColor(get("icon-color")), - iconHaloColor(get("icon-halo-color")), - iconHaloWidth(get("icon-halo-width")), - iconHaloBlur(get("icon-halo-blur")), - textOpacity(get("text-opacity")), - textColor(get("text-color")), - textHaloColor(get("text-halo-color")), - textHaloWidth(get("text-halo-width")), - textHaloBlur(get("text-halo-blur")), + iconSize(get("icon-size")), + iconImage(get("icon-image")), + iconRotate(get("icon-rotate")), + iconOffset(get("icon-offset")), + iconAnchor(get("icon-anchor")), + textField(get("text-field")), + textFont(get("text-font")), + textSize(get("text-size")), + textMaxWidth(get("text-max-width")), + textLetterSpacing(get("text-letter-spacing")), + textJustify(get("text-justify")), + textAnchor(get("text-anchor")), + textRotate(get("text-rotate")), + textTransform(get("text-transform")), + textOffset(get("text-offset")), + iconOpacity(get("icon-opacity")), + iconColor(get("icon-color")), + iconHaloColor(get("icon-halo-color")), + iconHaloWidth(get("icon-halo-width")), + iconHaloBlur(get("icon-halo-blur")), + textOpacity(get("text-opacity")), + textColor(get("text-color")), + textHaloColor(get("text-halo-color")), + textHaloWidth(get("text-halo-width")), + textHaloBlur(get("text-halo-blur")), + symbolZOrder(Property.SYMBOL_Z_ORDER_SOURCE) }; } @@ -246,25 +253,6 @@ public class SymbolManager { } /** - * Get the SymbolZOrder property - * - * @return property wrapper value around String - */ - @Property.SYMBOL_Z_ORDER - public String getSymbolZOrder() { - return layer.getSymbolZOrder().value; - } - - /** - * Set the SymbolZOrder property - * - * @param value property wrapper value around String - */ - public void setSymbolZOrder(@Property.SYMBOL_Z_ORDER String value) { - layer.setProperties(symbolZOrder(value)); - } - - /** * Get the IconAllowOverlap property * * @return property wrapper value around Boolean @@ -713,4 +701,10 @@ public class SymbolManager { } } + private class SymbolComparator implements Comparator<Feature> { + @Override + public int compare(Feature left, Feature right) { + return right.getProperty(Z_INDEX).getAsInt() - left.getProperty(Z_INDEX).getAsInt(); + } + } } |