Skip to content

Commit

Permalink
Merge pull request #1074 from toddwong/zero-text-halo-is=no-halo
Browse files Browse the repository at this point in the history
Zero text halo should be no halo
  • Loading branch information
ahocevar committed Jan 24, 2024
2 parents 2176724 + 0a68a67 commit 30ba366
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stylefunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ export function stylefunction(
),
opacity,
);
if (haloColor) {
if (haloColor && textHaloWidth > 0) {
textHalo.setColor(haloColor);
// spec here : https://docs.mapbox.com/mapbox-gl-js/style-spec/#paint-symbol-text-halo-width
// Halo width must be doubled because it is applied around the center of the text outline
Expand Down
18 changes: 18 additions & 0 deletions test/stylefunction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,24 @@ describe('stylefunction', function () {
done(err);
});
});

it('Zero width text halo should be no halo', function (done) {
style.layers[0].paint['text-halo-color'] = 'red';
style.layers[0].paint['text-halo-width'] = 0;
apply(document.createElement('div'), style)
.then(function (map) {
const layer = map.getLayers().item(0);
const styleFunction = layer.getStyle();
const feature = layer.getSource().getFeatures()[0];
const styles = styleFunction(feature, 1);
const text = styles[0].getText();
should(text.getStroke()).be.undefined();
done();
})
.catch(function (err) {
done(err);
});
});
});

describe('Declutter mode', function () {
Expand Down

0 comments on commit 30ba366

Please sign in to comment.