Skip to content

Commit

Permalink
Add support to insert a layer above a reference layer (#31)
Browse files Browse the repository at this point in the history
* Add support to insert a layer above a reference layer

Co-authored-by: Jonas Vautherin <jonas.vautherin@gmail.com>

* Update testapp with new annotation API

* Fix unit tests according to new layerId API

* Only allow one of [belowLayerId, aboveLayerId] to be set at a time

---------

Co-authored-by: Roman Bapst <bapstroman@gmail.com>
  • Loading branch information
JonasVautherin and RomanBapst committed Jun 23, 2023
1 parent 733ee86 commit a19c210
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void initMap(MapboxMap mapboxMap) {
});

mapboxMap.setStyle(new Style.Builder().fromUri(Style.getPredefinedStyle("Streets")), style -> {
symbolManager = new SymbolManager(mapView, mapboxMap, style, null, clusterOptions);
symbolManager = new SymbolManager(mapView, mapboxMap, style, null, null, clusterOptions);
symbolManager.setIconAllowOverlap(true);
loadData();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onMapReady(@NonNull MapboxMap map) {
map.setStyle(new Style.Builder().fromUri(Style.getPredefinedStyle("Streets")), style -> {
fillManager = new FillManager(mapView, map, style, "aerialway");
fillManager = new FillManager(mapView, map, style, "aerialway", null);
fillManager.addClickListener(fill -> {
Toast.makeText(
FillChangeActivity.this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected void onCreate(Bundle savedInstanceState) {

// create symbol manager
GeoJsonOptions geoJsonOptions = new GeoJsonOptions().withTolerance(0.4f);
symbolManager = new SymbolManager(mapView, mapboxMap, style, null, geoJsonOptions);
symbolManager = new SymbolManager(mapView, mapboxMap, style, null, null, geoJsonOptions);
symbolManager.addClickListener(symbol -> {
Toast.makeText(SymbolActivity.this,
String.format("Symbol clicked %s", symbol.getId()),
Expand Down
29 changes: 16 additions & 13 deletions plugin-annotation/scripts/annotation_manager.java.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,34 @@ public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize
*/
@UiThread
public <%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style) {
this(mapView, mapboxMap, style, null, (GeoJsonOptions) null);
this(mapView, mapboxMap, style, null, null, (GeoJsonOptions) null);
}

/**
* Create a <%- type %> manager, used to manage <%- type %>s.
*
* @param mapboxMap the map object to add <%- type %>s to
* @param style a valid a fully loaded style object
* @param belowLayerId the id of the layer above the circle layer
* @param belowLayerId the id of the layer above the <%- type %> layer
* @param aboveLayerId the id of the layer below the <%- type %> layer
*/
@UiThread
public <%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId) {
this(mapView, mapboxMap, style, belowLayerId, (GeoJsonOptions) null);
public <%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable String aboveLayerId) {
this(mapView, mapboxMap, style, belowLayerId, aboveLayerId, (GeoJsonOptions) null);
}

/**
* Create a <%- type %> manager, used to manage <%- type %>s.
*
* @param mapboxMap the map object to add <%- type %>s to
* @param style a valid a fully loaded style object
* @param belowLayerId the id of the layer above the circle layer
* @param belowLayerId the id of the layer above the <%- type %> layer
* @param aboveLayerId the id of the layer below the <%- type %> layer
* @param geoJsonOptions options for the internal source
*/
@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 <%- camelize(type) %>ElementProvider(), belowLayerId, geoJsonOptions, DraggableAnnotationController.getInstance(mapView, mapboxMap));
public <%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable String aboveLayerId, @Nullable GeoJsonOptions geoJsonOptions) {
this(mapView, mapboxMap, style, new <%- camelize(type) %>ElementProvider(), belowLayerId, aboveLayerId, geoJsonOptions, DraggableAnnotationController.getInstance(mapView, mapboxMap));
}
<% if (type === "symbol") { -%>
Expand All @@ -83,19 +85,20 @@ public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize
*
* @param mapboxMap the map object to add <%- type %>s to
* @param style a valid a fully loaded style object
* @param belowLayerId the id of the layer above the circle layer
* @param belowLayerId the id of the layer above the <%- type %> layer
* @param aboveLayerId the id of the layer below the <%- type %> layer
* @param clusterOptions options for the clustering configuration
*/
@UiThread
public <%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @NonNull ClusterOptions clusterOptions) {
this(mapView, mapboxMap, style, new SymbolElementProvider(), belowLayerId, new GeoJsonOptions().withCluster(true).withClusterRadius(clusterOptions.getClusterRadius()).withClusterMaxZoom(clusterOptions.getClusterMaxZoom()), DraggableAnnotationController.getInstance(mapView, mapboxMap));
public <%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable String aboveLayerId, @NonNull ClusterOptions clusterOptions) {
this(mapView, mapboxMap, style, new SymbolElementProvider(), belowLayerId, aboveLayerId, new GeoJsonOptions().withCluster(true).withClusterRadius(clusterOptions.getClusterRadius()).withClusterMaxZoom(clusterOptions.getClusterMaxZoom()), DraggableAnnotationController.getInstance(mapView, mapboxMap));
clusterOptions.apply(style, coreElementProvider.getSourceId());
}
<% } -%>

@VisibleForTesting
<%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<<%- camelize(type) %>Layer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController draggableAnnotationController) {
super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
@UiThread
<%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<<%- camelize(type) %>Layer> coreElementProvider, @Nullable String belowLayerId, @Nullable String aboveLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController draggableAnnotationController) {
super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, aboveLayerId, geoJsonOptions);
}

@Override
Expand Down
42 changes: 21 additions & 21 deletions plugin-annotation/scripts/annotation_manager_unit_test.junit.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testInitialization() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
verify(style).addSource(geoJsonSource);
verify(style).addLayer(<%- type %>Layer);
assertTrue(<%- type %>Manager.dataDrivenPropertyUsageMap.size() > 0);
Expand All @@ -76,7 +76,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testInitializationOnStyleReload() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
verify(style).addSource(geoJsonSource);
verify(style).addLayer(<%- type %>Layer);
assertTrue(<%- type %>Manager.dataDrivenPropertyUsageMap.size() > 0);
Expand Down Expand Up @@ -117,7 +117,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testLayerBelowInitialization() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, "test_layer", null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, "test_layer", null, null, draggableAnnotationController);
verify(style).addSource(geoJsonSource);
verify(style).addLayerBelow(<%- type %>Layer, "test_layer");
assertTrue(<%- type %>Manager.dataDrivenPropertyUsageMap.size() > 0);
Expand All @@ -130,7 +130,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testGeoJsonOptionsInitialization() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, geoJsonOptions, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, geoJsonOptions, draggableAnnotationController);
verify(style).addSource(optionedGeoJsonSource);
verify(style).addLayer(<%- type %>Layer);
assertTrue(<%- type %>Manager.dataDrivenPropertyUsageMap.size() > 0);
Expand All @@ -144,13 +144,13 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testLayerId() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, 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);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
<%- camelize(type) %> <%- type %> = <%- type %>Manager.create(new <%- camelize(type) %>Options().withLatLng(new LatLng()));
<% } else if (type === "line") { -%>
Expand All @@ -173,7 +173,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void add<%- camelize(type) %>FromFeatureCollection() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
Geometry geometry = Point.fromLngLat(10, 10);
<% } else if (type === "line") { -%>
Expand Down Expand Up @@ -232,7 +232,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void add<%- camelize(type) %>s() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
List<LatLng> latLngList = new ArrayList<>();
latLngList.add(new LatLng());
Expand Down Expand Up @@ -292,7 +292,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testDelete<%- camelize(type) %>() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
<%- camelize(type) %> <%- type %> = <%- type %>Manager.create(new <%- camelize(type) %>Options().withLatLng(new LatLng()));
<% } else if (type === "line") { -%>
Expand All @@ -315,7 +315,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testGeometry<%- camelize(type) %>() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
LatLng latLng = new LatLng(12, 34);
<%- camelize(type) %>Options options = new <%- camelize(type) %>Options().withLatLng(latLng);
Expand Down Expand Up @@ -370,7 +370,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testFeatureId<%- camelize(type) %>() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
<%- camelize(type) %> <%- type %>Zero = <%- type %>Manager.create(new <%- camelize(type) %>Options().withLatLng(new LatLng()));
<%- camelize(type) %> <%- type %>One = <%- type %>Manager.create(new <%- camelize(type) %>Options().withLatLng(new LatLng()));
Expand All @@ -396,7 +396,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void test<%- camelize(type) %>DraggableFlag() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
<%- camelize(type) %> <%- type %>Zero = <%- type %>Manager.create(new <%- camelize(type) %>Options().withLatLng(new LatLng()));
<% } else if (type === "line") { -%>
Expand Down Expand Up @@ -426,7 +426,7 @@ public class <%- camelize(type) %>ManagerTest {
@Test
public void test<%- camelize(property.name) %>LayerProperty() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
verify(<%- type %>Layer, times(0)).setProperties(argThat(new PropertyValueMatcher(<%- camelizeWithLeadingLowercase(property.name) %>(get("<%- property.name %>")))));
<% if (type === "circle" || type === "symbol") { -%>
Expand Down Expand Up @@ -456,7 +456,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void test<%- camelize(type) %>LayerFilter() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
Expression expression = Expression.eq(Expression.get("test"), "selected");
verify(<%- type %>Layer, times(0)).setFilter(expression);

Expand All @@ -471,7 +471,7 @@ public class <%- camelize(type) %>ManagerTest {
@Test
public void testClickListener() {
On<%- camelize(type) %>ClickListener listener = mock(On<%- camelize(type) %>ClickListener.class);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
assertTrue(<%- type %>Manager.getClickListeners().isEmpty());
<%- type %>Manager.addClickListener(listener);
assertTrue(<%- type %>Manager.getClickListeners().contains(listener));
Expand All @@ -482,7 +482,7 @@ public class <%- camelize(type) %>ManagerTest {
@Test
public void testLongClickListener() {
On<%- camelize(type) %>LongClickListener listener = mock(On<%- camelize(type) %>LongClickListener.class);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
assertTrue(<%- type %>Manager.getLongClickListeners().isEmpty());
<%- type %>Manager.addLongClickListener(listener);
assertTrue(<%- type %>Manager.getLongClickListeners().contains(listener));
Expand All @@ -493,7 +493,7 @@ public class <%- camelize(type) %>ManagerTest {
@Test
public void testDragListener() {
On<%- camelize(type) %>DragListener listener = mock(On<%- camelize(type) %>DragListener.class);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
assertTrue(<%- type %>Manager.getDragListeners().isEmpty());
<%- type %>Manager.addDragListener(listener);
assertTrue(<%- type %>Manager.getDragListeners().contains(listener));
Expand All @@ -503,7 +503,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testCustomData() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
<%- camelize(type) %>Options options = new <%- camelize(type) %>Options().withLatLng(new LatLng());
<% } else if (type === "line") { -%>
Expand All @@ -527,7 +527,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testClearAll() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
<%- camelize(type) %>Options options = new <%- camelize(type) %>Options().withLatLng(new LatLng());
<% } else if (type === "line") { -%>
Expand All @@ -552,7 +552,7 @@ public class <%- camelize(type) %>ManagerTest {

@Test
public void testIgnoreClearedAnnotations() {
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
<%- type %>Manager = new <%- camelize(type) %>Manager(mapView, mapboxMap, style, coreElementProvider, null, null, null, draggableAnnotationController);
<% if (type === "circle" || type === "symbol") { -%>
<%- camelize(type) %>Options options = new <%- camelize(type) %>Options().withLatLng(new LatLng());
<% } else if (type === "line") { -%>
Expand Down Expand Up @@ -580,4 +580,4 @@ public class <%- camelize(type) %>ManagerTest {
assertTrue(<%- type %>Manager.getAnnotations().isEmpty());
}

}
}
Loading

0 comments on commit a19c210

Please sign in to comment.