Skip to content

Commit

Permalink
Expose debug options (#630)
Browse files Browse the repository at this point in the history
* Expose MapWidgetDebugOptions

* Add debug options example

* lint

* Update CHANGELOG.md

Co-authored-by: Patrick Leonard <[email protected]>

* Add bottom padding to debug options FAB

* Add debug options badge

---------

Co-authored-by: Patrick Leonard <[email protected]>
  • Loading branch information
evil159 and pjleonard37 authored Jul 31, 2024
1 parent 8eb286c commit 13c35b9
Show file tree
Hide file tree
Showing 18 changed files with 771 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Support local assets for 3D puck and `ModelLayer`. To use a local assets, please specify it with `asset://` scheme in the uri.
* Fix map view crashing upon host activity destruction when using a cached Flutter engine.
* Fix a rare crash happening when map widget is being disposed.
* `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`.

### 2.1.0

Expand Down
40 changes: 40 additions & 0 deletions android/src/main/kotlin/com/mapbox/maps/mapbox_maps/Extentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mapbox.common.TileRegionError
import com.mapbox.geojson.*
import com.mapbox.maps.EdgeInsets
import com.mapbox.maps.StylePackError
import com.mapbox.maps.debugoptions.MapViewDebugOptions
import com.mapbox.maps.extension.style.expressions.dsl.generated.min
import com.mapbox.maps.extension.style.layers.properties.generated.ProjectionName
import com.mapbox.maps.extension.style.light.LightPosition
Expand All @@ -26,6 +27,25 @@ import java.io.ByteArrayOutputStream

// FLT to Android

fun _MapWidgetDebugOptions.toMapViewDebugOptions(): MapViewDebugOptions {
return when (this) {
_MapWidgetDebugOptions.TILE_BORDERS -> MapViewDebugOptions.TILE_BORDERS
_MapWidgetDebugOptions.PARSE_STATUS -> MapViewDebugOptions.PARSE_STATUS
_MapWidgetDebugOptions.TIMESTAMPS -> MapViewDebugOptions.TIMESTAMPS
_MapWidgetDebugOptions.COLLISION -> MapViewDebugOptions.COLLISION
_MapWidgetDebugOptions.OVERDRAW -> MapViewDebugOptions.OVERDRAW
_MapWidgetDebugOptions.STENCIL_CLIP -> MapViewDebugOptions.STENCIL_CLIP
_MapWidgetDebugOptions.DEPTH_BUFFER -> MapViewDebugOptions.DEPTH_BUFFER
_MapWidgetDebugOptions.MODEL_BOUNDS -> MapViewDebugOptions.MODEL_BOUNDS
_MapWidgetDebugOptions.TERRAIN_WIREFRAME -> MapViewDebugOptions.TERRAIN_WIREFRAME
_MapWidgetDebugOptions.LAYERS2DWIREFRAME -> MapViewDebugOptions.LAYERS2_DWIREFRAME
_MapWidgetDebugOptions.LAYERS3DWIREFRAME -> MapViewDebugOptions.LAYERS3_DWIREFRAME
_MapWidgetDebugOptions.LIGHT -> MapViewDebugOptions.LIGHT
_MapWidgetDebugOptions.CAMERA -> MapViewDebugOptions.CAMERA
_MapWidgetDebugOptions.PADDING -> MapViewDebugOptions.PADDING
}
}

fun GlyphsRasterizationMode.toGlyphsRasterizationMode(): com.mapbox.maps.GlyphsRasterizationMode {
return when (this) {
GlyphsRasterizationMode.NO_GLYPHS_RASTERIZED_LOCALLY -> com.mapbox.maps.GlyphsRasterizationMode.NO_GLYPHS_RASTERIZED_LOCALLY
Expand Down Expand Up @@ -376,6 +396,26 @@ fun Number.toDevicePixels(context: Context): Float {

// Android to FLT

fun MapViewDebugOptions.toFLTDebugOptions(): _MapWidgetDebugOptions? {
return when (this) {
MapViewDebugOptions.TILE_BORDERS -> _MapWidgetDebugOptions.TILE_BORDERS
MapViewDebugOptions.PARSE_STATUS -> _MapWidgetDebugOptions.PARSE_STATUS
MapViewDebugOptions.TIMESTAMPS -> _MapWidgetDebugOptions.TIMESTAMPS
MapViewDebugOptions.COLLISION -> _MapWidgetDebugOptions.COLLISION
MapViewDebugOptions.OVERDRAW -> _MapWidgetDebugOptions.OVERDRAW
MapViewDebugOptions.STENCIL_CLIP -> _MapWidgetDebugOptions.STENCIL_CLIP
MapViewDebugOptions.DEPTH_BUFFER -> _MapWidgetDebugOptions.DEPTH_BUFFER
MapViewDebugOptions.MODEL_BOUNDS -> _MapWidgetDebugOptions.MODEL_BOUNDS
MapViewDebugOptions.TERRAIN_WIREFRAME -> _MapWidgetDebugOptions.TERRAIN_WIREFRAME
MapViewDebugOptions.LAYERS2_DWIREFRAME -> _MapWidgetDebugOptions.LAYERS2DWIREFRAME
MapViewDebugOptions.LAYERS3_DWIREFRAME -> _MapWidgetDebugOptions.LAYERS3DWIREFRAME
MapViewDebugOptions.LIGHT -> _MapWidgetDebugOptions.LIGHT
MapViewDebugOptions.CAMERA -> _MapWidgetDebugOptions.CAMERA
MapViewDebugOptions.PADDING -> _MapWidgetDebugOptions.PADDING
else -> null
}
}

fun com.mapbox.maps.CanonicalTileID.toFLTCanonicalTileID(): CanonicalTileID {
return CanonicalTileID(z = z.toLong(), x = x.toLong(), y = y.toLong())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import com.google.gson.Gson
import com.mapbox.geojson.Feature
import com.mapbox.geojson.Point
import com.mapbox.maps.MapView
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.TileCacheBudget
import com.mapbox.maps.extension.observable.eventdata.MapLoadingErrorEventData
Expand All @@ -24,9 +25,14 @@ import com.mapbox.maps.mapbox_maps.pigeons.TileCacheBudgetInTiles
import com.mapbox.maps.mapbox_maps.pigeons.TileCoverOptions
import com.mapbox.maps.mapbox_maps.pigeons.ViewportMode
import com.mapbox.maps.mapbox_maps.pigeons._MapInterface
import com.mapbox.maps.mapbox_maps.pigeons._MapWidgetDebugOptionsBox
import com.mapbox.maps.plugin.delegates.listeners.OnMapLoadErrorListener

class MapInterfaceController(private val mapboxMap: MapboxMap, private val context: Context) : _MapInterface {
class MapInterfaceController(
private val mapboxMap: MapboxMap,
private val mapView: MapView,
private val context: Context
) : _MapInterface {
override fun loadStyleURI(styleURI: String, callback: (Result<Unit>) -> Unit) {
mapboxMap.loadStyleUri(
styleURI,
Expand Down Expand Up @@ -111,6 +117,16 @@ class MapInterfaceController(private val mapboxMap: MapboxMap, private val conte
return mapboxMap.getMapOptions().toFLTMapOptions(context)
}

override fun getDebugOptions(): List<_MapWidgetDebugOptionsBox?> {
return mapView.debugOptions.mapNotNull { nativeOption ->
nativeOption.toFLTDebugOptions()?.let { _MapWidgetDebugOptionsBox(it) }
}
}

override fun setDebugOptions(debugOptions: List<_MapWidgetDebugOptionsBox>) {
mapView.debugOptions = debugOptions.map { it.option.toMapViewDebugOptions() }.toSet()
}

override fun getDebug(): List<MapDebugOptions> {
return mapboxMap.getDebug().map { it.toFLTMapDebugOptions() }.toMutableList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class MapboxMapController(
styleController = StyleController(context, mapboxMap)
cameraController = CameraController(mapboxMap, context)
projectionController = MapProjectionController(mapboxMap)
mapInterfaceController = MapInterfaceController(mapboxMap, context)
mapInterfaceController = MapInterfaceController(mapboxMap, mapView, context)
animationController = AnimationController(mapboxMap, context)
annotationController = AnnotationController(mapView)
locationComponentController = LocationComponentController(mapView, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ enum class NorthOrientation(val raw: Int) {
}
}

enum class _MapWidgetDebugOptions(val raw: Int) {
TILE_BORDERS(0),
PARSE_STATUS(1),
TIMESTAMPS(2),
COLLISION(3),
OVERDRAW(4),
STENCIL_CLIP(5),
DEPTH_BUFFER(6),
MODEL_BOUNDS(7),
TERRAIN_WIREFRAME(8),
LAYERS2DWIREFRAME(9),
LAYERS3DWIREFRAME(10),
LIGHT(11),
CAMERA(12),
PADDING(13);

companion object {
fun ofRaw(raw: Int): _MapWidgetDebugOptions? {
return values().firstOrNull { it.raw == raw }
}
}
}

/** Options for enabling debugging features in a map. */
enum class MapDebugOptionsData(val raw: Int) {
/**
Expand Down Expand Up @@ -821,6 +844,29 @@ data class CoordinateBounds(
}
}

/**
* This class is needed because Pigeon does not encode properly arrays of enums.
*
* Generated class from Pigeon that represents data sent in messages.
*/
data class _MapWidgetDebugOptionsBox(
val option: _MapWidgetDebugOptions

) {
companion object {
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): _MapWidgetDebugOptionsBox {
val option = _MapWidgetDebugOptions.ofRaw(list[0] as Int)!!
return _MapWidgetDebugOptionsBox(option)
}
}
fun toList(): List<Any?> {
return listOf<Any?>(
option.raw,
)
}
}

/**
* Options for enabling debugging features in a map.
*
Expand Down Expand Up @@ -2250,6 +2296,11 @@ private object _CameraManagerCodec : StandardMessageCodec() {
TransitionOptions.fromList(it)
}
}
167.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
_MapWidgetDebugOptionsBox.fromList(it)
}
}
else -> super.readValueOfType(type, buffer)
}
}
Expand Down Expand Up @@ -2411,6 +2462,10 @@ private object _CameraManagerCodec : StandardMessageCodec() {
stream.write(166)
writeValue(stream, value.toList())
}
is _MapWidgetDebugOptionsBox -> {
stream.write(167)
writeValue(stream, value.toList())
}
else -> super.writeValue(stream, value)
}
}
Expand Down Expand Up @@ -3143,6 +3198,11 @@ private object _MapInterfaceCodec : StandardMessageCodec() {
TransitionOptions.fromList(it)
}
}
167.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
_MapWidgetDebugOptionsBox.fromList(it)
}
}
else -> super.readValueOfType(type, buffer)
}
}
Expand Down Expand Up @@ -3304,6 +3364,10 @@ private object _MapInterfaceCodec : StandardMessageCodec() {
stream.write(166)
writeValue(stream, value.toList())
}
is _MapWidgetDebugOptionsBox -> {
stream.write(167)
writeValue(stream, value.toList())
}
else -> super.writeValue(stream, value)
}
}
Expand Down Expand Up @@ -3382,6 +3446,8 @@ interface _MapInterface {
* @return The map's `map options`.
*/
fun getMapOptions(): MapOptions
fun getDebugOptions(): List<_MapWidgetDebugOptionsBox?>
fun setDebugOptions(debugOptions: List<_MapWidgetDebugOptionsBox>)
/**
* Returns the `map debug options`.
*
Expand Down Expand Up @@ -3802,6 +3868,41 @@ interface _MapInterface {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.getDebugOptions$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
var wrapped: List<Any?>
try {
wrapped = listOf<Any?>(api.getDebugOptions())
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.setDebugOptions$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val debugOptionsArg = args[0] as List<_MapWidgetDebugOptionsBox>
var wrapped: List<Any?>
try {
api.setDebugOptions(debugOptionsArg)
wrapped = listOf<Any?>(null)
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._MapInterface.getDebug$separatedMessageChannelSuffix", codec)
if (api != null) {
Expand Down Expand Up @@ -4851,6 +4952,11 @@ private object StyleManagerCodec : StandardMessageCodec() {
TransitionOptions.fromList(it)
}
}
167.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
_MapWidgetDebugOptionsBox.fromList(it)
}
}
else -> super.readValueOfType(type, buffer)
}
}
Expand Down Expand Up @@ -5012,6 +5118,10 @@ private object StyleManagerCodec : StandardMessageCodec() {
stream.write(166)
writeValue(stream, value.toList())
}
is _MapWidgetDebugOptionsBox -> {
stream.write(167)
writeValue(stream, value.toList())
}
else -> super.writeValue(stream, value)
}
}
Expand Down
30 changes: 30 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

linter:
rules:
- exhaustive_cases

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PODS:
- Flutter (1.0.0)
- integration_test (0.0.1):
- Flutter
- mapbox_maps_flutter (2.1.0):
- mapbox_maps_flutter (2.2.0-beta.1):
- Flutter
- MapboxMaps (~> 11.6.0-beta.1)
- Turf (= 2.8.0)
Expand Down Expand Up @@ -48,8 +48,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
integration_test: 13825b8a9334a850581300559b8839134b124670
mapbox_maps_flutter: 3f554cc330f15648f06ed8fef15a1c579af7b5df
integration_test: ce0a3ffa1de96d1a89ca0ac26fca7ea18a749ef4
mapbox_maps_flutter: 92560c1fe819ca74f83016cff9046a82e08533e6
MapboxCommon: 79432665253799a69280297bd630d8d4bdba0d94
MapboxCoreMaps: 5f7cb13a79665e5907315a47aaa49f341aba3f31
MapboxMaps: 45a3753ed3fa10b5c99ea040dfc4537f28f6da57
Expand Down
Loading

0 comments on commit 13c35b9

Please sign in to comment.