mapbox / mapbox-maps-flutter

Interactive, thoroughly customizable maps for Flutter powered by Mapbox Maps SDK
https://www.mapbox.com/mobile-maps-sdk
Other
252 stars 94 forks source link

Minimize icon/ allow clustering on zoom out #114

Closed okaforcj closed 1 year ago

okaforcj commented 1 year ago

Is there a way to minimize the pointer, reduce the size of the icon, or apply clustering on zoom out. I'm currently using point annotation, is there also a way to add extra data/metadata to the point annotation or are all these features available on only the view annotation. if it is the latter, is there any workaround for now as that feature is not available yet. See video of my issue below.

https://user-images.githubusercontent.com/34102565/223812799-a33f3bc4-6dca-4f11-b15c-c934a400b61c.mov

LjubiTech-Maxko commented 1 year ago

You should be using source and layers for larger number of points instead of point annotations. There is an example

okaforcj commented 1 year ago

You should be using source and layers for larger number of points instead of point annotations. There is an example

Thanks, I will give it a go and update

okaforcj commented 1 year ago

hey @LjubiTech-Maxko thanks for the nudge with using layers. I've converted my code and it works fine. I am not finding relevant documentation, however, on how to click on individual features i.e. open a popup when i click on a certain country represented by an icon. can you help please?

LjubiTech-Maxko commented 1 year ago

You could query for the features when user clicks on the map, for example:

// Callback for MapWidget onTapListener
Future<void> onTapListener(ScreenCoordinate coord) async {
    // need to convert coord to real ScreenCoordinate for querying features.
    final ScreenCoordinate conv = await _mapboxMap!.pixelForCoordinate(
      Point(
        coordinates: Position(
          coord.y, coord.x,
        ),
      ).toJson(),
    );

    // get the features user has clicked on
    final List<QueriedFeature?> features = await _mapboxMap!.queryRenderedFeatures(
      RenderedQueryGeometry(
        value: jsonEncode(conv.encode()),
        type: Type.SCREEN_COORDINATE,
      ),
      // add these options if you want to query only specific layer,
      // for example, your countries layer id
      RenderedQueryOptions(
        layerIds: ['layer_id_1', 'layer_id_2', ...],
      ),
    );

    // do what you need with the features
}

You can add the metadata you need to geojson feature properties and later get that properties from QueriedFeature. If you are clustering the data, you will get the data for that cluster and not only 1 feature. You get the data for country feature only when you click on the unclustered point. If you want to show for example list of countries to choose from when there are multiple features still clustered you could add properties from single features to properties of cluster. Or you could get the cluster expansion zoom to zoom until all the clustered features are unclustered and then when user clicks on unclustered point show the information. You could achieve the later with getGeoJsonClusterExpansionZoom.

okaforcj commented 1 year ago

Thank you sooo much for taking the time. I would give this a go, your description makes sense to me. Thanks again for taking the time!

okaforcj commented 1 year ago

This works for for me, perfect. Thanks again, i'll be closing this issue as resolved