Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to tap symbols on layer #711

Open
chooyan-eng opened this issue Oct 1, 2024 · 1 comment
Open

How to tap symbols on layer #711

chooyan-eng opened this issue Oct 1, 2024 · 1 comment

Comments

@chooyan-eng
Copy link

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.

@ThomasAunvik
Copy link

What do you use a style layer with symbols for?

Atm i can only think of a PointAnnotation that can do this.

Future<PointAnnotationManager> createPointManager(
    MapboxMap controller, {
    required void Function(PointAnnotation) callback,
}) async {
    final pointManager = await controller.annotations.createPointAnnotationManager();

    pointManager.addOnPointAnnotationClickListener(
        AnnotationClickListener(callback: callback),
    );

    return pointManager;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants