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

Add support for symbols clustering #515

Closed
5 tasks
AAverin opened this issue Jan 30, 2021 · 5 comments
Closed
5 tasks

Add support for symbols clustering #515

AAverin opened this issue Jan 30, 2021 · 5 comments

Comments

@AAverin
Copy link
Contributor

AAverin commented Jan 30, 2021

The biggest downside of Mapbox SDK approach is required support of GeoJSON. If you will want to have clustering you would have to force your API or data to be in GeoJSON format, even if you don't have tremendous amount of points to cluster.

Android

Sample from Mapbox SDK: https://docs.mapbox.com/android/maps/examples/circle-layer-clustering/

In official mapbox documentation, symbols clustering works through a strange combination of multiple layers:

  • there is geojson layer with all the points data
  • there are multiple Circle layers, one for each 'step'
  • there is an extra SymbolLayer to show the label

While it is not clear exactly from Mapbox SDK documentation, looks like all of mapbox layers have setFilter method that seems to be somehow connected to GeoJSON itself, filtering its data.

Even though the whole approach looks totally confusing, most likely this is what we will have to use to implement in flutter.

At the moment, single symbol layer is not yet exposed into flutter, symbols and circles use annotation plugin on Android, that rather leverages SymbolManager from the plugin.

GeoJSON support is also missing, only FillManager adding support for Fill (#71)

iOS

Sample from Mapbox SDK: https://docs.mapbox.com/ios/maps/examples/clustering/

For unknown for me reason, default behavior on IOS is to cluster symbols even without any implementation for circles provided. SDK seems to just do it by default which is very confusing, because visually all points look the same.

Looks like it's controlled by property setSymbolIconAllowOverlap, when set to true icons no longer disappear

The approach to support clustering on iOS is very similar to that of Android. The main difference is that iOS seems to support more advanced expressions to work with GeoJSON, so there is no need to have multiple circle layers, there is only one that uses more advanced formulas.

GeoJSON is represented by MGLShapeSource class. There is also MGLSymbolStyleLayer and MGLCircleStyleLayer that have a predicate property - it seems to accept some kind of advanced formula that can be used to change properties of the layer itself. Additionally, other properties can accept NSExpression, that allows to use more formulas to change the values.

If anybody knows iOS SDK better, please link documentation for this predicate feature.

Potential tasks

  • Expose SymbolLayer
  • Expose CircleLayer
  • Add support for setFilter method
  • Add support for GeoJSONLayer
  • Provide sample tying it all together
@Kephas3
Copy link

Kephas3 commented Feb 10, 2021

Now that the PR #1168 is merged for the mapbox plugins for android regarding symbols clustering, what is the requirement to get this update in the flutter plugin ?

I mean, does the behavior will be native as for iOS ? Or else, do we have to declare a specific parameter in the MapboxMap() widget to activate symbol clustering ?

@AAverin
Copy link
Contributor Author

AAverin commented Feb 10, 2021

@Kephas3 It seems that all of the Potential tasks will have to be done to make it work in Flutter. We would have to expose layers directly and not only via annotation plugin (this is how it works now). What is even more confusing, annotation plugins for Android and iOS are experimental and not supposed to be used in production.

Still, looking into mapbox annotation plugins, it looks like internally they still rely on GeoJSON features. So having clustering now work in Android annotation plugin, maybe there is a way to wire it in instead of using geojson manually in Flutter.

Would be great to get some more in-depth input from Mapbox devs, what would be the best approach.

The problem I see is that iOS annotation plugin doesn't seem to support clustering. Looks like it is tracked here mapbox/mapbox-plugins-ios#6, but it's silent since 2017.
So unless there is also clustering support for iOS plugin, we would have to still go with the route of GeoJSON direct integration.

@m0nac0
Copy link
Collaborator

m0nac0 commented Jan 14, 2022

Closed by #797

@m0nac0 m0nac0 closed this as completed Jan 14, 2022
@AAverin
Copy link
Contributor Author

AAverin commented Jan 14, 2022

@m0nac0 Does proper symbol clustering work already? I though geoJSON support only adds geoJSON, but clustering needs to be a separate PR

@m0nac0
Copy link
Collaborator

m0nac0 commented Jan 14, 2022

#797 states:

This will also add support for clustering, as this is part of the source spec

And that PR does indeed add the clustering options. If I remember correctly, it should be sufficient to create a new source with clustering enabled and a corresponding layer.

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

3 participants