From 5c0d3fb38b7377bab53b5ee379fc80f73d2c6b42 Mon Sep 17 00:00:00 2001 From: Mike Johnson Date: Mon, 20 Jan 2020 10:43:29 -0800 Subject: [PATCH] Support geographically sized text Update 4/20/20: adding fix to symbol_layout.addSymbol to correct text placement along lines --- src/data/bucket/symbol_bucket.js | 11 +++++++++-- src/shaders/symbol_sdf.vertex.glsl | 4 ++-- src/shaders/symbol_text_and_icon.vertex.glsl | 4 ++-- src/symbol/symbol_layout.js | 12 +++--------- src/symbol/symbol_size.js | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/data/bucket/symbol_bucket.js b/src/data/bucket/symbol_bucket.js index 2e57143c896..08005f03c37 100644 --- a/src/data/bucket/symbol_bucket.js +++ b/src/data/bucket/symbol_bucket.js @@ -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, diff --git a/src/shaders/symbol_sdf.vertex.glsl b/src/shaders/symbol_sdf.vertex.glsl index 71ccf3c81d7..75beb441e90 100644 --- a/src/shaders/symbol_sdf.vertex.glsl +++ b/src/shaders/symbol_sdf.vertex.glsl @@ -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; } diff --git a/src/shaders/symbol_text_and_icon.vertex.glsl b/src/shaders/symbol_text_and_icon.vertex.glsl index 647310fc9c9..8cedd4f6931 100644 --- a/src/shaders/symbol_text_and_icon.vertex.glsl +++ b/src/shaders/symbol_text_and_icon.vertex.glsl @@ -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; } diff --git a/src/symbol/symbol_layout.js b/src/symbol/symbol_layout.js index 9dec812e28d..943f08b0f31 100644 --- a/src/symbol/symbol_layout.js +++ b/src/symbol/symbol_layout.js @@ -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( diff --git a/src/symbol/symbol_size.js b/src/symbol/symbol_size.js index dab8f4b8989..e414934af24 100644 --- a/src/symbol/symbol_size.js +++ b/src/symbol/symbol_size.js @@ -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; }