diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java index 5c988d710..9e3a79431 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java @@ -218,6 +218,7 @@ public void whenMapCameraInitializesTilted_iconsGetPlacedWithCorrectOffset() thr locationLayerPlugin.setRenderMode(RenderMode.NORMAL); locationLayerPlugin.forceLocationUpdate(location); SymbolLayer layer = mapboxMap.getLayerAs(FOREGROUND_LAYER); + uiController.loopMainThreadForAtLeast(200); Float[] value = layer.getIconOffset().getValue(); Assert.assertEquals((-0.05 * 60), value[1], 0.1); }); diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPluginTest.java b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPluginTest.java index 11fd20898..cad3e330c 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPluginTest.java +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPluginTest.java @@ -9,8 +9,6 @@ import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.plugins.testapp.activity.TrafficActivity; -import com.mapbox.mapboxsdk.style.functions.CameraFunction; -import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; import com.mapbox.mapboxsdk.style.layers.LineLayer; import com.mapbox.mapboxsdk.style.layers.Property; import com.mapbox.mapboxsdk.utils.OnMapReadyIdlingResource; @@ -822,11 +820,7 @@ public void lineWidthFunctionLocalBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Local.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(2, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -838,11 +832,7 @@ public void lineWidthFunctionLocalCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Local.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(2, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -855,11 +845,7 @@ public void lineWidthFunctionSecondaryBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Secondary.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -871,11 +857,7 @@ public void lineWidthFunctionSecondaryCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Secondary.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -887,11 +869,7 @@ public void lineWidthFunctionPrimaryBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Primary.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -903,11 +881,7 @@ public void lineWidthFunctionPrimaryCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Primary.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -919,11 +893,7 @@ public void lineWidthFunctionTrunkBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Trunk.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(3, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -935,11 +905,7 @@ public void lineWidthFunctionTrunkCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Trunk.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -951,11 +917,7 @@ public void lineWidthFunctionMotorwayBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(MotorWay.BASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -967,11 +929,7 @@ public void lineWidthFunctionMotorwayCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(MotorWay.CASE_LAYER_ID); assertNotNull(layer.getLineWidth()); - assertNotNull(layer.getLineWidth().getFunction()); - assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + assertNotNull(layer.getLineWidth().getExpression()); } }); } @@ -983,11 +941,7 @@ public void lineOffsetFunctionLocalBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Local.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(2, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -999,11 +953,7 @@ public void lineOffsetFunctionLocalCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Local.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(2, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1016,11 +966,7 @@ public void lineOffsetFunctionSecondaryBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Secondary.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1032,11 +978,7 @@ public void lineOffsetFunctionSecondaryCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Secondary.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1048,11 +990,7 @@ public void lineOffsetFunctionPrimaryBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Primary.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1064,11 +1002,7 @@ public void lineOffsetFunctionPrimaryCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Primary.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1080,11 +1014,7 @@ public void lineOffsetFunctionTrunkBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Trunk.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1096,11 +1026,7 @@ public void lineOffsetFunctionTrunkCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(Trunk.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(4, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1112,11 +1038,7 @@ public void lineOffsetFunctionMotorwayBaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(MotorWay.BASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(5, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } @@ -1128,11 +1050,7 @@ public void lineOffsetFunctionMotorwayCaseLayer() throws Exception { public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) { LineLayer layer = mapboxMap.getLayerAs(MotorWay.CASE_LAYER_ID); assertNotNull(layer.getLineOffset()); - assertNotNull(layer.getLineOffset().getFunction()); - assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); - assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); - assertEquals(1.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); - assertEquals(5, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + assertNotNull(layer.getLineOffset().getExpression()); } }); } diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java b/app/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java index 31c699b4b..ff3ab5e4a 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/utils/OnMapReadyIdlingResource.java @@ -3,20 +3,25 @@ import android.app.Activity; import android.support.test.espresso.IdlingResource; -import timber.log.Timber; - +import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import java.lang.reflect.Field; -public class OnMapReadyIdlingResource implements IdlingResource { +public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback { - private final Activity activity; private MapboxMap mapboxMap; private IdlingResource.ResourceCallback resourceCallback; public OnMapReadyIdlingResource(Activity activity) { - this.activity = activity; + try { + Field field = activity.getClass().getDeclaredField("mapView"); + field.setAccessible(true); + ((MapView) field.get(activity)).getMapAsync(this); + } catch (Exception err) { + throw new RuntimeException(err); + } } @Override @@ -26,11 +31,7 @@ public String getName() { @Override public boolean isIdleNow() { - boolean idle = isMapboxMapReady(); - if (idle && resourceCallback != null) { - resourceCallback.onTransitionToIdle(); - } - return idle; + return mapboxMap != null; } @Override @@ -38,20 +39,15 @@ public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } - private boolean isMapboxMapReady() { - try { - Field field = activity.getClass().getDeclaredField("mapboxMap"); - field.setAccessible(true); - mapboxMap = (MapboxMap) field.get(activity); - Timber.e("isMapboxReady called with value " + (mapboxMap != null)); - return mapboxMap != null; - } catch (Exception exception) { - Timber.e("could not reflect", exception); - return false; - } - } - public MapboxMap getMapboxMap() { return mapboxMap; } + + @Override + public void onMapReady(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + if (resourceCallback != null) { + resourceCallback.onTransitionToIdle(); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/BuildingActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/BuildingActivity.java index 76a5f01a2..c081b2084 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/BuildingActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/BuildingActivity.java @@ -117,7 +117,6 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - switch (item.getItemId()) { case R.id.menu_building_min_zoom: buildingPlugin.setMinZoomLevel(14); diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index ab3e77bbf..e3199d76c 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -8,7 +8,7 @@ ext { ] version = [ - mapboxMapSdk : '6.0.0-beta.3', + mapboxMapSdk : '6.0.0-beta.5', mapboxGeocoding : '3.0.0-beta.3', mapboxGeoJson : '3.0.0-beta.3', mapboxServices : '2.2.10', diff --git a/plugin-building/src/main/java/com/mapbox/mapboxsdk/plugins/building/BuildingPlugin.java b/plugin-building/src/main/java/com/mapbox/mapboxsdk/plugins/building/BuildingPlugin.java index c0dfd11ae..89dfad003 100644 --- a/plugin-building/src/main/java/com/mapbox/mapboxsdk/plugins/building/BuildingPlugin.java +++ b/plugin-building/src/main/java/com/mapbox/mapboxsdk/plugins/building/BuildingPlugin.java @@ -8,14 +8,17 @@ import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.functions.Function; import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer; import com.mapbox.mapboxsdk.style.light.Light; import static com.mapbox.mapboxsdk.constants.MapboxConstants.MAXIMUM_ZOOM; import static com.mapbox.mapboxsdk.constants.MapboxConstants.MINIMUM_ZOOM; -import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; -import static com.mapbox.mapboxsdk.style.functions.stops.Stops.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.get; +import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; +import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; +import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; +import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; import static com.mapbox.mapboxsdk.style.layers.Property.NONE; import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor; @@ -93,13 +96,14 @@ private void initLayer(String belowLayer) { fillExtrusionLayer.setProperties( visibility(visible ? VISIBLE : NONE), fillExtrusionColor(color), - fillExtrusionHeight(Function.composite( - "height", - exponential( - stop(15f, 0f, fillExtrusionHeight(0f)), - stop(16f, 0f, fillExtrusionHeight(0f)), - stop(16f, 1000f, fillExtrusionHeight(1000f)) - ))), + fillExtrusionHeight( + interpolate( + exponential(1f), + zoom(), + stop(15, literal(0)), + stop(16, get("height")) + ) + ), fillExtrusionOpacity(opacity) ); addLayer(fillExtrusionLayer, belowLayer); diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java index 7d85f9e94..e82f0a22e 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java @@ -42,9 +42,10 @@ import static com.mapbox.mapboxsdk.plugins.locationlayer.Utils.generateShadow; import static com.mapbox.mapboxsdk.plugins.locationlayer.Utils.getBitmapFromDrawable; import static com.mapbox.mapboxsdk.plugins.locationlayer.Utils.getDrawable; -import static com.mapbox.mapboxsdk.style.functions.Function.zoom; -import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; -import static com.mapbox.mapboxsdk.style.functions.stops.Stops.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; +import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; +import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; import static com.mapbox.mapboxsdk.style.layers.Property.ICON_ROTATION_ALIGNMENT_MAP; import static com.mapbox.mapboxsdk.style.layers.Property.NONE; import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; @@ -164,14 +165,14 @@ private void addSymbolLayer(String layerId, String beforeLayerId) { layer.setProperties( iconAllowOverlap(true), iconIgnorePlacement(true), - iconSize(zoom( - exponential( - stop(22f, iconSize(1f)), - stop(12f, iconSize(1f)), - stop(10f, iconSize(0.6f)), - stop(0f, iconSize(0.6f)) - ).withBase(1f) - )), + iconSize( + interpolate(exponential(1f), zoom(), + stop(22f, 1f), + stop(12f, 1f), + stop(10f, 0.6f), + stop(0f, 0.6f) + ) + ), iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP)); addLayerToMap(layer, beforeLayerId); } diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerAnimator.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerAnimator.java index 1c1fb3569..25bc6f38c 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerAnimator.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerAnimator.java @@ -382,7 +382,7 @@ private void cancelCameraCompassAnimations() { } private void resetCameraCompassAnimation(CameraPosition currentCameraPosition) { - if (cameraCompassBearingAnimator == null) { + if (cameraCompassBearingAnimator == null || cameraLatLngAnimator == null) { return; } long duration = cameraLatLngAnimator.getDuration(); diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerCamera.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerCamera.java index 865fa7a13..3af147b53 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerCamera.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerCamera.java @@ -39,7 +39,7 @@ void initializeOptions(LocationLayerOptions options) { } void setCameraMode(@CameraMode.Mode int cameraMode) { - boolean wasTracking = isLocationTracking(); + final boolean wasTracking = isLocationTracking(); this.cameraMode = cameraMode; mapboxMap.cancelTransitions(); adjustGesturesThresholds(); @@ -120,7 +120,7 @@ private void notifyCameraTrackingChangeListener(boolean wasTracking) { internalCameraTrackingChangedListener.onCameraTrackingChanged(cameraMode); if (wasTracking && !isLocationTracking()) { mapboxMap.getUiSettings().setFocalPoint(null); - moveGestureDetector.setMoveThreshold(moveGestureDetector.getDefaultMoveThreshold()); + moveGestureDetector.setMoveThreshold(0f); internalCameraTrackingChangedListener.onCameraTrackingDismissed(); } } diff --git a/plugin-traffic/src/main/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPlugin.java b/plugin-traffic/src/main/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPlugin.java index c9d6b56e1..68747b996 100644 --- a/plugin-traffic/src/main/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPlugin.java +++ b/plugin-traffic/src/main/java/com/mapbox/mapboxsdk/plugins/traffic/TrafficPlugin.java @@ -7,13 +7,11 @@ import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.functions.CameraFunction; -import com.mapbox.mapboxsdk.style.functions.Function; -import com.mapbox.mapboxsdk.style.functions.stops.Stop; -import com.mapbox.mapboxsdk.style.layers.Filter; +import com.mapbox.mapboxsdk.style.expressions.Expression; 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.PropertyFactory; import com.mapbox.mapboxsdk.style.layers.SymbolLayer; import com.mapbox.mapboxsdk.style.sources.Source; import com.mapbox.mapboxsdk.style.sources.VectorSource; @@ -23,12 +21,14 @@ import timber.log.Timber; -import static com.mapbox.mapboxsdk.style.functions.Function.zoom; -import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop; -import static com.mapbox.mapboxsdk.style.functions.stops.Stops.categorical; -import static com.mapbox.mapboxsdk.style.functions.stops.Stops.exponential; -import static com.mapbox.mapboxsdk.style.layers.Filter.in; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor; +import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.get; +import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; +import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; +import static com.mapbox.mapboxsdk.style.expressions.Expression.match; +import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; +import static com.mapbox.mapboxsdk.style.expressions.Expression.toColor; +import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin; @@ -336,25 +336,25 @@ private void addTrafficLayersToMap(Layer layerCase, Layer layer, String idAboveL private static class TrafficLayer { - static LineLayer getLineLayer(String lineLayerId, float minZoom, Filter.Statement statement, - Function lineColor, CameraFunction lineWidth, Function lineOffset) { + static LineLayer getLineLayer(String lineLayerId, float minZoom, Expression statement, + Expression lineColor, Expression lineWidth, Expression lineOffset) { return getLineLayer(lineLayerId, minZoom, statement, lineColor, lineWidth, lineOffset, null); } - static LineLayer getLineLayer(String lineLayerId, float minZoom, Filter.Statement statement, - Function lineColor, CameraFunction lineWidth, Function lineOffset, - Function lineOpacity) { + static LineLayer getLineLayer(String lineLayerId, float minZoom, Expression statement, + Expression lineColorExpression, Expression lineWidthExpression, + Expression lineOffsetExpression, Expression lineOpacityExpression) { LineLayer lineLayer = new LineLayer(lineLayerId, TrafficData.SOURCE_ID); lineLayer.setSourceLayer(TrafficData.SOURCE_LAYER); lineLayer.setProperties( lineCap("round"), lineJoin("round"), - lineColor(lineColor), - lineWidth(lineWidth), - lineOffset(lineOffset) + lineColor(lineColorExpression), + lineWidth(lineWidthExpression), + lineOffset(lineOffsetExpression) ); - if (lineOpacity != null) { - lineLayer.setProperties(lineOpacity(lineOpacity)); + if (lineOpacityExpression != null) { + lineLayer.setProperties(lineOpacity(lineOpacityExpression)); } lineLayer.setFilter(statement); @@ -364,29 +364,14 @@ static LineLayer getLineLayer(String lineLayerId, float minZoom, Filter.Statemen } private static class TrafficFunction { - static Function getLineColorFunction(@ColorInt int low, @ColorInt int moderate, @ColorInt int heavy, - @ColorInt int severe) { - return Function.property( - "congestion", - categorical( - stop("low", fillColor(low)), - stop("moderate", fillColor(moderate)), - stop("heavy", fillColor(heavy)), - stop("severe", fillColor(severe)) - ) - ).withDefaultValue(fillColor(Color.TRANSPARENT)); - } - - static CameraFunction getOffsetFunction(Stop... stops) { - return zoom(exponential(stops).withBase(1.5f)); - } - - static CameraFunction getWidthFunction(Stop... stops) { - return zoom(exponential(stops).withBase(1.5f)); - } - - static Function getOpacityFunction(Stop... stops) { - return zoom(exponential(stops)); + static Expression getLineColorFunction(@ColorInt int low, @ColorInt int moderate, @ColorInt int heavy, + @ColorInt int severe) { + // fixme replace toColor with color expression after 6.0.0-beta.5 + return match(get("congestion"), toColor(literal(PropertyFactory.colorToRgbaString(Color.TRANSPARENT))), + stop("low", toColor(literal(PropertyFactory.colorToRgbaString(low)))), + stop("moderate", toColor(literal(PropertyFactory.colorToRgbaString(moderate)))), + stop("heavy", toColor(literal(PropertyFactory.colorToRgbaString(heavy)))), + stop("severe", toColor(literal(PropertyFactory.colorToRgbaString(severe))))); } } @@ -397,9 +382,9 @@ static class TrafficData { } private static class TrafficType { - static final Function FUNCTION_LINE_COLOR = TrafficFunction.getLineColorFunction(TrafficColor.BASE_GREEN, + static final Expression FUNCTION_LINE_COLOR = TrafficFunction.getLineColorFunction(TrafficColor.BASE_GREEN, TrafficColor.BASE_YELLOW, TrafficColor.BASE_ORANGE, TrafficColor.BASE_RED); - static final Function FUNCTION_LINE_COLOR_CASE = TrafficFunction.getLineColorFunction( + static final Expression FUNCTION_LINE_COLOR_CASE = TrafficFunction.getLineColorFunction( TrafficColor.CASE_GREEN, TrafficColor.CASE_YELLOW, TrafficColor.CASE_ORANGE, TrafficColor.CASE_RED); } @@ -407,78 +392,157 @@ static class MotorWay extends TrafficType { static final String BASE_LAYER_ID = "traffic-motorway"; static final String CASE_LAYER_ID = "traffic-motorway-bg"; static final float ZOOM_LEVEL = 6.0f; - static final Filter.Statement FILTER = in("class", "motorway"); - static final CameraFunction FUNCTION_LINE_WIDTH = TrafficFunction.getWidthFunction( - stop(6, lineWidth(0.5f)), stop(9, lineWidth(1.5f)), stop(18.0f, lineWidth(14.0f)), - stop(20.0f, lineWidth(18.0f))); - static final CameraFunction FUNCTION_LINE_WIDTH_CASE = TrafficFunction.getWidthFunction( - stop(6, lineWidth(0.5f)), stop(9, lineWidth(3.0f)), stop(18.0f, lineWidth(16.0f)), - stop(20.0f, lineWidth(20.0f))); - static final CameraFunction FUNCTION_LINE_OFFSET = TrafficFunction.getOffsetFunction( - stop(7, lineOffset(0.0f)), stop(9, lineOffset(1.2f)), stop(11, lineOffset(1.2f)), - stop(18, lineOffset(10.0f)), stop(20, lineOffset(15.5f))); + static final Expression FILTER = match( + get("class"), literal(false), + stop("motorway", true) + ); + + static final Expression FUNCTION_LINE_WIDTH = interpolate(exponential(1.5f), zoom(), + stop(6, 0.5f), + stop(9, 1.5f), + stop(18.0f, 14.0f), + stop(20.0f, 18.0f) + ); + + static final Expression FUNCTION_LINE_WIDTH_CASE = interpolate(exponential(1.5f), zoom(), + stop(6, 0.5f), + stop(9, 3.0f), + stop(18.0f, 16.0f), + stop(20.0f, 20.0f) + ); + + static final Expression FUNCTION_LINE_OFFSET = interpolate(exponential(1.5f), zoom(), + stop(7, 0.0f), + stop(9, 1.2f), + stop(11, 1.2f), + stop(18, 10.0f), + stop(20, 15.5f)); } static class Trunk extends TrafficType { static final String BASE_LAYER_ID = "traffic-trunk"; static final String CASE_LAYER_ID = "traffic-trunk-bg"; static final float ZOOM_LEVEL = 6.0f; - static final Filter.Statement FILTER = in("class", "trunk"); - static final CameraFunction FUNCTION_LINE_WIDTH = TrafficFunction.getWidthFunction( - stop(8, lineWidth(0.75f)), stop(18, lineWidth(11f)), stop(20f, lineWidth(15.0f))); - static final CameraFunction FUNCTION_LINE_WIDTH_CASE = TrafficFunction.getWidthFunction( - stop(8, lineWidth(0.5f)), stop(9, lineWidth(2.25f)), stop(18.0f, lineWidth(13.0f)), - stop(20.0f, lineWidth(17.5f))); - static final CameraFunction FUNCTION_LINE_OFFSET = TrafficFunction.getOffsetFunction( - stop(7, lineOffset(0.0f)), stop(9, lineOffset(1f)), stop(18, lineOffset(13f)), - stop(20, lineOffset(18.0f))); + + static final Expression FILTER = match( + get("class"), literal(false), + stop("trunk", true) + ); + + static final Expression FUNCTION_LINE_WIDTH = interpolate(exponential(1.5f), zoom(), + stop(8, 0.75f), + stop(18, 11f), + stop(20f, 15.0f) + ); + + static final Expression FUNCTION_LINE_WIDTH_CASE = interpolate(exponential(1.5f), zoom(), + stop(8, 0.5f), + stop(9, 2.25f), + stop(18.0f, 13.0f), + stop(20.0f, 17.5f) + ); + + static final Expression FUNCTION_LINE_OFFSET = interpolate(exponential(1.5f), zoom(), + stop(7, 0.0f), + stop(9, 1f), + stop(18, 13f), + stop(20, 18.0f)); } static class Primary extends TrafficType { static final String BASE_LAYER_ID = "traffic-primary"; static final String CASE_LAYER_ID = "traffic-primary-bg"; static final float ZOOM_LEVEL = 6.0f; - static final Filter.Statement FILTER = in("class", "primary"); - static final CameraFunction FUNCTION_LINE_WIDTH = TrafficFunction.getWidthFunction( - stop(10, lineWidth(1.0f)), stop(15, lineWidth(4.0f)), stop(20, lineWidth(16f))); - static final CameraFunction FUNCTION_LINE_WIDTH_CASE = TrafficFunction.getWidthFunction( - stop(10, lineWidth(0.75f)), stop(15, lineWidth(6f)), stop(20.0f, lineWidth(18.0f))); - static final CameraFunction FUNCTION_LINE_OFFSET = TrafficFunction.getOffsetFunction( - stop(10, lineOffset(0.0f)), stop(12, lineOffset(1.5f)), stop(18, lineOffset(13f)), - stop(20, lineOffset(16.0f))); - static final Function FUNCTION_LINE_OPACITY_CASE = TrafficFunction.getOpacityFunction( - stop(11, lineOpacity(0.0f)), stop(12, lineOpacity(1.0f))); + + static final Expression FILTER = match( + get("class"), literal(false), + stop("primary", literal(true)) + ); + + static final Expression FUNCTION_LINE_WIDTH = interpolate(exponential(1.5f), zoom(), + stop(10, 1.0f), + stop(15, 4.0f), + stop(20, 16f) + ); + + static final Expression FUNCTION_LINE_WIDTH_CASE = interpolate(exponential(1.5f), zoom(), + stop(10, 0.75f), + stop(15, 6f), + stop(20.0f, 18.0f) + ); + + static final Expression FUNCTION_LINE_OFFSET = interpolate(exponential(1.5f), zoom(), + stop(10, 0.0f), + stop(12, 1.5f), + stop(18, 13f), + stop(20, 16.0f) + ); + + static final Expression FUNCTION_LINE_OPACITY_CASE = interpolate(exponential(1.0f), zoom(), + stop(11, 0.0f), + stop(12, 1.0f) + ); } static class Secondary extends TrafficType { static final String BASE_LAYER_ID = "traffic-secondary-tertiary"; static final String CASE_LAYER_ID = "traffic-secondary-tertiary-bg"; static final float ZOOM_LEVEL = 6.0f; - static final Filter.Statement FILTER = in("class", "secondary", "tertiary"); - static final CameraFunction FUNCTION_LINE_WIDTH = TrafficFunction.getWidthFunction( - stop(9, lineWidth(0.5f)), stop(18, lineWidth(9.0f)), stop(20, lineWidth(14f))); - static final CameraFunction FUNCTION_LINE_WIDTH_CASE = TrafficFunction.getWidthFunction( - stop(9, lineWidth(1.5f)), stop(18, lineWidth(11f)), stop(20.0f, lineWidth(16.5f))); - static final CameraFunction FUNCTION_LINE_OFFSET = TrafficFunction.getOffsetFunction( - stop(10, lineOffset(0.5f)), stop(15, lineOffset(5f)), stop(18, lineOffset(11f)), - stop(20, lineOffset(14.5f))); - static final Function FUNCTION_LINE_OPACITY_CASE = TrafficFunction.getOpacityFunction( - stop(13, lineOpacity(0.0f)), stop(14, lineOpacity(1.0f))); + static final String[] FILTER_LAYERS = new String[] {"secondary", "tertiary"}; + + static final Expression FILTER = match(get("class"), literal(false), literal(FILTER_LAYERS), literal(true)); + + static final Expression FUNCTION_LINE_WIDTH = interpolate(exponential(1.5f), zoom(), + stop(9, 0.5f), + stop(18, 9.0f), + stop(20, 14f) + ); + + static final Expression FUNCTION_LINE_WIDTH_CASE = interpolate(exponential(1.5f), zoom(), + stop(9, 1.5f), + stop(18, 11f), + stop(20.0f, 16.5f) + ); + + static final Expression FUNCTION_LINE_OFFSET = interpolate(exponential(1.5f), zoom(), + stop(10, 0.5f), + stop(15, 5f), + stop(18, 11f), + stop(20, 14.5f) + ); + + static final Expression FUNCTION_LINE_OPACITY_CASE = interpolate(exponential(1.0f), zoom(), + stop(13, 0.0f), + stop(14, 1.0f) + ); } static class Local extends TrafficType { static final String BASE_LAYER_ID = "traffic-local"; static final String CASE_LAYER_ID = "traffic-local-case"; static final float ZOOM_LEVEL = 15.0f; - static final Filter.Statement FILTER = in("class", "motorway_link", "service", "street"); - static final CameraFunction FUNCTION_LINE_WIDTH = TrafficFunction.getWidthFunction( - stop(14, lineWidth(1.5f)), stop(20, lineWidth(13.5f))); - static final CameraFunction FUNCTION_LINE_WIDTH_CASE = TrafficFunction.getWidthFunction( - stop(14, lineWidth(2.5f)), stop(20, lineWidth(15.5f))); - static final CameraFunction FUNCTION_LINE_OFFSET = TrafficFunction.getOffsetFunction( - stop(14, lineOffset(2f)), stop(20, lineOffset(18f))); - static final Function FUNCTION_LINE_OPACITY_CASE = TrafficFunction.getOpacityFunction( - stop(15, lineOpacity(0.0f)), stop(16, lineOpacity(1.0f))); + + static final String[] FILTER_LAYERS = new String[] {"motorway_link", "service", "street"}; + + static final Expression FILTER = match(get("class"), literal(false), literal(FILTER_LAYERS), literal(true)); + + static final Expression FUNCTION_LINE_WIDTH = interpolate(exponential(1.5f), zoom(), + stop(14, 1.5f), + stop(20, 13.5f) + ); + static final Expression FUNCTION_LINE_WIDTH_CASE = interpolate(exponential(1.5f), zoom(), + stop(14, 2.5f), + stop(20, 15.5f) + ); + static final Expression FUNCTION_LINE_OFFSET = interpolate(exponential(1.5f), zoom(), + stop(14, 2f), + stop(20, 18f) + ); + + static final Expression FUNCTION_LINE_OPACITY_CASE = interpolate(exponential(1.0f), zoom(), + stop(15, 0.0f), + stop(16, 1.0f) + ); } private static class TrafficColor {