Skip to content

Commit

Permalink
Support geographically sized text
Browse files Browse the repository at this point in the history
Update 4/20/20: adding fix to symbol_layout.addSymbol to correct text placement along lines
  • Loading branch information
mike-unearth committed Apr 20, 2020
1 parent 2e3ffcd commit 5c0d3fb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
11 changes: 9 additions & 2 deletions src/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,15 @@ const shaderOpacityAttributes = [
];

function addVertex(array, anchorX, anchorY, ox, oy, tx, ty, sizeVertex, isSDF: boolean, pixelOffsetX, pixelOffsetY, minFontScaleX, minFontScaleY) {
const aSizeX = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[0])) : 0;
const aSizeY = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[1])) : 0;
let aSizeX,
aSizeY;
if (isSDF) {
aSizeX = sizeVertex ? Math.round(sizeVertex[0]) : 0;
aSizeY = sizeVertex ? Math.round(sizeVertex[1]) : 0;
} else {
aSizeX = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[0])) : 0;
aSizeY = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[1])) : 0;
}
array.emplaceBack(
// a_pos_offset
anchorX,
Expand Down
4 changes: 2 additions & 2 deletions src/shaders/symbol_sdf.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ void main() {
float size;

if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {
size = mix(a_size_min, a_size[1], u_size_t) / 128.0;
size = mix(a_size_min, a_size[1], u_size_t);
} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {
size = a_size_min / 128.0;
size = a_size_min;
} else {
size = u_size;
}
Expand Down
4 changes: 2 additions & 2 deletions src/shaders/symbol_text_and_icon.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ void main() {
float size;

if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {
size = mix(a_size_min, a_size[1], u_size_t) / 128.0;
size = mix(a_size_min, a_size[1], u_size_t);
} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {
size = a_size_min / 128.0;
size = a_size_min;
} else {
size = u_size;
}
Expand Down
12 changes: 3 additions & 9 deletions src/symbol/symbol_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,19 +496,13 @@ function addTextVertices(bucket: SymbolBucket,

if (sizeData.kind === 'source') {
textSizeData = [
SIZE_PACK_FACTOR * layer.layout.get('text-size').evaluate(feature, {})
layer.layout.get('text-size').evaluate(feature, {})
];
if (textSizeData[0] > MAX_PACKED_SIZE) {
warnOnce(`${bucket.layerIds[0]}: Value for "text-size" is >= ${MAX_GLYPH_ICON_SIZE}. Reduce your "text-size".`);
}
} else if (sizeData.kind === 'composite') {
textSizeData = [
SIZE_PACK_FACTOR * sizes.compositeTextSizes[0].evaluate(feature, {}, canonical),
SIZE_PACK_FACTOR * sizes.compositeTextSizes[1].evaluate(feature, {}, canonical)
sizes.compositeTextSizes[0].evaluate(feature, {}, canonical),
sizes.compositeTextSizes[1].evaluate(feature, {}, canonical)
];
if (textSizeData[0] > MAX_PACKED_SIZE || textSizeData[1] > MAX_PACKED_SIZE) {
warnOnce(`${bucket.layerIds[0]}: Value for "text-size" is >= ${MAX_GLYPH_ICON_SIZE}. Reduce your "text-size".`);
}
}

bucket.addSymbols(
Expand Down
4 changes: 2 additions & 2 deletions src/symbol/symbol_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ function evaluateSizeForFeature(sizeData: SizeData,
{uSize, uSizeT}: { uSize: number, uSizeT: number },
{lowerSize, upperSize}: { lowerSize: number, upperSize: number}) {
if (sizeData.kind === 'source') {
return lowerSize / SIZE_PACK_FACTOR;
return lowerSize;
} else if (sizeData.kind === 'composite') {
return interpolate(lowerSize / SIZE_PACK_FACTOR, upperSize / SIZE_PACK_FACTOR, uSizeT);
return interpolate(lowerSize, upperSize, uSizeT);
}
return uSize;
}
Expand Down

0 comments on commit 5c0d3fb

Please sign in to comment.