1

I can use the data driven feature to color points, works great

MAP.addLayer({
"id": "schools",
"type": "circle",
"source": "markers",
"layout": { },
"paint": {
    "circle-radius": 8
    'circle-color': {               // for data driven colors need v0.18.0
        'property': 'type',
        'type': 'categorical',
        'stops': [
            ['ELEMENTARY', '#009900'], 
            ['MIDDLE', '#cc00ff'], 
            ['HIGH', '#1666ff'] 
   }
}   
});

I also want the label to be the same color as the point. All my text labels default to the first stop color. Can I use the data driven feature for text labels, and if so what am I doing wrong?

MAP.addLayer({
"id": "school_label",
"type": "symbol",
"source": "markers",
"layout": {
    "text-font": ["Open Sans Regular"],
    "text-field": "{full_name}",
    "symbol-placement": "point",
    "text-size": 10
},
"paint": {
    //"text-color": "#ff0000",
    'text-color': {
        'property': 'type',
        'type': 'categorical',
        'stops': [
            ['ELEMENTARY', '#009900'], 
            ['MIDDLE', '#cc00ff'], 
            ['HIGH', '#1666ff'] 
    }
    }
});   
0

2 Answers 2

1

I just read this in a mapbox blog, and to answer my own question I cannot do data driven labels.
"data driven styles have been one of the biggest tasks in Mapbox GL’s history, but they stand to change everything. Right now we just support data-driven styles for Mapbox GL JS, and only for circle-radius and circle-color."

1
  • Don't forget to accept your answer by clicking the green-faded tick on the left-hand side :)
    – Joseph
    Nov 30, 2017 at 11:59
1

Just tried with version 0.37 and it works now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.