mapbox-gl
Version:
A WebGL interactive maps library
42 lines (33 loc) • 1.19 kB
JavaScript
;
var resolveTokens = require('../util/token');
module.exports = resolveText;
/**
* For an array of features determine what glyphs need to be loaded
* and apply any text preprocessing. The remaining users of text should
* use the `textFeatures` key returned by this function rather than accessing
* feature text directly.
* @private
*/
function resolveText(features, layoutProperties, codepoints) {
var textFeatures = [];
for (var i = 0, fl = features.length; i < fl; i++) {
var text = resolveTokens(features[i].properties, layoutProperties['text-field']);
if (!text) {
textFeatures[i] = null;
continue;
}
text = text.toString();
var transform = layoutProperties['text-transform'];
if (transform === 'uppercase') {
text = text.toLocaleUpperCase();
} else if (transform === 'lowercase') {
text = text.toLocaleLowerCase();
}
for (var j = 0; j < text.length; j++) {
codepoints[text.charCodeAt(j)] = true;
}
// Track indexes of features with text.
textFeatures[i] = text;
}
return textFeatures;
}