diff --git a/app/src/androidTest/java/com/mapbox/maps/testapp/BaseMapTest.kt b/app/src/androidTest/java/com/mapbox/maps/testapp/BaseMapTest.kt index fdfb38068b..87eb23669e 100644 --- a/app/src/androidTest/java/com/mapbox/maps/testapp/BaseMapTest.kt +++ b/app/src/androidTest/java/com/mapbox/maps/testapp/BaseMapTest.kt @@ -65,15 +65,16 @@ abstract class BaseMapTest { protected open fun loadMap() { val latch = CountDownLatch(1) - rule.scenario.onActivity { - it.runOnUiThread { + rule.scenario.onActivity { activity -> + activity.runOnUiThread { mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { style -> - this@BaseMapTest.style = style - latch.countDown() - } + Style.MAPBOX_STREETS, + { + this@BaseMapTest.style = it + latch.countDown() + } + ) mapView.onStart() } } diff --git a/app/src/androidTest/java/com/mapbox/maps/testapp/location/LocationComponentTest.kt b/app/src/androidTest/java/com/mapbox/maps/testapp/location/LocationComponentTest.kt index eef94715de..4cfdca1c04 100644 --- a/app/src/androidTest/java/com/mapbox/maps/testapp/location/LocationComponentTest.kt +++ b/app/src/androidTest/java/com/mapbox/maps/testapp/location/LocationComponentTest.kt @@ -53,37 +53,43 @@ class LocationComponentTest { fun modelSourceTest() { rule.scenario.onActivity { activity -> activity.runOnUiThread { - mapboxMap.loadStyleUri(Style.MAPBOX_STREETS) { - val locationComponent = mapView.getLocationPlugin() - locationComponent.activateLocationComponent( - LocationComponentActivationOptions - .builder(activity, it) - .useDefaultLocationEngine(false) - .locationModelLayerOptions(LocationModelLayerOptions("asset://race_car_model.gltf")) - .build() - ) - locationComponent.enabled = true - locationComponent.randomLocationUpdates() - Handler().postDelayed( - { - locationComponent.randomLocationUpdates() - mapboxMap.loadStyleUri(Style.DARK) { + mapboxMap.loadStyleUri( + Style.MAPBOX_STREETS, + { + val locationComponent = mapView.getLocationPlugin() + locationComponent.activateLocationComponent( + LocationComponentActivationOptions + .builder(activity, it) + .useDefaultLocationEngine(false) + .locationModelLayerOptions(LocationModelLayerOptions("asset://race_car_model.gltf")) + .build() + ) + locationComponent.enabled = true + locationComponent.randomLocationUpdates() + Handler().postDelayed( + { locationComponent.randomLocationUpdates() - Handler().postDelayed( + mapboxMap.loadStyleUri( + Style.DARK, { locationComponent.randomLocationUpdates() - countDownLatch.countDown() - }, - 500 + Handler().postDelayed( + { + locationComponent.randomLocationUpdates() + countDownLatch.countDown() + }, + 500 + ) + locationComponent.randomLocationUpdates() + } ) locationComponent.randomLocationUpdates() - } - locationComponent.randomLocationUpdates() - }, - 500 - ) - locationComponent.randomLocationUpdates() - } + }, + 500 + ) + locationComponent.randomLocationUpdates() + } + ) } } countDownLatch = CountDownLatch(1) @@ -96,36 +102,42 @@ class LocationComponentTest { fun locationLayerTest() { rule.scenario.onActivity { activity -> activity.runOnUiThread { - mapboxMap.loadStyleUri(Style.MAPBOX_STREETS) { - val locationComponent = mapView.getLocationPlugin() - locationComponent.activateLocationComponent( - LocationComponentActivationOptions - .builder(activity, it) - .useDefaultLocationEngine(false) - .build() - ) - locationComponent.enabled = true - locationComponent.randomLocationUpdates() - Handler().postDelayed( - { - locationComponent.randomLocationUpdates() - mapboxMap.loadStyleUri(Style.DARK) { + mapboxMap.loadStyleUri( + Style.MAPBOX_STREETS, + { + val locationComponent = mapView.getLocationPlugin() + locationComponent.activateLocationComponent( + LocationComponentActivationOptions + .builder(activity, it) + .useDefaultLocationEngine(false) + .build() + ) + locationComponent.enabled = true + locationComponent.randomLocationUpdates() + Handler().postDelayed( + { locationComponent.randomLocationUpdates() - Handler().postDelayed( + mapboxMap.loadStyleUri( + Style.DARK, { locationComponent.randomLocationUpdates() - countDownLatch.countDown() - }, - 500 + Handler().postDelayed( + { + locationComponent.randomLocationUpdates() + countDownLatch.countDown() + }, + 500 + ) + locationComponent.randomLocationUpdates() + } ) locationComponent.randomLocationUpdates() - } - locationComponent.randomLocationUpdates() - }, - 500 - ) - locationComponent.randomLocationUpdates() - } + }, + 500 + ) + locationComponent.randomLocationUpdates() + } + ) } } countDownLatch = CountDownLatch(1) diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/AnimateMapCameraActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/AnimateMapCameraActivity.kt index 81b06c9780..15bf618180 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/AnimateMapCameraActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/AnimateMapCameraActivity.kt @@ -24,15 +24,17 @@ class AnimateMapCameraActivity : AppCompatActivity(), OnMapClickListener { setContentView(R.layout.activity_camera_animate) mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { // Toast instructing user to tap on the map - Toast.makeText( - this@AnimateMapCameraActivity, - getString(R.string.tap_on_map_instruction), - Toast.LENGTH_LONG - ).show() - mapboxMap.addOnMapClickListener(this@AnimateMapCameraActivity) - } + Style.MAPBOX_STREETS, + { + // Toast instructing user to tap on the map + Toast.makeText( + this@AnimateMapCameraActivity, + getString(R.string.tap_on_map_instruction), + Toast.LENGTH_LONG + ).show() + mapboxMap.addOnMapClickListener(this@AnimateMapCameraActivity) + } + ) } override fun onMapClick(point: Point): Boolean { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/BasicLocationPulsingCircleActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/BasicLocationPulsingCircleActivity.kt index 902efabb81..09d0727405 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/BasicLocationPulsingCircleActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/BasicLocationPulsingCircleActivity.kt @@ -43,11 +43,12 @@ class BasicLocationPulsingCircleActivity : AppCompatActivity() { private fun onMapReady() { mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { - initLocationComponent(it) - lastStyleUri = it.styleURI - } + Style.MAPBOX_STREETS, + { + initLocationComponent(it) + lastStyleUri = it.styleURI + } + ) } private fun initLocationComponent(style: Style) { @@ -131,8 +132,8 @@ class BasicLocationPulsingCircleActivity : AppCompatActivity() { private fun loadNewStyle() { val styleUrl = if (lastStyleUri == Style.DARK) Style.LIGHT else Style.DARK mapboxMap.loadStyleUri( - styleUrl - ) { lastStyleUri = styleUrl } + styleUrl, { lastStyleUri = styleUrl } + ) } override fun onRequestPermissionsResult( diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/CircleLayerClusteringActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/CircleLayerClusteringActivity.kt index 706f7e9d1f..66a187cc2a 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/CircleLayerClusteringActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/CircleLayerClusteringActivity.kt @@ -35,39 +35,40 @@ class CircleLayerClusteringActivity : AppCompatActivity() { val mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.LIGHT - ) { - // Disable any type of fading transition when icons collide on the map. This enhances the visual - // look of the data clustering together and breaking apart. - it.styleTransition = TransitionOptions.Builder() - .duration(0) - .delay(0) - .enablePlacementTransitions(false) - .build() - - mapboxMap.flyTo( - CameraOptions.Builder() - .center(Point.fromLngLat(-79.045, 12.099)) - .zoom(3.0) + Style.LIGHT, + { + // Disable any type of fading transition when icons collide on the map. This enhances the visual + // look of the data clustering together and breaking apart. + it.styleTransition = TransitionOptions.Builder() + .duration(0) + .delay(0) + .enablePlacementTransitions(false) .build() - ) - addClusteredGeoJsonSource(it) + mapboxMap.flyTo( + CameraOptions.Builder() + .center(Point.fromLngLat(-79.045, 12.099)) + .zoom(3.0) + .build() + ) - val drawable = ContextCompat.getDrawable( - this@CircleLayerClusteringActivity, - R.drawable.ic_cross - ) - BitmapUtils.getBitmapFromDrawable(drawable)?.let { bitmap -> - it.addImage(CROSS_ICON_ID, bitmap, true) - } + addClusteredGeoJsonSource(it) - Toast.makeText( - this@CircleLayerClusteringActivity, - R.string.zoom_map_in_and_out_instruction, - Toast.LENGTH_SHORT - ).show() - } + val drawable = ContextCompat.getDrawable( + this@CircleLayerClusteringActivity, + R.drawable.ic_cross + ) + BitmapUtils.getBitmapFromDrawable(drawable)?.let { bitmap -> + it.addImage(CROSS_ICON_ID, bitmap, true) + } + + Toast.makeText( + this@CircleLayerClusteringActivity, + R.string.zoom_map_in_and_out_instruction, + Toast.LENGTH_SHORT + ).show() + } + ) } private fun addClusteredGeoJsonSource(style: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/FillExtrusionActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/FillExtrusionActivity.kt index c4c5669fea..ace3f22d13 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/FillExtrusionActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/FillExtrusionActivity.kt @@ -38,11 +38,12 @@ class FillExtrusionActivity : AppCompatActivity() { ) mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { style -> - setupBuildings(style) - setupLight(style) - } + Style.MAPBOX_STREETS, + { + setupBuildings(it) + setupLight(it) + } + ) } private fun setupBuildings(style: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/HeatmapLayerActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/HeatmapLayerActivity.kt index 6ecfba9811..115b1bf9a6 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/HeatmapLayerActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/HeatmapLayerActivity.kt @@ -27,8 +27,8 @@ class HeatmapLayerActivity : AppCompatActivity() { mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - styleUri = Style.DARK - ) { style -> addRuntimeLayers(style) } + styleUri = Style.DARK, { style -> addRuntimeLayers(style) } + ) } private fun addRuntimeLayers(style: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/InsetMapActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/InsetMapActivity.kt index e62281cb4b..9952aeb2c1 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/InsetMapActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/InsetMapActivity.kt @@ -18,11 +18,11 @@ import com.mapbox.maps.extension.style.sources.addSource import com.mapbox.maps.extension.style.sources.generated.GeoJsonSource import com.mapbox.maps.extension.style.sources.generated.geoJsonSource import com.mapbox.maps.extension.style.sources.getSource +import com.mapbox.maps.listener.OnCameraChangeListener import com.mapbox.maps.plugin.animation.MapAnimationOptions.Companion.mapAnimationOptions import com.mapbox.maps.plugin.animation.flyTo import com.mapbox.maps.plugin.attribution.getAttributionPlugin import com.mapbox.maps.plugin.compass.getCompassPlugin -import com.mapbox.maps.plugin.delegates.listeners.OnCameraChangeListener import com.mapbox.maps.plugin.gestures.getGesturesPlugin import com.mapbox.maps.plugin.logo.getLogoPlugin import com.mapbox.maps.plugin.scalebar.getScaleBarPlugin @@ -41,8 +41,8 @@ class InsetMapActivity : AppCompatActivity(), OnCameraChangeListener { mainMapView = findViewById(R.id.mapView) mainMapboxMap = mainMapView.getMapboxMap() mainMapboxMap.loadStyleUri( - styleUri = STYLE_URL - ) { mainMapboxMap.addOnCameraChangeListener(this@InsetMapActivity) } + styleUri = STYLE_URL, { mainMapboxMap.addOnCameraChangeListener(this@InsetMapActivity) } + ) var insetMapFragment: MapFragment? = supportFragmentManager.findFragmentByTag(INSET_FRAGMENT_TAG) as? MapFragment @@ -54,24 +54,25 @@ class InsetMapActivity : AppCompatActivity(), OnCameraChangeListener { insetMapFragment.getMapAsync { insetMapboxMap = it insetMapboxMap.loadStyleUri( - styleUri = STYLE_URL - ) { style -> - val source = geoJsonSource(BOUNDS_LINE_LAYER_SOURCE_ID) { - feature(Feature.fromGeometry(LineString.fromLngLats(getRectanglePoints()))) - } - style.addSource(source) - - // The layer properties for our line. This is where we make the line dotted, set the color, etc. - val layer = lineLayer(BOUNDS_LINE_LAYER_LAYER_ID, BOUNDS_LINE_LAYER_SOURCE_ID) { - lineCap(LineCap.ROUND) - lineJoin(LineJoin.ROUND) - lineWidth(3.0) - lineColor(Color.YELLOW) - visibility(Visibility.VISIBLE) + styleUri = STYLE_URL, + { style -> + val source = geoJsonSource(BOUNDS_LINE_LAYER_SOURCE_ID) { + feature(Feature.fromGeometry(LineString.fromLngLats(getRectanglePoints()))) + } + style.addSource(source) + + // The layer properties for our line. This is where we make the line dotted, set the color, etc. + val layer = lineLayer(BOUNDS_LINE_LAYER_LAYER_ID, BOUNDS_LINE_LAYER_SOURCE_ID) { + lineCap(LineCap.ROUND) + lineJoin(LineJoin.ROUND) + lineWidth(3.0) + lineColor(Color.YELLOW) + visibility(Visibility.VISIBLE) + } + style.addLayer(layer) + updateInsetMapLineLayerBounds(style) } - style.addLayer(layer) - updateInsetMapLineLayerBounds(style) - } + ) insetMapFragment.getMapView()?.apply { getLogoPlugin().enabled = false getScaleBarPlugin().enabled = false diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/LineGradientActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/LineGradientActivity.kt index 65db3c4b8b..69988d7d4a 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/LineGradientActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/LineGradientActivity.kt @@ -21,9 +21,10 @@ class LineGradientActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_line_gradient) - mapView.getMapboxMap().loadStyle(createStyle()) { - Logger.d(TAG, "Style loaded: ${it.styleURI}") - } + mapView.getMapboxMap() + .loadStyle(createStyle()) { style -> + Logger.d(TAG, "Style loaded: ${style.styleURI}") + } } private fun createStyle() = style(styleUri = Style.TRAFFIC_DAY) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/LocationModesActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/LocationModesActivity.kt index 14c3b20867..79aa267651 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/LocationModesActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/LocationModesActivity.kt @@ -83,11 +83,12 @@ class LocationModesActivity : private fun onMapReady() { mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { - initLocationComponent(it) - lastStyleUri = Style.MAPBOX_STREETS - } + Style.MAPBOX_STREETS, + { + initLocationComponent(it) + lastStyleUri = Style.MAPBOX_STREETS + } + ) } private fun initLocationComponent(style: Style) { @@ -235,8 +236,8 @@ class LocationModesActivity : locationComponent?.let { val styleUrl = if (lastStyleUri == Style.DARK) Style.LIGHT else Style.DARK mapboxMap.loadStyleUri( - styleUrl - ) { lastStyleUri = styleUrl } + styleUrl, { lastStyleUri = styleUrl } + ) } } diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/LocationTrackingActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/LocationTrackingActivity.kt index 0c61887f39..ab7ebe01d5 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/LocationTrackingActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/LocationTrackingActivity.kt @@ -41,11 +41,12 @@ class LocationTrackingActivity : AppCompatActivity(), OnCameraTrackingChangedLis .build() ) mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { - initLocationComponent(it) - Style.MAPBOX_STREETS - } + Style.MAPBOX_STREETS, + { + initLocationComponent(it) + Style.MAPBOX_STREETS + } + ) } private fun initLocationComponent(style: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/LowLevelCameraAnimatorActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/LowLevelCameraAnimatorActivity.kt index a2fda9832e..12bfec8256 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/LowLevelCameraAnimatorActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/LowLevelCameraAnimatorActivity.kt @@ -32,11 +32,12 @@ class LowLevelCameraAnimatorActivity : AppCompatActivity() { setContentView(R.layout.activity_camera_animate) mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { - setupBuildings(it) - animateCameraDelayed() - } + Style.MAPBOX_STREETS, + { + setupBuildings(it) + animateCameraDelayed() + } + ) } private fun animateCameraDelayed() { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/MovingIconWithTrailingLineActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/MovingIconWithTrailingLineActivity.kt index 3028dac64c..8dcab46644 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/MovingIconWithTrailingLineActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/MovingIconWithTrailingLineActivity.kt @@ -59,10 +59,11 @@ class MovingIconWithTrailingLineActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_dds_moving_icon_with_trailing_line) mapView.getMapboxMap().loadStyleUri( - Style.LIGHT - ) { // Use the Mapbox Directions API to get a directions route - getRoute() - } + Style.LIGHT, + { // Use the Mapbox Directions API to get a directions route + getRoute() + } + ) } /** diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/MultipleGeometriesActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/MultipleGeometriesActivity.kt index 5c683df118..9cbb00ba96 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/MultipleGeometriesActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/MultipleGeometriesActivity.kt @@ -28,12 +28,13 @@ class MultipleGeometriesActivity : AppCompatActivity() { mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.LIGHT - ) { - createGeoJsonSource(it) - addPolygonLayer(it) - addLineStringLayer(it) - } + Style.LIGHT, + { + createGeoJsonSource(it) + addPolygonLayer(it) + addLineStringLayer(it) + } + ) } private fun createGeoJsonSource(loadedMapStyle: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/PolygonHolesActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/PolygonHolesActivity.kt index 61758ed3f1..d662bd7e6e 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/PolygonHolesActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/PolygonHolesActivity.kt @@ -39,30 +39,31 @@ class PolygonHolesActivity : AppCompatActivity() { .build() ) loadStyleUri( - Style.MAPBOX_STREETS - ) { style -> - val outerLineString: LineString = LineString.fromLngLats(POLYGON_COORDINATES) - val innerLineString: LineString = LineString.fromLngLats(HOLE_COORDINATES[0]) - val secondInnerLineString: LineString = LineString.fromLngLats(HOLE_COORDINATES[1]) - val innerList: MutableList = ArrayList() - innerList.add(innerLineString) - innerList.add(secondInnerLineString) - style.addSource( - geoJsonSource( - "source-id" - ) { - feature(Feature.fromGeometry(Polygon.fromOuterInner(outerLineString, innerList))) + Style.MAPBOX_STREETS, + { style -> + val outerLineString: LineString = LineString.fromLngLats(POLYGON_COORDINATES) + val innerLineString: LineString = LineString.fromLngLats(HOLE_COORDINATES[0]) + val secondInnerLineString: LineString = LineString.fromLngLats(HOLE_COORDINATES[1]) + val innerList: MutableList = ArrayList() + innerList.add(innerLineString) + innerList.add(secondInnerLineString) + style.addSource( + geoJsonSource( + "source-id" + ) { + feature(Feature.fromGeometry(Polygon.fromOuterInner(outerLineString, innerList))) + } + ) + val polygonFillLayer: FillLayer = FillLayer("layer-id", "source-id").apply { + fillColor(BLUE_COLOR) + } + if (style.getLayer("road-number-shield") != null) { + style.addLayerBelow(polygonFillLayer, "road-number-shield") + } else { + style.addLayer(polygonFillLayer) } - ) - val polygonFillLayer: FillLayer = FillLayer("layer-id", "source-id").apply { - fillColor(BLUE_COLOR) - } - if (style.getLayer("road-number-shield") != null) { - style.addLayerBelow(polygonFillLayer, "road-number-shield") - } else { - style.addLayer(polygonFillLayer) } - } + ) } } diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/RawExpressionActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/RawExpressionActivity.kt index 4424f3d89a..c7ab93ce18 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/RawExpressionActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/RawExpressionActivity.kt @@ -41,8 +41,11 @@ class RawExpressionActivity : AppCompatActivity() { setContentView(R.layout.activity_simple_map) mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { addExpressionToStyle(it) } + Style.MAPBOX_STREETS, + { + addExpressionToStyle(it) + } + ) } private fun addExpressionToStyle(style: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/RawGeoJsonActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/RawGeoJsonActivity.kt index 6f72d4260b..cf7a2c5557 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/RawGeoJsonActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/RawGeoJsonActivity.kt @@ -43,8 +43,11 @@ class RawGeoJsonActivity : AppCompatActivity() { setContentView(R.layout.activity_simple_map) mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { addGeoJsonSource(it) } + Style.MAPBOX_STREETS, + { + addGeoJsonSource(it) + } + ) } private fun addGeoJsonSource(style: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/RawSourceLayerActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/RawSourceLayerActivity.kt index d3078ad176..b02c9fa57e 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/RawSourceLayerActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/RawSourceLayerActivity.kt @@ -46,8 +46,11 @@ class RawSourceLayerActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_simple_map) mapView.getMapboxMap().loadStyleUri( - Style.MAPBOX_STREETS - ) { addGeoJsonSource(it) } + Style.MAPBOX_STREETS, + { + addGeoJsonSource(it) + } + ) } private fun addGeoJsonSource(style: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/RuntimeStylingActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/RuntimeStylingActivity.kt index bb8e2f0cd0..f6a70b66c0 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/RuntimeStylingActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/RuntimeStylingActivity.kt @@ -38,8 +38,8 @@ class RuntimeStylingActivity : AppCompatActivity() { mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { setupStyle(it) } + Style.MAPBOX_STREETS, { setupStyle(it) } + ) } private fun setupStyle(style: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/SpaceStationLocationActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/SpaceStationLocationActivity.kt index 516fd44954..041f0fc315 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/SpaceStationLocationActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/SpaceStationLocationActivity.kt @@ -47,13 +47,13 @@ class SpaceStationLocationActivity : AppCompatActivity() { setContentView(R.layout.activity_lab_space_station_location) mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.SATELLITE_STREETS - ) { - initSpaceStationSymbolLayer(it) - callApi() - showHintToast() - } - + Style.SATELLITE_STREETS, + { + initSpaceStationSymbolLayer(it) + callApi() + showHintToast() + } + ) mapboxMap.jumpTo(CameraOptions.Builder().zoom(2.0).build()) } diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/WmsSourceActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/WmsSourceActivity.kt index 2b0e61c47d..abb85d8ab0 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/WmsSourceActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/WmsSourceActivity.kt @@ -21,24 +21,25 @@ class WmsSourceActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_wms_source) mapView.getMapboxMap().loadStyleUri( - Style.LIGHT - ) { - it.addSource( - rasterSource(WMS_SOURCE_ID) { - tileSize(256) - tileSet(TILESET_JSON, listOf(WMS_SOURCE_URL)) {} - } - ) - - if (it.getLayer(BELOW_LAYER_ID) != null) { - it.addLayerBelow( - RasterLayer(RASTER_LAYER_ID, WMS_SOURCE_ID), - BELOW_LAYER_ID + Style.LIGHT, + { + it.addSource( + rasterSource(WMS_SOURCE_ID) { + tileSize(256) + tileSet(TILESET_JSON, listOf(WMS_SOURCE_URL)) {} + } ) - } else { - it.addLayer(RasterLayer(RASTER_LAYER_ID, WMS_SOURCE_ID)) + + if (it.getLayer(BELOW_LAYER_ID) != null) { + it.addLayerBelow( + RasterLayer(RASTER_LAYER_ID, WMS_SOURCE_ID), + BELOW_LAYER_ID + ) + } else { + it.addLayer(RasterLayer(RASTER_LAYER_ID, WMS_SOURCE_ID)) + } } - } + ) } override fun onStart() { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/CircleActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/CircleActivity.kt index f818c177de..5e53f46d04 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/CircleActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/CircleActivity.kt @@ -28,51 +28,54 @@ class CircleActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_annotation) - mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) { - val annotationPlugin = mapView.getAnnotationPlugin() - circleManager = annotationPlugin.getCircleManager().apply { - addClickListener( - OnCircleClickListener { - Toast.makeText(this@CircleActivity, "click", Toast.LENGTH_LONG).show() - false - } - ) + mapView.getMapboxMap().loadStyleUri( + Style.MAPBOX_STREETS, + { + val annotationPlugin = mapView.getAnnotationPlugin() + circleManager = annotationPlugin.getCircleManager().apply { + addClickListener( + OnCircleClickListener { + Toast.makeText(this@CircleActivity, "click", Toast.LENGTH_LONG).show() + false + } + ) - val circleOptions: CircleOptions = CircleOptions() - .withPoint(Point.fromLngLat(0.381457, 6.687337)) - .withCircleColor(ColorUtils.colorToRgbaString(Color.YELLOW)) - .withCircleRadius(12.0) - .withDraggable(true) - create(circleOptions) + val circleOptions: CircleOptions = CircleOptions() + .withPoint(Point.fromLngLat(0.381457, 6.687337)) + .withCircleColor(ColorUtils.colorToRgbaString(Color.YELLOW)) + .withCircleRadius(12.0) + .withDraggable(true) + create(circleOptions) - // random add circles across the globe - val circleOptionsList: MutableList = ArrayList() - for (i in 0..20) { - val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256)) - circleOptionsList.add( - CircleOptions() - .withPoint(createRandomPoints()) - .withCircleColor(ColorUtils.colorToRgbaString(color)) - .withCircleRadius(8.0) - .withDraggable(true) - ) - } - create(circleOptionsList) + // random add circles across the globe + val circleOptionsList: MutableList = ArrayList() + for (i in 0..20) { + val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256)) + circleOptionsList.add( + CircleOptions() + .withPoint(createRandomPoints()) + .withCircleColor(ColorUtils.colorToRgbaString(color)) + .withCircleRadius(8.0) + .withDraggable(true) + ) + } + create(circleOptionsList) - try { - create( - FeatureCollection.fromJson( - Assets.loadStringFromAssets( - this@CircleActivity, - "annotations.json" + try { + create( + FeatureCollection.fromJson( + Assets.loadStringFromAssets( + this@CircleActivity, + "annotations.json" + ) ) ) - ) - } catch (e: IOException) { - throw RuntimeException("Unable to parse annotations.json") + } catch (e: IOException) { + throw RuntimeException("Unable to parse annotations.json") + } } } - } + ) deleteAll.setOnClickListener { circleManager?.deleteAll() } } diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/FillActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/FillActivity.kt index 9565a959cc..276bc900d1 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/FillActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/FillActivity.kt @@ -29,56 +29,59 @@ class FillActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_annotation) - mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) { - val annotationPlugin = mapView.getAnnotationPlugin() - fillManager = annotationPlugin.getFillManager().apply { - addClickListener( - OnFillClickListener { - Toast.makeText(this@FillActivity, "click", Toast.LENGTH_LONG).show() - false - } - ) - val points = listOf( - listOf( - Point.fromLngLat(-3.363937, -10.733102), - Point.fromLngLat(1.754703, -19.716317), - Point.fromLngLat(-15.747196, -21.085074), - Point.fromLngLat(-3.363937, -10.733102) + mapView.getMapboxMap().loadStyleUri( + Style.MAPBOX_STREETS, + { + val annotationPlugin = mapView.getAnnotationPlugin() + fillManager = annotationPlugin.getFillManager().apply { + addClickListener( + OnFillClickListener { + Toast.makeText(this@FillActivity, "click", Toast.LENGTH_LONG).show() + false + } + ) + val points = listOf( + listOf( + Point.fromLngLat(-3.363937, -10.733102), + Point.fromLngLat(1.754703, -19.716317), + Point.fromLngLat(-15.747196, -21.085074), + Point.fromLngLat(-3.363937, -10.733102) + ) ) - ) - val fillOptions: FillOptions = FillOptions() - .withPoints(points) - .withData(JsonPrimitive("Foobar")) - .withFillColor(ColorUtils.colorToRgbaString(Color.RED)) - create(fillOptions) + val fillOptions: FillOptions = FillOptions() + .withPoints(points) + .withData(JsonPrimitive("Foobar")) + .withFillColor(ColorUtils.colorToRgbaString(Color.RED)) + create(fillOptions) - // random add fills across the globe - val fillOptionsList: MutableList = ArrayList() - for (i in 0..2) { - val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256)) - fillOptionsList.add( - FillOptions() - .withPoints(createRandomPoints()) - .withFillColor(ColorUtils.colorToRgbaString(color)) - ) - } - create(fillOptionsList) + // random add fills across the globe + val fillOptionsList: MutableList = ArrayList() + for (i in 0..2) { + val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256)) + fillOptionsList.add( + FillOptions() + .withPoints(createRandomPoints()) + .withFillColor(ColorUtils.colorToRgbaString(color)) + ) + } + create(fillOptionsList) - try { - create( - FeatureCollection.fromJson( - Assets.loadStringFromAssets( - this@FillActivity, - "annotations.json" + try { + create( + FeatureCollection.fromJson( + Assets.loadStringFromAssets( + this@FillActivity, + "annotations.json" + ) ) ) - ) - } catch (e: IOException) { - throw RuntimeException("Unable to parse annotations.json") + } catch (e: IOException) { + throw RuntimeException("Unable to parse annotations.json") + } } } - } + ) deleteAll.setOnClickListener { fillManager?.deleteAll() } } @@ -101,6 +104,7 @@ class FillActivity : AppCompatActivity() { points.add(firstLast) return listOf(points) } + override fun onStart() { super.onStart() mapView.onStart() diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/LineActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/LineActivity.kt index 8d76f74ec9..9be93db544 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/LineActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/LineActivity.kt @@ -28,60 +28,63 @@ class LineActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_annotation) - mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) { - val annotationPlugin = mapView.getAnnotationPlugin() - lineManager = annotationPlugin.getLineManager().apply { - addClickListener( - OnLineClickListener { - Toast.makeText( - this@LineActivity, - "click", - Toast.LENGTH_LONG - ).show() - false - } - ) + mapView.getMapboxMap().loadStyleUri( + Style.MAPBOX_STREETS, + { + val annotationPlugin = mapView.getAnnotationPlugin() + lineManager = annotationPlugin.getLineManager().apply { + addClickListener( + OnLineClickListener { + Toast.makeText( + this@LineActivity, + "click", + Toast.LENGTH_LONG + ).show() + false + } + ) - val points = listOf( - Point.fromLngLat(-4.375974, -2.178992), - Point.fromLngLat(-7.639772, -4.107888), - Point.fromLngLat(-11.439207, 2.798737), - ) + val points = listOf( + Point.fromLngLat(-4.375974, -2.178992), + Point.fromLngLat(-7.639772, -4.107888), + Point.fromLngLat(-11.439207, 2.798737), + ) - val lineOptions: LineOptions = LineOptions() - .withPoints(points) - .withLineColor(ColorUtils.colorToRgbaString(Color.RED)) - .withLineWidth(5.0) - create(lineOptions) + val lineOptions: LineOptions = LineOptions() + .withPoints(points) + .withLineColor(ColorUtils.colorToRgbaString(Color.RED)) + .withLineWidth(5.0) + create(lineOptions) - // random add lines across the globe - val lists: MutableList> = ArrayList>() - for (i in 0..99) { - lists.add(createRandomPoints()) - } - val lineOptionsList = lists.map { - val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256)) - LineOptions() - .withPoints(it) - .withLineColor(ColorUtils.colorToRgbaString(color)) - } + // random add lines across the globe + val lists: MutableList> = ArrayList>() + for (i in 0..99) { + lists.add(createRandomPoints()) + } + val lineOptionsList = lists.map { + val color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256)) + LineOptions() + .withPoints(it) + .withLineColor(ColorUtils.colorToRgbaString(color)) + } - create(lineOptionsList) + create(lineOptionsList) - try { - create( - FeatureCollection.fromJson( - Assets.loadStringFromAssets( - this@LineActivity, - "annotations.json" + try { + create( + FeatureCollection.fromJson( + Assets.loadStringFromAssets( + this@LineActivity, + "annotations.json" + ) ) ) - ) - } catch (e: IOException) { - throw RuntimeException("Unable to parse annotations.json") + } catch (e: IOException) { + throw RuntimeException("Unable to parse annotations.json") + } } } - } + ) deleteAll.setOnClickListener { lineManager?.deleteAll() } } diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/SymbolActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/SymbolActivity.kt index 26463035f4..f4d4e72f46 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/SymbolActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/annotation/SymbolActivity.kt @@ -44,85 +44,89 @@ class SymbolActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_annotation) - mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) { style -> - BitmapUtils.getBitmapFromDrawable( - ResourcesCompat.getDrawable( - resources, - R.drawable.ic_airplanemode_active_black_24dp, - this@SymbolActivity.theme - ) - )?.let { - style.addImage( - ID_ICON_AIRPORT, - it, true - ) - } + mapView.getMapboxMap().loadStyleUri( + Style.MAPBOX_STREETS, + { style -> + BitmapUtils.getBitmapFromDrawable( + ResourcesCompat.getDrawable( + resources, + R.drawable.ic_airplanemode_active_black_24dp, + this@SymbolActivity.theme + ) + )?.let { + style.addImage( + ID_ICON_AIRPORT, + it, true + ) + } - val annotationPlugin = mapView.getAnnotationPlugin() - symbolManager = annotationPlugin.getSymbolManager().apply { - addClickListener( - OnSymbolClickListener { - Toast.makeText(this@SymbolActivity, "Click: $it", Toast.LENGTH_LONG).show() - false - } - ) + val annotationPlugin = mapView.getAnnotationPlugin() + symbolManager = annotationPlugin.getSymbolManager().apply { + addClickListener( + OnSymbolClickListener { + Toast.makeText(this@SymbolActivity, "Click: $it", Toast.LENGTH_LONG).show() + false + } + ) - addLongClickListener( - OnSymbolLongClickListener { - Toast.makeText(this@SymbolActivity, "LongClick: $it", Toast.LENGTH_LONG).show() - false - } - ) - - // set non data driven properties - iconAllowOverlap = true - textAllowOverlap = true - - // create a symbol - val symbolOptions: SymbolOptions = SymbolOptions() - .withPoint(Point.fromLngLat(0.381457, 6.687337)) - .withIconImage(ID_ICON_AIRPORT) - .withIconSize(1.3) - .withSymbolSortKey(10.0) - .withDraggable(true) - symbol = create(symbolOptions) - - // create nearby symbols - val nearbyOptions: SymbolOptions = SymbolOptions() - .withPoint(Point.fromLngLat(0.367099, 6.626384)) - .withIconImage(MAKI_ICON_CIRCLE) - .withIconColor(ColorUtils.colorToRgbaString(Color.YELLOW)) - .withIconSize(2.5) - .withSymbolSortKey(5.0) - .withDraggable(true) - create(nearbyOptions) - - // random add symbols across the globe - val symbolOptionsList: MutableList = ArrayList() - for (i in 0..20) { - symbolOptionsList.add( - SymbolOptions() - .withPoint(createRandomPoints()) - .withIconImage(MAKI_ICON_CAR) - .withDraggable(true) + addLongClickListener( + OnSymbolLongClickListener { + Toast.makeText(this@SymbolActivity, "LongClick: $it", Toast.LENGTH_LONG).show() + false + } ) - } - create(symbolOptionsList) - - try { - create( - FeatureCollection.fromJson( - Assets.loadStringFromAssets( - this@SymbolActivity, - "annotations.json" + + // set non data driven properties + iconAllowOverlap = true + textAllowOverlap = true + + // create a symbol + val symbolOptions: SymbolOptions = SymbolOptions() + .withPoint(Point.fromLngLat(0.381457, 6.687337)) + .withIconImage(ID_ICON_AIRPORT) + .withIconSize(1.3) + .withSymbolSortKey(10.0) + .withDraggable(true) + symbol = create(symbolOptions) + + // create nearby symbols + val nearbyOptions: SymbolOptions = SymbolOptions() + .withPoint(Point.fromLngLat(0.367099, 6.626384)) + .withIconImage(MAKI_ICON_CIRCLE) + .withIconColor(ColorUtils.colorToRgbaString(Color.YELLOW)) + .withIconSize(2.5) + .withSymbolSortKey(5.0) + .withDraggable(true) + create(nearbyOptions) + + // random add symbols across the globe + val symbolOptionsList: MutableList = ArrayList() + for (i in 0..20) { + symbolOptionsList.add( + SymbolOptions() + .withPoint(createRandomPoints()) + .withIconImage(MAKI_ICON_CAR) + .withDraggable(true) + ) + } + + create(symbolOptionsList) + + try { + create( + FeatureCollection.fromJson( + Assets.loadStringFromAssets( + this@SymbolActivity, + "annotations.json" + ) ) ) - ) - } catch (e: IOException) { - throw RuntimeException("Unable to parse annotations.json") + } catch (e: IOException) { + throw RuntimeException("Unable to parse annotations.json") + } } } - } + ) deleteAll.setOnClickListener { symbolManager?.deleteAll() } } diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/CustomLayerActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/CustomLayerActivity.kt index 1ed07e2c2e..51c53c3f20 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/CustomLayerActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/CustomLayerActivity.kt @@ -24,13 +24,14 @@ class CustomLayerActivity : AppCompatActivity() { setContentView(R.layout.activity_custom_layer) mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { - mapboxMap.jumpTo( - CameraOptions.Builder().center(Point.fromLngLat(-243.60947, 39.91448)).zoom(10.0).build() - ) - initFab() - } + Style.MAPBOX_STREETS, + { + mapboxMap.jumpTo( + CameraOptions.Builder().center(Point.fromLngLat(-243.60947, 39.91448)).zoom(10.0).build() + ) + initFab() + } + ) } private fun initFab() { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/NativeCustomLayerActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/NativeCustomLayerActivity.kt index 99ecc5a948..e7f3b7381c 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/NativeCustomLayerActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/NativeCustomLayerActivity.kt @@ -25,14 +25,15 @@ class NativeCustomLayerActivity : AppCompatActivity() { setContentView(R.layout.activity_custom_layer) mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { - mapboxMap.jumpTo( - CameraOptions.Builder().center(Point.fromLngLat(-243.60947, 39.91448)).zoom(10.0) - .build() - ) - initFab() - } + Style.MAPBOX_STREETS, + { + mapboxMap.jumpTo( + CameraOptions.Builder().center(Point.fromLngLat(-243.60947, 39.91448)).zoom(10.0) + .build() + ) + initFab() + } + ) } private fun initFab() { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/TriangleCustomLayerActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/TriangleCustomLayerActivity.kt index 96cca9b933..6c0e698410 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/TriangleCustomLayerActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/customlayer/TriangleCustomLayerActivity.kt @@ -24,12 +24,13 @@ class TriangleCustomLayerActivity : AppCompatActivity() { setContentView(R.layout.activity_custom_layer) mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { - mapboxMap.jumpTo(CAMERA) - addCustomLayer(it) - initFab() - } + Style.MAPBOX_STREETS, + { + mapboxMap.jumpTo(CAMERA) + addCustomLayer(it) + initFab() + } + ) } private fun addCustomLayer(style: Style) { diff --git a/app/src/main/java/com/mapbox/maps/testapp/examples/terrain/Terrain3DShowcaseActivity.kt b/app/src/main/java/com/mapbox/maps/testapp/examples/terrain/Terrain3DShowcaseActivity.kt index 947be299cf..6174006940 100644 --- a/app/src/main/java/com/mapbox/maps/testapp/examples/terrain/Terrain3DShowcaseActivity.kt +++ b/app/src/main/java/com/mapbox/maps/testapp/examples/terrain/Terrain3DShowcaseActivity.kt @@ -12,9 +12,9 @@ import com.mapbox.maps.extension.style.layers.properties.generated.SkyType import com.mapbox.maps.extension.style.sources.generated.rasterDemSource import com.mapbox.maps.extension.style.style import com.mapbox.maps.extension.style.terrain.generated.terrain +import com.mapbox.maps.listener.OnDidFinishRenderingMapListener import com.mapbox.maps.plugin.animation.MapAnimationOptions import com.mapbox.maps.plugin.animation.easeTo -import com.mapbox.maps.plugin.delegates.listeners.OnDidFinishRenderingMapListener import com.mapbox.maps.testapp.R import kotlinx.android.synthetic.main.activity_simple_map.* diff --git a/extension-style-app/src/androidTest/java/com/mapbox/maps/testapp/style/BaseStyleTest.kt b/extension-style-app/src/androidTest/java/com/mapbox/maps/testapp/style/BaseStyleTest.kt index 66ba22dae7..072b9dee46 100644 --- a/extension-style-app/src/androidTest/java/com/mapbox/maps/testapp/style/BaseStyleTest.kt +++ b/extension-style-app/src/androidTest/java/com/mapbox/maps/testapp/style/BaseStyleTest.kt @@ -39,20 +39,21 @@ abstract class BaseStyleTest { @Before fun before() { val latch = CountDownLatch(1) - rule.scenario.onActivity { - it.runOnUiThread { + rule.scenario.onActivity { activity -> + activity.runOnUiThread { val context = InstrumentationRegistry.getInstrumentation().targetContext mapView = MapView(context) mapView.id = R.id.mapView - it.setContentView(mapView) + activity.setContentView(mapView) mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.DARK - ) { - this@BaseStyleTest.style = it - latch.countDown() - } + Style.DARK, + { + this@BaseStyleTest.style = it + latch.countDown() + } + ) mapView.onStart() } } diff --git a/plugin-gestures/src/main/java/com/mapbox/maps/plugin/gestures/GesturesPluginImpl.kt b/plugin-gestures/src/main/java/com/mapbox/maps/plugin/gestures/GesturesPluginImpl.kt index 757ddc0824..dea0facb19 100644 --- a/plugin-gestures/src/main/java/com/mapbox/maps/plugin/gestures/GesturesPluginImpl.kt +++ b/plugin-gestures/src/main/java/com/mapbox/maps/plugin/gestures/GesturesPluginImpl.kt @@ -12,6 +12,7 @@ import android.view.MotionEvent import android.view.animation.DecelerateInterpolator import com.mapbox.android.gestures.* import com.mapbox.maps.CameraOptions +import com.mapbox.maps.ObservableInterface import com.mapbox.maps.ScreenCoordinate import com.mapbox.maps.plugin.InvalidPluginConfigurationException import com.mapbox.maps.plugin.PLUGIN_CAMERA_ANIMATIONS_CLASS_NAME @@ -1587,112 +1588,112 @@ fun MapPluginProviderDelegate.getGesturesPlugin(): GesturesPlugin { /** * Add a callback that is invoked when the map is clicked. */ -fun MapListenerDelegate.addOnMapClickListener(onMapClickListener: OnMapClickListener) { +fun ObservableInterface.addOnMapClickListener(onMapClickListener: OnMapClickListener) { gesturesPlugin?.addOnMapClickListener(onMapClickListener) } /** * Remove a callback that is invoked when the map is clicked. */ -fun MapListenerDelegate.removeOnMapClickListener(onMapClickListener: OnMapClickListener) { +fun ObservableInterface.removeOnMapClickListener(onMapClickListener: OnMapClickListener) { gesturesPlugin?.removeOnMapClickListener(onMapClickListener) } /** * Add a callback that is invoked when the map is long clicked. */ -fun MapListenerDelegate.addOnMapLongClickListener(onMapLongClickListener: OnMapLongClickListener) { +fun ObservableInterface.addOnMapLongClickListener(onMapLongClickListener: OnMapLongClickListener) { gesturesPlugin?.addOnMapLongClickListener(onMapLongClickListener) } /** * Remove a callback that is invoked when the map is long clicked. */ -fun MapListenerDelegate.removeOnMapLongClickListener(onMapLongClickListener: OnMapLongClickListener) { +fun ObservableInterface.removeOnMapLongClickListener(onMapLongClickListener: OnMapLongClickListener) { gesturesPlugin?.removeOnMapLongClickListener(onMapLongClickListener) } /** * Add a callback that is invoked when the map is has received a fling gesture. */ -fun MapListenerDelegate.addOnFlingListener(onFlingListener: OnFlingListener) { +fun ObservableInterface.addOnFlingListener(onFlingListener: OnFlingListener) { gesturesPlugin?.addOnFlingListener(onFlingListener) } /** * Remove a callback that is invoked when the map is has received a fling gesture. */ -fun MapListenerDelegate.removeOnFlingListener(onFlingListener: OnFlingListener) { +fun ObservableInterface.removeOnFlingListener(onFlingListener: OnFlingListener) { gesturesPlugin?.removeOnFlingListener(onFlingListener) } /** * Add a callback that is invoked when the map is moved. */ -fun MapListenerDelegate.addOnMoveListener(listener: OnMoveListener) { +fun ObservableInterface.addOnMoveListener(listener: OnMoveListener) { gesturesPlugin?.addOnMoveListener(listener) } /** * Remove a callback that is invoked when the map is moved. */ -fun MapListenerDelegate.removeOnMoveListener(listener: OnMoveListener) { +fun ObservableInterface.removeOnMoveListener(listener: OnMoveListener) { gesturesPlugin?.removeOnMoveListener(listener) } /** * Add a callback that is invoked when the map is rotated. */ -fun MapListenerDelegate.addOnRotateListener(listener: OnRotateListener) { +fun ObservableInterface.addOnRotateListener(listener: OnRotateListener) { gesturesPlugin?.addOnRotateListener(listener) } /** * Remove a callback that is invoked when the map is rotated. */ -fun MapListenerDelegate.removeOnRotateListener(listener: OnRotateListener) { +fun ObservableInterface.removeOnRotateListener(listener: OnRotateListener) { gesturesPlugin?.removeOnRotateListener(listener) } /** * Add a callback that is invoked when the map is scaled. */ -fun MapListenerDelegate.addOnScaleListener(listener: OnScaleListener) { +fun ObservableInterface.addOnScaleListener(listener: OnScaleListener) { gesturesPlugin?.addOnScaleListener(listener) } /** * Remove a callback that is invoked when the map is scaled. */ -fun MapListenerDelegate.removeOnScaleListener(listener: OnScaleListener) { +fun ObservableInterface.removeOnScaleListener(listener: OnScaleListener) { gesturesPlugin?.removeOnScaleListener(listener) } /** * Add a callback that is invoked when the map is shoved. */ -fun MapListenerDelegate.addOnShoveListener(listener: OnShoveListener) { +fun ObservableInterface.addOnShoveListener(listener: OnShoveListener) { gesturesPlugin?.addOnShoveListener(listener) } /** * Remove a callback that is invoked when the map is shoved. */ -fun MapListenerDelegate.removeOnShoveListener(listener: OnShoveListener) { +fun ObservableInterface.removeOnShoveListener(listener: OnShoveListener) { gesturesPlugin?.removeOnShoveListener(listener) } /** * Get the current configured AndroidGesturesManager. */ -fun MapListenerDelegate.getGesturesManager(): AndroidGesturesManager? { +fun ObservableInterface.getGesturesManager(): AndroidGesturesManager? { return gesturesPlugin?.getGesturesManager() } /** * Set the AndroidGesturesManager instance. */ -fun MapListenerDelegate.setGesturesManager( +fun ObservableInterface.setGesturesManager( androidGesturesManager: AndroidGesturesManager, attachDefaultListeners: Boolean, setDefaultMutuallyExclusives: Boolean @@ -1707,4 +1708,4 @@ fun MapListenerDelegate.setGesturesManager( /** * The gesture configuration object. */ -fun MapListenerDelegate.getGesturesSettings() = gesturesPlugin?.getSettings() \ No newline at end of file +fun ObservableInterface.getGesturesSettings() = gesturesPlugin?.getSettings() \ No newline at end of file diff --git a/plugin-overlay/src/main/java/com/mapbox/maps/plugin/overlay/MapOverlayPluginImpl.kt b/plugin-overlay/src/main/java/com/mapbox/maps/plugin/overlay/MapOverlayPluginImpl.kt index f4e5a81ace..2cfc347e4b 100644 --- a/plugin-overlay/src/main/java/com/mapbox/maps/plugin/overlay/MapOverlayPluginImpl.kt +++ b/plugin-overlay/src/main/java/com/mapbox/maps/plugin/overlay/MapOverlayPluginImpl.kt @@ -270,6 +270,7 @@ class MapOverlayPluginImpl : MapOverlayPlugin { * Called when the map is destroyed. Should be used to cleanup plugin resources for that map. */ override fun cleanup() { + unregisterMapOverlayCoordinatesProvider() unregisterMapOverlayCoordinatesProvider() mapOverlays.clear() } diff --git a/plugin-scalebar/src/main/java/com/mapbox/maps/plugin/scalebar/ScaleBarPluginImpl.kt b/plugin-scalebar/src/main/java/com/mapbox/maps/plugin/scalebar/ScaleBarPluginImpl.kt index bf8a34b344..b34ce9c663 100644 --- a/plugin-scalebar/src/main/java/com/mapbox/maps/plugin/scalebar/ScaleBarPluginImpl.kt +++ b/plugin-scalebar/src/main/java/com/mapbox/maps/plugin/scalebar/ScaleBarPluginImpl.kt @@ -7,7 +7,6 @@ import android.view.ViewGroup import android.widget.FrameLayout import com.mapbox.maps.Projection.getMetersPerPixelAtLatitude import com.mapbox.maps.plugin.delegates.* -import com.mapbox.maps.plugin.delegates.listeners.OnCameraChangeListener import com.mapbox.maps.plugin.scalebar.generated.ScaleBarAttributeParser import com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettings import com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettingsBase @@ -21,15 +20,10 @@ open class ScaleBarPluginImpl( private lateinit var scaleBar: ScaleBar private lateinit var mapCameraDelegate: MapCameraDelegate - private lateinit var mapListenerDelegate: MapListenerDelegate private lateinit var mapTransformDelegate: MapTransformDelegate override var internalSettings: ScaleBarSettings = ScaleBarSettings() - private val cameraChangeListener = OnCameraChangeListener { - invalidateScaleBar() - } - override fun applySettings() { scaleBar.settings = internalSettings } @@ -42,7 +36,7 @@ open class ScaleBarPluginImpl( override fun onSizeChanged(width: Int, height: Int) { scaleBar.mapViewWidth = width.toFloat() if (enabled) { - invalidateScaleBar() + invalidateScaleBar(mapCameraDelegate.getLat(), mapCameraDelegate.getZoom()) } } @@ -60,10 +54,18 @@ open class ScaleBarPluginImpl( } /** - * Called when the map is destroyed. Should be used to cleanup plugin resources for that map. + * Called when the map camera is moved */ - override fun cleanup() { - mapListenerDelegate.removeOnCameraChangeListener(cameraChangeListener) + override fun onCameraMove( + lat: Double, + lon: Double, + zoom: Double, + pitch: Double, + bearing: Double, + padding: Array?, + anchor: Pair? + ) { + invalidateScaleBar(lat, zoom) } /** @@ -71,17 +73,13 @@ open class ScaleBarPluginImpl( */ override fun initialize() { applySettings() - mapListenerDelegate.addOnCameraChangeListener(cameraChangeListener) } /** * Invalid scale bar */ - internal fun invalidateScaleBar() { - val metersPerPixelAtLatitude = getMetersPerPixelAtLatitude( - mapCameraDelegate.getLat(), - mapCameraDelegate.getZoom() - ) + private fun invalidateScaleBar(lat: Double, zoom: Double) { + val metersPerPixelAtLatitude = getMetersPerPixelAtLatitude(lat, zoom) val pixelRatio = mapTransformDelegate.getMapOptions().pixelRatio scaleBar.distancePerPixel = (metersPerPixelAtLatitude / pixelRatio).toFloat() } @@ -91,7 +89,6 @@ open class ScaleBarPluginImpl( */ override fun onDelegateProvider(delegateProvider: MapDelegateProvider) { mapCameraDelegate = delegateProvider.mapCameraDelegate - mapListenerDelegate = delegateProvider.mapListenerDelegate mapTransformDelegate = delegateProvider.mapTransformDelegate } @@ -112,10 +109,7 @@ open class ScaleBarPluginImpl( get() = internalSettings.enabled set(value) { if (value) { - mapListenerDelegate.addOnCameraChangeListener(cameraChangeListener) - invalidateScaleBar() - } else { - mapListenerDelegate.removeOnCameraChangeListener(cameraChangeListener) + invalidateScaleBar(mapCameraDelegate.getLat(), mapCameraDelegate.getZoom()) } internalSettings.enabled = value scaleBar.enable = value diff --git a/plugin-scalebar/src/test/java/com/mapbox/maps/plugin/scalebar/ScaleBarPluginTest.kt b/plugin-scalebar/src/test/java/com/mapbox/maps/plugin/scalebar/ScaleBarPluginTest.kt index 4bea60fb1e..80cbd16b21 100644 --- a/plugin-scalebar/src/test/java/com/mapbox/maps/plugin/scalebar/ScaleBarPluginTest.kt +++ b/plugin-scalebar/src/test/java/com/mapbox/maps/plugin/scalebar/ScaleBarPluginTest.kt @@ -9,7 +9,6 @@ import com.mapbox.maps.MapOptions import com.mapbox.maps.Projection import com.mapbox.maps.plugin.delegates.MapCameraDelegate import com.mapbox.maps.plugin.delegates.MapDelegateProvider -import com.mapbox.maps.plugin.delegates.MapListenerDelegate import com.mapbox.maps.plugin.delegates.MapTransformDelegate import com.mapbox.maps.plugin.scalebar.generated.ScaleBarAttributeParser import io.mockk.* @@ -29,7 +28,6 @@ class ScaleBarPluginTest { private val scaleBarView = mockk(relaxUnitFun = true) private val delegateProvider = mockk(relaxUnitFun = true) private val mapCameraDelegate = mockk() - private val mapListenerManagerDelegate = mockk(relaxed = true) private val mapTransformDelegate = mockk() private val mapOptions = mockk() private val mapView = mockk() @@ -46,7 +44,6 @@ class ScaleBarPluginTest { every { mapTransformDelegate.getMapOptions() } returns mapOptions every { mapOptions.pixelRatio } returns 1.0f every { delegateProvider.mapCameraDelegate } returns mapCameraDelegate - every { delegateProvider.mapListenerDelegate } returns mapListenerManagerDelegate every { delegateProvider.mapTransformDelegate } returns mapTransformDelegate every { mapView.width } returns 1024 every { mapView.context } returns context diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/MapDelegateProvider.kt b/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/MapDelegateProvider.kt index 4204c38d51..caf89a148d 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/MapDelegateProvider.kt +++ b/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/MapDelegateProvider.kt @@ -42,11 +42,6 @@ interface MapDelegateProvider { */ val mapFeatureQueryDelegate: MapFeatureQueryDelegate - /** - * Delegate used to manager listeners. - */ - val mapListenerDelegate: MapListenerDelegate - /** * Delegate used for style state. */ diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/MapListenerDelegate.kt b/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/MapListenerDelegate.kt deleted file mode 100644 index ec30476648..0000000000 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/MapListenerDelegate.kt +++ /dev/null @@ -1,79 +0,0 @@ -package com.mapbox.maps.plugin.delegates - -import com.mapbox.maps.plugin.delegates.listeners.* - -/** - * Definition of a listener manager delegate to manage all kinds of listeners. - */ -interface MapListenerDelegate { - - /** - * Add a listener that's going to be invoked whenever map state changes. - */ - fun addOnMapChangedListener(onMapChangeListener: OnMapChangedListener) - - /** - * Remove the map change listener. - */ - fun removeOnMapChangedListener(onMapChangedListener: OnMapChangedListener) - - /** - * Add a listener that's going to be invoked whenever a map load error occurs. - */ - fun addOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener) - - /** - * Remove the map load error listener. - */ - fun removeOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener) - - /** - * Add a listener that's going to be invoked whenever frame finished rendering. - */ - fun addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener) - - /** - * Remove the finish rendering frame listener. - */ - fun removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener) - - /** - * Add a listener that's going to be invoked whenever the camera position changes. - */ - fun addOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener) - - /** - * Remove the camera change listener. - */ - fun removeOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener) - - /** - * Add a listener that's going to be invoked whenever a source changes. - */ - fun addOnSourceChangeListener(onSourceChangeListener: OnSourceChangeListener) - - /** - * Remove the source change listener. - */ - fun removeOnSourceChangeListener(onSourceChangeListener: OnSourceChangeListener) - - /** - * Add a listener that's going to be invoked whenever style image state changes. - */ - fun addOnStyleImageChangeListener(onStyleImageChangeListener: OnStyleImageChangeListener) - - /** - * Remove the style image change listener. - */ - fun removeOnStyleImageChangeListener(onStyleImageChangeListener: OnStyleImageChangeListener) - - /** - * Add a listener that's going to be invoked whenever the map finished rendering. - */ - fun addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener: OnDidFinishRenderingMapListener) - - /** - * Remove the did finish rendering map listener. - */ - fun removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener: OnDidFinishRenderingMapListener) -} \ No newline at end of file diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnMapChangedListener.kt b/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnMapChangedListener.kt deleted file mode 100644 index a2a121397b..0000000000 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnMapChangedListener.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.mapbox.maps.plugin.delegates.listeners - -import com.mapbox.maps.MapChange - -/** - * Definition for listener invoked whenever the map state changes. - * See [MapChange]. - */ -fun interface OnMapChangedListener { - /** - * Invoked whenever the map state changes. - * - * @param mapChange the [MapChange] change - */ - fun onMapChange(mapChange: MapChange) -} \ No newline at end of file diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnMapLoadErrorListener.kt b/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnMapLoadErrorListener.kt deleted file mode 100644 index f4391db9b6..0000000000 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnMapLoadErrorListener.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mapbox.maps.plugin.delegates.listeners - -import com.mapbox.maps.MapLoadError - -/** - * Definition for listener invoked whenever the map load errors out. - * See [MapLoadError]. - */ -interface OnMapLoadErrorListener { - /** - * Invoked whenever the map load errors out - * - * @param mapViewLoadError the [MapLoadError] - * @param msg the error message string - */ - fun onMapLoadError(mapViewLoadError: MapLoadError, msg: String) -} \ No newline at end of file diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/scalebar/ScaleBarPlugin.kt b/sdk-base/src/main/java/com/mapbox/maps/plugin/scalebar/ScaleBarPlugin.kt index 13d31742de..89643e96bb 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/scalebar/ScaleBarPlugin.kt +++ b/sdk-base/src/main/java/com/mapbox/maps/plugin/scalebar/ScaleBarPlugin.kt @@ -1,5 +1,6 @@ package com.mapbox.maps.plugin.scalebar +import com.mapbox.maps.plugin.MapCameraPlugin import com.mapbox.maps.plugin.MapSizePlugin import com.mapbox.maps.plugin.ViewPlugin import com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettingsInterface @@ -7,7 +8,7 @@ import com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettingsInterface /** * Presenter interface for the ScaleBar. */ -interface ScaleBarPlugin : ViewPlugin, MapSizePlugin, ScaleBarSettingsInterface { +interface ScaleBarPlugin : ViewPlugin, MapSizePlugin, MapCameraPlugin, ScaleBarSettingsInterface { /** * How many meters in each pixel. */ diff --git a/sdk/src/androidTest/java/com/mapbox/maps/BaseAnimationMapTest.kt b/sdk/src/androidTest/java/com/mapbox/maps/BaseAnimationMapTest.kt index 82cb8062b6..211bf0ca16 100644 --- a/sdk/src/androidTest/java/com/mapbox/maps/BaseAnimationMapTest.kt +++ b/sdk/src/androidTest/java/com/mapbox/maps/BaseAnimationMapTest.kt @@ -49,11 +49,12 @@ abstract class BaseAnimationMapTest { mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.DARK - ) { style -> - this@BaseAnimationMapTest.style = style - latch.countDown() - } + Style.DARK, + { style -> + this@BaseAnimationMapTest.style = style + latch.countDown() + } + ) mapView.onStart() } } diff --git a/sdk/src/androidTest/java/com/mapbox/maps/StyleLoadTest.kt b/sdk/src/androidTest/java/com/mapbox/maps/StyleLoadTest.kt index d99128667b..ecaec97b48 100644 --- a/sdk/src/androidTest/java/com/mapbox/maps/StyleLoadTest.kt +++ b/sdk/src/androidTest/java/com/mapbox/maps/StyleLoadTest.kt @@ -57,12 +57,13 @@ class StyleLoadTest { mapboxMap.getStyle { countDownLatch.countDown() } mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { style -> - assertNotNull("Style should but non null", style) - assertTrue("Style should be fully loaded", style.fullyLoaded) - countDownLatch.countDown() - } + Style.MAPBOX_STREETS, + { style -> + assertNotNull("Style should but non null", style) + assertTrue("Style should be fully loaded", style.fullyLoaded) + countDownLatch.countDown() + } + ) } } countDownLatch = CountDownLatch(2) @@ -76,14 +77,15 @@ class StyleLoadTest { rule.scenario.onActivity { it.runOnUiThread { mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { style -> - assertNotNull("Style should but non null", style) - assertTrue("Style should be fully loaded", style.fullyLoaded) - mapboxMap.loadStyleUri(Style.DARK) - assertFalse("Map shouldn't be fully loaded", style.fullyLoaded) - countDownLatch.countDown() - } + Style.MAPBOX_STREETS, + { style -> + assertNotNull("Style should but non null", style) + assertTrue("Style should be fully loaded", style.fullyLoaded) + mapboxMap.loadStyleUri(Style.DARK) + assertFalse("Map shouldn't be fully loaded", style.fullyLoaded) + countDownLatch.countDown() + } + ) } } countDownLatch = CountDownLatch(1) diff --git a/sdk/src/androidTest/java/com/mapbox/maps/TestActivity.kt b/sdk/src/androidTest/java/com/mapbox/maps/TestActivity.kt index 3af29b4d4d..b913acb08e 100644 --- a/sdk/src/androidTest/java/com/mapbox/maps/TestActivity.kt +++ b/sdk/src/androidTest/java/com/mapbox/maps/TestActivity.kt @@ -18,8 +18,8 @@ class TestActivity : AppCompatActivity() { mapboxMap = mapView.getMapboxMap() mapboxMap.loadStyleUri( - Style.MAPBOX_STREETS - ) { loaded = true } + Style.MAPBOX_STREETS, { loaded = true } + ) } override fun onStart() { diff --git a/sdk/src/main/java/com/mapbox/maps/MapController.kt b/sdk/src/main/java/com/mapbox/maps/MapController.kt index 3df7ab5186..921854e127 100644 --- a/sdk/src/main/java/com/mapbox/maps/MapController.kt +++ b/sdk/src/main/java/com/mapbox/maps/MapController.kt @@ -7,8 +7,6 @@ import com.mapbox.annotation.module.MapboxModuleType import com.mapbox.common.Logger import com.mapbox.common.module.provider.MapboxModuleProvider import com.mapbox.common.module.provider.ModuleProviderArgument -import com.mapbox.mapboxsdk.assets.AssetManagerProvider -import com.mapbox.maps.loader.MapboxMapStaticInitializer import com.mapbox.maps.module.MapTelemetry import com.mapbox.maps.plugin.* import com.mapbox.maps.plugin.animation.CameraAnimationsPlugin @@ -16,8 +14,6 @@ import com.mapbox.maps.plugin.annotation.AnnotationPluginImpl import com.mapbox.maps.plugin.attribution.AttributionPlugin import com.mapbox.maps.plugin.compass.CompassPlugin import com.mapbox.maps.plugin.delegates.MapPluginProviderDelegate -import com.mapbox.maps.plugin.delegates.listeners.OnCameraChangeListener -import com.mapbox.maps.plugin.delegates.listeners.OnMapChangedListener import com.mapbox.maps.plugin.gestures.GesturesPlugin import com.mapbox.maps.plugin.location.LocationPlugin import com.mapbox.maps.plugin.logo.LogoPlugin @@ -30,11 +26,9 @@ internal class MapController : MapPluginProviderDelegate, MapControllable { private val renderer: MapboxRenderer private val mapObserver: NativeMapObserver private val mapboxMapOptions: MapboxMapOptions - private val nativeMap: MapInterface private val mapboxMap: MapboxMap - private val pluginRegistry: MapPluginRegistry - private val cameraChangeListener: OnCameraChangeListener - private val mapChangeListener: OnMapChangedListener + internal val pluginRegistry: MapPluginRegistry + internal val nativeMap: MapInterface constructor( renderer: MapboxRenderer, @@ -44,11 +38,9 @@ internal class MapController : MapPluginProviderDelegate, MapControllable { this.renderer = renderer this.mapObserver = mapObserver this.mapboxMapOptions = mapboxMapOptions - AssetManagerProvider().initialize(mapboxMapOptions.context.assets) this.nativeMap = MapProvider.getNativeMap( mapboxMapOptions, - renderer, - mapObserver + renderer ) this.mapboxMap = MapProvider.getMapboxMap(nativeMap, mapObserver, mapboxMapOptions.pixelRatio) this.pluginRegistry = MapProvider.getMapPluginRegistry( @@ -56,20 +48,6 @@ internal class MapController : MapPluginProviderDelegate, MapControllable { this, dispatchTelemetryTurnstileEvent() ) - this.cameraChangeListener = OnCameraChangeListener { - pluginRegistry.onCameraMove(nativeMap.getCameraOptions(null)) - } - this.mapChangeListener = OnMapChangedListener { - when (it) { - MapChange.WILL_START_LOADING_MAP -> pluginRegistry.onStyleLoading() - MapChange.DID_FINISH_LOADING_STYLE -> mapboxMap.getStyle { style -> - pluginRegistry.onStyleChanged( - style - ) - } - else -> Unit - } - } renderer.setMap(nativeMap) this.mapboxMapOptions.cameraOptions?.let { mapboxMap.jumpTo(it) @@ -82,8 +60,7 @@ internal class MapController : MapPluginProviderDelegate, MapControllable { mapboxMapOptions: MapboxMapOptions, nativeMap: MapInterface, mapboxMap: MapboxMap, - pluginRegistry: MapPluginRegistry, - mapChangeListener: OnMapChangedListener + pluginRegistry: MapPluginRegistry ) { this.renderer = renderer this.mapObserver = mapObserver @@ -91,10 +68,6 @@ internal class MapController : MapPluginProviderDelegate, MapControllable { this.nativeMap = nativeMap this.mapboxMap = mapboxMap this.pluginRegistry = pluginRegistry - this.cameraChangeListener = OnCameraChangeListener { - pluginRegistry.onCameraMove(nativeMap.getCameraOptions(null)) - } - this.mapChangeListener = mapChangeListener } override fun getMapboxMap(): MapboxMap { @@ -102,8 +75,6 @@ internal class MapController : MapPluginProviderDelegate, MapControllable { } override fun onStart() { - mapObserver.addOnCameraChangeListener(cameraChangeListener) - mapObserver.addOnMapChangedListener(mapChangeListener) renderer.onStart() pluginRegistry.onStart() } @@ -113,8 +84,6 @@ internal class MapController : MapPluginProviderDelegate, MapControllable { } override fun onStop() { - mapObserver.removeOnCameraChangeListener(cameraChangeListener) - mapObserver.removeOnMapChangedListener(mapChangeListener) renderer.onStop() pluginRegistry.onStop() } @@ -345,9 +314,5 @@ internal class MapController : MapPluginProviderDelegate, MapControllable { companion object { const val TAG = "MapController" - - init { - MapboxMapStaticInitializer.loadMapboxMapNativeLib() - } } } \ No newline at end of file diff --git a/sdk/src/main/java/com/mapbox/maps/MapProvider.kt b/sdk/src/main/java/com/mapbox/maps/MapProvider.kt index 05cdd81c6b..d4a766ae55 100644 --- a/sdk/src/main/java/com/mapbox/maps/MapProvider.kt +++ b/sdk/src/main/java/com/mapbox/maps/MapProvider.kt @@ -9,11 +9,9 @@ internal object MapProvider { fun getNativeMap( mapboxMapOptions: MapboxMapOptions, mapClient: MapClient, - mapObserver: MapObserver ): MapInterface = NativeMapImpl( Map( mapClient, - mapObserver, mapboxMapOptions.mapOptions, mapboxMapOptions.resourceOptions ) diff --git a/sdk/src/main/java/com/mapbox/maps/MapSurface.kt b/sdk/src/main/java/com/mapbox/maps/MapSurface.kt index 33501627cd..ded719ebb2 100644 --- a/sdk/src/main/java/com/mapbox/maps/MapSurface.kt +++ b/sdk/src/main/java/com/mapbox/maps/MapSurface.kt @@ -2,8 +2,6 @@ package com.mapbox.maps import android.content.Context import android.graphics.Bitmap -import android.os.Handler -import android.os.Looper import android.view.MotionEvent import android.view.Surface import com.mapbox.maps.plugin.delegates.MapPluginProviderDelegate @@ -28,6 +26,7 @@ class MapSurface : MapPluginProviderDelegate, MapControllable { private val mapObserver: MapObserver private val mapController: MapController private val renderer: MapboxSurfaceRenderer + private val nativeMapObserver: NativeMapObserver constructor( context: Context, @@ -44,11 +43,17 @@ class MapSurface : MapPluginProviderDelegate, MapControllable { this.surface = surface this.mapObserver = mapObserver this.renderer = MapboxSurfaceRenderer() + this.nativeMapObserver = NativeMapObserver() this.mapController = MapController( renderer, - NativeMapObserver(Handler(Looper.getMainLooper())), + nativeMapObserver, mapboxMapOptions ) + nativeMapObserver.initialize( + mapController.pluginRegistry, + mapController.nativeMap, + mapController.getMapboxMap() + ) mapController.initializePlugins( null, mapboxMapOptions.context, diff --git a/sdk/src/main/java/com/mapbox/maps/MapView.kt b/sdk/src/main/java/com/mapbox/maps/MapView.kt index 2b15feb0e2..d5485a58b3 100644 --- a/sdk/src/main/java/com/mapbox/maps/MapView.kt +++ b/sdk/src/main/java/com/mapbox/maps/MapView.kt @@ -5,8 +5,6 @@ import android.annotation.TargetApi import android.content.Context import android.graphics.Bitmap import android.os.Build -import android.os.Handler -import android.os.Looper import android.util.AttributeSet import android.view.MotionEvent import android.view.SurfaceView @@ -107,17 +105,23 @@ class MapView : FrameLayout, MapPluginProviderDelegate, MapControllable { } else { SurfaceView(context, attrs) } + + val observer = NativeMapObserver() mapController = MapController( when (view) { is SurfaceView -> MapboxSurfaceHolderRenderer(view.holder) is TextureView -> MapboxTextureViewRenderer(WeakReference(view)) else -> throw IllegalArgumentException("Provided view has to be a texture or a surface.") }, - NativeMapObserver(Handler(Looper.getMainLooper())), + observer, options ) addView(view, 0) - + observer.initialize( + mapController.pluginRegistry, + mapController.nativeMap, + mapController.getMapboxMap() + ) mapController.initializePlugins(this, context, attrs, options.pixelRatio) } diff --git a/sdk/src/main/java/com/mapbox/maps/MapboxMap.kt b/sdk/src/main/java/com/mapbox/maps/MapboxMap.kt index 5769533891..de5c0957f8 100644 --- a/sdk/src/main/java/com/mapbox/maps/MapboxMap.kt +++ b/sdk/src/main/java/com/mapbox/maps/MapboxMap.kt @@ -4,9 +4,10 @@ import com.mapbox.bindgen.Value import com.mapbox.geojson.Feature import com.mapbox.geojson.Geometry import com.mapbox.geojson.Point +import com.mapbox.maps.Style.OnStyleLoadedInternal import com.mapbox.maps.extension.style.StyleContract +import com.mapbox.maps.listener.* import com.mapbox.maps.plugin.delegates.* -import com.mapbox.maps.plugin.delegates.listeners.* import java.lang.ref.WeakReference import java.util.* @@ -31,7 +32,6 @@ class MapboxMap internal constructor( MapProjectionDelegate, MapFeatureQueryDelegate, ObservableInterface, - MapListenerDelegate, MapStyleStateDelegate { private val nativeMapWeakRef = WeakReference(nativeMap) @@ -66,32 +66,21 @@ class MapboxMap internal constructor( fun loadStyleUri( styleUri: String, onStyleLoaded: Style.OnStyleLoaded? = null, - onMapLoadErrorListener: OnMapLoadErrorListener? = null + onStyleError: Style.OnStyleError? = null ) { - initializeStyleLoad(onStyleLoaded, onMapLoadErrorListener) + initializeStyleLoad(onStyleLoaded, onStyleError) nativeMapWeakRef.call { (this as StyleManagerInterface).styleURI = styleUri } } - /** - * Will load a new map style asynchronous from the specified URI. - * - * @param styleUri The style URI - * @param onStyleLoaded The OnStyleLoaded callback - */ - fun loadStyleUri( - styleUri: String, - onStyleLoaded: Style.OnStyleLoaded - ) = loadStyleUri(styleUri, onStyleLoaded, null) - /** * Load style JSON */ fun loadStyleJSON( json: String, onStyleLoaded: Style.OnStyleLoaded? = null, - onMapLoadErrorListener: OnMapLoadErrorListener? = null + onStyleError: Style.OnStyleError? = null ) { - initializeStyleLoad(onStyleLoaded, onMapLoadErrorListener) + initializeStyleLoad(onStyleLoaded, onStyleError) nativeMapWeakRef.call { (this as StyleManagerInterface).styleJSON = json } @@ -111,12 +100,12 @@ class MapboxMap internal constructor( fun loadStyle( styleExtension: StyleContract.StyleExtension, onStyleLoaded: Style.OnStyleLoaded? = null, - onMapLoadErrorListener: OnMapLoadErrorListener? = null + onStyleError: Style.OnStyleError? = null ) { this.loadStyleUri( styleExtension.styleUri, { style -> onFinishLoadingStylePlugin(style, styleExtension, onStyleLoaded) }, - onMapLoadErrorListener + onStyleError ) } @@ -153,47 +142,44 @@ class MapboxMap internal constructor( private fun initializeStyleLoad( onStyleLoaded: Style.OnStyleLoaded? = null, - onMapLoadErrorListener: OnMapLoadErrorListener? = null + onStyleError: Style.OnStyleError? = null ) { if (::style.isInitialized) { style.fullyLoaded = false } - onMapLoadErrorListener?.let { - addOnMapLoadErrorListener(it) - } - addOnMapChangedListener( - object : OnMapChangedListener { - override fun onMapChange(mapChange: MapChange) { - if (mapChange == MapChange.DID_FINISH_LOADING_STYLE) { - onFinishLoadingStyle(onStyleLoaded, onMapLoadErrorListener) - removeOnMapChangedListener(this) - } + + if (mapObserver.onStyleLoaded == null) { + mapObserver.onStyleLoaded = object : OnStyleLoadedInternal { + override fun onLoad(): Style { + return onFinishLoadingStyle() } } - ) + } + + onStyleLoaded?.let { + mapObserver.awaitingStyleGetters.add(it) + } + + onStyleError?.let { + mapObserver.awaitingStyleErrors.add(it) + } } /** * Handle the style loading through native map */ - internal fun onFinishLoadingStyle( - onStyleLoaded: Style.OnStyleLoaded? = null, - onMapLoadErrorListener: OnMapLoadErrorListener? = null - ) { + internal fun onFinishLoadingStyle(): Style { nativeMapWeakRef.get()?.let { style = Style(it as StyleManagerInterface, pixelRatio) - // notify the listener provided with the style setter - onStyleLoaded?.onStyleLoaded(style) // notify style getters for (styleGetter in mapObserver.awaitingStyleGetters) { styleGetter.onStyleLoaded(style) } mapObserver.awaitingStyleGetters.clear() + mapObserver.awaitingStyleErrors.clear() } - onMapLoadErrorListener?.let { - addOnMapLoadErrorListener(it) - } + return style } /** @@ -873,101 +859,73 @@ class MapboxMap internal constructor( } } - /** - * Add a listener that's going to be invoked whenever map state changes. - */ - override fun addOnMapChangedListener(onMapChangeListener: OnMapChangedListener) { - mapObserver.addOnMapChangedListener(onMapChangeListener) - } - - /** - * Remove the map change listener. - */ - override fun removeOnMapChangedListener(onMapChangedListener: OnMapChangedListener) { - mapObserver.removeOnMapChangedListener(onMapChangedListener) - } - - /** - * Add a listener that's going to be invoked whenever a map load error occurs. - */ - override fun addOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener) { - mapObserver.addOnMapLoadErrorListener(onMapLoadErrorListener) - } - - /** - * Remove the map load error listener. - */ - override fun removeOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener) { - mapObserver.removeOnMapLoadErrorListener(onMapLoadErrorListener) - } - /** * Add a listener that's going to be invoked whenever frame finished rendering. */ - override fun addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener) { + fun addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener) { mapObserver.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener) } /** * Remove the finish rendering frame listener. */ - override fun removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener) { + fun removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener) { mapObserver.removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener) } /** * Add a listener that's going to be invoked whenever the camera position changes. */ - override fun addOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener) { + fun addOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener) { mapObserver.addOnCameraChangeListener(onCameraChangeListener) } /** * Remove the camera change listener. */ - override fun removeOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener) { + fun removeOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener) { mapObserver.removeOnCameraChangeListener(onCameraChangeListener) } /** * Add a listener that's going to be invoked whenever a source changes. */ - override fun addOnSourceChangeListener(onSourceChangeListener: OnSourceChangeListener) { + fun addOnSourceChangeListener(onSourceChangeListener: OnSourceChangeListener) { mapObserver.addOnSourceChangeListener(onSourceChangeListener) } /** * Remove the source change listener. */ - override fun removeOnSourceChangeListener(onSourceChangeListener: OnSourceChangeListener) { + fun removeOnSourceChangeListener(onSourceChangeListener: OnSourceChangeListener) { mapObserver.removeOnSourceChangeListener(onSourceChangeListener) } /** * Add a listener that's going to be invoked whenever style image state changes. */ - override fun addOnStyleImageChangeListener(onStyleImageChangeListener: OnStyleImageChangeListener) { + fun addOnStyleImageChangeListener(onStyleImageChangeListener: OnStyleImageChangeListener) { mapObserver.addOnStyleImageChangeListener(onStyleImageChangeListener) } /** * Remove the style image change listener. */ - override fun removeOnStyleImageChangeListener(onStyleImageChangeListener: OnStyleImageChangeListener) { + fun removeOnStyleImageChangeListener(onStyleImageChangeListener: OnStyleImageChangeListener) { mapObserver.removeOnStyleImageChangeListener(onStyleImageChangeListener) } /** * Add a listener that's going to be invoked whenever the map finished rendering. */ - override fun addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener: OnDidFinishRenderingMapListener) { + fun addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener: OnDidFinishRenderingMapListener) { mapObserver.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener) } /** * Remove the did finish rendering map listener. */ - override fun removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener: OnDidFinishRenderingMapListener) { + fun removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener: OnDidFinishRenderingMapListener) { mapObserver.removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener) } diff --git a/sdk/src/main/java/com/mapbox/maps/NativeMapObserver.kt b/sdk/src/main/java/com/mapbox/maps/NativeMapObserver.kt index b2847e5ead..2a618683d7 100644 --- a/sdk/src/main/java/com/mapbox/maps/NativeMapObserver.kt +++ b/sdk/src/main/java/com/mapbox/maps/NativeMapObserver.kt @@ -1,135 +1,224 @@ package com.mapbox.maps -import android.os.Handler -import com.mapbox.common.Logger -import com.mapbox.maps.plugin.delegates.listeners.* +import com.mapbox.bindgen.Value +import com.mapbox.maps.listener.* +import com.mapbox.maps.plugin.MapPluginRegistry +import java.util.* import java.util.concurrent.CopyOnWriteArrayList +import kotlin.collections.HashMap -internal class NativeMapObserver(private val mainHandler: Handler) : MapObserver() { +internal class NativeMapObserver : Observer() { - val onMapChangedListeners = CopyOnWriteArrayList() - val onMapLoadErrorListeners = CopyOnWriteArrayList() - val onDidFinishRenderingFrameListeners = - CopyOnWriteArrayList() - val onCameraChangeListeners = CopyOnWriteArrayList() - val onSourceChangeListeners = CopyOnWriteArrayList() - val onStyleImageChangeListeners = - CopyOnWriteArrayList() - val onDidFinishRenderingMapListeners = - CopyOnWriteArrayList() - val awaitingStyleGetters = mutableListOf() + private lateinit var mapboxMap: MapboxMap + private lateinit var nativeMap: MapInterface + private lateinit var pluginRegistry: MapPluginRegistry - // - // Internal callbacks - // + // Style handlers + internal val awaitingStyleGetters = mutableListOf() + internal val awaitingStyleErrors = mutableListOf() + internal var onStyleLoaded: Style.OnStyleLoadedInternal? = null - override fun onMapChanged(mapViewChange: MapChange) { - if (onMapChangedListeners.isEmpty()) { - return - } + // High level listeners + internal val onDidFinishRenderingFrameListeners = + CopyOnWriteArrayList() + internal val onCameraChangeListeners = CopyOnWriteArrayList() + internal val onSourceChangeListeners = CopyOnWriteArrayList() + internal val onStyleImageChangeListeners = CopyOnWriteArrayList() + internal val onDidFinishRenderingMapListeners = + CopyOnWriteArrayList() + internal val onDidBecomeIdleListeners = CopyOnWriteArrayList() + internal val onDidFinishLoadingMapListeners = + CopyOnWriteArrayList() + internal val onWillStartLoadingMapListeners = + CopyOnWriteArrayList() + internal val onWillStartRenderingFrameListeners = + CopyOnWriteArrayList() + internal val onWillStartRenderingMapListeners = + CopyOnWriteArrayList() - mainHandler.post { - onMapChangedListeners.forEach { it.onMapChange(mapViewChange) } - } + fun initialize(pluginRegistry: MapPluginRegistry, nativeMap: MapInterface, mapboxMap: MapboxMap) { + this.pluginRegistry = pluginRegistry + this.nativeMap = nativeMap + this.mapboxMap = mapboxMap + mapboxMap.subscribe( + this, + listOf( + MapEvents.CAMERA_DID_CHANGE, + MapEvents.CAMERA_WILL_CHANGE, + MapEvents.CAMERA_IS_CHANGING, + MapEvents.MAP_IDLE, + MapEvents.MAP_LOADING_FINISHED, + MapEvents.STYLE_LOADING_FINISHED, + MapEvents.RENDER_FRAME_FINISHED, + MapEvents.RENDER_MAP_FINISHED, + MapEvents.MAP_LOADING_ERROR, + MapEvents.SOURCE_CHANGED, + MapEvents.STYLE_IMAGE_MISSING, + MapEvents.STYLE_IMAGE_REMOVE_UNUSED, + MapEvents.MAP_LOADING_STARTED, + MapEvents.RENDER_FRAME_STARTED, + MapEvents.RENDER_MAP_STARTED + ) + ) } - override fun onMapLoadError(mapViewLoadError: MapLoadError, msg: String) { - Logger.e(TAG, "$mapViewLoadError, msg: $msg") - if (onMapLoadErrorListeners.isEmpty()) { - return - } - mainHandler.post { - onMapLoadErrorListeners.forEach { it.onMapLoadError(mapViewLoadError, msg) } - } - } + fun clearListeners() { + // unsubscribe core + mapboxMap.unsubscribe(this) + // style + onStyleLoaded = null + awaitingStyleErrors.clear() + awaitingStyleGetters.clear() - override fun onDidFinishRenderingFrame(status: RenderFrameStatus) { - if (onDidFinishRenderingFrameListeners.isEmpty()) { - return - } - mainHandler.post { - onDidFinishRenderingFrameListeners.forEach { it.onDidFinishRenderingFrame(status) } - } + // listeners + onDidFinishRenderingFrameListeners.clear() + onCameraChangeListeners.clear() + onSourceChangeListeners.clear() + onStyleImageChangeListeners.clear() + onDidFinishRenderingMapListeners.clear() + onDidBecomeIdleListeners.clear() + onDidFinishLoadingMapListeners.clear() + onWillStartLoadingMapListeners.clear() + onWillStartRenderingFrameListeners.clear() + onWillStartRenderingMapListeners.clear() } - override fun onCameraChange( - changeEvent: CameraChange, - mode: CameraChangeMode - ) { - if (onCameraChangeListeners.isEmpty()) { - return - } - mainHandler.post { - if (changeEvent == CameraChange.CAMERA_DID_CHANGE) { - onCameraChangeListeners.forEach { it.onCameraChanged() } + override fun notify(event: Event) { + when (event.type) { + MapEvents.CAMERA_DID_CHANGE -> { + pluginRegistry.onCameraMove(nativeMap.getCameraOptions(null)) + if (!onCameraChangeListeners.isEmpty()) { + for (onCameraChangeListener in onCameraChangeListeners) { + onCameraChangeListener.onCameraChanged() + } + } + return } - } - } - - override fun onSourceChanged(id: String) { - if (onSourceChangeListeners.isEmpty()) { - return - } - mainHandler.post { - onSourceChangeListeners.forEach { - it.onSourceChanged(id) + MapEvents.MAP_IDLE -> { + if (!onDidBecomeIdleListeners.isEmpty()) { + for (listener in onDidBecomeIdleListeners) { + listener.onIdle() + } + } + return } - } - } - - override fun onStyleImageMissing(id: String) { - if (onStyleImageChangeListeners.isEmpty()) { - return - } - mainHandler.post { - onStyleImageChangeListeners.forEach { - it.onStyleImageMissing(id) + MapEvents.MAP_LOADING_FINISHED -> { + if (!onDidFinishLoadingMapListeners.isEmpty()) { + for (listener in onDidFinishLoadingMapListeners) { + listener.onDidFinishLoadingMapListener() + } + } + return } - } - } - - override fun onCanRemoveUnusedStyleImage(id: String): Boolean { - if (onStyleImageChangeListeners.isEmpty()) { - return false - } - onStyleImageChangeListeners.forEach { - if (it.onCanRemoveUnusedStyleImage(id)) { - return true + MapEvents.STYLE_LOADING_FINISHED -> { + onStyleLoaded?.let { + val style = it.onLoad() + pluginRegistry.onStyleChanged(style) + } + return } - } - return false - } - - override fun onDidFinishRenderingMap(mode: RenderMode) { - if (onDidFinishRenderingMapListeners.isEmpty()) { - return - } - mainHandler.post { - onDidFinishRenderingMapListeners.forEach { - it.onDidFinishRenderingMap(mode) + MapEvents.RENDER_FRAME_FINISHED -> { + if (!onDidFinishRenderingFrameListeners.isEmpty()) { + for (listener in onDidFinishRenderingFrameListeners) { + val data = event.data.contents as HashMap + val renderFrameStatus = RenderFrameStatus( + RenderMode.valueOf( + data["render-mode"]!!.contents.toString().toUpperCase(Locale.getDefault()) + ), + data["needs-repaint"]!!.contents.toString() == "true", + data["placement-changed"]!!.contents.toString() == "true" + ) + listener.onDidFinishRenderingFrame(renderFrameStatus) + } + } + return + } + MapEvents.RENDER_MAP_FINISHED -> { + if (!onDidFinishRenderingMapListeners.isEmpty()) { + val data = event.data.contents as HashMap + val renderMode = RenderMode.valueOf( + data["render-mode"]!!.contents.toString().toUpperCase(Locale.getDefault()) + ) + for (listener in onDidFinishRenderingMapListeners) { + listener.onDidFinishRenderingMap(renderMode) + } + } + return + } + MapEvents.SOURCE_CHANGED -> { + if (!onSourceChangeListeners.isEmpty()) { + val data: HashMap = event.data.contents as HashMap + data["id"]?.contents.let { + for (listener in onSourceChangeListeners) { + listener.onSourceChanged(it.toString()) + } + } + } + return + } + MapEvents.STYLE_IMAGE_MISSING -> { + if (!onStyleImageChangeListeners.isEmpty()) { + val data: HashMap = event.data.contents as HashMap + data["id"]?.contents.let { + for (listener in onStyleImageChangeListeners) { + listener.onStyleImageMissing(it.toString()) + } + } + } + return + } + MapEvents.STYLE_IMAGE_REMOVE_UNUSED -> { + if (!onStyleImageChangeListeners.isEmpty()) { + val data: HashMap = event.data.contents as HashMap + data["id"]?.contents.let { + for (listener in onStyleImageChangeListeners) { + listener.onCanRemoveUnusedStyleImage(it.toString()) + } + } + } + return + } + MapEvents.MAP_LOADING_STARTED -> { + pluginRegistry.onStyleLoading() + if (!onWillStartLoadingMapListeners.isEmpty()) { + for (listener in onWillStartLoadingMapListeners) { + listener.onWillStartLoadingMap() + } + } + return + } + MapEvents.RENDER_FRAME_STARTED -> { + if (!onWillStartRenderingFrameListeners.isEmpty()) { + for (listener in onWillStartRenderingFrameListeners) { + listener.onWillStartRenderingFrame() + } + } + return + } + MapEvents.RENDER_MAP_STARTED -> { + if (!onWillStartRenderingMapListeners.isEmpty()) { + for (listener in onWillStartRenderingMapListeners) { + listener.onWillStartRenderingMap() + } + } + return + } + MapEvents.MAP_LOADING_ERROR -> { + val data: HashMap = event.data.contents as HashMap + val error = "${data["error"]!!.contents} ${data["description"]!!.contents}" + for (awaitingStyleError in awaitingStyleErrors) { + awaitingStyleError.onStyleError(error) + } + awaitingStyleErrors.clear() + awaitingStyleGetters.clear() + return } } } - // - // Add / Remove - // - - fun addOnMapChangedListener(onMapChangeListener: OnMapChangedListener) { - onMapChangedListeners.add(onMapChangeListener) - } - - fun removeOnMapChangedListener(onMapChangedListener: OnMapChangedListener) { - onMapChangedListeners.remove(onMapChangedListener) - } - - fun addOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener) { - onMapLoadErrorListeners.add(onMapLoadErrorListener) - } - - fun removeOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener) { - onMapLoadErrorListeners.remove(onMapLoadErrorListener) - } +// +// Add / Remove +// fun addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener) { onDidFinishRenderingFrameListeners.add(onDidFinishRenderingFrameListener) @@ -171,18 +260,43 @@ internal class NativeMapObserver(private val mainHandler: Handler) : MapObserver onDidFinishRenderingMapListeners.remove(onDidFinishRenderingMapListener) } - fun clearListeners() { - onMapChangedListeners.clear() - onMapLoadErrorListeners.clear() - onDidFinishRenderingFrameListeners.clear() - onCameraChangeListeners.clear() - onSourceChangeListeners.clear() - onStyleImageChangeListeners.clear() - onDidFinishRenderingMapListeners.clear() - awaitingStyleGetters.clear() + fun addOnDidBecomeIdleListener(onDidBecomeIdleListener: OnDidBecomeIdleListener) { + onDidBecomeIdleListeners.add(onDidBecomeIdleListener) + } + + fun removeOnDidBecomeIdleListener(onDidBecomeIdleListener: OnDidBecomeIdleListener) { + onDidBecomeIdleListeners.remove(onDidBecomeIdleListener) + } + + fun addOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener: OnDidFinishLoadingMapListener) { + onDidFinishLoadingMapListeners.add(onDidFinishLoadingMapListener) + } + + fun removeOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener: OnDidFinishLoadingMapListener) { + onDidFinishLoadingMapListeners.remove(onDidFinishLoadingMapListener) + } + + fun addOnWillStartLoadingMapListener(onWillStartLoadingMapListener: OnWillStartLoadingMapListener) { + onWillStartLoadingMapListeners.add(onWillStartLoadingMapListener) + } + + fun removeOnWillStartLoadingMapListener(onWillStartLoadingMapListener: OnWillStartLoadingMapListener) { + onWillStartLoadingMapListeners.remove(onWillStartLoadingMapListener) + } + + fun addOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener: OnWillStartRenderingFrameListener) { + onWillStartRenderingFrameListeners.add(onWillStartRenderingFrameListener) + } + + fun removeOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener: OnWillStartRenderingFrameListener) { + onWillStartRenderingFrameListeners.remove(onWillStartRenderingFrameListener) + } + + fun addOnWillStartRenderingMapListener(onWillStartRenderingMapListener: OnWillStartRenderingMapListener) { + onWillStartRenderingMapListeners.add(onWillStartRenderingMapListener) } - companion object { - private const val TAG = "Mapbox-MapController" + fun removeOnWillStartRenderingMapListener(onWillStartRenderingMapListener: OnWillStartRenderingMapListener) { + onWillStartRenderingMapListeners.remove(onWillStartRenderingMapListener) } } \ No newline at end of file diff --git a/sdk/src/main/java/com/mapbox/maps/Style.kt b/sdk/src/main/java/com/mapbox/maps/Style.kt index 93d2794310..527cd0bbe6 100644 --- a/sdk/src/main/java/com/mapbox/maps/Style.kt +++ b/sdk/src/main/java/com/mapbox/maps/Style.kt @@ -827,4 +827,20 @@ class Style internal constructor( */ fun onStyleLoaded(style: Style) } + + /** + * Callback to be invoked when a style load has failed. + */ + interface OnStyleError { + /** + * Invoked when a style has failed loading. + * + * @param errorMessage the error message of the style load failed event + */ + fun onStyleError(errorMessage: String) + } + + internal interface OnStyleLoadedInternal { + fun onLoad(): Style + } } \ No newline at end of file diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnCameraChangeListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnCameraChangeListener.kt similarity index 92% rename from sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnCameraChangeListener.kt rename to sdk/src/main/java/com/mapbox/maps/listener/OnCameraChangeListener.kt index 07fd30cfcb..b76adf9c0a 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnCameraChangeListener.kt +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnCameraChangeListener.kt @@ -1,4 +1,4 @@ -package com.mapbox.maps.plugin.delegates.listeners +package com.mapbox.maps.listener import com.mapbox.maps.plugin.animation.CameraAnimationsLifecycleListener import com.mapbox.maps.plugin.animation.CameraAnimationsPlugin diff --git a/sdk/src/main/java/com/mapbox/maps/listener/OnDidBecomeIdleListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnDidBecomeIdleListener.kt new file mode 100644 index 0000000000..13115fda4b --- /dev/null +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnDidBecomeIdleListener.kt @@ -0,0 +1,11 @@ +package com.mapbox.maps.listener + +/** + * Definition for listener invoked whenever the map has become idle. + */ +interface OnDidBecomeIdleListener { + /** + * Called when the map is in an idle state. + */ + fun onIdle() +} \ No newline at end of file diff --git a/sdk/src/main/java/com/mapbox/maps/listener/OnDidFinishLoadingMapListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnDidFinishLoadingMapListener.kt new file mode 100644 index 0000000000..67097ceb0e --- /dev/null +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnDidFinishLoadingMapListener.kt @@ -0,0 +1,12 @@ +package com.mapbox.maps.listener + +/** + * Definition for listener invoked whenever the map has finished loading. + */ +interface OnDidFinishLoadingMapListener { + + /** + * Called when the map has finished loading + */ + fun onDidFinishLoadingMapListener() +} \ No newline at end of file diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnDidFinishRenderingFrameListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnDidFinishRenderingFrameListener.kt similarity index 88% rename from sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnDidFinishRenderingFrameListener.kt rename to sdk/src/main/java/com/mapbox/maps/listener/OnDidFinishRenderingFrameListener.kt index df835c24c8..35f36ff359 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnDidFinishRenderingFrameListener.kt +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnDidFinishRenderingFrameListener.kt @@ -1,4 +1,4 @@ -package com.mapbox.maps.plugin.delegates.listeners +package com.mapbox.maps.listener import com.mapbox.maps.RenderFrameStatus diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnDidFinishRenderingMapListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnDidFinishRenderingMapListener.kt similarity index 87% rename from sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnDidFinishRenderingMapListener.kt rename to sdk/src/main/java/com/mapbox/maps/listener/OnDidFinishRenderingMapListener.kt index b82b9b92f3..75bdfcb489 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnDidFinishRenderingMapListener.kt +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnDidFinishRenderingMapListener.kt @@ -1,4 +1,4 @@ -package com.mapbox.maps.plugin.delegates.listeners +package com.mapbox.maps.listener import com.mapbox.maps.RenderMode diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnSourceChangeListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnSourceChangeListener.kt similarity index 84% rename from sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnSourceChangeListener.kt rename to sdk/src/main/java/com/mapbox/maps/listener/OnSourceChangeListener.kt index 93ad50ac9d..54196774c0 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnSourceChangeListener.kt +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnSourceChangeListener.kt @@ -1,4 +1,4 @@ -package com.mapbox.maps.plugin.delegates.listeners +package com.mapbox.maps.listener /** * Definition for listener invoked whenever a source definition has changed. diff --git a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnStyleImageChangeListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnStyleImageChangeListener.kt similarity index 93% rename from sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnStyleImageChangeListener.kt rename to sdk/src/main/java/com/mapbox/maps/listener/OnStyleImageChangeListener.kt index a89a420ff6..2ea59e19cf 100644 --- a/sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/listeners/OnStyleImageChangeListener.kt +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnStyleImageChangeListener.kt @@ -1,4 +1,4 @@ -package com.mapbox.maps.plugin.delegates.listeners +package com.mapbox.maps.listener /** * Definition for listener invoked whenever an style image is requested that hasn't been added diff --git a/sdk/src/main/java/com/mapbox/maps/listener/OnWillStartLoadingMapListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnWillStartLoadingMapListener.kt new file mode 100644 index 0000000000..500b329df3 --- /dev/null +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnWillStartLoadingMapListener.kt @@ -0,0 +1,12 @@ +package com.mapbox.maps.listener + +/** + * Definition for listener invoked whenever the map will start loading. + */ +interface OnWillStartLoadingMapListener { + + /** + * Called when the map will start loading. + */ + fun onWillStartLoadingMap() +} \ No newline at end of file diff --git a/sdk/src/main/java/com/mapbox/maps/listener/OnWillStartRenderingFrameListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnWillStartRenderingFrameListener.kt new file mode 100644 index 0000000000..1e9fc004f4 --- /dev/null +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnWillStartRenderingFrameListener.kt @@ -0,0 +1,12 @@ +package com.mapbox.maps.listener + +/** + * Definition for listener invoked whenever the map will stant rendering a frame. + */ +interface OnWillStartRenderingFrameListener { + + /** + * Called when the Map will start rendering a frame. + */ + fun onWillStartRenderingFrame() +} \ No newline at end of file diff --git a/sdk/src/main/java/com/mapbox/maps/listener/OnWillStartRenderingMapListener.kt b/sdk/src/main/java/com/mapbox/maps/listener/OnWillStartRenderingMapListener.kt new file mode 100644 index 0000000000..1fae8dc61c --- /dev/null +++ b/sdk/src/main/java/com/mapbox/maps/listener/OnWillStartRenderingMapListener.kt @@ -0,0 +1,12 @@ +package com.mapbox.maps.listener + +/** + * Definition for listener invoked whenever the map will starting rendering a map. + */ +interface OnWillStartRenderingMapListener { + + /** + * Called when the map will start rendering a map. + */ + fun onWillStartRenderingMap() +} \ No newline at end of file diff --git a/sdk/src/main/java/com/mapbox/maps/plugin/MapDelegateProviderImpl.kt b/sdk/src/main/java/com/mapbox/maps/plugin/MapDelegateProviderImpl.kt index ccfb1bf3ab..c3890b4342 100644 --- a/sdk/src/main/java/com/mapbox/maps/plugin/MapDelegateProviderImpl.kt +++ b/sdk/src/main/java/com/mapbox/maps/plugin/MapDelegateProviderImpl.kt @@ -1,10 +1,10 @@ package com.mapbox.maps.plugin -import com.mapbox.maps.* import com.mapbox.maps.MapController +import com.mapbox.maps.MapboxMap +import com.mapbox.maps.StyleManagerInterface import com.mapbox.maps.module.MapTelemetry import com.mapbox.maps.plugin.delegates.* -import com.mapbox.maps.plugin.delegates.MapAttributionDelegate internal class MapDelegateProviderImpl constructor(val mapboxMap: MapboxMap, mapController: MapController, telemetry: MapTelemetry) : MapDelegateProvider { override val mapCameraDelegate: MapCameraDelegate by lazy { MapCameraDelegateImpl(mapboxMap) } @@ -13,7 +13,6 @@ internal class MapDelegateProviderImpl constructor(val mapboxMap: MapboxMap, map override val mapAttributionDelegate: MapAttributionDelegate by lazy { MapAttributionDelegateImpl(mapboxMap, telemetry) } override val mapFeatureQueryDelegate: MapFeatureQueryDelegate by lazy { mapboxMap } override val mapPluginProviderDelegate: MapPluginProviderDelegate by lazy { mapController } - override val mapListenerDelegate: MapListenerDelegate by lazy { mapboxMap } override val styleStateDelegate: MapStyleStateDelegate by lazy { mapboxMap } override fun getStyle(callback: (StyleManagerInterface) -> Unit) { diff --git a/sdk/src/main/java/com/mapbox/maps/plugin/MapPluginRegistry.kt b/sdk/src/main/java/com/mapbox/maps/plugin/MapPluginRegistry.kt index 5666fcdaa6..61328f8c7f 100644 --- a/sdk/src/main/java/com/mapbox/maps/plugin/MapPluginRegistry.kt +++ b/sdk/src/main/java/com/mapbox/maps/plugin/MapPluginRegistry.kt @@ -175,5 +175,11 @@ MapPluginRegistry(private val mapDelegateProvider: MapDelegateProvider) { plugins.forEach { it.value.cleanup() } + plugins.clear() + viewPlugins.clear() + cameraPlugins.clear() + gesturePlugins.clear() + styleObserverPlugins.clear() + mapSizePlugins.clear() } } \ No newline at end of file diff --git a/sdk/src/test/java/com/mapbox/maps/MapControllerTest.kt b/sdk/src/test/java/com/mapbox/maps/MapControllerTest.kt index 89007c08f4..b0abc5ba6b 100644 --- a/sdk/src/test/java/com/mapbox/maps/MapControllerTest.kt +++ b/sdk/src/test/java/com/mapbox/maps/MapControllerTest.kt @@ -5,7 +5,6 @@ import android.view.MotionEvent import com.mapbox.common.ShadowLogger import com.mapbox.maps.loader.MapboxMapStaticInitializer import com.mapbox.maps.plugin.MapPluginRegistry -import com.mapbox.maps.plugin.delegates.listeners.OnCameraChangeListener import com.mapbox.maps.renderer.MapboxRenderer import io.mockk.* import org.junit.Assert @@ -58,8 +57,7 @@ class MapControllerTest { every { MapProvider.getNativeMap( mapboxMapOptions, - renderer, - mapObserver + renderer ) } answers { nativeMap } every { nativeMap.getCameraOptions(any()) } returns cameraOptions @@ -75,7 +73,6 @@ class MapControllerTest { nativeMap, mapboxMap, pluginRegistry, - mockk() ) } @@ -128,18 +125,6 @@ class MapControllerTest { Assert.assertEquals(mapboxMap, mapController.getMapboxMap()) } - @Test - fun cameraPluginNotified() { - val onCameraChangeListenerSlot = slot() - every { mapObserver.addOnCameraChangeListener(capture(onCameraChangeListenerSlot)) } answers {} - mapController.onStart() - val onCameraChangeListener = onCameraChangeListenerSlot.captured - - onCameraChangeListener.onCameraChanged() - verify { nativeMap.getCameraOptions(null) } - verify { pluginRegistry.onCameraMove(cameraOptions) } - } - @Test fun createPlugin() { val mapView = mockk() diff --git a/sdk/src/test/java/com/mapbox/maps/MapboxMapTest.kt b/sdk/src/test/java/com/mapbox/maps/MapboxMapTest.kt index 7eb2854223..9e7885b42b 100644 --- a/sdk/src/test/java/com/mapbox/maps/MapboxMapTest.kt +++ b/sdk/src/test/java/com/mapbox/maps/MapboxMapTest.kt @@ -4,7 +4,7 @@ import com.mapbox.bindgen.Value import com.mapbox.geojson.Feature import com.mapbox.geojson.Point import com.mapbox.maps.extension.style.StyleContract -import com.mapbox.maps.plugin.delegates.listeners.* +import com.mapbox.maps.listener.* import io.mockk.every import io.mockk.mockk import io.mockk.verify @@ -27,28 +27,24 @@ class MapboxMapTest { @Test fun loadStyleUri() { mapboxMap.loadStyleUri("foo") - verify { mapObserver.addOnMapChangedListener(any()) } verify { nativeMap.styleURI = "foo" } } @Test fun loadStyleUriLambda() { - mapboxMap.loadStyleUri("foo") {} - verify { mapObserver.addOnMapChangedListener(any()) } + mapboxMap.loadStyleUri("foo") verify { nativeMap.styleURI = "foo" } } @Test fun loadStyleJSON() { mapboxMap.loadStyleJSON("foo") - verify { mapObserver.addOnMapChangedListener(any()) } verify { nativeMap.styleJSON = "foo" } } @Test fun loadStyleJSONLambda() { mapboxMap.loadStyleJSON("foo") {} - verify { mapObserver.addOnMapChangedListener(any()) } verify { nativeMap.styleJSON = "foo" } } @@ -56,7 +52,7 @@ class MapboxMapTest { fun loadStyle() { val stylePlugin = mockk() every { stylePlugin.styleUri } returns "foobar" - val onMapLoadError = mockk() + val onMapLoadError = mockk() val onStyleLoadError = mockk() mapboxMap.loadStyle(stylePlugin, onStyleLoadError, onMapLoadError) verify { nativeMap.styleURI = "foobar" } @@ -70,15 +66,6 @@ class MapboxMapTest { verify { nativeMap.styleURI = "foobar" } } - @Test - fun finishLoadingStyle() { - val styleLoadCallback = mockk(relaxed = true) - val mapLoadError = mockk() - mapboxMap.onFinishLoadingStyle(styleLoadCallback, mapLoadError) - verify { styleLoadCallback.onStyleLoaded(any()) } - verify { mapObserver.awaitingStyleGetters.clear() } - } - @Test fun finishLoadingStylePlugin() { val style = mockk