Search code examples
fluttermapboxmarkermapbox-gl

Remove added symbol from mapbox_gl flutter


I want to remove added symbol from map and I'm using mapbox and mapbox_gl latest package.

await controller.addSymbol(
        SymbolOptions(
          draggable: true,
          geometry: LatLng(selection.geometry['coordinates'][1],
              selection.geometry['coordinates'][0]),
          iconSize: 0.1,
          iconImage: "square",
        ),
      );

Here, icon is added to map. but i cant able to remove it. Please help me. Thanks in advance.


Solution

  • You need to store the reference to the symbol. This allows you to interact later e.g.:

    var symbol = await controller.addSymbol(
        SymbolOptions(
            draggable: true,
            geometry: LatLng(selection.geometry['coordinates'][1],
                selection.geometry['coordinates'][0]),
            iconSize: 0.1,
            iconImage: "square",
        ),
    );
    

    You then can do:

    await controller.removeSymbol(symbol);