mapbox-maps-flutter
mapbox-maps-flutter copied to clipboard
How to tap symbols on layer
How can we tap symbols added with SymbolLayer
?
I have the source code below to show a symbol, but can't find how to make this tappable.
class _MapScreenState extends State<MapScreen> {
final position = Position.named(lng: 24.9458, lat: 60.17180);
MapboxMap? _mapboxMap;
@override
Widget build(BuildContext context) {
return Scaffold(
body: MapWidget(
cameraOptions: CameraOptions(zoom: 3.0),
styleUri: '[my_style_uri]',
textureView: true,
onMapCreated: (map) => _mapboxMap = map,
onStyleLoadedListener: _onStyleLoadedCallback,
),
);
}
Future<void> _onStyleLoadedCallback(StyleLoadedEventData event) async {
final point = Point(coordinates: position);
await _mapboxMap?.style.addSource(GeoJsonSource(
id: 'sourceId',
data: json.encode(point),
));
var modelLayer = SymbolLayer(
id: 'layerId',
sourceId: 'sourceId',
iconImage: '[my_icon_name]',
);
_mapboxMap?.style.addLayer(modelLayer);
}
}
This shows one icon on my map, but that's it.
Do we have any examples or docs for this? Thanks.