diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineChangeActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineChangeActivity.java index cb4fa8970..bc525dedc 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineChangeActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/LineChangeActivity.java @@ -1,6 +1,5 @@ package com.mapbox.mapboxsdk.plugins.testapp.activity.annotation; - import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; @@ -8,6 +7,8 @@ import android.view.MenuItem; import android.view.View; import android.widget.Toast; +import com.mapbox.geojson.LineString; +import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapView; @@ -75,6 +76,15 @@ protected void onCreate(Bundle savedInstanceState) { LineChangeActivity.this, "Clicked: " + line.getId(), Toast.LENGTH_SHORT).show()); + + LineManager dottedLineManger = new LineManager(mapView, mapboxMap, style); + dottedLineManger.create(new LineOptions() + .withLinePattern("airfield-11") + .withLineWidth(5.0f) + .withGeometry(LineString.fromLngLats(new ArrayList() {{ + add(Point.fromLngLat(9.997167, 53.547476)); + add(Point.fromLngLat(12.587986, 55.675313)); + }}))); }); }); diff --git a/plugin-annotation/scripts/annotation_element_provider.java.ejs b/plugin-annotation/scripts/annotation_element_provider.java.ejs new file mode 100644 index 000000000..900187b5f --- /dev/null +++ b/plugin-annotation/scripts/annotation_element_provider.java.ejs @@ -0,0 +1,49 @@ +<% + const type = locals.type; + const properties = locals.properties; + const doc = locals.doc; +-%> +// This file is generated. + +package com.mapbox.mapboxsdk.plugins.annotation; + +import android.support.annotation.Nullable; +import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * Concrete instance of a core element provider for <%- camelize(type) %>. + */ +class <%- camelize(type) %>ElementProvider implements CoreElementProvider<<%- camelize(type) %>Layer>{ + + private static final AtomicLong ID_GENERATOR = new AtomicLong(0); + private static final String ID_GEOJSON_LAYER = "mapbox-android-<%- type %>-layer-%s"; + private static final String ID_GEOJSON_SOURCE = "mapbox-android-<%- type %>-source-%s"; + + private final String layerId; + private final String sourceId; + + <%- camelize(type) %>ElementProvider() { + long id = ID_GENERATOR.incrementAndGet(); + this.layerId = String.format(ID_GEOJSON_LAYER, id); + this.sourceId = String.format(ID_GEOJSON_SOURCE, id); + } + + @Override + public String getLayerId() { + return layerId; + } + + @Override + public <%- camelize(type) %>Layer getLayer() { + return new <%- camelize(type) %>Layer(layerId, sourceId); + } + + @Override + public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { + return new GeoJsonSource(sourceId, geoJsonOptions); + } +} \ No newline at end of file diff --git a/plugin-annotation/scripts/annotation_manager.java.ejs b/plugin-annotation/scripts/annotation_manager.java.ejs index 94a7a44ba..a676cd60b 100644 --- a/plugin-annotation/scripts/annotation_manager.java.ejs +++ b/plugin-annotation/scripts/annotation_manager.java.ejs @@ -22,7 +22,6 @@ import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer; import com.mapbox.mapboxsdk.style.layers.PropertyValue; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; @@ -36,9 +35,6 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; */ public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize(type) %>Layer, <%- camelize(type) %>, <%- camelize(type) %>Options, On<%- camelize(type) %>DragListener, On<%- camelize(type) %>ClickListener, On<%- camelize(type) %>LongClickListener> { - public static final String ID_GEOJSON_SOURCE = "mapbox-android-<%- type %>-source"; - public static final String ID_GEOJSON_LAYER = "mapbox-android-<%- type %>-layer"; - <% for (const property of properties) { -%> <% if (!supportsPropertyFunction(property) && property.name !== "line-gradient" && property.name !== "symbol-z-order") { -%> private static final String PROPERTY_<%- snakeCaseUpper(property.name) %> = "<%- property.name %>"; @@ -78,23 +74,7 @@ public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize */ @UiThread public <%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) { - this(mapView, mapboxMap, style, - new CoreElementProvider<<%- camelize(type) %>Layer>() { - @Override - public <%- camelize(type) %>Layer getLayer() { - return new <%- camelize(type) %>Layer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE); - } - - @Override - public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { - if (geoJsonOptions != null) { - return new GeoJsonSource(ID_GEOJSON_SOURCE, geoJsonOptions); - } else { - return new GeoJsonSource(ID_GEOJSON_SOURCE); - } - } - }, - belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); + this(mapView, mapboxMap, style, new <%- camelize(type) %>ElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); } @VisibleForTesting @@ -200,16 +180,6 @@ public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize return create(options); } - /** - * Get the layer id of the annotation layer. - * - * @return the layer id - */ - @Override - String getAnnotationLayerId() { - return ID_GEOJSON_LAYER; - } - /** * Get the key of the id of the annotation. * diff --git a/plugin-annotation/scripts/code-gen.js b/plugin-annotation/scripts/code-gen.js index a84cf0e48..4fa3ae30f 100644 --- a/plugin-annotation/scripts/code-gen.js +++ b/plugin-annotation/scripts/code-gen.js @@ -387,6 +387,7 @@ global.supportsPropertyFunction = function (property) { const annotationJava = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation.java.ejs', 'utf8'), {strict: true}); const annotationOptionsJava = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_options.java.ejs', 'utf8'), {strict: true}); const annotationManagerJava = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_manager.java.ejs', 'utf8'), {strict: true}); +const annotationElementProvider = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_element_provider.java.ejs', 'utf8'), {strict: true}); const annotationDragListener = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_drag_listener.java.ejs', 'utf8'), {strict: true}); const annotationClickListener = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_click_listener.java.ejs', 'utf8'), {strict: true}); const annotationLongClickListener = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_long_click_listener.java.ejs', 'utf8'), {strict: true}); @@ -402,6 +403,7 @@ for (const layer of layers) { writeIfModified(`plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}.java`, annotationJava(layer)); writeIfModified(`plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}Options.java`, annotationOptionsJava(layer)); writeIfModified(`plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}Manager.java`, annotationManagerJava(layer)); + writeIfModified(`plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}ElementProvider.java`, annotationElementProvider(layer)); writeIfModified(`app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}Test.java`, annotationJavaInstrumentationTests(layer)); writeIfModified(`app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}ManagerTest.java`, annotationManagerJavaInstrumentationTests(layer)); writeIfModified(`plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}ManagerTest.java`, annotationManagerJavaUnitTests(layer)); diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java index f0837eeb2..709af08fa 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; /** * Generic AnnotationManager, can be used to create annotation specific managers. @@ -327,8 +328,6 @@ public void onDestroy() { longClickListeners.clear(); } - abstract String getAnnotationLayerId(); - abstract String getAnnotationIdKey(); abstract void initializeDataDrivenPropertyMap(); @@ -398,7 +397,7 @@ private T queryMapForFeatures(@NonNull LatLng point) { @Nullable T queryMapForFeatures(@NonNull PointF point) { - List features = mapboxMap.queryRenderedFeatures(point, getAnnotationLayerId()); + List features = mapboxMap.queryRenderedFeatures(point, coreElementProvider.getLayerId()); if (!features.isEmpty()) { long id = features.get(0).getProperty(getAnnotationIdKey()).getAsLong(); return annotations.get(id); diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleElementProvider.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleElementProvider.java new file mode 100644 index 000000000..4f6faea0b --- /dev/null +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleElementProvider.java @@ -0,0 +1,44 @@ +// This file is generated. + +package com.mapbox.mapboxsdk.plugins.annotation; + +import android.support.annotation.Nullable; +import com.mapbox.mapboxsdk.style.layers.CircleLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * Concrete instance of a core element provider for Circle. + */ +class CircleElementProvider implements CoreElementProvider{ + + private static final AtomicLong ID_GENERATOR = new AtomicLong(0); + private static final String ID_GEOJSON_LAYER = "mapbox-android-circle-layer-%s"; + private static final String ID_GEOJSON_SOURCE = "mapbox-android-circle-source-%s"; + + private final String layerId; + private final String sourceId; + + CircleElementProvider() { + long id = ID_GENERATOR.incrementAndGet(); + this.layerId = String.format(ID_GEOJSON_LAYER, id); + this.sourceId = String.format(ID_GEOJSON_SOURCE, id); + } + + @Override + public String getLayerId() { + return layerId; + } + + @Override + public CircleLayer getLayer() { + return new CircleLayer(layerId, sourceId); + } + + @Override + public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { + return new GeoJsonSource(sourceId, geoJsonOptions); + } +} \ No newline at end of file diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManager.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManager.java index a6b660ff3..496037267 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManager.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManager.java @@ -17,7 +17,6 @@ import com.mapbox.mapboxsdk.style.layers.PropertyValue; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; @@ -31,9 +30,6 @@ */ public class CircleManager extends AnnotationManager { - public static final String ID_GEOJSON_SOURCE = "mapbox-android-circle-source"; - public static final String ID_GEOJSON_LAYER = "mapbox-android-circle-layer"; - private static final String PROPERTY_CIRCLE_TRANSLATE = "circle-translate"; private static final String PROPERTY_CIRCLE_TRANSLATE_ANCHOR = "circle-translate-anchor"; private static final String PROPERTY_CIRCLE_PITCH_SCALE = "circle-pitch-scale"; @@ -72,23 +68,7 @@ public CircleManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @No */ @UiThread public CircleManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) { - this(mapView, mapboxMap, style, - new CoreElementProvider() { - @Override - public CircleLayer getLayer() { - return new CircleLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE); - } - - @Override - public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { - if (geoJsonOptions != null) { - return new GeoJsonSource(ID_GEOJSON_SOURCE, geoJsonOptions); - } else { - return new GeoJsonSource(ID_GEOJSON_SOURCE); - } - } - }, - belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); + this(mapView, mapboxMap, style, new CircleElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); } @VisibleForTesting @@ -196,16 +176,6 @@ public List create(@NonNull FeatureCollection featureCollection) { return create(options); } - /** - * Get the layer id of the annotation layer. - * - * @return the layer id - */ - @Override - String getAnnotationLayerId() { - return ID_GEOJSON_LAYER; - } - /** * Get the key of the id of the annotation. * diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CoreElementProvider.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CoreElementProvider.java index 7bb27d28c..9428abfaf 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CoreElementProvider.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/CoreElementProvider.java @@ -1,13 +1,14 @@ package com.mapbox.mapboxsdk.plugins.annotation; import android.support.annotation.Nullable; - import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; interface CoreElementProvider { + String getLayerId(); + L getLayer(); GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions); diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillElementProvider.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillElementProvider.java new file mode 100644 index 000000000..003d13e3f --- /dev/null +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillElementProvider.java @@ -0,0 +1,44 @@ +// This file is generated. + +package com.mapbox.mapboxsdk.plugins.annotation; + +import android.support.annotation.Nullable; +import com.mapbox.mapboxsdk.style.layers.FillLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * Concrete instance of a core element provider for Fill. + */ +class FillElementProvider implements CoreElementProvider{ + + private static final AtomicLong ID_GENERATOR = new AtomicLong(0); + private static final String ID_GEOJSON_LAYER = "mapbox-android-fill-layer-%s"; + private static final String ID_GEOJSON_SOURCE = "mapbox-android-fill-source-%s"; + + private final String layerId; + private final String sourceId; + + FillElementProvider() { + long id = ID_GENERATOR.incrementAndGet(); + this.layerId = String.format(ID_GEOJSON_LAYER, id); + this.sourceId = String.format(ID_GEOJSON_SOURCE, id); + } + + @Override + public String getLayerId() { + return layerId; + } + + @Override + public FillLayer getLayer() { + return new FillLayer(layerId, sourceId); + } + + @Override + public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { + return new GeoJsonSource(sourceId, geoJsonOptions); + } +} \ No newline at end of file diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillManager.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillManager.java index ff18385fb..cf08e9941 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillManager.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/FillManager.java @@ -17,7 +17,6 @@ import com.mapbox.mapboxsdk.style.layers.PropertyValue; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; @@ -31,9 +30,6 @@ */ public class FillManager extends AnnotationManager { - public static final String ID_GEOJSON_SOURCE = "mapbox-android-fill-source"; - public static final String ID_GEOJSON_LAYER = "mapbox-android-fill-layer"; - private static final String PROPERTY_FILL_ANTIALIAS = "fill-antialias"; private static final String PROPERTY_FILL_TRANSLATE = "fill-translate"; private static final String PROPERTY_FILL_TRANSLATE_ANCHOR = "fill-translate-anchor"; @@ -71,23 +67,7 @@ public FillManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonN */ @UiThread public FillManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) { - this(mapView, mapboxMap, style, - new CoreElementProvider() { - @Override - public FillLayer getLayer() { - return new FillLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE); - } - - @Override - public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { - if (geoJsonOptions != null) { - return new GeoJsonSource(ID_GEOJSON_SOURCE, geoJsonOptions); - } else { - return new GeoJsonSource(ID_GEOJSON_SOURCE); - } - } - }, - belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); + this(mapView, mapboxMap, style, new FillElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); } @VisibleForTesting @@ -177,16 +157,6 @@ public List create(@NonNull FeatureCollection featureCollection) { return create(options); } - /** - * Get the layer id of the annotation layer. - * - * @return the layer id - */ - @Override - String getAnnotationLayerId() { - return ID_GEOJSON_LAYER; - } - /** * Get the key of the id of the annotation. * diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineElementProvider.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineElementProvider.java new file mode 100644 index 000000000..cbdf5f890 --- /dev/null +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineElementProvider.java @@ -0,0 +1,44 @@ +// This file is generated. + +package com.mapbox.mapboxsdk.plugins.annotation; + +import android.support.annotation.Nullable; +import com.mapbox.mapboxsdk.style.layers.LineLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * Concrete instance of a core element provider for Line. + */ +class LineElementProvider implements CoreElementProvider{ + + private static final AtomicLong ID_GENERATOR = new AtomicLong(0); + private static final String ID_GEOJSON_LAYER = "mapbox-android-line-layer-%s"; + private static final String ID_GEOJSON_SOURCE = "mapbox-android-line-source-%s"; + + private final String layerId; + private final String sourceId; + + LineElementProvider() { + long id = ID_GENERATOR.incrementAndGet(); + this.layerId = String.format(ID_GEOJSON_LAYER, id); + this.sourceId = String.format(ID_GEOJSON_SOURCE, id); + } + + @Override + public String getLayerId() { + return layerId; + } + + @Override + public LineLayer getLayer() { + return new LineLayer(layerId, sourceId); + } + + @Override + public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { + return new GeoJsonSource(sourceId, geoJsonOptions); + } +} \ No newline at end of file diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineManager.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineManager.java index 699de7d88..9761d624a 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineManager.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/LineManager.java @@ -17,7 +17,6 @@ import com.mapbox.mapboxsdk.style.layers.PropertyValue; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; @@ -31,9 +30,6 @@ */ public class LineManager extends AnnotationManager { - public static final String ID_GEOJSON_SOURCE = "mapbox-android-line-source"; - public static final String ID_GEOJSON_LAYER = "mapbox-android-line-layer"; - private static final String PROPERTY_LINE_CAP = "line-cap"; private static final String PROPERTY_LINE_MITER_LIMIT = "line-miter-limit"; private static final String PROPERTY_LINE_ROUND_LIMIT = "line-round-limit"; @@ -74,23 +70,7 @@ public LineManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonN */ @UiThread public LineManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) { - this(mapView, mapboxMap, style, - new CoreElementProvider() { - @Override - public LineLayer getLayer() { - return new LineLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE); - } - - @Override - public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { - if (geoJsonOptions != null) { - return new GeoJsonSource(ID_GEOJSON_SOURCE, geoJsonOptions); - } else { - return new GeoJsonSource(ID_GEOJSON_SOURCE); - } - } - }, - belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); + this(mapView, mapboxMap, style, new LineElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); } @VisibleForTesting @@ -204,16 +184,6 @@ public List create(@NonNull FeatureCollection featureCollection) { return create(options); } - /** - * Get the layer id of the annotation layer. - * - * @return the layer id - */ - @Override - String getAnnotationLayerId() { - return ID_GEOJSON_LAYER; - } - /** * Get the key of the id of the annotation. * diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolElementProvider.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolElementProvider.java new file mode 100644 index 000000000..b060283be --- /dev/null +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolElementProvider.java @@ -0,0 +1,44 @@ +// This file is generated. + +package com.mapbox.mapboxsdk.plugins.annotation; + +import android.support.annotation.Nullable; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * Concrete instance of a core element provider for Symbol. + */ +class SymbolElementProvider implements CoreElementProvider{ + + private static final AtomicLong ID_GENERATOR = new AtomicLong(0); + private static final String ID_GEOJSON_LAYER = "mapbox-android-symbol-layer-%s"; + private static final String ID_GEOJSON_SOURCE = "mapbox-android-symbol-source-%s"; + + private final String layerId; + private final String sourceId; + + SymbolElementProvider() { + long id = ID_GENERATOR.incrementAndGet(); + this.layerId = String.format(ID_GEOJSON_LAYER, id); + this.sourceId = String.format(ID_GEOJSON_SOURCE, id); + } + + @Override + public String getLayerId() { + return layerId; + } + + @Override + public SymbolLayer getLayer() { + return new SymbolLayer(layerId, sourceId); + } + + @Override + public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { + return new GeoJsonSource(sourceId, geoJsonOptions); + } +} \ No newline at end of file diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManager.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManager.java index d1b406a8f..d4cef0325 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManager.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManager.java @@ -17,7 +17,6 @@ import com.mapbox.mapboxsdk.style.layers.PropertyValue; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.layers.Property; import java.util.ArrayList; @@ -31,9 +30,6 @@ */ public class SymbolManager extends AnnotationManager { - public static final String ID_GEOJSON_SOURCE = "mapbox-android-symbol-source"; - public static final String ID_GEOJSON_LAYER = "mapbox-android-symbol-layer"; - private static final String PROPERTY_SYMBOL_PLACEMENT = "symbol-placement"; private static final String PROPERTY_SYMBOL_SPACING = "symbol-spacing"; private static final String PROPERTY_SYMBOL_AVOID_EDGES = "symbol-avoid-edges"; @@ -93,23 +89,7 @@ public SymbolManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @No */ @UiThread public SymbolManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) { - this(mapView, mapboxMap, style, - new CoreElementProvider() { - @Override - public SymbolLayer getLayer() { - return new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE); - } - - @Override - public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) { - if (geoJsonOptions != null) { - return new GeoJsonSource(ID_GEOJSON_SOURCE, geoJsonOptions); - } else { - return new GeoJsonSource(ID_GEOJSON_SOURCE); - } - } - }, - belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); + this(mapView, mapboxMap, style, new SymbolElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap)); } @VisibleForTesting @@ -331,16 +311,6 @@ public List create(@NonNull FeatureCollection featureCollection) { return create(options); } - /** - * Get the layer id of the annotation layer. - * - * @return the layer id - */ - @Override - String getAnnotationLayerId() { - return ID_GEOJSON_LAYER; - } - /** * Get the key of the id of the annotation. *