Skip to content

Commit 13c35b9

Browse files
evil159pjleonard37
andauthored
Expose debug options (#630)
* Expose MapWidgetDebugOptions * Add debug options example * lint * Update CHANGELOG.md Co-authored-by: Patrick Leonard <pjleonard37@users.noreply.github.com> * Add bottom padding to debug options FAB * Add debug options badge --------- Co-authored-by: Patrick Leonard <pjleonard37@users.noreply.github.com>
1 parent 8eb286c commit 13c35b9

18 files changed

+771
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Support local assets for 3D puck and `ModelLayer`. To use a local assets, please specify it with `asset://` scheme in the uri.
88
* Fix map view crashing upon host activity destruction when using a cached Flutter engine.
99
* Fix a rare crash happening when map widget is being disposed.
10+
* `MapDebugOptions` is superseded by `MapWidgetDebugOptions`, expanding existing debug options with the new `light`, `camera`, and `padding` debug options in addition to the new Android-specific options: `layers2DWireframe` and `layers3DWireframe`.
1011

1112
### 2.1.0
1213

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/Extentions.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.mapbox.common.TileRegionError
1010
import com.mapbox.geojson.*
1111
import com.mapbox.maps.EdgeInsets
1212
import com.mapbox.maps.StylePackError
13+
import com.mapbox.maps.debugoptions.MapViewDebugOptions
1314
import com.mapbox.maps.extension.style.expressions.dsl.generated.min
1415
import com.mapbox.maps.extension.style.layers.properties.generated.ProjectionName
1516
import com.mapbox.maps.extension.style.light.LightPosition
@@ -26,6 +27,25 @@ import java.io.ByteArrayOutputStream
2627

2728
// FLT to Android
2829

30+
fun _MapWidgetDebugOptions.toMapViewDebugOptions(): MapViewDebugOptions {
31+
return when (this) {
32+
_MapWidgetDebugOptions.TILE_BORDERS -> MapViewDebugOptions.TILE_BORDERS
33+
_MapWidgetDebugOptions.PARSE_STATUS -> MapViewDebugOptions.PARSE_STATUS
34+
_MapWidgetDebugOptions.TIMESTAMPS -> MapViewDebugOptions.TIMESTAMPS
35+
_MapWidgetDebugOptions.COLLISION -> MapViewDebugOptions.COLLISION
36+
_MapWidgetDebugOptions.OVERDRAW -> MapViewDebugOptions.OVERDRAW
37+
_MapWidgetDebugOptions.STENCIL_CLIP -> MapViewDebugOptions.STENCIL_CLIP
38+
_MapWidgetDebugOptions.DEPTH_BUFFER -> MapViewDebugOptions.DEPTH_BUFFER
39+
_MapWidgetDebugOptions.MODEL_BOUNDS -> MapViewDebugOptions.MODEL_BOUNDS
40+
_MapWidgetDebugOptions.TERRAIN_WIREFRAME -> MapViewDebugOptions.TERRAIN_WIREFRAME
41+
_MapWidgetDebugOptions.LAYERS2DWIREFRAME -> MapViewDebugOptions.LAYERS2_DWIREFRAME
42+
_MapWidgetDebugOptions.LAYERS3DWIREFRAME -> MapViewDebugOptions.LAYERS3_DWIREFRAME
43+
_MapWidgetDebugOptions.LIGHT -> MapViewDebugOptions.LIGHT
44+
_MapWidgetDebugOptions.CAMERA -> MapViewDebugOptions.CAMERA
45+
_MapWidgetDebugOptions.PADDING -> MapViewDebugOptions.PADDING
46+
}
47+
}
48+
2949
fun GlyphsRasterizationMode.toGlyphsRasterizationMode(): com.mapbox.maps.GlyphsRasterizationMode {
3050
return when (this) {
3151
GlyphsRasterizationMode.NO_GLYPHS_RASTERIZED_LOCALLY -> com.mapbox.maps.GlyphsRasterizationMode.NO_GLYPHS_RASTERIZED_LOCALLY
@@ -376,6 +396,26 @@ fun Number.toDevicePixels(context: Context): Float {
376396

377397
// Android to FLT
378398

399+
fun MapViewDebugOptions.toFLTDebugOptions(): _MapWidgetDebugOptions? {
400+
return when (this) {
401+
MapViewDebugOptions.TILE_BORDERS -> _MapWidgetDebugOptions.TILE_BORDERS
402+
MapViewDebugOptions.PARSE_STATUS -> _MapWidgetDebugOptions.PARSE_STATUS
403+
MapViewDebugOptions.TIMESTAMPS -> _MapWidgetDebugOptions.TIMESTAMPS
404+
MapViewDebugOptions.COLLISION -> _MapWidgetDebugOptions.COLLISION
405+
MapViewDebugOptions.OVERDRAW -> _MapWidgetDebugOptions.OVERDRAW
406+
MapViewDebugOptions.STENCIL_CLIP -> _MapWidgetDebugOptions.STENCIL_CLIP
407+
MapViewDebugOptions.DEPTH_BUFFER -> _MapWidgetDebugOptions.DEPTH_BUFFER
408+
MapViewDebugOptions.MODEL_BOUNDS -> _MapWidgetDebugOptions.MODEL_BOUNDS
409+
MapViewDebugOptions.TERRAIN_WIREFRAME -> _MapWidgetDebugOptions.TERRAIN_WIREFRAME
410+
MapViewDebugOptions.LAYERS2_DWIREFRAME -> _MapWidgetDebugOptions.LAYERS2DWIREFRAME
411+
MapViewDebugOptions.LAYERS3_DWIREFRAME -> _MapWidgetDebugOptions.LAYERS3DWIREFRAME
412+
MapViewDebugOptions.LIGHT -> _MapWidgetDebugOptions.LIGHT
413+
MapViewDebugOptions.CAMERA -> _MapWidgetDebugOptions.CAMERA
414+
MapViewDebugOptions.PADDING -> _MapWidgetDebugOptions.PADDING
415+
else -> null
416+
}
417+
}
418+
379419
fun com.mapbox.maps.CanonicalTileID.toFLTCanonicalTileID(): CanonicalTileID {
380420
return CanonicalTileID(z = z.toLong(), x = x.toLong(), y = y.toLong())
381421
}

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapInterfaceController.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import com.google.gson.Gson
55
import com.mapbox.geojson.Feature
66
import com.mapbox.geojson.Point
7+
import com.mapbox.maps.MapView
78
import com.mapbox.maps.MapboxMap
89
import com.mapbox.maps.TileCacheBudget
910
import com.mapbox.maps.extension.observable.eventdata.MapLoadingErrorEventData
@@ -24,9 +25,14 @@ import com.mapbox.maps.mapbox_maps.pigeons.TileCacheBudgetInTiles
2425
import com.mapbox.maps.mapbox_maps.pigeons.TileCoverOptions
2526
import com.mapbox.maps.mapbox_maps.pigeons.ViewportMode
2627
import com.mapbox.maps.mapbox_maps.pigeons._MapInterface
28+
import com.mapbox.maps.mapbox_maps.pigeons._MapWidgetDebugOptionsBox
2729
import com.mapbox.maps.plugin.delegates.listeners.OnMapLoadErrorListener
2830

29-
class MapInterfaceController(private val mapboxMap: MapboxMap, private val context: Context) : _MapInterface {
31+
class MapInterfaceController(
32+
private val mapboxMap: MapboxMap,
33+
private val mapView: MapView,
34+
private val context: Context
35+
) : _MapInterface {
3036
override fun loadStyleURI(styleURI: String, callback: (Result<Unit>) -> Unit) {
3137
mapboxMap.loadStyleUri(
3238
styleURI,
@@ -111,6 +117,16 @@ class MapInterfaceController(private val mapboxMap: MapboxMap, private val conte
111117
return mapboxMap.getMapOptions().toFLTMapOptions(context)
112118
}
113119

120+
override fun getDebugOptions(): List<_MapWidgetDebugOptionsBox?> {
121+
return mapView.debugOptions.mapNotNull { nativeOption ->
122+
nativeOption.toFLTDebugOptions()?.let { _MapWidgetDebugOptionsBox(it) }
123+
}
124+
}
125+
126+
override fun setDebugOptions(debugOptions: List<_MapWidgetDebugOptionsBox>) {
127+
mapView.debugOptions = debugOptions.map { it.option.toMapViewDebugOptions() }.toSet()
128+
}
129+
114130
override fun getDebug(): List<MapDebugOptions> {
115131
return mapboxMap.getDebug().map { it.toFLTMapDebugOptions() }.toMutableList()
116132
}

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class MapboxMapController(
131131
styleController = StyleController(context, mapboxMap)
132132
cameraController = CameraController(mapboxMap, context)
133133
projectionController = MapProjectionController(mapboxMap)
134-
mapInterfaceController = MapInterfaceController(mapboxMap, context)
134+
mapInterfaceController = MapInterfaceController(mapboxMap, mapView, context)
135135
animationController = AnimationController(mapboxMap, context)
136136
annotationController = AnnotationController(mapView)
137137
locationComponentController = LocationComponentController(mapView, context)

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/MapInterfaces.kt

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ enum class NorthOrientation(val raw: Int) {
117117
}
118118
}
119119

120+
enum class _MapWidgetDebugOptions(val raw: Int) {
121+
TILE_BORDERS(0),
122+
PARSE_STATUS(1),
123+
TIMESTAMPS(2),
124+
COLLISION(3),
125+
OVERDRAW(4),
126+
STENCIL_CLIP(5),
127+
DEPTH_BUFFER(6),
128+
MODEL_BOUNDS(7),
129+
TERRAIN_WIREFRAME(8),
130+
LAYERS2DWIREFRAME(9),
131+
LAYERS3DWIREFRAME(10),
132+
LIGHT(11),
133+
CAMERA(12),
134+
PADDING(13);
135+
136+
companion object {
137+
fun ofRaw(raw: Int): _MapWidgetDebugOptions? {
138+
return values().firstOrNull { it.raw == raw }
139+
}
140+
}
141+
}
142+
120143
/** Options for enabling debugging features in a map. */
121144
enum class MapDebugOptionsData(val raw: Int) {
122145
/**
@@ -821,6 +844,29 @@ data class CoordinateBounds(
821844
}
822845
}
823846

847+
/**
848+
* This class is needed because Pigeon does not encode properly arrays of enums.
849+
*
850+
* Generated class from Pigeon that represents data sent in messages.
851+
*/
852+
data class _MapWidgetDebugOptionsBox(
853+
val option: _MapWidgetDebugOptions
854+
855+
) {
856+
companion object {
857+
@Suppress("UNCHECKED_CAST")
858+
fun fromList(list: List<Any?>): _MapWidgetDebugOptionsBox {
859+
val option = _MapWidgetDebugOptions.ofRaw(list[0] as Int)!!
860+
return _MapWidgetDebugOptionsBox(option)
861+
}
862+
}
863+
fun toList(): List<Any?> {
864+
return listOf<Any?>(
865+
option.raw,
866+
)
867+
}
868+
}
869+
824870
/**
825871
* Options for enabling debugging features in a map.
826872
*
@@ -2250,6 +2296,11 @@ private object _CameraManagerCodec : StandardMessageCodec() {
22502296
TransitionOptions.fromList(it)
22512297
}
22522298
}
2299+
167.toByte() -> {
2300+
return (readValue(buffer) as? List<Any?>)?.let {
2301+
_MapWidgetDebugOptionsBox.fromList(it)
2302+
}
2303+
}
22532304
else -> super.readValueOfType(type, buffer)
22542305
}
22552306
}
@@ -2411,6 +2462,10 @@ private object _CameraManagerCodec : StandardMessageCodec() {
24112462
stream.write(166)
24122463
writeValue(stream, value.toList())
24132464
}
2465+
is _MapWidgetDebugOptionsBox -> {
2466+
stream.write(167)
2467+
writeValue(stream, value.toList())
2468+
}
24142469
else -> super.writeValue(stream, value)
24152470
}
24162471
}
@@ -3143,6 +3198,11 @@ private object _MapInterfaceCodec : StandardMessageCodec() {
31433198
TransitionOptions.fromList(it)
31443199
}
31453200
}
3201+
167.toByte() -> {
3202+
return (readValue(buffer) as? List<Any?>)?.let {
3203+
_MapWidgetDebugOptionsBox.fromList(it)
3204+
}
3205+
}
31463206
else -> super.readValueOfType(type, buffer)
31473207
}
31483208
}
@@ -3304,6 +3364,10 @@ private object _MapInterfaceCodec : StandardMessageCodec() {
33043364
stream.write(166)
33053365
writeValue(stream, value.toList())
33063366
}
3367+
is _MapWidgetDebugOptionsBox -> {
3368+
stream.write(167)
3369+
writeValue(stream, value.toList())
3370+
}
33073371
else -> super.writeValue(stream, value)
33083372
}
33093373
}
@@ -3382,6 +3446,8 @@ interface _MapInterface {
33823446
* @return The map's `map options`.
33833447
*/
33843448
fun getMapOptions(): MapOptions
3449+
fun getDebugOptions(): List<_MapWidgetDebugOptionsBox?>
3450+
fun setDebugOptions(debugOptions: List<_MapWidgetDebugOptionsBox>)
33853451
/**
33863452
* Returns the `map debug options`.
33873453
*
@@ -3802,6 +3868,41 @@ interface _MapInterface {
38023868
channel.setMessageHandler(null)
38033869
}
38043870
}
3871+
run {
3872+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.getDebugOptions$separatedMessageChannelSuffix", codec)
3873+
if (api != null) {
3874+
channel.setMessageHandler { _, reply ->
3875+
var wrapped: List<Any?>
3876+
try {
3877+
wrapped = listOf<Any?>(api.getDebugOptions())
3878+
} catch (exception: Throwable) {
3879+
wrapped = wrapError(exception)
3880+
}
3881+
reply.reply(wrapped)
3882+
}
3883+
} else {
3884+
channel.setMessageHandler(null)
3885+
}
3886+
}
3887+
run {
3888+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.setDebugOptions$separatedMessageChannelSuffix", codec)
3889+
if (api != null) {
3890+
channel.setMessageHandler { message, reply ->
3891+
val args = message as List<Any?>
3892+
val debugOptionsArg = args[0] as List<_MapWidgetDebugOptionsBox>
3893+
var wrapped: List<Any?>
3894+
try {
3895+
api.setDebugOptions(debugOptionsArg)
3896+
wrapped = listOf<Any?>(null)
3897+
} catch (exception: Throwable) {
3898+
wrapped = wrapError(exception)
3899+
}
3900+
reply.reply(wrapped)
3901+
}
3902+
} else {
3903+
channel.setMessageHandler(null)
3904+
}
3905+
}
38053906
run {
38063907
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.getDebug$separatedMessageChannelSuffix", codec)
38073908
if (api != null) {
@@ -4851,6 +4952,11 @@ private object StyleManagerCodec : StandardMessageCodec() {
48514952
TransitionOptions.fromList(it)
48524953
}
48534954
}
4955+
167.toByte() -> {
4956+
return (readValue(buffer) as? List<Any?>)?.let {
4957+
_MapWidgetDebugOptionsBox.fromList(it)
4958+
}
4959+
}
48544960
else -> super.readValueOfType(type, buffer)
48554961
}
48564962
}
@@ -5012,6 +5118,10 @@ private object StyleManagerCodec : StandardMessageCodec() {
50125118
stream.write(166)
50135119
writeValue(stream, value.toList())
50145120
}
5121+
is _MapWidgetDebugOptionsBox -> {
5122+
stream.write(167)
5123+
writeValue(stream, value.toList())
5124+
}
50155125
else -> super.writeValue(stream, value)
50165126
}
50175127
}

example/analysis_options.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file configures the static analysis results for your project (errors,
2+
# warnings, and lints).
3+
#
4+
# This enables the 'recommended' set of lints from `package:lints`.
5+
# This set helps identify many issues that may lead to problems when running
6+
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
7+
# style and format.
8+
#
9+
# If you want a smaller set of lints you can change this to specify
10+
# 'package:lints/core.yaml'. These are just the most critical lints
11+
# (the recommended set includes the core lints).
12+
# The core lints are also what is used by pub.dev for scoring packages.
13+
14+
include: package:lints/recommended.yaml
15+
16+
# Uncomment the following section to specify additional rules.
17+
18+
linter:
19+
rules:
20+
- exhaustive_cases
21+
22+
# analyzer:
23+
# exclude:
24+
# - path/to/excluded/files/**
25+
26+
# For more information about the core and recommended set of lints, see
27+
# https://dart.dev/go/core-lints
28+
29+
# For additional information about configuring this file, see
30+
# https://dart.dev/guides/language/analysis-options

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PODS:
22
- Flutter (1.0.0)
33
- integration_test (0.0.1):
44
- Flutter
5-
- mapbox_maps_flutter (2.1.0):
5+
- mapbox_maps_flutter (2.2.0-beta.1):
66
- Flutter
77
- MapboxMaps (~> 11.6.0-beta.1)
88
- Turf (= 2.8.0)
@@ -48,8 +48,8 @@ EXTERNAL SOURCES:
4848

4949
SPEC CHECKSUMS:
5050
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
51-
integration_test: 13825b8a9334a850581300559b8839134b124670
52-
mapbox_maps_flutter: 3f554cc330f15648f06ed8fef15a1c579af7b5df
51+
integration_test: ce0a3ffa1de96d1a89ca0ac26fca7ea18a749ef4
52+
mapbox_maps_flutter: 92560c1fe819ca74f83016cff9046a82e08533e6
5353
MapboxCommon: 79432665253799a69280297bd630d8d4bdba0d94
5454
MapboxCoreMaps: 5f7cb13a79665e5907315a47aaa49f341aba3f31
5555
MapboxMaps: 45a3753ed3fa10b5c99ea040dfc4537f28f6da57

0 commit comments

Comments
 (0)