From e8b17b143ecd65d715d0a00b14867c6d5e7f864f Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Tue, 11 Apr 2017 15:41:09 +0200 Subject: [PATCH] [android] - expose source layer identifier --- platform/android/CHANGELOG.md | 1 + .../mapboxsdk/style/layers/CircleLayer.java | 9 ++++ .../mapboxsdk/style/layers/FillLayer.java | 9 ++++ .../mapbox/mapboxsdk/style/layers/Layer.java | 2 + .../mapboxsdk/style/layers/LineLayer.java | 9 ++++ .../mapboxsdk/style/layers/SymbolLayer.java | 9 ++++ .../mapboxsdk/style/layers/layer.java.ejs | 9 ++++ .../testapp/style/BackgroundLayerTest.java | 1 - .../testapp/style/CircleLayerTest.java | 18 +++++-- .../testapp/style/FillLayerTest.java | 16 +++++- .../testapp/style/LineLayerTest.java | 19 +++++-- .../testapp/style/RasterLayerTest.java | 1 - .../testapp/style/SymbolLayerTest.java | 50 ++++++------------- .../mapboxsdk/testapp/style/layer.junit.ejs | 18 ++++++- .../activity/style/RuntimeStyleActivity.java | 23 ++++++++- platform/android/src/style/layers/layer.cpp | 20 ++++++++ platform/android/src/style/layers/layer.hpp | 6 ++- .../android/src/style/layers/layer.hpp.ejs | 1 - 18 files changed, 168 insertions(+), 53 deletions(-) diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index 2d3660faaf9..3b36669db7c 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -17,6 +17,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to * OfflineRegion are validated if the bounds is found in the world bounds, else onError will be invoked [#8517](https://github.com/mapbox/mapbox-gl-native/pull/8517) * Polygon holes [#8557](https://github.com/mapbox/mapbox-gl-native/pull/8557) and [#8722](https://github.com/mapbox/mapbox-gl-native/pull/8722) * Custom location source [#8710](https://github.com/mapbox/mapbox-gl-native/pull/8710) +* Expose source layer identifier [#8709](https://github.com/mapbox/mapbox-gl-native/pull/8709). ## 5.0.2 - April 3, 2017 diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java index d5cc80f7e9f..1a7df06031e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java @@ -59,6 +59,15 @@ public CircleLayer withSourceLayer(String sourceLayer) { return this; } + /** + * Get the source layer. + * + * @return sourceLayer the source layer to get + */ + public String getSourceLayer() { + return nativeGetSourceLayer(); + } + /** * Set a single filter. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java index b765aa66424..3719ae9e1b3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java @@ -59,6 +59,15 @@ public FillLayer withSourceLayer(String sourceLayer) { return this; } + /** + * Get the source layer. + * + * @return sourceLayer the source layer to get + */ + public String getSourceLayer() { + return nativeGetSourceLayer(); + } + /** * Set a single filter. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java index b4120f4f9ad..5015dd009d8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java @@ -73,6 +73,8 @@ public void setMaxZoom(float zoom) { protected native void nativeSetSourceLayer(String sourceLayer); + protected native String nativeGetSourceLayer(); + protected native float nativeGetMinZoom(); protected native float nativeGetMaxZoom(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java index 575b582988d..ca106cc1063 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java @@ -59,6 +59,15 @@ public LineLayer withSourceLayer(String sourceLayer) { return this; } + /** + * Get the source layer. + * + * @return sourceLayer the source layer to get + */ + public String getSourceLayer() { + return nativeGetSourceLayer(); + } + /** * Set a single filter. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java index 318991c0324..290e162da85 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java @@ -59,6 +59,15 @@ public SymbolLayer withSourceLayer(String sourceLayer) { return this; } + /** + * Get the source layer. + * + * @return sourceLayer the source layer to get + */ + public String getSourceLayer() { + return nativeGetSourceLayer(); + } + /** * Set a single filter. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs index 316b3aeac1c..56e0af8b452 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs @@ -79,6 +79,15 @@ public class <%- camelize(type) %>Layer extends Layer { <% } -%> <% if (type !== 'background' && type !== 'raster') { -%> + /** + * Get the source layer. + * + * @return sourceLayer the source layer to get + */ + public String getSourceLayer() { + return nativeGetSourceLayer(); + } + /** * Set a single filter. * diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java index 4f94dcc28ba..ef73dc78508 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java @@ -234,7 +234,6 @@ public void testBackgroundOpacityAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).size()); } - @After public void unregisterIntentServiceIdlingResource() { Espresso.unregisterIdlingResources(idlingResource); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java index 7b8a03fb351..11843ce28fe 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java @@ -83,6 +83,21 @@ public void testSetVisibility() { assertEquals(layer.getVisibility().getValue(), NONE); } + @Test + public void testSourceLayer() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + } + @Test public void testCircleRadiusTransition() { checkViewIsDisplayed(R.id.mapView); @@ -737,7 +752,6 @@ public void testCircleTranslateAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getCircleTranslate().getFunction().getStops()).size()); } - @Test public void testCircleTranslateAnchorAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -774,7 +788,6 @@ public void testCircleTranslateAnchorAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getCircleTranslateAnchor().getFunction().getStops()).size()); } - @Test public void testCirclePitchScaleAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1259,7 +1272,6 @@ public void testCircleStrokeOpacityAsCompositeFunction() { assertEquals(0.9f, stop.out, 0.001f); } - @After public void unregisterIntentServiceIdlingResource() { Espresso.unregisterIdlingResources(idlingResource); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java index 63dac76eddd..edbfcb1106e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java @@ -83,6 +83,20 @@ public void testSetVisibility() { assertEquals(layer.getVisibility().getValue(), NONE); } + @Test + public void testSourceLayer() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + } @Test public void testFillAntialiasAsConstant() { @@ -594,7 +608,6 @@ public void testFillTranslateAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getFillTranslate().getFunction().getStops()).size()); } - @Test public void testFillTranslateAnchorAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -679,7 +692,6 @@ public void testFillPatternAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getFillPattern().getFunction().getStops()).size()); } - @After public void unregisterIntentServiceIdlingResource() { Espresso.unregisterIdlingResources(idlingResource); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java index 110d23dd901..7263b5de73a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java @@ -83,6 +83,20 @@ public void testSetVisibility() { assertEquals(layer.getVisibility().getValue(), NONE); } + @Test + public void testSourceLayer() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + } @Test public void testLineCapAsConstant() { @@ -120,7 +134,6 @@ public void testLineCapAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getLineCap().getFunction().getStops()).size()); } - @Test public void testLineJoinAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -157,7 +170,6 @@ public void testLineJoinAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getLineJoin().getFunction().getStops()).size()); } - @Test public void testLineMiterLimitAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -195,7 +207,6 @@ public void testLineMiterLimitAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getLineMiterLimit().getFunction().getStops()).size()); } - @Test public void testLineRoundLimitAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -573,7 +584,6 @@ public void testLineTranslateAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getLineTranslate().getFunction().getStops()).size()); } - @Test public void testLineTranslateAnchorAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1226,7 +1236,6 @@ public void testLinePatternAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getLinePattern().getFunction().getStops()).size()); } - @After public void unregisterIntentServiceIdlingResource() { Espresso.unregisterIdlingResources(idlingResource); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java index 2d902a74327..8ff3911cd1a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java @@ -426,7 +426,6 @@ public void testRasterFadeDurationAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getRasterFadeDuration().getFunction().getStops()).size()); } - @After public void unregisterIntentServiceIdlingResource() { Espresso.unregisterIdlingResources(idlingResource); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java index d81965f2c9e..97fc3e07d3c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java @@ -83,6 +83,20 @@ public void testSetVisibility() { assertEquals(layer.getVisibility().getValue(), NONE); } + @Test + public void testSourceLayer() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + } @Test public void testSymbolPlacementAsConstant() { @@ -120,7 +134,6 @@ public void testSymbolPlacementAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getSymbolPlacement().getFunction().getStops()).size()); } - @Test public void testSymbolSpacingAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -158,7 +171,6 @@ public void testSymbolSpacingAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getSymbolSpacing().getFunction().getStops()).size()); } - @Test public void testSymbolAvoidEdgesAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -195,7 +207,6 @@ public void testSymbolAvoidEdgesAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getSymbolAvoidEdges().getFunction().getStops()).size()); } - @Test public void testIconAllowOverlapAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -232,7 +243,6 @@ public void testIconAllowOverlapAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getIconAllowOverlap().getFunction().getStops()).size()); } - @Test public void testIconIgnorePlacementAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -269,7 +279,6 @@ public void testIconIgnorePlacementAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getIconIgnorePlacement().getFunction().getStops()).size()); } - @Test public void testIconOptionalAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -306,7 +315,6 @@ public void testIconOptionalAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getIconOptional().getFunction().getStops()).size()); } - @Test public void testIconRotationAlignmentAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -343,7 +351,6 @@ public void testIconRotationAlignmentAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getIconRotationAlignment().getFunction().getStops()).size()); } - @Test public void testIconSizeAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -381,7 +388,6 @@ public void testIconSizeAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getIconSize().getFunction().getStops()).size()); } - @Test public void testIconSizeAsIdentitySourceFunction() { checkViewIsDisplayed(R.id.mapView); @@ -526,7 +532,6 @@ public void testIconTextFitAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getIconTextFit().getFunction().getStops()).size()); } - @Test public void testIconTextFitPaddingAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -564,7 +569,6 @@ public void testIconTextFitPaddingAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getIconTextFitPadding().getFunction().getStops()).size()); } - @Test public void testIconImageAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -601,7 +605,6 @@ public void testIconImageAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getIconImage().getFunction().getStops()).size()); } - @Test public void testIconImageAsIdentitySourceFunction() { checkViewIsDisplayed(R.id.mapView); @@ -792,7 +795,6 @@ public void testIconRotateAsCompositeFunction() { assertEquals(0.9f, stop.out, 0.001f); } - @Test public void testIconPaddingAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -830,7 +832,6 @@ public void testIconPaddingAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getIconPadding().getFunction().getStops()).size()); } - @Test public void testIconKeepUprightAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -867,7 +868,6 @@ public void testIconKeepUprightAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getIconKeepUpright().getFunction().getStops()).size()); } - @Test public void testIconOffsetAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -950,7 +950,6 @@ public void testIconOffsetAsIntervalSourceFunction() { assertEquals(IntervalStops.class, layer.getIconOffset().getFunction().getStops().getClass()); } - @Test public void testTextPitchAlignmentAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -987,7 +986,6 @@ public void testTextPitchAlignmentAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getTextPitchAlignment().getFunction().getStops()).size()); } - @Test public void testTextRotationAlignmentAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1024,7 +1022,6 @@ public void testTextRotationAlignmentAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getTextRotationAlignment().getFunction().getStops()).size()); } - @Test public void testTextFieldAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1106,7 +1103,6 @@ public void testTextFieldAsIntervalSourceFunction() { assertEquals(IntervalStops.class, layer.getTextField().getFunction().getStops().getClass()); } - @Test public void testTextFontAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1143,7 +1139,6 @@ public void testTextFontAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getTextFont().getFunction().getStops()).size()); } - @Test public void testTextSizeAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1181,7 +1176,6 @@ public void testTextSizeAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getTextSize().getFunction().getStops()).size()); } - @Test public void testTextSizeAsIdentitySourceFunction() { checkViewIsDisplayed(R.id.mapView); @@ -1327,7 +1321,6 @@ public void testTextMaxWidthAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getTextMaxWidth().getFunction().getStops()).size()); } - @Test public void testTextLineHeightAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1365,7 +1358,6 @@ public void testTextLineHeightAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getTextLineHeight().getFunction().getStops()).size()); } - @Test public void testTextLetterSpacingAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1403,7 +1395,6 @@ public void testTextLetterSpacingAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getTextLetterSpacing().getFunction().getStops()).size()); } - @Test public void testTextJustifyAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1440,7 +1431,6 @@ public void testTextJustifyAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getTextJustify().getFunction().getStops()).size()); } - @Test public void testTextAnchorAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1477,7 +1467,6 @@ public void testTextAnchorAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getTextAnchor().getFunction().getStops()).size()); } - @Test public void testTextMaxAngleAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1515,7 +1504,6 @@ public void testTextMaxAngleAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getTextMaxAngle().getFunction().getStops()).size()); } - @Test public void testTextRotateAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1553,7 +1541,6 @@ public void testTextRotateAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getTextRotate().getFunction().getStops()).size()); } - @Test public void testTextRotateAsIdentitySourceFunction() { checkViewIsDisplayed(R.id.mapView); @@ -1699,7 +1686,6 @@ public void testTextPaddingAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getTextPadding().getFunction().getStops()).size()); } - @Test public void testTextKeepUprightAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1736,7 +1722,6 @@ public void testTextKeepUprightAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getTextKeepUpright().getFunction().getStops()).size()); } - @Test public void testTextTransformAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1818,7 +1803,6 @@ public void testTextTransformAsIntervalSourceFunction() { assertEquals(IntervalStops.class, layer.getTextTransform().getFunction().getStops().getClass()); } - @Test public void testTextOffsetAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1901,7 +1885,6 @@ public void testTextOffsetAsIntervalSourceFunction() { assertEquals(IntervalStops.class, layer.getTextOffset().getFunction().getStops().getClass()); } - @Test public void testTextAllowOverlapAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1938,7 +1921,6 @@ public void testTextAllowOverlapAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getTextAllowOverlap().getFunction().getStops()).size()); } - @Test public void testTextIgnorePlacementAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -1975,7 +1957,6 @@ public void testTextIgnorePlacementAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getTextIgnorePlacement().getFunction().getStops()).size()); } - @Test public void testTextOptionalAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -2800,7 +2781,6 @@ public void testIconTranslateAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getIconTranslate().getFunction().getStops()).size()); } - @Test public void testIconTranslateAnchorAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -3625,7 +3605,6 @@ public void testTextTranslateAsCameraFunction() { assertEquals(1, ((ExponentialStops) layer.getTextTranslate().getFunction().getStops()).size()); } - @Test public void testTextTranslateAnchorAsConstant() { checkViewIsDisplayed(R.id.mapView); @@ -3662,7 +3641,6 @@ public void testTextTranslateAnchorAsCameraFunction() { assertEquals(1, ((IntervalStops) layer.getTextTranslateAnchor().getFunction().getStops()).size()); } - @After public void unregisterIntentServiceIdlingResource() { Espresso.unregisterIdlingResources(idlingResource); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs index 8aa0f159545..fd0c177fb87 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs @@ -91,9 +91,26 @@ public class <%- camelize(type) %>LayerTest extends BaseStyleTest { layer.setProperties(visibility(NONE)); assertEquals(layer.getVisibility().getValue(), NONE); } +<% if (!(type === 'background' || type === 'raster')) { -%> + @Test + public void testSourceLayer() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + } +<% } -%> <% for (const property of properties) { -%> <% if (property.transition) { -%> + @Test public void test<%- camelize(property.name) %>Transition() { checkViewIsDisplayed(R.id.mapView); @@ -363,7 +380,6 @@ public class <%- camelize(type) %>LayerTest extends BaseStyleTest { assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED); } <% } -%> - <% } -%> @After diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java index f63ede9bce9..f6754af0f93 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java @@ -17,12 +17,14 @@ import com.mapbox.mapboxsdk.style.functions.Function; import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.functions.stops.Stop; +import com.mapbox.mapboxsdk.style.layers.CircleLayer; import com.mapbox.mapboxsdk.style.layers.FillLayer; import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.layers.LineLayer; import com.mapbox.mapboxsdk.style.layers.Property; import com.mapbox.mapboxsdk.style.layers.PropertyValue; import com.mapbox.mapboxsdk.style.layers.RasterLayer; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import com.mapbox.mapboxsdk.style.sources.RasterSource; @@ -41,6 +43,7 @@ import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import timber.log.Timber; @@ -408,7 +411,25 @@ private void addTerrainLayer() { lineWidth(20f) ); - mapboxMap.addLayer(layer); + // adding layers below "road" layers + List layers = mapboxMap.getLayers(); + Layer latestLayer = null; + Collections.reverse(layers); + for (Layer currentLayer : layers) { + if (currentLayer instanceof FillLayer && ((FillLayer) currentLayer).getSourceLayer().equals("road")) { + latestLayer = currentLayer; + } else if (currentLayer instanceof CircleLayer && ((CircleLayer) currentLayer).getSourceLayer().equals("road")) { + latestLayer = currentLayer; + } else if (currentLayer instanceof SymbolLayer && ((SymbolLayer) currentLayer).getSourceLayer().equals("road")) { + latestLayer = currentLayer; + } else if (currentLayer instanceof LineLayer && ((LineLayer) currentLayer).getSourceLayer().equals("road")) { + latestLayer = currentLayer; + } + } + + if (latestLayer != null) { + mapboxMap.addLayerBelow(layer, latestLayer.getId()); + } // Need to get a fresh handle layer = mapboxMap.getLayerAs("terrainLayer"); diff --git a/platform/android/src/style/layers/layer.cpp b/platform/android/src/style/layers/layer.cpp index 6c9de51a0d6..58c0c5ee84a 100644 --- a/platform/android/src/style/layers/layer.cpp +++ b/platform/android/src/style/layers/layer.cpp @@ -144,6 +144,25 @@ namespace android { } } + jni::String Layer::getSourceLayer(jni::JNIEnv& env) { + using namespace mbgl::style; + + std::string sourceLayerId; + if (layer.is()) { + sourceLayerId = layer.as()->getSourceLayer(); + } else if (layer.is()) { + sourceLayerId = layer.as()->getSourceLayer(); + } else if (layer.is()) { + sourceLayerId = layer.as()->getSourceLayer(); + } else if (layer.is()) { + sourceLayerId = layer.as()->getSourceLayer(); + } else { + mbgl::Log::Warning(mbgl::Event::JNI, "Layer doesn't support source layer"); + } + + return jni::Make(env, sourceLayerId); + } + jni::jfloat Layer::getMinZoom(jni::JNIEnv&){ return layer.getMinZoom(); } @@ -180,6 +199,7 @@ namespace android { METHOD(&Layer::setPaintProperty, "nativeSetPaintProperty"), METHOD(&Layer::setFilter, "nativeSetFilter"), METHOD(&Layer::setSourceLayer, "nativeSetSourceLayer"), + METHOD(&Layer::getSourceLayer, "nativeGetSourceLayer"), METHOD(&Layer::getMinZoom, "nativeGetMinZoom"), METHOD(&Layer::getMaxZoom, "nativeGetMaxZoom"), METHOD(&Layer::setMinZoom, "nativeSetMinZoom"), diff --git a/platform/android/src/style/layers/layer.hpp b/platform/android/src/style/layers/layer.hpp index deea7a66131..78c3f80b481 100644 --- a/platform/android/src/style/layers/layer.hpp +++ b/platform/android/src/style/layers/layer.hpp @@ -66,9 +66,11 @@ class Layer : private mbgl::util::noncopyable { /* common properties, but not shared by all */ - void setFilter(jni::JNIEnv& env, jni::Array> jfilter); + void setFilter(jni::JNIEnv&, jni::Array>); - void setSourceLayer(jni::JNIEnv& env, jni::String sourceLayer); + void setSourceLayer(jni::JNIEnv&, jni::String); + + jni::String getSourceLayer(jni::JNIEnv&); // Property getters diff --git a/platform/android/src/style/layers/layer.hpp.ejs b/platform/android/src/style/layers/layer.hpp.ejs index d1e84ac2d44..837049b4c37 100644 --- a/platform/android/src/style/layers/layer.hpp.ejs +++ b/platform/android/src/style/layers/layer.hpp.ejs @@ -44,7 +44,6 @@ public: jni::Object get<%- camelize(property.name) %>Transition(jni::JNIEnv&); <% } -%> <% } -%> - jni::jobject* createJavaPeer(jni::JNIEnv&); }; // class <%- camelize(type) %>Layer