Jake Madden
Jake Madden

Reputation: 237

Android Mapbox dynamically create a SymbolLayer

I'm still getting my head around the various approaches I can take to plotting points! Does a SymbolManager have as much flexibility as the SymbolLayer option? I'm unable to find much in the way of data related styling options with the SymbolManager. I'm currently using a SymbolManager, but only because I can't figure out how to dynamically create a SymbolLayer given a variable list of points! I considered creating a geoJson file on the fly but that seems a bit much? The only options I've been able to find are to load source layers from an asset or url.

EDIT: I'm also struggling to figure out how to clear all the data from a SymbolManager, or alternatively remove a symbolManager from the map?

Upvotes: 1

Views: 309

Answers (1)

Łukasz Paczos
Łukasz Paczos

Reputation: 607

SymbolManager is getting closer and closer to feature parity with the SymbolLayer, but its main advantage is easy of use.

To answer your questions about the manager - for now, it uses only constants for styling, but if you'd like to use Expressions, the support is on its way and should be available in the v0.4.0. You can remove an annotation by calling SymbolManager#delete, and in order to remove them all, simply iterate through the array that can be obtained with SymbolManager#getAnnotations.

When it comes to dynamically managing datasets of the SymbolLayer, the best approach would be using FeatureCollection. You can create Feature objects (which are equivalent to GeoJSON features) with static factories like Feature#fromLngLat and FeatureCollection#fromFeatures. Then set this collection on your GeoJsonSource and you should be ready to go. Check out the example activity that generates features on the fly.

Upvotes: 2

Related Questions