maplibre / flutter-maplibre-gl

Customizable, performant and vendor-free vector and raster maps, flutter wrapper for maplibre-native and maplibre-gl-js (fork of flutter-mapbox-gl/maps)
https://pub.dev/packages/maplibre_gl
Other
185 stars 106 forks source link

[BUG] circle color layer crashes ios app #438

Open XanderD99 opened 3 weeks ago

XanderD99 commented 3 weeks ago

Platforms

iOS

Version of flutter maplibre_gl

0.19.0

Bug Description

this might be an ios issue but creating a circle layer properties with expressions results in an error being thrown when adding it to a map.

Steps to Reproduce

  1. create any type of expressions for color
  2. add it to the circleColor property in CircleLayerProperties
  3. add that layer to the map
  4. 💥 error

Expected Results

the layer to be added just like android

Actual Results

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -constantValue only defined for abstract class.  Define -[NSFunctionExpression constantValue]!'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000180491128 __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x000000018008412c objc_exception_throw + 56
    2   Foundation                          0x0000000180ed1cd8 _NSRequestConcreteObject + 0
    3   Foundation                          0x0000000180d120d4 -[NSExpression constantValue] + 48
    4   Mapbox                              0x0000000106909ee0 -[NSExpression(MGLAdditions) mgl_jsonIfExpressionObject] + 516
    5   Mapbox                              0x0000000106907e20 -[NSExpression(MGLAdditions) mgl_jsonExpressionObject] + 7664
    6   Mapbox                              0x000000010688bdc8 _ZN24MGLStyleValueTransformerIN4mbgl5ColorEU8__strongP7UIColorS1_S4_E15toPropertyValueINS0_5style13PropertyValueIS1_EEEENSt3__19enable_ifIXntsr3std7is_sameIT_NS7_22ColorRampPropertyValueEEE5value  7   Mapbox                              0x0000000106899b94 -[MGLCircleStyleLayer setCircleColor:] + 108
    8   maplibre_gl                         0x0000000105e36768 $s11maplibre_gl22LayerPropertyConverterC19addCircleProperties06circleC010propertiesySo014MGLCircleStyleC0C_SDyS2SGtFZ + 744
    9   maplibre_gl                         0x0000000105e5fca8 $s11maplibre_gl19MapboxMapControllerC14addCircleLayer8sourceId05layerJ005belowhJ00iH10Identifier16minimumZoomLevel07maximumoP06filter17enableInteraction10propertiess6ResultOyytAA15MethodCallError  10  maplibre_gl                         0x0000000105e4c410 $s11maplibre_gl19MapboxMapControllerC12onMethodCall06methodH06resultySo07FluttergH0C_yypSgctF + 50876
    11  maplibre_gl                         0x0000000105e3f720 $s11maplibre_gl19MapboxMapControllerC9withFrame14viewIdentifier9arguments9registrarACSo6CGRectV_s5Int64VypSgSo22FlutterPluginRegistrar_ptcfcySo0N10MethodCallC_yALctcfU_ + 224
    12  maplibre_gl                         0x0000000105e3f7cc $sSo17FlutterMethodCallCypSgIegn_Ieggg_AByXlSgIeyBy_IeyByy_TR + 136
    13  Flutter                             0x000000010a2dfa08 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 164
    14  Flutter                             0x0000000109d082d0 ___ZN7flutter25PlatformMessageHandlerIos21HandlePlatformMessageENSt3_fl10unique_ptrINS_15PlatformMessageENS1_14default_deleteIS3_EEEE_block_invoke + 108
    15  libdispatch.dylib                   0x00000001058400f0 _dispatch_call_block_and_release + 24
    16  libdispatch.dylib                   0x000000010584193c _dispatch_client_callout + 16
    17  libdispatch.dylib                   0x00000001058515e4 _dispatch_main_queue_drain + 1228
    18  libdispatch.dylib                   0x0000000105851108 _dispatch_main_queue_callback_4CF + 40
    19  CoreFoundation                      0x00000001803f1a30 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
    20  CoreFoundation                      0x00000001803ec148 __CFRunLoopRun + 1936
    21  CoreFoundation                      0x00000001803eb5a4 CFRunLoopRunSpecific + 572
    22  GraphicsServices                    0x000000018e9fbae4 GSEventRunModal + 160
    23  UIKitCore                           0x00000001852f02e4 -[UIApplication _run] + 868
    24  UIKitCore                           0x00000001852f3f5c UIApplicationMain + 124
    25  Runner                              0x00000001046ffd08 main + 64
    26  dyld                                0x0000000104875544 start_sim + 20
    27  ???                                 0x000000010490a0e0 0x0 + 4371554528
    28  ???                                 0x4760000000000000 0x0 + 5143110774457106432
)

Code Sample

the function are just utilities I wrote to make it easier for me to write expressions. When this is added to the map by calling EventLayer(controller) the ios app just crashes.

class EventLayerManager extends AnnotationManager {
  EventLayerManager(super.controller, {required super.enableInteraction});

  @override
  int Function(Annotation p1)? get selectLayer =>
      (final Annotation annotation) => switch (annotation) {
            Circle() => 1,
            _ => -1,
          };

  @override
  List<LayerProperties> get allLayerProperties => [
        CircleLayerProperties(
          circleRadius: 3,
          circleColor: ifelseCase(
            cases: {
              boolean('category'): categoryColor,
            },
            defValue: 'black',
          ),
        ),
      ];
}