Skip to content

Symbol data is null in onTap, symbol tap doesn't consume click event #332

Closed

Description

@hussenIbrahim

Hello
i have some problem
1 - the symbol's center is placed at the target not the bottom edge of it
2 - on symbol tap i get null data
3 - on symbol tap also onMapClick is triggered
4 - symbol draggable is not working

  MapboxMapController mapController;

  void _onMapCreated(MapboxMapController controller) {
    mapController = controller;
    addImageFromAsset();
    mapController.onSymbolTapped.add((argument) {
      _onSymbolTapped(argument);
    });
  }

  Future<void> addImageFromAsset() async {
    final ByteData bytes = await rootBundle.load("assets/marker.png");
    final Uint8List list = bytes.buffer.asUint8List();
    return mapController.addImage("marker", list);
  }

  void _add() {
  
      final map = {'data': "data is "};
      mapController.addSymbol(_getSymbolOptions("marker"), map);
    
  }

  void _onSymbolTapped(Symbol symbol) {
    print(symbol.data);
  }


  SymbolOptions _getSymbolOptions(String iconImage) {
    return SymbolOptions(
        draggable: true,
        iconSize: 0.5,
        geometry: LatLng(0.0,0.0),
        iconImage: iconImage,
        zIndex: 1);
  }


//in scaffold body
 MapboxMap(
          onMapClick: (point, coordinates) {
            print(point);
            print(coordinates);
          },
          compassEnabled: false,
          myLocationEnabled: true,
          onMapCreated: _onMapCreated,
          initialCameraPosition: const CameraPosition(
              target: LatLng(0, 0), zoom: 15),
        )

Activity

  1. m0nac0 commented on Jun 15, 2020

    @m0nac0
    Collaborator

    @hussenIbrahim Thank you for reporting it.
    1 This is the expected behaviour, you can specify the iconOffset in SymbolOptions to adjust the symbol's position.
    2 & 3 are indeed bugs
    4 is a known issue on Android, tracked at #130, it's an issue with the Mapbox SDK upstream (tracked there at mapbox/mapbox-plugins-android#863)

    Could you also tell us what version of the plugin and flutter you're using and on which platform these bugs occur, please?

  2. added
    bug
    on Jun 15, 2020
  3. hussenIbrahim commented on Jun 15, 2020

    @hussenIbrahim
    Author

    Flutter 1.19.0-4.0pre
    plugin version 0.7.0
    Android platform

  4. m0nac0 commented on Jun 16, 2020

    @m0nac0
    Collaborator

    @hussenIbrahim I haven't been able to reproduce 2.
    I did some research regarding 3 and this has been fixed upstream (see mapbox/mapbox-plugins-android#1124), so we'll have to wait for the next release of the Annotation plugin.

  5. changed the title [-]Symbol geometry , on symbol tapped data[/-] [+]Symbol data is null in onTap, symbol tap doesn't consume click event[/+] on Jun 16, 2020
  6. luiscavanillas commented on Jun 24, 2020

    @luiscavanillas

    Regarding 2: addSymbol() function does not use [this.data] parameter at all. It is actually skipped (not implemented).

    By comparing mapbox 0.7.0 plugin and the mapbox example code you can see that "data" is only assigned to the symbol in the second one.

  7. m0nac0 commented on Jun 25, 2020

    @m0nac0
    Collaborator

    @luiscavanillas @saily-io @hussenIbrahim Could you please try using the latest version from Github with this dependency in pubspec.yaml:

    mapbox_gl:
      git:
        url: https://github.com/tobrun/flutter-mapbox-gl.git

    I think this should be fixed on master.

  8. luiscavanillas commented on Jun 25, 2020

    @luiscavanillas

    @m0nac0 Just did and it works.

  9. hussenIbrahim commented on Jun 25, 2020

    @hussenIbrahim
    Author

    @luiscavanillas @saily-io @hussenIbrahim Could you please try using the latest version from Github with this dependency in pubspec.yaml:

    mapbox_gl:
      git:
        url: https://github.com/tobrun/flutter-mapbox-gl.git

    I think this should be fixed on master.

  10. TimothySealy commented on Jul 1, 2020

    @TimothySealy
    Collaborator

    As I understand it the status of these this issue is:

    1. Expected behaviour (the symbol's center is placed at the target not the bottom edge of it)
    2. Resolved in master (on symbol tap i get null data)
    3. Fixed upstream waiting on release (on symbol tap also onMapClick is triggered)
    4. Duplicate of Symbol draggable not working #130 (symbol draggable is not working)

    Can we may close this issue and open a separate one for tracking nr 3?

  11. m0nac0 commented on Jul 2, 2020

    @m0nac0
    Collaborator

    @TimothySealy Sounds good. I haven't tested this but I think data will likely also be null for circles and lines right now, as the data parameter is ignored here:
    https://github.com/tobrun/flutter-mapbox-gl/blob/4ce26231f3250b598060063d1b8b65950694754e/lib/src/controller.dart#L507-L515
    This was only fixed for symbols with the symbol batch editing. So we might want to track that as well.

  12. IcyTv commented on Nov 7, 2020

    @IcyTv

    So, since the onSymbolTap is still not consuming the onMapTap yet, here is a very simple fix.
    use a class bool, default to false,
    onSymbolTap sets this to true
    onMarkerTap checks for bool and if it's true set it to false and return.

    (DON'T use setState. It is unnecessary and only impacts Performance)

    Sorry if this is the wrong issue to post this on, but I still hope it helps someone

  13. Khader-1 commented on Mar 4, 2021

    @Khader-1

    I think this issue is present in the current version 0.10.0
    image

  14. leeprobert commented on Mar 14, 2021

    @leeprobert

    I can confirm that this is not fixed in 0.10.0 ... I think the issue is that the getter is not set for Symbol.
    Screenshot 2021-03-14 at 15 46 17
    This breakpoint is on the controller changeNotifier.

  15. m0nac0 commented on Mar 15, 2021

    @m0nac0
    Collaborator

    @Khader-1 In your code, data would be expected to be null. You have to explicitly pass the optional parameter data to addSymbol(...), otherwise it defaults to null (see https://pub.dev/documentation/mapbox_gl/latest/mapbox_gl/MapboxMapController/addSymbol.html).

  16. delajose90 commented on Jul 11, 2022

    @delajose90

    It works for me @m0nac0 thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions