Search code examples
javaandroidmapboxmapbox-android

How to set the Mapbox symbol layer textfield with GeoJSON property value?


I want to create a symbol layer with the textfield set to a property from my GeoJSON file. For instance, in my GeoJSON file each Feature has a property called "rlabel" and I would like to set the value of this label as the symbol layers textfield. How do I do this?

String geojsonString = loadJsonFromDownloadedFile(...);
source = new GeoJsonSource("source-id", geojsonString);

SymbolLayer symbolLayer = new SymbolLayer("symbol-layer-id", "source-id");
symbolLayer.setProperties(
    PropertyFactory.textField(  ???   ) // what goes here?
);     
style.addLayer(symbolLayer);

Thanks


Solution

  • Try the following code:

    PropertyFactory.textField(get("rlabl"))
    

    Specifically the get() method is com.mapbox.mapboxsdk.style.expressions.Expression.get() This class has a lot of matchers.