diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2018-08-30 17:23:12 +0200 |
---|---|---|
committer | tobrun <tobrun.van.nuland@gmail.com> | 2018-09-06 11:49:35 +0200 |
commit | 98f05d736a550c20357a44b660f0f083b3121dc7 (patch) | |
tree | 8e38840dba1564ff808eb0a4e89883c25ebab76b | |
parent | 315a9e3cdfef828da9d359209ce367d0d2b3ebe8 (diff) | |
download | qtlocation-mapboxgl-98f05d736a550c20357a44b660f0f083b3121dc7.tar.gz |
[android] - code generation for a high level symbol api
12 files changed, 2483 insertions, 1 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/Symbol.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/Symbol.java new file mode 100644 index 0000000000..f4155e1b07 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/Symbol.java @@ -0,0 +1,566 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.symbol; + +import android.support.annotation.UiThread; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.mapbox.geojson.Geometry; +import com.mapbox.geojson.Point; +import com.mapbox.mapboxsdk.geometry.LatLng; + +@UiThread +public class Symbol { + + public static final String ID_KEY = "id-symbol"; + + private final SymbolManager symbolManager; + private final JsonObject jsonObject = new JsonObject(); + private Geometry geometry; + + /** + * Create a symbol. + * + * @param symbolManager the symbol manager created and managing the symbol + * @param id the id of the symbol + */ + Symbol(SymbolManager symbolManager, long id) { + this.symbolManager = symbolManager; + this.jsonObject.addProperty(ID_KEY, id); + } + + /** + * Get the symbol geometry. + * + * @return the symbol geometry + */ + Geometry getGeometry() { + if (geometry == null) { + throw new IllegalStateException(); + } + return geometry; + } + + /** + * Get the symbol feature properties. + * + * @return the symbol feature properties + */ + JsonObject getFeature() { + return jsonObject; + } + + /** + * Set the LatLng of the symbol, which represents the location of the symbol on the map + * + * @param latLng the location of the symbol in a longitude and latitude pair + */ + public void setLatLng(LatLng latLng) { + geometry = Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()); + symbolManager.updateSource(); + } + + // Property accessors + /** + * Get the IconSize property + * + * @return property wrapper value around Float + */ + public Float getIconSize() { + return jsonObject.get("icon-size").getAsFloat(); + } + + /** + * Set the IconSize property + * + * @return property wrapper value around Float + */ + public void setIconSize(Float value) { + jsonObject.addProperty("icon-size", value); + symbolManager.updateSource(); + } + + /** + * Get the IconImage property + * + * @return property wrapper value around String + */ + public String getIconImage() { + return jsonObject.get("icon-image").getAsString(); + } + + /** + * Set the IconImage property + * + * @return property wrapper value around String + */ + public void setIconImage(String value) { + jsonObject.addProperty("icon-image", value); + symbolManager.updateSource(); + } + + /** + * Get the IconRotate property + * + * @return property wrapper value around Float + */ + public Float getIconRotate() { + return jsonObject.get("icon-rotate").getAsFloat(); + } + + /** + * Set the IconRotate property + * + * @return property wrapper value around Float + */ + public void setIconRotate(Float value) { + jsonObject.addProperty("icon-rotate", value); + symbolManager.updateSource(); + } + + /** + * Get the IconOffset property + * + * @return property wrapper value around Float[] + */ + public Float[] getIconOffset() { + JsonArray jsonArray = jsonObject.getAsJsonArray("icon-offset"); + Float[] value = new Float[jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + value[i] = jsonArray.get(i).getAsFloat(); + } + return value; + } + + /** + * Set the IconOffset property + * + * @return property wrapper value around Float[] + */ + public void setIconOffset(Float[] value) { + JsonArray jsonArray = new JsonArray(); + for (Float element : value) { + jsonArray.add(element); + } + jsonObject.add("icon-offset", jsonArray); + symbolManager.updateSource(); + } + + /** + * Get the IconAnchor property + * + * @return property wrapper value around String + */ + public String getIconAnchor() { + return jsonObject.get("icon-anchor").getAsString(); + } + + /** + * Set the IconAnchor property + * + * @return property wrapper value around String + */ + public void setIconAnchor(String value) { + jsonObject.addProperty("icon-anchor", value); + symbolManager.updateSource(); + } + + /** + * Get the TextField property + * + * @return property wrapper value around String + */ + public String getTextField() { + return jsonObject.get("text-field").getAsString(); + } + + /** + * Set the TextField property + * + * @return property wrapper value around String + */ + public void setTextField(String value) { + jsonObject.addProperty("text-field", value); + symbolManager.updateSource(); + } + + /** + * Get the TextFont property + * + * @return property wrapper value around String[] + */ + public String[] getTextFont() { + JsonArray jsonArray = jsonObject.getAsJsonArray("text-font"); + String[] value = new String[jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + value[i] = jsonArray.get(i).getAsString(); + } + return value; + } + + /** + * Set the TextFont property + * + * @return property wrapper value around String[] + */ + public void setTextFont(String[] value) { + JsonArray jsonArray = new JsonArray(); + for (String element : value) { + jsonArray.add(element); + } + jsonObject.add("text-font", jsonArray); + symbolManager.updateSource(); + } + + /** + * Get the TextSize property + * + * @return property wrapper value around Float + */ + public Float getTextSize() { + return jsonObject.get("text-size").getAsFloat(); + } + + /** + * Set the TextSize property + * + * @return property wrapper value around Float + */ + public void setTextSize(Float value) { + jsonObject.addProperty("text-size", value); + symbolManager.updateSource(); + } + + /** + * Get the TextMaxWidth property + * + * @return property wrapper value around Float + */ + public Float getTextMaxWidth() { + return jsonObject.get("text-max-width").getAsFloat(); + } + + /** + * Set the TextMaxWidth property + * + * @return property wrapper value around Float + */ + public void setTextMaxWidth(Float value) { + jsonObject.addProperty("text-max-width", value); + symbolManager.updateSource(); + } + + /** + * Get the TextLetterSpacing property + * + * @return property wrapper value around Float + */ + public Float getTextLetterSpacing() { + return jsonObject.get("text-letter-spacing").getAsFloat(); + } + + /** + * Set the TextLetterSpacing property + * + * @return property wrapper value around Float + */ + public void setTextLetterSpacing(Float value) { + jsonObject.addProperty("text-letter-spacing", value); + symbolManager.updateSource(); + } + + /** + * Get the TextJustify property + * + * @return property wrapper value around String + */ + public String getTextJustify() { + return jsonObject.get("text-justify").getAsString(); + } + + /** + * Set the TextJustify property + * + * @return property wrapper value around String + */ + public void setTextJustify(String value) { + jsonObject.addProperty("text-justify", value); + symbolManager.updateSource(); + } + + /** + * Get the TextAnchor property + * + * @return property wrapper value around String + */ + public String getTextAnchor() { + return jsonObject.get("text-anchor").getAsString(); + } + + /** + * Set the TextAnchor property + * + * @return property wrapper value around String + */ + public void setTextAnchor(String value) { + jsonObject.addProperty("text-anchor", value); + symbolManager.updateSource(); + } + + /** + * Get the TextRotate property + * + * @return property wrapper value around Float + */ + public Float getTextRotate() { + return jsonObject.get("text-rotate").getAsFloat(); + } + + /** + * Set the TextRotate property + * + * @return property wrapper value around Float + */ + public void setTextRotate(Float value) { + jsonObject.addProperty("text-rotate", value); + symbolManager.updateSource(); + } + + /** + * Get the TextTransform property + * + * @return property wrapper value around String + */ + public String getTextTransform() { + return jsonObject.get("text-transform").getAsString(); + } + + /** + * Set the TextTransform property + * + * @return property wrapper value around String + */ + public void setTextTransform(String value) { + jsonObject.addProperty("text-transform", value); + symbolManager.updateSource(); + } + + /** + * Get the TextOffset property + * + * @return property wrapper value around Float[] + */ + public Float[] getTextOffset() { + JsonArray jsonArray = jsonObject.getAsJsonArray("text-offset"); + Float[] value = new Float[jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + value[i] = jsonArray.get(i).getAsFloat(); + } + return value; + } + + /** + * Set the TextOffset property + * + * @return property wrapper value around Float[] + */ + public void setTextOffset(Float[] value) { + JsonArray jsonArray = new JsonArray(); + for (Float element : value) { + jsonArray.add(element); + } + jsonObject.add("text-offset", jsonArray); + symbolManager.updateSource(); + } + + /** + * Get the IconOpacity property + * + * @return property wrapper value around Float + */ + public Float getIconOpacity() { + return jsonObject.get("icon-opacity").getAsFloat(); + } + + /** + * Set the IconOpacity property + * + * @return property wrapper value around Float + */ + public void setIconOpacity(Float value) { + jsonObject.addProperty("icon-opacity", value); + symbolManager.updateSource(); + } + + /** + * Get the IconColor property + * + * @return property wrapper value around String + */ + public String getIconColor() { + return jsonObject.get("icon-color").getAsString(); + } + + /** + * Set the IconColor property + * + * @return property wrapper value around String + */ + public void setIconColor(String value) { + jsonObject.addProperty("icon-color", value); + symbolManager.updateSource(); + } + + /** + * Get the IconHaloColor property + * + * @return property wrapper value around String + */ + public String getIconHaloColor() { + return jsonObject.get("icon-halo-color").getAsString(); + } + + /** + * Set the IconHaloColor property + * + * @return property wrapper value around String + */ + public void setIconHaloColor(String value) { + jsonObject.addProperty("icon-halo-color", value); + symbolManager.updateSource(); + } + + /** + * Get the IconHaloWidth property + * + * @return property wrapper value around Float + */ + public Float getIconHaloWidth() { + return jsonObject.get("icon-halo-width").getAsFloat(); + } + + /** + * Set the IconHaloWidth property + * + * @return property wrapper value around Float + */ + public void setIconHaloWidth(Float value) { + jsonObject.addProperty("icon-halo-width", value); + symbolManager.updateSource(); + } + + /** + * Get the IconHaloBlur property + * + * @return property wrapper value around Float + */ + public Float getIconHaloBlur() { + return jsonObject.get("icon-halo-blur").getAsFloat(); + } + + /** + * Set the IconHaloBlur property + * + * @return property wrapper value around Float + */ + public void setIconHaloBlur(Float value) { + jsonObject.addProperty("icon-halo-blur", value); + symbolManager.updateSource(); + } + + /** + * Get the TextOpacity property + * + * @return property wrapper value around Float + */ + public Float getTextOpacity() { + return jsonObject.get("text-opacity").getAsFloat(); + } + + /** + * Set the TextOpacity property + * + * @return property wrapper value around Float + */ + public void setTextOpacity(Float value) { + jsonObject.addProperty("text-opacity", value); + symbolManager.updateSource(); + } + + /** + * Get the TextColor property + * + * @return property wrapper value around String + */ + public String getTextColor() { + return jsonObject.get("text-color").getAsString(); + } + + /** + * Set the TextColor property + * + * @return property wrapper value around String + */ + public void setTextColor(String value) { + jsonObject.addProperty("text-color", value); + symbolManager.updateSource(); + } + + /** + * Get the TextHaloColor property + * + * @return property wrapper value around String + */ + public String getTextHaloColor() { + return jsonObject.get("text-halo-color").getAsString(); + } + + /** + * Set the TextHaloColor property + * + * @return property wrapper value around String + */ + public void setTextHaloColor(String value) { + jsonObject.addProperty("text-halo-color", value); + symbolManager.updateSource(); + } + + /** + * Get the TextHaloWidth property + * + * @return property wrapper value around Float + */ + public Float getTextHaloWidth() { + return jsonObject.get("text-halo-width").getAsFloat(); + } + + /** + * Set the TextHaloWidth property + * + * @return property wrapper value around Float + */ + public void setTextHaloWidth(Float value) { + jsonObject.addProperty("text-halo-width", value); + symbolManager.updateSource(); + } + + /** + * Get the TextHaloBlur property + * + * @return property wrapper value around Float + */ + public Float getTextHaloBlur() { + return jsonObject.get("text-halo-blur").getAsFloat(); + } + + /** + * Set the TextHaloBlur property + * + * @return property wrapper value around Float + */ + public void setTextHaloBlur(Float value) { + jsonObject.addProperty("text-halo-blur", value); + symbolManager.updateSource(); + } + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/SymbolManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/SymbolManager.java new file mode 100644 index 0000000000..c0b745d954 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/SymbolManager.java @@ -0,0 +1,597 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.symbol; + +import android.support.annotation.NonNull; +import android.support.annotation.UiThread; +import android.support.annotation.VisibleForTesting; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.layers.PropertyValue; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; + +import java.util.ArrayList; +import java.util.List; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.get; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +/** + * The symbol manager allows to add symbols to a map. + */ +public class SymbolManager { + + public static final String ID_GEOJSON_SOURCE = "mapbox-android-symbol-source"; + public static final String ID_GEOJSON_LAYER = "mapbox-android-symbol-layer"; + + // map integration components + private GeoJsonSource geoJsonSource; + private SymbolLayer symbolLayer; + + // internal data set + private List<Symbol> symbolList = new ArrayList<>(); + private long currentMarkerId; + + /** + * Create a symbol manager, used to manage symbols. + * + * @param mapboxMap the map object to add symbols to + */ + @UiThread + public SymbolManager(@NonNull MapboxMap mapboxMap) { + this(mapboxMap, new GeoJsonSource(ID_GEOJSON_SOURCE), new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE) + .withProperties( + getLayerDefinition() + ) + ); + } + + /** + * Create a symbol manager, used to manage symbols. + * + * @param mapboxMap the map object to add symbols to + * @param geoJsonSource the geojson source to add symbols to + * @param symbolLayer the sybol layer to visualise symbols with + */ + @VisibleForTesting + public SymbolManager(MapboxMap mapboxMap, @NonNull GeoJsonSource geoJsonSource, SymbolLayer symbolLayer) { + this.geoJsonSource = geoJsonSource; + this.symbolLayer = symbolLayer; + mapboxMap.addSource(geoJsonSource); + mapboxMap.addLayer(symbolLayer); + } + + /** + * Create a symbol on the map from a LatLng coordinate. + * + * @param latLng place to layout the symbol on the map + * @return the newly created symbol + */ + @UiThread + public Symbol createSymbol(@NonNull LatLng latLng) { + Symbol symbol = new Symbol(this, currentMarkerId); + symbol.setLatLng(latLng); + currentMarkerId++; + symbolList.add(symbol); + return symbol; + } + + /** + * Delete a symbol from the map. + * + * @param symbol to be deleted + */ + @UiThread + public void deleteSymbol(@NonNull Symbol symbol) { + symbolList.remove(symbol); + updateSource(); + } + + /** + * Get a list of current symbols. + * + * @return list of symbols + */ + @UiThread + public List<Symbol> getSymbols() { + return symbolList; + } + + /** + * Trigger an update to the underlying source + */ + public void updateSource() { + // todo move feature creation to a background thread? + List<Feature> features = new ArrayList<>(); + for (Symbol symbol : symbolList) { + features.add(Feature.fromGeometry(symbol.getGeometry(), symbol.getFeature())); + } + geoJsonSource.setGeoJson(FeatureCollection.fromFeatures(features)); + } + + + 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")), + }; + } + + // Property accessors + /** + * Get the SymbolPlacement property + * + * @return property wrapper value around String + */ + public String getSymbolPlacement() { + return symbolLayer.getSymbolPlacement().value; + } + + /** + * Set the SymbolPlacement property + * + * @param value property wrapper value around String + */ + public void setSymbolPlacement(String value) { + symbolLayer.setProperties(symbolPlacement(value)); + } + + /** + * Get the SymbolSpacing property + * + * @return property wrapper value around Float + */ + public Float getSymbolSpacing() { + return symbolLayer.getSymbolSpacing().value; + } + + /** + * Set the SymbolSpacing property + * + * @param value property wrapper value around Float + */ + public void setSymbolSpacing(Float value) { + symbolLayer.setProperties(symbolSpacing(value)); + } + + /** + * Get the SymbolAvoidEdges property + * + * @return property wrapper value around Boolean + */ + public Boolean getSymbolAvoidEdges() { + return symbolLayer.getSymbolAvoidEdges().value; + } + + /** + * Set the SymbolAvoidEdges property + * + * @param value property wrapper value around Boolean + */ + public void setSymbolAvoidEdges(Boolean value) { + symbolLayer.setProperties(symbolAvoidEdges(value)); + } + + /** + * Get the IconAllowOverlap property + * + * @return property wrapper value around Boolean + */ + public Boolean getIconAllowOverlap() { + return symbolLayer.getIconAllowOverlap().value; + } + + /** + * Set the IconAllowOverlap property + * + * @param value property wrapper value around Boolean + */ + public void setIconAllowOverlap(Boolean value) { + symbolLayer.setProperties(iconAllowOverlap(value)); + } + + /** + * Get the IconIgnorePlacement property + * + * @return property wrapper value around Boolean + */ + public Boolean getIconIgnorePlacement() { + return symbolLayer.getIconIgnorePlacement().value; + } + + /** + * Set the IconIgnorePlacement property + * + * @param value property wrapper value around Boolean + */ + public void setIconIgnorePlacement(Boolean value) { + symbolLayer.setProperties(iconIgnorePlacement(value)); + } + + /** + * Get the IconOptional property + * + * @return property wrapper value around Boolean + */ + public Boolean getIconOptional() { + return symbolLayer.getIconOptional().value; + } + + /** + * Set the IconOptional property + * + * @param value property wrapper value around Boolean + */ + public void setIconOptional(Boolean value) { + symbolLayer.setProperties(iconOptional(value)); + } + + /** + * Get the IconRotationAlignment property + * + * @return property wrapper value around String + */ + public String getIconRotationAlignment() { + return symbolLayer.getIconRotationAlignment().value; + } + + /** + * Set the IconRotationAlignment property + * + * @param value property wrapper value around String + */ + public void setIconRotationAlignment(String value) { + symbolLayer.setProperties(iconRotationAlignment(value)); + } + + /** + * Get the IconTextFit property + * + * @return property wrapper value around String + */ + public String getIconTextFit() { + return symbolLayer.getIconTextFit().value; + } + + /** + * Set the IconTextFit property + * + * @param value property wrapper value around String + */ + public void setIconTextFit(String value) { + symbolLayer.setProperties(iconTextFit(value)); + } + + /** + * Get the IconTextFitPadding property + * + * @return property wrapper value around Float[] + */ + public Float[] getIconTextFitPadding() { + return symbolLayer.getIconTextFitPadding().value; + } + + /** + * Set the IconTextFitPadding property + * + * @param value property wrapper value around Float[] + */ + public void setIconTextFitPadding(Float[] value) { + symbolLayer.setProperties(iconTextFitPadding(value)); + } + + /** + * Get the IconPadding property + * + * @return property wrapper value around Float + */ + public Float getIconPadding() { + return symbolLayer.getIconPadding().value; + } + + /** + * Set the IconPadding property + * + * @param value property wrapper value around Float + */ + public void setIconPadding(Float value) { + symbolLayer.setProperties(iconPadding(value)); + } + + /** + * Get the IconKeepUpright property + * + * @return property wrapper value around Boolean + */ + public Boolean getIconKeepUpright() { + return symbolLayer.getIconKeepUpright().value; + } + + /** + * Set the IconKeepUpright property + * + * @param value property wrapper value around Boolean + */ + public void setIconKeepUpright(Boolean value) { + symbolLayer.setProperties(iconKeepUpright(value)); + } + + /** + * Get the IconPitchAlignment property + * + * @return property wrapper value around String + */ + public String getIconPitchAlignment() { + return symbolLayer.getIconPitchAlignment().value; + } + + /** + * Set the IconPitchAlignment property + * + * @param value property wrapper value around String + */ + public void setIconPitchAlignment(String value) { + symbolLayer.setProperties(iconPitchAlignment(value)); + } + + /** + * Get the TextPitchAlignment property + * + * @return property wrapper value around String + */ + public String getTextPitchAlignment() { + return symbolLayer.getTextPitchAlignment().value; + } + + /** + * Set the TextPitchAlignment property + * + * @param value property wrapper value around String + */ + public void setTextPitchAlignment(String value) { + symbolLayer.setProperties(textPitchAlignment(value)); + } + + /** + * Get the TextRotationAlignment property + * + * @return property wrapper value around String + */ + public String getTextRotationAlignment() { + return symbolLayer.getTextRotationAlignment().value; + } + + /** + * Set the TextRotationAlignment property + * + * @param value property wrapper value around String + */ + public void setTextRotationAlignment(String value) { + symbolLayer.setProperties(textRotationAlignment(value)); + } + + /** + * Get the TextLineHeight property + * + * @return property wrapper value around Float + */ + public Float getTextLineHeight() { + return symbolLayer.getTextLineHeight().value; + } + + /** + * Set the TextLineHeight property + * + * @param value property wrapper value around Float + */ + public void setTextLineHeight(Float value) { + symbolLayer.setProperties(textLineHeight(value)); + } + + /** + * Get the TextMaxAngle property + * + * @return property wrapper value around Float + */ + public Float getTextMaxAngle() { + return symbolLayer.getTextMaxAngle().value; + } + + /** + * Set the TextMaxAngle property + * + * @param value property wrapper value around Float + */ + public void setTextMaxAngle(Float value) { + symbolLayer.setProperties(textMaxAngle(value)); + } + + /** + * Get the TextPadding property + * + * @return property wrapper value around Float + */ + public Float getTextPadding() { + return symbolLayer.getTextPadding().value; + } + + /** + * Set the TextPadding property + * + * @param value property wrapper value around Float + */ + public void setTextPadding(Float value) { + symbolLayer.setProperties(textPadding(value)); + } + + /** + * Get the TextKeepUpright property + * + * @return property wrapper value around Boolean + */ + public Boolean getTextKeepUpright() { + return symbolLayer.getTextKeepUpright().value; + } + + /** + * Set the TextKeepUpright property + * + * @param value property wrapper value around Boolean + */ + public void setTextKeepUpright(Boolean value) { + symbolLayer.setProperties(textKeepUpright(value)); + } + + /** + * Get the TextAllowOverlap property + * + * @return property wrapper value around Boolean + */ + public Boolean getTextAllowOverlap() { + return symbolLayer.getTextAllowOverlap().value; + } + + /** + * Set the TextAllowOverlap property + * + * @param value property wrapper value around Boolean + */ + public void setTextAllowOverlap(Boolean value) { + symbolLayer.setProperties(textAllowOverlap(value)); + } + + /** + * Get the TextIgnorePlacement property + * + * @return property wrapper value around Boolean + */ + public Boolean getTextIgnorePlacement() { + return symbolLayer.getTextIgnorePlacement().value; + } + + /** + * Set the TextIgnorePlacement property + * + * @param value property wrapper value around Boolean + */ + public void setTextIgnorePlacement(Boolean value) { + symbolLayer.setProperties(textIgnorePlacement(value)); + } + + /** + * Get the TextOptional property + * + * @return property wrapper value around Boolean + */ + public Boolean getTextOptional() { + return symbolLayer.getTextOptional().value; + } + + /** + * Set the TextOptional property + * + * @param value property wrapper value around Boolean + */ + public void setTextOptional(Boolean value) { + symbolLayer.setProperties(textOptional(value)); + } + + /** + * Get the IconTranslate property + * + * @return property wrapper value around Float[] + */ + public Float[] getIconTranslate() { + return symbolLayer.getIconTranslate().value; + } + + /** + * Set the IconTranslate property + * + * @param value property wrapper value around Float[] + */ + public void setIconTranslate(Float[] value) { + symbolLayer.setProperties(iconTranslate(value)); + } + + /** + * Get the IconTranslateAnchor property + * + * @return property wrapper value around String + */ + public String getIconTranslateAnchor() { + return symbolLayer.getIconTranslateAnchor().value; + } + + /** + * Set the IconTranslateAnchor property + * + * @param value property wrapper value around String + */ + public void setIconTranslateAnchor(String value) { + symbolLayer.setProperties(iconTranslateAnchor(value)); + } + + /** + * Get the TextTranslate property + * + * @return property wrapper value around Float[] + */ + public Float[] getTextTranslate() { + return symbolLayer.getTextTranslate().value; + } + + /** + * Set the TextTranslate property + * + * @param value property wrapper value around Float[] + */ + public void setTextTranslate(Float[] value) { + symbolLayer.setProperties(textTranslate(value)); + } + + /** + * Get the TextTranslateAnchor property + * + * @return property wrapper value around String + */ + public String getTextTranslateAnchor() { + return symbolLayer.getTextTranslateAnchor().value; + } + + /** + * Set the TextTranslateAnchor property + * + * @param value property wrapper value around String + */ + public void setTextTranslateAnchor(String value) { + symbolLayer.setProperties(textTranslateAnchor(value)); + } + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/symbol.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/symbol.java.ejs new file mode 100644 index 0000000000..966e1681de --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/symbol.java.ejs @@ -0,0 +1,123 @@ +<% + const type = locals.type; + const properties = locals.properties; + const doc = locals.doc; +-%> +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.symbol; + +import android.support.annotation.UiThread; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.mapbox.geojson.Geometry; +import com.mapbox.geojson.Point; +import com.mapbox.mapboxsdk.geometry.LatLng; + +@UiThread +public class Symbol { + + public static final String ID_KEY = "id-symbol"; + + private final SymbolManager symbolManager; + private final JsonObject jsonObject = new JsonObject(); + private Geometry geometry; + + /** + * Create a symbol. + * + * @param symbolManager the symbol manager created and managing the symbol + * @param id the id of the symbol + */ + Symbol(SymbolManager symbolManager, long id) { + this.symbolManager = symbolManager; + this.jsonObject.addProperty(ID_KEY, id); + } + + /** + * Get the symbol geometry. + * + * @return the symbol geometry + */ + Geometry getGeometry() { + if (geometry == null) { + throw new IllegalStateException(); + } + return geometry; + } + + /** + * Get the symbol feature properties. + * + * @return the symbol feature properties + */ + JsonObject getFeature() { + return jsonObject; + } + + /** + * Set the LatLng of the symbol, which represents the location of the symbol on the map + * + * @param latLng the location of the symbol in a longitude and latitude pair + */ + public void setLatLng(LatLng latLng) { + geometry = Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()); + symbolManager.updateSource(); + } + + // Property accessors +<% for (const property of properties) { -%> +<% if (supportsPropertyFunction(property)) { -%> +<% if (propertyType(property).endsWith("[]")) { -%> + /** + * Get the <%- camelize(property.name) %> property + * + * @return property wrapper value around <%- propertyType(property) %> + */ + public <%- propertyType(property) %> get<%- camelize(property.name) %>() { + JsonArray jsonArray = jsonObject.getAsJsonArray("<%-property.name %>"); + <%- propertyType(property) %> value = new <%- propertyType(property).substring(0, propertyType(property).length-1) %>jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + value[i] = jsonArray.get(i).getAs<%- propertyType(property).substring(0, propertyType(property).length-2) %>(); + } + return value; + } + + /** + * Set the <%- camelize(property.name) %> property + * + * @return property wrapper value around <%- propertyType(property) %> + */ + public void set<%- camelize(property.name) %>(<%- propertyType(property) %> value) { + JsonArray jsonArray = new JsonArray(); + for (<%- propertyType(property).substring(0, propertyType(property).length-2) %> element : value) { + jsonArray.add(element); + } + jsonObject.add("<%-property.name %>", jsonArray); + symbolManager.updateSource(); + } + +<% } else { -%> + /** + * Get the <%- camelize(property.name) %> property + * + * @return property wrapper value around <%- propertyType(property) %> + */ + public <%- propertyType(property) %> get<%- camelize(property.name) %>() { + return jsonObject.get("<%- property.name %>").getAs<%- propertyType(property) %>(); + } + + /** + * Set the <%- camelize(property.name) %> property + * + * @return property wrapper value around <%- propertyType(property) %> + */ + public void set<%- camelize(property.name) %>(<%- propertyType(property) %> value) { + jsonObject.addProperty("<%- property.name %>", value); + symbolManager.updateSource(); + } + +<% } -%> +<% } -%> +<% } -%> +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/symbolManager.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/symbolManager.java.ejs new file mode 100644 index 0000000000..6beb700241 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/symbolManager.java.ejs @@ -0,0 +1,153 @@ +<% + const type = locals.type; + const properties = locals.properties; + const doc = locals.doc; +-%> +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.symbol; + +import android.support.annotation.NonNull; +import android.support.annotation.UiThread; +import android.support.annotation.VisibleForTesting; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.layers.PropertyValue; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; + +import java.util.ArrayList; +import java.util.List; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.get; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +/** + * The symbol manager allows to add symbols to a map. + */ +public class SymbolManager { + + public static final String ID_GEOJSON_SOURCE = "mapbox-android-symbol-source"; + public static final String ID_GEOJSON_LAYER = "mapbox-android-symbol-layer"; + + // map integration components + private GeoJsonSource geoJsonSource; + private SymbolLayer symbolLayer; + + // internal data set + private List<Symbol> symbolList = new ArrayList<>(); + private long currentMarkerId; + + /** + * Create a symbol manager, used to manage symbols. + * + * @param mapboxMap the map object to add symbols to + */ + @UiThread + public SymbolManager(@NonNull MapboxMap mapboxMap) { + this(mapboxMap, new GeoJsonSource(ID_GEOJSON_SOURCE), new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE) + .withProperties( + getLayerDefinition() + ) + ); + } + + /** + * Create a symbol manager, used to manage symbols. + * + * @param mapboxMap the map object to add symbols to + * @param geoJsonSource the geojson source to add symbols to + * @param symbolLayer the sybol layer to visualise symbols with + */ + @VisibleForTesting + public SymbolManager(MapboxMap mapboxMap, @NonNull GeoJsonSource geoJsonSource, SymbolLayer symbolLayer) { + this.geoJsonSource = geoJsonSource; + this.symbolLayer = symbolLayer; + mapboxMap.addSource(geoJsonSource); + mapboxMap.addLayer(symbolLayer); + } + + /** + * Create a symbol on the map from a LatLng coordinate. + * + * @param latLng place to layout the symbol on the map + * @return the newly created symbol + */ + @UiThread + public Symbol createSymbol(@NonNull LatLng latLng) { + Symbol symbol = new Symbol(this, currentMarkerId); + symbol.setLatLng(latLng); + currentMarkerId++; + symbolList.add(symbol); + return symbol; + } + + /** + * Delete a symbol from the map. + * + * @param symbol to be deleted + */ + @UiThread + public void deleteSymbol(@NonNull Symbol symbol) { + symbolList.remove(symbol); + updateSource(); + } + + /** + * Get a list of current symbols. + * + * @return list of symbols + */ + @UiThread + public List<Symbol> getSymbols() { + return symbolList; + } + + /** + * Trigger an update to the underlying source + */ + public void updateSource() { + // todo move feature creation to a background thread? + List<Feature> features = new ArrayList<>(); + for (Symbol symbol : symbolList) { + features.add(Feature.fromGeometry(symbol.getGeometry(), symbol.getFeature())); + } + geoJsonSource.setGeoJson(FeatureCollection.fromFeatures(features)); + } + + + private static PropertyValue<?>[] getLayerDefinition() { + return new PropertyValue[]{ +<% for (const property of properties) { -%> +<% if (supportsPropertyFunction(property)) { -%> + <%- camelizeWithLeadingLowercase(property.name) %>(get("<%- property.name %>")), +<% } -%><% } -%> + }; + } + + // Property accessors +<% for (const property of properties) { -%> +<% if (!supportsPropertyFunction(property)) { -%> + /** + * Get the <%- camelize(property.name) %> property + * + * @return property wrapper value around <%- propertyType(property) %> + */ + public <%- propertyType(property) %> get<%- camelize(property.name) %>() { + return symbolLayer.get<%- camelize(property.name) %>().value; + } + + /** + * Set the <%- camelize(property.name) %> property + * + * @param value property wrapper value around <%- propertyType(property) %> + */ + public void set<%- camelize(property.name) %>(<%- propertyType(property) %> value) { + symbolLayer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(value)); + } + +<% } -%> +<% } -%> +} diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/symbol/SymbolManagerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/symbol/SymbolManagerTest.java new file mode 100644 index 0000000000..d2f76dfaa7 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/symbol/SymbolManagerTest.java @@ -0,0 +1,56 @@ +package com.mapbox.mapboxsdk.symbol; + +import com.mapbox.geojson.Point; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + +import static junit.framework.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +public class SymbolManagerTest { + + private MapboxMap mapboxMap = mock(MapboxMap.class); + private GeoJsonSource geoJsonSource = mock(GeoJsonSource.class); + private SymbolLayer symbolLayer = mock(SymbolLayer.class); + private SymbolManager symbolManager; + + @Before + public void beforeTest() { + symbolManager = new SymbolManager(mapboxMap, geoJsonSource, symbolLayer); + } + + @Test + public void testAddSymbol() { + final Symbol symbol = symbolManager.createSymbol(new LatLng(12, 34)); + assertEquals(symbolManager.getSymbols(), new ArrayList<Symbol>() {{ + add(symbol); + }}); + } + + @Test + public void testDeleteSymbol() { + Symbol symbol = symbolManager.createSymbol(new LatLng(12, 34)); + symbolManager.deleteSymbol(symbol); + assertEquals(symbolManager.getSymbols(), new ArrayList<Symbol>()); + } + + @Test + public void testGeometrySymbol() { + Symbol symbol = symbolManager.createSymbol(new LatLng(12, 34)); + assertEquals(symbol.getGeometry(), Point.fromLngLat(34, 12)); + } + + @Test + public void testFeatureIdSymbol() { + Symbol symbolZero = symbolManager.createSymbol(new LatLng()); + Symbol symbolOne = symbolManager.createSymbol(new LatLng()); + assertEquals(symbolZero.getFeature().get(Symbol.ID_KEY).getAsLong(), 0); + assertEquals(symbolOne.getFeature().get(Symbol.ID_KEY).getAsLong(), 1); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/SymbolManagerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/SymbolManagerTest.java new file mode 100644 index 0000000000..6a135d9490 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/SymbolManagerTest.java @@ -0,0 +1,367 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.testapp.symbol; + +import android.support.test.runner.AndroidJUnit4; + +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.symbol.Symbol; +import com.mapbox.mapboxsdk.symbol.SymbolManager; +import timber.log.Timber; + +import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; + +import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for SymbolManager + */ +@RunWith(AndroidJUnit4.class) +public class SymbolManagerTest extends BaseActivityTest { + + private SymbolManager symbolManager; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupSymbolManager() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + symbolManager = new SymbolManager(mapboxMap); + }); + } + + @Test + public void testSymbolPlacementAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("symbol-placement"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setSymbolPlacement(SYMBOL_PLACEMENT_POINT); + assertEquals((String) symbolManager.getSymbolPlacement(), (String) SYMBOL_PLACEMENT_POINT); + }); + } + + @Test + public void testSymbolSpacingAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("symbol-spacing"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setSymbolSpacing(0.3f); + assertEquals((Float) symbolManager.getSymbolSpacing(), (Float) 0.3f); + }); + } + + @Test + public void testSymbolAvoidEdgesAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("symbol-avoid-edges"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setSymbolAvoidEdges(true); + assertEquals((Boolean) symbolManager.getSymbolAvoidEdges(), (Boolean) true); + }); + } + + @Test + public void testIconAllowOverlapAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-allow-overlap"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconAllowOverlap(true); + assertEquals((Boolean) symbolManager.getIconAllowOverlap(), (Boolean) true); + }); + } + + @Test + public void testIconIgnorePlacementAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-ignore-placement"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconIgnorePlacement(true); + assertEquals((Boolean) symbolManager.getIconIgnorePlacement(), (Boolean) true); + }); + } + + @Test + public void testIconOptionalAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-optional"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconOptional(true); + assertEquals((Boolean) symbolManager.getIconOptional(), (Boolean) true); + }); + } + + @Test + public void testIconRotationAlignmentAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-rotation-alignment"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP); + assertEquals((String) symbolManager.getIconRotationAlignment(), (String) ICON_ROTATION_ALIGNMENT_MAP); + }); + } + + @Test + public void testIconTextFitAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-text-fit"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconTextFit(ICON_TEXT_FIT_NONE); + assertEquals((String) symbolManager.getIconTextFit(), (String) ICON_TEXT_FIT_NONE); + }); + } + + @Test + public void testIconTextFitPaddingAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-text-fit-padding"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconTextFitPadding(new Float[] {0f, 0f, 0f, 0f}); + assertEquals((Float[]) symbolManager.getIconTextFitPadding(), (Float[]) new Float[] {0f, 0f, 0f, 0f}); + }); + } + + @Test + public void testIconPaddingAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-padding"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconPadding(0.3f); + assertEquals((Float) symbolManager.getIconPadding(), (Float) 0.3f); + }); + } + + @Test + public void testIconKeepUprightAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-keep-upright"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconKeepUpright(true); + assertEquals((Boolean) symbolManager.getIconKeepUpright(), (Boolean) true); + }); + } + + @Test + public void testIconPitchAlignmentAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-pitch-alignment"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconPitchAlignment(ICON_PITCH_ALIGNMENT_MAP); + assertEquals((String) symbolManager.getIconPitchAlignment(), (String) ICON_PITCH_ALIGNMENT_MAP); + }); + } + + @Test + public void testTextPitchAlignmentAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-pitch-alignment"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextPitchAlignment(TEXT_PITCH_ALIGNMENT_MAP); + assertEquals((String) symbolManager.getTextPitchAlignment(), (String) TEXT_PITCH_ALIGNMENT_MAP); + }); + } + + @Test + public void testTextRotationAlignmentAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-rotation-alignment"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextRotationAlignment(TEXT_ROTATION_ALIGNMENT_MAP); + assertEquals((String) symbolManager.getTextRotationAlignment(), (String) TEXT_ROTATION_ALIGNMENT_MAP); + }); + } + + @Test + public void testTextLineHeightAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-line-height"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextLineHeight(0.3f); + assertEquals((Float) symbolManager.getTextLineHeight(), (Float) 0.3f); + }); + } + + @Test + public void testTextMaxAngleAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-max-angle"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextMaxAngle(0.3f); + assertEquals((Float) symbolManager.getTextMaxAngle(), (Float) 0.3f); + }); + } + + @Test + public void testTextPaddingAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-padding"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextPadding(0.3f); + assertEquals((Float) symbolManager.getTextPadding(), (Float) 0.3f); + }); + } + + @Test + public void testTextKeepUprightAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-keep-upright"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextKeepUpright(true); + assertEquals((Boolean) symbolManager.getTextKeepUpright(), (Boolean) true); + }); + } + + @Test + public void testTextAllowOverlapAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-allow-overlap"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextAllowOverlap(true); + assertEquals((Boolean) symbolManager.getTextAllowOverlap(), (Boolean) true); + }); + } + + @Test + public void testTextIgnorePlacementAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-ignore-placement"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextIgnorePlacement(true); + assertEquals((Boolean) symbolManager.getTextIgnorePlacement(), (Boolean) true); + }); + } + + @Test + public void testTextOptionalAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-optional"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextOptional(true); + assertEquals((Boolean) symbolManager.getTextOptional(), (Boolean) true); + }); + } + + @Test + public void testIconTranslateAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-translate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconTranslate(new Float[] {0f, 0f}); + assertEquals((Float[]) symbolManager.getIconTranslate(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testIconTranslateAnchorAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("icon-translate-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setIconTranslateAnchor(ICON_TRANSLATE_ANCHOR_MAP); + assertEquals((String) symbolManager.getIconTranslateAnchor(), (String) ICON_TRANSLATE_ANCHOR_MAP); + }); + } + + @Test + public void testTextTranslateAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-translate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextTranslate(new Float[] {0f, 0f}); + assertEquals((Float[]) symbolManager.getTextTranslate(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testTextTranslateAnchorAsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("text-translate-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.setTextTranslateAnchor(TEXT_TRANSLATE_ANCHOR_MAP); + assertEquals((String) symbolManager.getTextTranslateAnchor(), (String) TEXT_TRANSLATE_ANCHOR_MAP); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/SymbolTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/SymbolTest.java new file mode 100644 index 0000000000..bfd9ec400c --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/SymbolTest.java @@ -0,0 +1,368 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.testapp.symbol; + +import android.support.test.runner.AndroidJUnit4; + +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.symbol.Symbol; +import com.mapbox.mapboxsdk.symbol.SymbolManager; +import timber.log.Timber; + +import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; + +import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for Symbol + */ +@RunWith(AndroidJUnit4.class) +public class SymbolTest extends BaseActivityTest { + + private Symbol symbol; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupSymbol() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + SymbolManager symbolManager = new SymbolManager(mapboxMap); + symbol = symbolManager.createSymbol(new LatLng()); + }); + } + + @Test + public void testIconSize() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-size"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconSize(0.3f); + assertEquals((Float) symbol.getIconSize(), (Float) 0.3f); + }); + } + + @Test + public void testIconImage() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-image"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconImage("undefined"); + assertEquals((String) symbol.getIconImage(), (String) "undefined"); + }); + } + + @Test + public void testIconRotate() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-rotate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconRotate(0.3f); + assertEquals((Float) symbol.getIconRotate(), (Float) 0.3f); + }); + } + + @Test + public void testIconOffset() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-offset"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconOffset(new Float[] {0f, 0f}); + assertEquals((Float[]) symbol.getIconOffset(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testIconAnchor() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconAnchor(ICON_ANCHOR_CENTER); + assertEquals((String) symbol.getIconAnchor(), (String) ICON_ANCHOR_CENTER); + }); + } + + @Test + public void testTextField() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-field"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextField(""); + assertEquals((String) symbol.getTextField(), (String) ""); + }); + } + + @Test + public void testTextFont() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-font"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextFont(new String[]{"Open Sans Regular", "Arial Unicode MS Regular"}); + assertEquals((String[]) symbol.getTextFont(), (String[]) new String[]{"Open Sans Regular", "Arial Unicode MS Regular"}); + }); + } + + @Test + public void testTextSize() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-size"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextSize(0.3f); + assertEquals((Float) symbol.getTextSize(), (Float) 0.3f); + }); + } + + @Test + public void testTextMaxWidth() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-max-width"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextMaxWidth(0.3f); + assertEquals((Float) symbol.getTextMaxWidth(), (Float) 0.3f); + }); + } + + @Test + public void testTextLetterSpacing() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-letter-spacing"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextLetterSpacing(0.3f); + assertEquals((Float) symbol.getTextLetterSpacing(), (Float) 0.3f); + }); + } + + @Test + public void testTextJustify() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-justify"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextJustify(TEXT_JUSTIFY_LEFT); + assertEquals((String) symbol.getTextJustify(), (String) TEXT_JUSTIFY_LEFT); + }); + } + + @Test + public void testTextAnchor() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextAnchor(TEXT_ANCHOR_CENTER); + assertEquals((String) symbol.getTextAnchor(), (String) TEXT_ANCHOR_CENTER); + }); + } + + @Test + public void testTextRotate() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-rotate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextRotate(0.3f); + assertEquals((Float) symbol.getTextRotate(), (Float) 0.3f); + }); + } + + @Test + public void testTextTransform() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-transform"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextTransform(TEXT_TRANSFORM_NONE); + assertEquals((String) symbol.getTextTransform(), (String) TEXT_TRANSFORM_NONE); + }); + } + + @Test + public void testTextOffset() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-offset"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextOffset(new Float[] {0f, 0f}); + assertEquals((Float[]) symbol.getTextOffset(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testIconOpacity() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconOpacity(0.3f); + assertEquals((Float) symbol.getIconOpacity(), (Float) 0.3f); + }); + } + + @Test + public void testIconColor() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconColor("rgba(0, 0, 0, 1)"); + assertEquals((String) symbol.getIconColor(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testIconHaloColor() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-halo-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconHaloColor("rgba(0, 0, 0, 1)"); + assertEquals((String) symbol.getIconHaloColor(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testIconHaloWidth() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-halo-width"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconHaloWidth(0.3f); + assertEquals((Float) symbol.getIconHaloWidth(), (Float) 0.3f); + }); + } + + @Test + public void testIconHaloBlur() { + validateTestSetup(); + setupSymbol(); + Timber.i("icon-halo-blur"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setIconHaloBlur(0.3f); + assertEquals((Float) symbol.getIconHaloBlur(), (Float) 0.3f); + }); + } + + @Test + public void testTextOpacity() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextOpacity(0.3f); + assertEquals((Float) symbol.getTextOpacity(), (Float) 0.3f); + }); + } + + @Test + public void testTextColor() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextColor("rgba(0, 0, 0, 1)"); + assertEquals((String) symbol.getTextColor(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testTextHaloColor() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-halo-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextHaloColor("rgba(0, 0, 0, 1)"); + assertEquals((String) symbol.getTextHaloColor(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testTextHaloWidth() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-halo-width"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextHaloWidth(0.3f); + assertEquals((Float) symbol.getTextHaloWidth(), (Float) 0.3f); + }); + } + + @Test + public void testTextHaloBlur() { + validateTestSetup(); + setupSymbol(); + Timber.i("text-halo-blur"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.setTextHaloBlur(0.3f); + assertEquals((Float) symbol.getTextHaloBlur(), (Float) 0.3f); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/symbol.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/symbol.junit.ejs new file mode 100644 index 0000000000..eebcec649d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/symbol.junit.ejs @@ -0,0 +1,64 @@ +<% + const type = locals.type; + const properties = locals.properties; +-%> +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.testapp.symbol; + +import android.support.test.runner.AndroidJUnit4; + +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.symbol.Symbol; +import com.mapbox.mapboxsdk.symbol.SymbolManager; +import timber.log.Timber; + +import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; + +import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for <%- camelize(type) %> + */ +@RunWith(AndroidJUnit4.class) +public class <%- camelize(type) %>Test extends BaseActivityTest { + + private Symbol symbol; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupSymbol() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + SymbolManager symbolManager = new SymbolManager(mapboxMap); + symbol = symbolManager.createSymbol(new LatLng()); + }); + } +<% for (const property of properties) { -%> +<% if (supportsPropertyFunction(property)) { -%> + + @Test + public void test<%- camelize(property.name) %>() { + validateTestSetup(); + setupSymbol(); + Timber.i("<%- property.name %>"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbol); + + symbol.set<%- camelize(property.name) %>(<%- defaultValueJava(property) %>); + assertEquals((<%- propertyType(property) %>) symbol.get<%- camelize(property.name) %>(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>); + }); + } +<% } -%> +<% } -%> +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/symbolmanager.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/symbolmanager.junit.ejs new file mode 100644 index 0000000000..65d45ad555 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/symbolmanager.junit.ejs @@ -0,0 +1,63 @@ +<% + const type = locals.type; + const properties = locals.properties; +-%> +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.testapp.symbol; + +import android.support.test.runner.AndroidJUnit4; + +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.symbol.Symbol; +import com.mapbox.mapboxsdk.symbol.SymbolManager; +import timber.log.Timber; + +import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; + +import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for <%- camelize(type) %>Manager + */ +@RunWith(AndroidJUnit4.class) +public class <%- camelize(type) %>ManagerTest extends BaseActivityTest { + + private SymbolManager symbolManager; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupSymbolManager() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + symbolManager = new SymbolManager(mapboxMap); + }); + } +<% for (const property of properties) { -%> +<% if (!supportsPropertyFunction(property)) { -%> + + @Test + public void test<%- camelize(property.name) %>AsConstant() { + validateTestSetup(); + setupSymbolManager(); + Timber.i("<%- property.name %>"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(symbolManager); + + symbolManager.set<%- camelize(property.name) %>(<%- defaultValueJava(property) %>); + assertEquals((<%- propertyType(property) %>) symbolManager.get<%- camelize(property.name) %>(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>); + }); + } +<% } -%> +<% } -%> +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java index a1f7b4af01..d61122d4b0 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java @@ -1,24 +1,99 @@ package com.mapbox.mapboxsdk.testapp.activity.maplayout; +import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.style.layers.Property; +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; +import com.mapbox.mapboxsdk.symbol.Symbol; +import com.mapbox.mapboxsdk.symbol.SymbolManager; import com.mapbox.mapboxsdk.testapp.R; +import java.util.Random; + /** * Test activity showcasing a simple MapView without any MapboxMap interaction. */ public class SimpleMapActivity extends AppCompatActivity { + private final Random random = new Random(); + private static final String MAKI_ICON_AIRPORT = "airport-15"; + private static final String MAKI_ICON_CAR = "car-15"; + private static final String MAKI_ICON_CAFE = "cafe-15"; + private MapView mapView; + private Symbol symbol; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map_simple); - mapView = (MapView) findViewById(R.id.mapView); + mapView = findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); + mapView.getMapAsync(mapboxMap -> { + mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2)); + + // create symbol manager + SymbolManager symbolManager = new SymbolManager(mapboxMap); + // set non data driven properties + symbolManager.setIconAllowOverlap(true); + symbolManager.setTextAllowOverlap(true); + + // create a symbol + symbol = symbolManager.createSymbol(new LatLng(6.687337, 0.381457)); + symbol.setIconImage(MAKI_ICON_AIRPORT); + symbol.setIconSize(1.2f); + + // random add symbols accross the globe + Symbol currentSymbol; + for (int i = 0; i < 1250; i++) { + currentSymbol = symbolManager.createSymbol(createRandomLatLng()); + currentSymbol.setIconImage(MAKI_ICON_CAR); + } + }); + } + + private LatLng createRandomLatLng(){ + return new LatLng((random.nextDouble() * -180.0) + 90.0, + (random.nextDouble() * -360.0) + 180.0); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_symbolmanager, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.menu_action_icon) { + symbol.setIconImage(MAKI_ICON_CAFE); + } else if (item.getItemId() == R.id.menu_action_rotation) { + symbol.setIconRotate(45.0f); + } else if (item.getItemId() == R.id.menu_action_text) { + symbol.setTextField("Hello world!"); + } else if (item.getItemId() == R.id.menu_action_anchor) { + symbol.setIconAnchor(Property.ICON_ANCHOR_BOTTOM); + } else if (item.getItemId() == R.id.menu_action_opacity) { + symbol.setIconOpacity(0.5f); + } else if (item.getItemId() == R.id.menu_action_offset) { + symbol.setIconOffset(new Float[] {10.0f, 20.0f}); + } else if (item.getItemId() == R.id.menu_action_text_anchor) { + symbol.setTextAnchor(Property.TEXT_ANCHOR_TOP); + }else if (item.getItemId() == R.id.menu_action_text_color) { + symbol.setTextColor(PropertyFactory.colorToRgbaString(Color.WHITE)); + }else if(item.getItemId() == R.id.menu_action_text_size) { + symbol.setTextSize(22f); + } else { + return super.onOptionsItemSelected(item); + } + return true; } @Override diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_symbolmanager.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_symbolmanager.xml new file mode 100644 index 0000000000..f3c3e13898 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_symbolmanager.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + <item + android:id="@+id/menu_action_icon" + android:title="Change icon to coffee" + app:showAsAction="never"/> + <item + android:id="@+id/menu_action_rotation" + android:title="Set icon rotation to 45" + app:showAsAction="never"/> + <item + android:id="@+id/menu_action_anchor" + android:title="Set icon anchor bottom" + app:showAsAction="never"/> + <item + android:id="@+id/menu_action_opacity" + android:title="Set icon opacity to 0.5f" + app:showAsAction="never"/> + <item + android:id="@+id/menu_action_offset" + android:title="Offset icon by 10, 20" + app:showAsAction="never"/> + <item + android:id="@+id/menu_action_text" + android:title="Add text" + app:showAsAction="never"/> + <item + android:id="@+id/menu_action_text_color" + android:title="Set text color to white" + app:showAsAction="never"/> + <item + android:id="@+id/menu_action_text_size" + android:title="Set text size" + app:showAsAction="never"/> + <item + android:id="@+id/menu_action_text_anchor" + android:title="Set text anchor top" + app:showAsAction="never"/> +</menu> diff --git a/platform/android/scripts/generate-style-code.js b/platform/android/scripts/generate-style-code.js index 0825ef1c26..0262b78437 100755 --- a/platform/android/scripts/generate-style-code.js +++ b/platform/android/scripts/generate-style-code.js @@ -348,9 +348,19 @@ writeIfModified(`platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java const layerHpp = ejs.compile(fs.readFileSync('platform/android/src/style/layers/layer.hpp.ejs', 'utf8'), {strict: true}); const layerCpp = ejs.compile(fs.readFileSync('platform/android/src/style/layers/layer.cpp.ejs', 'utf8'), {strict: true}); const layerJava = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs', 'utf8'), {strict: true}); +const symbolJava = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/symbol.java.ejs', 'utf8'), {strict: true}); +const symbolManagerJava = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/symbolManager.java.ejs', 'utf8'), {strict: true}); const layerJavaUnitTests = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs', 'utf8'), {strict: true}); +const symbolJavaUnitTests = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/symbol.junit.ejs', 'utf8'), {strict: true}); +const symbolManagerJavaUnitTests = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/symbolmanager.junit.ejs', 'utf8'), {strict: true}); for (const layer of layers) { + if(layer.type === "symbol"){ + writeIfModified(`platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/${camelize(layer.type)}.java`, symbolJava(layer)); + writeIfModified(`platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/symbol/${camelize(layer.type)}Manager.java`, symbolManagerJava(layer)); + writeIfModified(`platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/${camelize(layer.type)}Test.java`, symbolJavaUnitTests(layer)); + writeIfModified(`platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/symbol/${camelize(layer.type)}ManagerTest.java`, symbolManagerJavaUnitTests(layer)); + } writeIfModified(`platform/android/src/style/layers/${layer.type.replace('-', '_')}_layer.hpp`, layerHpp(layer)); writeIfModified(`platform/android/src/style/layers/${layer.type.replace('-', '_')}_layer.cpp`, layerCpp(layer)); writeIfModified(`platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/${camelize(layer.type)}Layer.java`, layerJava(layer)); |