From 5bcdbc5135fa2e982446f368d8652ea8b587c319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Tue, 19 Nov 2019 12:50:06 +0100 Subject: [PATCH] [annotation] expose underlying, generated Layer ID --- .../scripts/annotation_manager_unit_test.junit.ejs | 8 ++++++++ .../plugins/annotation/AnnotationManager.java | 11 +++++++++++ .../plugins/annotation/CircleManagerTest.java | 8 ++++++++ .../mapboxsdk/plugins/annotation/FillManagerTest.java | 8 ++++++++ .../mapboxsdk/plugins/annotation/LineManagerTest.java | 8 ++++++++ .../plugins/annotation/SymbolManagerTest.java | 8 ++++++++ 6 files changed, 51 insertions(+) diff --git a/plugin-annotation/scripts/annotation_manager_unit_test.junit.ejs b/plugin-annotation/scripts/annotation_manager_unit_test.junit.ejs index 5b7f6ee24..c114499c8 100644 --- a/plugin-annotation/scripts/annotation_manager_unit_test.junit.ejs +++ b/plugin-annotation/scripts/annotation_manager_unit_test.junit.ejs @@ -43,6 +43,7 @@ public class <%- camelize(type) %>ManagerTest { private Style style = mock(Style.class); private GeoJsonSource geoJsonSource = mock(GeoJsonSource.class); private GeoJsonSource optionedGeoJsonSource = mock(GeoJsonSource.class); + private String layerId = "annotation_layer"; private <%- camelize(type) %>Layer <%- type %>Layer = mock(<%- camelize(type) %>Layer.class); private <%- camelize(type) %>Manager <%- type %>Manager; private CoreElementProvider<<%- camelize(type) %>Layer> coreElementProvider = mock(CoreElementProvider.class); @@ -50,6 +51,7 @@ public class <%- camelize(type) %>ManagerTest { @Before public void beforeTest() { + when(<%- type %>Layer.getId()).thenReturn(layerId); when(coreElementProvider.getLayer()).thenReturn(<%- type %>Layer); when(coreElementProvider.getSource(null)).thenReturn(geoJsonSource); when(coreElementProvider.getSource(geoJsonOptions)).thenReturn(optionedGeoJsonSource); @@ -153,6 +155,12 @@ public class <%- camelize(type) %>ManagerTest { verify(geoJsonSource, times(1)).setGeoJson(any(FeatureCollection.class)); } + @Test + public void testLayerId() { + <%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); + assertEquals(layerId, <%- type %>Manager.getLayerId()); + } + @Test public void testAdd<%- camelize(type) %>() { <%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); 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 3e1c84ab6..511fcbc7c 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 @@ -101,6 +101,17 @@ public void onStyleLoaded(@NonNull Style loadedStyle) { }); } + /** + * Returns a layer ID that annotations created by this manager are laid out on. + * + * This reference can be used together with {@link Style#addLayerAbove(Layer, String)} + * or {@link Style#addLayerBelow(Layer, String)} to improve other layers positioning in relation to this manager. + * @return underlying layer's ID + */ + public String getLayerId() { + return layer.getId(); + } + /** * Get a list of current annotations. * diff --git a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManagerTest.java b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManagerTest.java index c559e5338..629a086c7 100644 --- a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManagerTest.java +++ b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/CircleManagerTest.java @@ -38,6 +38,7 @@ public class CircleManagerTest { private Style style = mock(Style.class); private GeoJsonSource geoJsonSource = mock(GeoJsonSource.class); private GeoJsonSource optionedGeoJsonSource = mock(GeoJsonSource.class); + private String layerId = "annotation_layer"; private CircleLayer circleLayer = mock(CircleLayer.class); private CircleManager circleManager; private CoreElementProvider coreElementProvider = mock(CoreElementProvider.class); @@ -45,6 +46,7 @@ public class CircleManagerTest { @Before public void beforeTest() { + when(circleLayer.getId()).thenReturn(layerId); when(coreElementProvider.getLayer()).thenReturn(circleLayer); when(coreElementProvider.getSource(null)).thenReturn(geoJsonSource); when(coreElementProvider.getSource(geoJsonOptions)).thenReturn(optionedGeoJsonSource); @@ -148,6 +150,12 @@ public void testNoUpdateOnStyleReload() { verify(geoJsonSource, times(1)).setGeoJson(any(FeatureCollection.class)); } + @Test + public void testLayerId() { + circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); + assertEquals(layerId, circleManager.getLayerId()); + } + @Test public void testAddCircle() { circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); diff --git a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/FillManagerTest.java b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/FillManagerTest.java index 347b18983..8760f9f6c 100644 --- a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/FillManagerTest.java +++ b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/FillManagerTest.java @@ -38,6 +38,7 @@ public class FillManagerTest { private Style style = mock(Style.class); private GeoJsonSource geoJsonSource = mock(GeoJsonSource.class); private GeoJsonSource optionedGeoJsonSource = mock(GeoJsonSource.class); + private String layerId = "annotation_layer"; private FillLayer fillLayer = mock(FillLayer.class); private FillManager fillManager; private CoreElementProvider coreElementProvider = mock(CoreElementProvider.class); @@ -45,6 +46,7 @@ public class FillManagerTest { @Before public void beforeTest() { + when(fillLayer.getId()).thenReturn(layerId); when(coreElementProvider.getLayer()).thenReturn(fillLayer); when(coreElementProvider.getSource(null)).thenReturn(geoJsonSource); when(coreElementProvider.getSource(geoJsonOptions)).thenReturn(optionedGeoJsonSource); @@ -148,6 +150,12 @@ public void testNoUpdateOnStyleReload() { verify(geoJsonSource, times(1)).setGeoJson(any(FeatureCollection.class)); } + @Test + public void testLayerId() { + fillManager = new FillManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); + assertEquals(layerId, fillManager.getLayerId()); + } + @Test public void testAddFill() { fillManager = new FillManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); diff --git a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/LineManagerTest.java b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/LineManagerTest.java index 874c3c241..25970c1ae 100644 --- a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/LineManagerTest.java +++ b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/LineManagerTest.java @@ -38,6 +38,7 @@ public class LineManagerTest { private Style style = mock(Style.class); private GeoJsonSource geoJsonSource = mock(GeoJsonSource.class); private GeoJsonSource optionedGeoJsonSource = mock(GeoJsonSource.class); + private String layerId = "annotation_layer"; private LineLayer lineLayer = mock(LineLayer.class); private LineManager lineManager; private CoreElementProvider coreElementProvider = mock(CoreElementProvider.class); @@ -45,6 +46,7 @@ public class LineManagerTest { @Before public void beforeTest() { + when(lineLayer.getId()).thenReturn(layerId); when(coreElementProvider.getLayer()).thenReturn(lineLayer); when(coreElementProvider.getSource(null)).thenReturn(geoJsonSource); when(coreElementProvider.getSource(geoJsonOptions)).thenReturn(optionedGeoJsonSource); @@ -148,6 +150,12 @@ public void testNoUpdateOnStyleReload() { verify(geoJsonSource, times(1)).setGeoJson(any(FeatureCollection.class)); } + @Test + public void testLayerId() { + lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); + assertEquals(layerId, lineManager.getLayerId()); + } + @Test public void testAddLine() { lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); diff --git a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManagerTest.java b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManagerTest.java index 354a35954..c01734911 100644 --- a/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManagerTest.java +++ b/plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/SymbolManagerTest.java @@ -38,6 +38,7 @@ public class SymbolManagerTest { private Style style = mock(Style.class); private GeoJsonSource geoJsonSource = mock(GeoJsonSource.class); private GeoJsonSource optionedGeoJsonSource = mock(GeoJsonSource.class); + private String layerId = "annotation_layer"; private SymbolLayer symbolLayer = mock(SymbolLayer.class); private SymbolManager symbolManager; private CoreElementProvider coreElementProvider = mock(CoreElementProvider.class); @@ -45,6 +46,7 @@ public class SymbolManagerTest { @Before public void beforeTest() { + when(symbolLayer.getId()).thenReturn(layerId); when(coreElementProvider.getLayer()).thenReturn(symbolLayer); when(coreElementProvider.getSource(null)).thenReturn(geoJsonSource); when(coreElementProvider.getSource(geoJsonOptions)).thenReturn(optionedGeoJsonSource); @@ -148,6 +150,12 @@ public void testNoUpdateOnStyleReload() { verify(geoJsonSource, times(1)).setGeoJson(any(FeatureCollection.class)); } + @Test + public void testLayerId() { + symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController); + assertEquals(layerId, symbolManager.getLayerId()); + } + @Test public void testAddSymbol() { symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);