@antv/l7-layers 2.28.11 → 2.28.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/es/core/interface.d.ts +4 -0
  2. package/es/plugins/DataMappingPlugin.js +3 -3
  3. package/es/plugins/index.d.ts +1 -1
  4. package/es/point/models/billboard_point.js +1 -1
  5. package/es/point/models/earthFill.js +1 -1
  6. package/es/point/models/fill.js +1 -1
  7. package/es/point/models/fillImage.js +1 -1
  8. package/es/point/models/image.js +1 -1
  9. package/es/point/models/normal.js +1 -1
  10. package/es/point/models/radar.js +1 -1
  11. package/es/point/models/text.d.ts +41 -6
  12. package/es/point/models/text.js +227 -25
  13. package/es/point/shaders/billboard/billboard_point_vert.glsl +4 -2
  14. package/es/point/shaders/image/image_vert.glsl +4 -2
  15. package/es/point/shaders/normal/normal_vert.glsl +4 -2
  16. package/es/point/shaders/text/text_frag.glsl +46 -6
  17. package/es/point/shaders/text/text_vert.glsl +15 -1
  18. package/es/tile/tile/Tile.d.ts +1 -1
  19. package/es/tile/tile/util.d.ts +1 -1
  20. package/es/utils/symbol-layout.js +5 -7
  21. package/lib/core/interface.d.ts +4 -0
  22. package/lib/plugins/DataMappingPlugin.js +3 -3
  23. package/lib/plugins/index.d.ts +1 -1
  24. package/lib/point/models/billboard_point.js +1 -1
  25. package/lib/point/models/earthFill.js +1 -1
  26. package/lib/point/models/fill.js +1 -1
  27. package/lib/point/models/fillImage.js +1 -1
  28. package/lib/point/models/image.js +1 -1
  29. package/lib/point/models/normal.js +1 -1
  30. package/lib/point/models/radar.js +1 -1
  31. package/lib/point/models/text.d.ts +41 -6
  32. package/lib/point/models/text.js +229 -25
  33. package/lib/point/shaders/billboard/billboard_point_vert.glsl +4 -2
  34. package/lib/point/shaders/image/image_vert.glsl +4 -2
  35. package/lib/point/shaders/normal/normal_vert.glsl +4 -2
  36. package/lib/point/shaders/text/text_frag.glsl +46 -6
  37. package/lib/point/shaders/text/text_vert.glsl +15 -1
  38. package/lib/tile/tile/Tile.d.ts +1 -1
  39. package/lib/tile/tile/util.d.ts +1 -1
  40. package/lib/utils/symbol-layout.js +5 -7
  41. package/package.json +6 -6
@@ -4,48 +4,132 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.TextBackgroundTrianglation = TextBackgroundTrianglation;
8
+ exports.TextGlyphTrianglation = TextGlyphTrianglation;
7
9
  exports.TextTrianglation = TextTrianglation;
8
10
  exports.default = void 0;
9
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
14
  var _l7Core = require("@antv/l7-core");
13
15
  var _l7Utils = require("@antv/l7-utils");
14
16
  var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
15
17
  var _collisionIndex = _interopRequireDefault(require("../../utils/collision-index"));
16
18
  var _symbolLayout = require("../../utils/symbol-layout");
17
19
  /* babel-plugin-inline-import '../shaders/text/text_frag.glsl' */
18
- const textFrag = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 48.0\n\nuniform sampler2D u_sdf_map;\nlayout(std140) uniform commonUniforms {\n vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n vec2 u_sdf_map_size;\n float u_raisingHeight: 0.0;\n float u_stroke_width : 2;\n float u_gamma_scale : 0.5;\n float u_halo_blur : 0.5;\n};\n\nin vec2 v_uv;\nin float v_gamma_scale;\nin vec4 v_color;\nin vec4 v_stroke_color;\nin float v_fontScale;\n\nout vec4 outputColor;\n\n#pragma include \"picking\"\nvoid main() {\n // get style data mapping\n\n // get sdf from atlas\n float dist = texture(SAMPLER_2D(u_sdf_map), v_uv).a;\n\n lowp float buff = (6.0 - u_stroke_width / v_fontScale) / SDF_PX;\n highp float gamma = (u_halo_blur * 1.19 / SDF_PX + EDGE_GAMMA) / (v_fontScale * u_gamma_scale) / 1.0;\n\n highp float gamma_scaled = gamma * v_gamma_scale;\n\n highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);\n\n // \u6839\u636E stroke \u7684 alpha \u503C\u8C03\u6574\u6DF7\u5408\u6743\u91CD\uFF0C\u907F\u514D\u900F\u660E stroke \u5F71\u54CD\u6587\u672C\u989C\u8272\n float stroke_mix_factor = smoothstep(0., 0.5, 1.- dist) * v_stroke_color.a;\n outputColor = mix(v_color, v_stroke_color, stroke_mix_factor);\n\n outputColor.a *= alpha;\n // \u4F5C\u4E3A mask \u6A21\u677F\u65F6\u9700\u8981\u4E22\u5F03\u900F\u660E\u7684\u50CF\u7D20\n if (outputColor.a < 0.01) {\n discard;\n }\n outputColor = filterColor(outputColor);\n}\n";
20
+ const textFrag = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 48.0\n\nuniform sampler2D u_sdf_map;\nlayout(std140) uniform commonUniforms {\n vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n vec4 u_background_color : [0.0, 0.0, 0.0, 0.0];\n vec2 u_sdf_map_size;\n float u_raisingHeight: 0.0;\n float u_stroke_width : 2;\n float u_background_radius : 0.0;\n float u_background_shape : 0.0;\n float u_gamma_scale : 0.5;\n float u_halo_blur : 0.5;\n};\n\nin vec2 v_uv;\nin vec2 v_backgroundUV;\nin vec2 v_backgroundSize;\nin float v_gamma_scale;\nin float v_textQuadType;\nin vec4 v_color;\nin vec4 v_stroke_color;\nin vec4 v_background_color;\nin float v_fontScale;\n\nout vec4 outputColor;\n\n#pragma include \"picking\"\nvoid main() {\n // get style data mapping\n\n if (v_textQuadType > 0.5) {\n vec2 halfSize = v_backgroundSize * 0.5;\n float radius = clamp(u_background_radius, 0.0, min(halfSize.x, halfSize.y));\n if (u_background_shape > 0.5) {\n radius = min(halfSize.x, halfSize.y);\n }\n\n vec2 centered = (v_backgroundUV - 0.5) * v_backgroundSize;\n vec2 q = abs(centered) - (halfSize - vec2(radius));\n float signedDistance = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius;\n float aa = max(fwidth(signedDistance), 1.0);\n float backgroundAlpha = (1.0 - smoothstep(0.0, aa, signedDistance)) * v_background_color.a;\n outputColor = vec4(v_background_color.rgb, backgroundAlpha);\n if (outputColor.a < 0.01) {\n discard;\n }\n outputColor = filterColor(outputColor);\n return;\n }\n\n // get sdf from atlas\n float dist = texture(SAMPLER_2D(u_sdf_map), v_uv).a;\n\n lowp float fill_buff = 6.0 / SDF_PX;\n lowp float stroke_buff = (6.0 - u_stroke_width / v_fontScale) / SDF_PX;\n highp float gamma = (u_halo_blur * 1.19 / SDF_PX + EDGE_GAMMA) / (v_fontScale * u_gamma_scale) / 1.0;\n\n highp float gamma_scaled = gamma * v_gamma_scale;\n\n highp float fill_alpha = smoothstep(\n fill_buff - gamma_scaled,\n fill_buff + gamma_scaled,\n dist\n ) * v_color.a;\n highp float outer_alpha = smoothstep(\n stroke_buff - gamma_scaled,\n stroke_buff + gamma_scaled,\n dist\n );\n highp float stroke_alpha = max(outer_alpha - fill_alpha / max(v_color.a, 0.0001), 0.0) * v_stroke_color.a;\n\n float out_alpha = clamp(fill_alpha + stroke_alpha, 0.0, 1.0);\n vec3 out_rgb = vec3(0.0);\n if (out_alpha > 0.0) {\n out_rgb = (v_color.rgb * fill_alpha + v_stroke_color.rgb * stroke_alpha) / out_alpha;\n }\n\n outputColor = vec4(out_rgb, out_alpha);\n // \u4F5C\u4E3A mask \u6A21\u677F\u65F6\u9700\u8981\u4E22\u5F03\u900F\u660E\u7684\u50CF\u7D20\n if (outputColor.a < 0.01) {\n discard;\n }\n outputColor = filterColor(outputColor);\n}\n";
19
21
  /* babel-plugin-inline-import '../shaders/text/text_vert.glsl' */
20
- const textVert = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 24.0\n\nlayout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\nlayout(location = ATTRIBUTE_LOCATION_TEXT_OFFSETS) in vec2 a_textOffsets;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_tex;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n vec2 u_sdf_map_size;\n float u_raisingHeight: 0.0;\n float u_stroke_width : 2;\n float u_gamma_scale : 0.5;\n float u_halo_blur : 0.5;\n};\n\nout vec2 v_uv;\nout float v_gamma_scale;\nout vec4 v_color;\nout vec4 v_stroke_color;\nout float v_fontScale;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n#pragma include \"rotation_2d\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n v_uv = a_tex / u_sdf_map_size;\n\n\n\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n v_stroke_color = vec4(u_stroke_color.xyz, u_stroke_color.w * opacity);\n\n // \u6587\u672C\u7F29\u653E\u6BD4\u4F8B\n float fontScale = a_Size / FONT_SIZE;\n v_fontScale = fontScale;\n\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n // vec4 projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n vec2 offset = rotate_matrix(a_textOffsets,rotation);\n\n // gl_Position = vec4(projected_position.xy / projected_position.w + rotation_matrix * a_textOffsets * fontScale / u_ViewportSize * 2.0 * u_DevicePixelRatio, 0.0, 1.0);\n\n float raiseHeight = u_raisingHeight;\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n raiseHeight = u_raisingHeight * mapboxZoomScale;\n }\n\n vec4 projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz + vec3(0.0, 0.0, raiseHeight), 1.0));\n\n gl_Position = vec4(\n projected_position.xy / projected_position.w + offset * fontScale / u_ViewportSize * 2.0 * u_DevicePixelRatio, 0.0, 1.0);\n v_gamma_scale = gl_Position.w;\n setPickingColor(a_PickingColor);\n\n}\n";
22
+ const textVert = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 24.0\n\nlayout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\nlayout(location = ATTRIBUTE_LOCATION_TEXT_OFFSETS) in vec2 a_textOffsets;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_tex;\nlayout(location = ATTRIBUTE_LOCATION_TEXT_QUAD_TYPE) in float a_textQuadType;\nlayout(location = ATTRIBUTE_LOCATION_TEXT_BACKGROUND_UV) in vec2 a_backgroundUV;\nlayout(location = ATTRIBUTE_LOCATION_TEXT_BACKGROUND_SIZE) in vec2 a_backgroundSize;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n vec4 u_background_color : [0.0, 0.0, 0.0, 0.0];\n vec2 u_sdf_map_size;\n float u_raisingHeight: 0.0;\n float u_stroke_width : 2;\n float u_background_radius : 0.0;\n float u_background_shape : 0.0;\n float u_gamma_scale : 0.5;\n float u_halo_blur : 0.5;\n};\n\nout vec2 v_uv;\nout vec2 v_backgroundUV;\nout vec2 v_backgroundSize;\nout float v_gamma_scale;\nout float v_textQuadType;\nout vec4 v_color;\nout vec4 v_stroke_color;\nout vec4 v_background_color;\nout float v_fontScale;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n#pragma include \"rotation_2d\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n v_uv = a_tex / u_sdf_map_size;\n v_backgroundUV = a_backgroundUV;\n v_backgroundSize = a_backgroundSize;\n v_textQuadType = a_textQuadType;\n\n\n\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n v_stroke_color = vec4(u_stroke_color.xyz, u_stroke_color.w * opacity);\n v_background_color = vec4(u_background_color.xyz, u_background_color.w * opacity);\n\n // \u6587\u672C\u7F29\u653E\u6BD4\u4F8B\n float fontScale = a_Size / FONT_SIZE;\n v_fontScale = fontScale;\n\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n // vec4 projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n vec2 offset = rotate_matrix(a_textOffsets,rotation);\n\n // gl_Position = vec4(projected_position.xy / projected_position.w + rotation_matrix * a_textOffsets * fontScale / u_ViewportSize * 2.0 * u_DevicePixelRatio, 0.0, 1.0);\n\n float raiseHeight = u_raisingHeight;\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n raiseHeight = u_raisingHeight * mapboxZoomScale;\n }\n\n vec4 projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz + vec3(0.0, 0.0, raiseHeight), 1.0));\n\n gl_Position = vec4(\n projected_position.xy / projected_position.w + offset * fontScale / u_ViewportSize * 2.0 * u_DevicePixelRatio, 0.0, 1.0);\n v_gamma_scale = projected_position.w;\n setPickingColor(a_PickingColor);\n\n}\n";
21
23
  const {
22
24
  isEqual
23
25
  } = _l7Utils.lodashUtil;
26
+ const TEXT_BACKGROUND_SHAPE = {
27
+ rect: 0,
28
+ circle: 1,
29
+ 'circle-rect': 2
30
+ };
31
+ function normalizePadding(padding = [0, 0]) {
32
+ return Array.isArray(padding) ? padding : [padding, padding];
33
+ }
34
+ function hasBackground(backgroundColor) {
35
+ return (0, _l7Utils.rgb2arr)(backgroundColor || '')[3] > 0;
36
+ }
37
+ function getBackgroundQuad(glyphQuads, backgroundPadding, backgroundShape) {
38
+ const x1Bounds = Math.min(...glyphQuads.map(quad => Math.min(quad.tl.x, quad.bl.x)));
39
+ const y1Bounds = Math.min(...glyphQuads.map(quad => Math.min(quad.tl.y, quad.tr.y)));
40
+ const x2Bounds = Math.max(...glyphQuads.map(quad => Math.max(quad.tr.x, quad.br.x)));
41
+ const y2Bounds = Math.max(...glyphQuads.map(quad => Math.max(quad.bl.y, quad.br.y)));
42
+ let x1 = x1Bounds - backgroundPadding[0];
43
+ let y1 = y1Bounds - backgroundPadding[1];
44
+ let x2 = x2Bounds + backgroundPadding[0];
45
+ let y2 = y2Bounds + backgroundPadding[1];
46
+ if (backgroundShape === 'circle') {
47
+ const centerX = (x1 + x2) / 2;
48
+ const centerY = (y1 + y2) / 2;
49
+ const diameter = Math.max(x2 - x1, y2 - y1);
50
+ x1 = centerX - diameter / 2;
51
+ x2 = centerX + diameter / 2;
52
+ y1 = centerY - diameter / 2;
53
+ y2 = centerY + diameter / 2;
54
+ }
55
+ return {
56
+ tl: {
57
+ x: x1,
58
+ y: y1
59
+ },
60
+ tr: {
61
+ x: x2,
62
+ y: y1
63
+ },
64
+ br: {
65
+ x: x2,
66
+ y: y2
67
+ },
68
+ bl: {
69
+ x: x1,
70
+ y: y2
71
+ },
72
+ size: [x2 - x1, y2 - y1]
73
+ };
74
+ }
24
75
  function TextTrianglation(feature) {
76
+ return buildTextTriangles.call(this, feature, 'all');
77
+ }
78
+ function TextBackgroundTrianglation(feature) {
79
+ return buildTextTriangles.call(this, feature, 'background');
80
+ }
81
+ function TextGlyphTrianglation(feature) {
82
+ return buildTextTriangles.call(this, feature, 'glyph');
83
+ }
84
+ function buildTextTriangles(feature, mode) {
25
85
  // @ts-ignore
26
86
  const that = this;
27
87
  const id = feature.id;
28
88
  const vertices = [];
29
89
  const indices = [];
90
+ const pushQuad = (quad, index, coord) => {
91
+ const baseIndex = index * 4;
92
+ const tex = 'tex' in quad && quad.tex ? quad.tex : {
93
+ x: 0,
94
+ y: 0,
95
+ width: 0,
96
+ height: 0
97
+ };
98
+ const bgUV = 'quadType' in quad && quad.quadType > 0 ? [[0, 0], [1, 0], [1, 1], [0, 1]] : [[0, 0], [0, 0], [0, 0], [0, 0]];
99
+ const bgSize = 'size' in quad ? quad.size : [0, 0];
100
+ const quadType = 'quadType' in quad ? quad.quadType : 0;
101
+ vertices.push(...coord, tex.x, tex.y + tex.height, quad.tl.x, quad.tl.y, quadType, bgUV[0][0], bgUV[0][1], bgSize[0], bgSize[1], ...coord, tex.x + tex.width, tex.y + tex.height, quad.tr.x, quad.tr.y, quadType, bgUV[1][0], bgUV[1][1], bgSize[0], bgSize[1], ...coord, tex.x + tex.width, tex.y, quad.br.x, quad.br.y, quadType, bgUV[2][0], bgUV[2][1], bgSize[0], bgSize[1], ...coord, tex.x, tex.y, quad.bl.x, quad.bl.y, quadType, bgUV[3][0], bgUV[3][1], bgSize[0], bgSize[1]);
102
+ indices.push(baseIndex, baseIndex + 1, baseIndex + 2, baseIndex + 2, baseIndex + 3, baseIndex);
103
+ };
30
104
  if (!that.glyphInfoMap || !that.glyphInfoMap[id]) {
31
105
  return {
32
106
  vertices: [],
33
107
  // [ x, y, z, tex.x,tex.y, offset.x. offset.y]
34
108
  indices: [],
35
- size: 7
109
+ size: 12
36
110
  };
37
111
  }
38
- const centroid = that.glyphInfoMap[id].centroid; // 计算中心点
112
+ const textRenderInfo = that.glyphInfoMap[id];
113
+ const centroid = textRenderInfo.centroid; // 计算中心点
39
114
  const coord = centroid.length === 2 ? [centroid[0], centroid[1], 0] : centroid;
40
- that.glyphInfoMap[id].glyphQuads.forEach((quad, index) => {
41
- vertices.push(...coord, quad.tex.x, quad.tex.y + quad.tex.height, quad.tl.x, quad.tl.y, ...coord, quad.tex.x + quad.tex.width, quad.tex.y + quad.tex.height, quad.tr.x, quad.tr.y, ...coord, quad.tex.x + quad.tex.width, quad.tex.y, quad.br.x, quad.br.y, ...coord, quad.tex.x, quad.tex.y, quad.bl.x, quad.bl.y);
42
- indices.push(0 + index * 4, 1 + index * 4, 2 + index * 4, 2 + index * 4, 3 + index * 4, 0 + index * 4);
43
- });
115
+ let quadIndex = 0;
116
+ if (mode !== 'glyph' && textRenderInfo.backgroundQuad) {
117
+ pushQuad((0, _objectSpread2.default)((0, _objectSpread2.default)({}, textRenderInfo.backgroundQuad), {}, {
118
+ quadType: 1
119
+ }), quadIndex, coord);
120
+ quadIndex += 1;
121
+ }
122
+ if (mode !== 'background') {
123
+ textRenderInfo.glyphQuads.forEach(quad => {
124
+ pushQuad(quad, quadIndex, coord);
125
+ quadIndex += 1;
126
+ });
127
+ }
44
128
  return {
45
129
  vertices,
46
130
  // [ x, y, z, tex.x,tex.y, offset.x. offset.y]
47
131
  indices,
48
- size: 7
132
+ size: 12
49
133
  };
50
134
  }
51
135
  class TextModel extends _BaseModel.default {
@@ -63,9 +147,11 @@ class TextModel extends _BaseModel.default {
63
147
  (0, _defineProperty2.default)(this, "textCount", 0);
64
148
  (0, _defineProperty2.default)(this, "preTextStyle", {});
65
149
  (0, _defineProperty2.default)(this, "mapping", /*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
150
+ _this.rawEncodeData = _this.layer.getEncodedData();
66
151
  _this.initGlyph(); //
67
152
  _this.updateTexture();
68
153
  yield _this.reBuildModel();
154
+ _this.layer.renderLayers();
69
155
  }));
70
156
  }
71
157
  get attributeLocation() {
@@ -73,7 +159,10 @@ class TextModel extends _BaseModel.default {
73
159
  MAX: super.attributeLocation.MAX,
74
160
  SIZE: 9,
75
161
  TEXT_OFFSETS: 10,
76
- UV: 11
162
+ UV: 11,
163
+ TEXT_QUAD_TYPE: 12,
164
+ TEXT_BACKGROUND_UV: 13,
165
+ TEXT_BACKGROUND_SIZE: 14
77
166
  });
78
167
  }
79
168
  getUninforms() {
@@ -85,9 +174,14 @@ class TextModel extends _BaseModel.default {
85
174
  });
86
175
  }
87
176
  getCommonUniformsInfo() {
177
+ var _TEXT_BACKGROUND_SHAP;
88
178
  const {
89
179
  stroke = '#fff',
180
+ strokeOpacity = 1,
90
181
  strokeWidth = 0,
182
+ backgroundColor = 'rgba(0, 0, 0, 0)',
183
+ backgroundRadius = 0,
184
+ backgroundShape = 'rect',
91
185
  halo = 0.5,
92
186
  gamma = 2.0,
93
187
  raisingHeight = 0
@@ -99,11 +193,16 @@ class TextModel extends _BaseModel.default {
99
193
  this.textCount = Object.keys(mapping).length;
100
194
  }
101
195
  this.preTextStyle = this.getTextStyle();
196
+ const strokeColor = (0, _l7Utils.rgb2arr)(stroke);
197
+ const bgColor = (0, _l7Utils.rgb2arr)(backgroundColor);
102
198
  const commonOptions = {
103
- u_stroke_color: (0, _l7Utils.rgb2arr)(stroke),
199
+ u_stroke_color: [strokeColor[0], strokeColor[1], strokeColor[2], strokeColor[3] * strokeOpacity],
200
+ u_background_color: bgColor,
104
201
  u_sdf_map_size: [(canvas === null || canvas === void 0 ? void 0 : canvas.width) || 1, (canvas === null || canvas === void 0 ? void 0 : canvas.height) || 1],
105
202
  u_raisingHeight: Number(raisingHeight),
106
203
  u_stroke_width: strokeWidth,
204
+ u_background_radius: backgroundRadius,
205
+ u_background_shape: (_TEXT_BACKGROUND_SHAP = TEXT_BACKGROUND_SHAPE[backgroundShape]) !== null && _TEXT_BACKGROUND_SHAP !== void 0 ? _TEXT_BACKGROUND_SHAP : TEXT_BACKGROUND_SHAPE.rect,
107
206
  u_gamma_scale: gamma,
108
207
  u_halo_blur: halo
109
208
  };
@@ -126,7 +225,8 @@ class TextModel extends _BaseModel.default {
126
225
  var _this3 = this;
127
226
  return (0, _asyncToGenerator2.default)(function* () {
128
227
  const {
129
- textAllowOverlap = false
228
+ textAllowOverlap = false,
229
+ backgroundColor
130
230
  } = _this3.layer.getLayerConfig();
131
231
 
132
232
  // this.mapping(); 重复调用
@@ -135,18 +235,32 @@ class TextModel extends _BaseModel.default {
135
235
  if (!textAllowOverlap) {
136
236
  _this3.filterGlyphs();
137
237
  }
138
- const model = yield _this3.layer.buildLayerModel({
238
+ const textModel = yield _this3.layer.buildLayerModel({
239
+ moduleName: 'pointText',
240
+ vertexShader: textVert,
241
+ fragmentShader: textFrag,
242
+ defines: _this3.getDefines(),
243
+ inject: _this3.getInject(),
244
+ triangulation: TextGlyphTrianglation.bind(_this3),
245
+ depth: {
246
+ enable: false
247
+ }
248
+ });
249
+ if (!hasBackground(backgroundColor)) {
250
+ return [textModel];
251
+ }
252
+ const backgroundModel = yield _this3.layer.buildLayerModel({
139
253
  moduleName: 'pointText',
140
254
  vertexShader: textVert,
141
255
  fragmentShader: textFrag,
142
256
  defines: _this3.getDefines(),
143
257
  inject: _this3.getInject(),
144
- triangulation: TextTrianglation.bind(_this3),
258
+ triangulation: TextBackgroundTrianglation.bind(_this3),
145
259
  depth: {
146
260
  enable: false
147
261
  }
148
262
  });
149
- return [model];
263
+ return [backgroundModel, textModel];
150
264
  })();
151
265
  }
152
266
  // 需要更新的场景
@@ -163,10 +277,13 @@ class TextModel extends _BaseModel.default {
163
277
  textAnchor = 'center',
164
278
  textOffset,
165
279
  padding,
280
+ backgroundColor,
281
+ backgroundPadding,
282
+ backgroundShape,
166
283
  fontFamily,
167
284
  fontWeight
168
285
  } = _this4.getTextStyle();
169
- if (!isEqual(padding, _this4.preTextStyle.padding) || !isEqual(textOffset, _this4.preTextStyle.textOffset) || !isEqual(textAnchor, _this4.preTextStyle.textAnchor) || !isEqual(fontFamily, _this4.preTextStyle.fontFamily) || !isEqual(fontWeight, _this4.preTextStyle.fontWeight)) {
286
+ if (!isEqual(padding, _this4.preTextStyle.padding) || backgroundColor !== _this4.preTextStyle.backgroundColor || !isEqual(backgroundPadding, _this4.preTextStyle.backgroundPadding) || backgroundShape !== _this4.preTextStyle.backgroundShape || !isEqual(textOffset, _this4.preTextStyle.textOffset) || !isEqual(textAnchor, _this4.preTextStyle.textAnchor) || !isEqual(fontFamily, _this4.preTextStyle.fontFamily) || !isEqual(fontWeight, _this4.preTextStyle.fontWeight)) {
170
287
  yield _this4.mapping();
171
288
  return true;
172
289
  }
@@ -233,6 +350,57 @@ class TextModel extends _BaseModel.default {
233
350
  }
234
351
  }
235
352
  });
353
+ this.styleAttributeService.registerStyleAttribute({
354
+ name: 'textQuadType',
355
+ type: _l7Core.AttributeType.Attribute,
356
+ descriptor: {
357
+ name: 'a_textQuadType',
358
+ shaderLocation: this.attributeLocation.TEXT_QUAD_TYPE,
359
+ buffer: {
360
+ usage: _l7Core.gl.DYNAMIC_DRAW,
361
+ data: [],
362
+ type: _l7Core.gl.FLOAT
363
+ },
364
+ size: 1,
365
+ update: (feature, featureIdx, vertex) => {
366
+ return [vertex[7]];
367
+ }
368
+ }
369
+ });
370
+ this.styleAttributeService.registerStyleAttribute({
371
+ name: 'textBackgroundUv',
372
+ type: _l7Core.AttributeType.Attribute,
373
+ descriptor: {
374
+ name: 'a_backgroundUV',
375
+ shaderLocation: this.attributeLocation.TEXT_BACKGROUND_UV,
376
+ buffer: {
377
+ usage: _l7Core.gl.DYNAMIC_DRAW,
378
+ data: [],
379
+ type: _l7Core.gl.FLOAT
380
+ },
381
+ size: 2,
382
+ update: (feature, featureIdx, vertex) => {
383
+ return [vertex[8], vertex[9]];
384
+ }
385
+ }
386
+ });
387
+ this.styleAttributeService.registerStyleAttribute({
388
+ name: 'textBackgroundSize',
389
+ type: _l7Core.AttributeType.Attribute,
390
+ descriptor: {
391
+ name: 'a_backgroundSize',
392
+ shaderLocation: this.attributeLocation.TEXT_BACKGROUND_SIZE,
393
+ buffer: {
394
+ usage: _l7Core.gl.DYNAMIC_DRAW,
395
+ data: [],
396
+ type: _l7Core.gl.FLOAT
397
+ },
398
+ size: 2,
399
+ update: (feature, featureIdx, vertex) => {
400
+ return [vertex[10], vertex[11]];
401
+ }
402
+ }
403
+ });
236
404
 
237
405
  // point layer size;
238
406
  this.styleAttributeService.registerStyleAttribute({
@@ -331,6 +499,10 @@ class TextModel extends _BaseModel.default {
331
499
  padding = [0, 0],
332
500
  textAnchor = 'center',
333
501
  textOffset = [0, 0],
502
+ backgroundColor = 'rgba(0, 0, 0, 0)',
503
+ backgroundPadding = [0, 0],
504
+ backgroundRadius = 0,
505
+ backgroundShape = 'rect',
334
506
  opacity = 1,
335
507
  strokeOpacity = 1,
336
508
  strokeWidth = 0,
@@ -341,6 +513,10 @@ class TextModel extends _BaseModel.default {
341
513
  fontFamily,
342
514
  textAllowOverlap,
343
515
  padding,
516
+ backgroundColor,
517
+ backgroundPadding: normalizePadding(backgroundPadding),
518
+ backgroundRadius,
519
+ backgroundShape,
344
520
  textAnchor,
345
521
  textOffset,
346
522
  opacity,
@@ -358,7 +534,10 @@ class TextModel extends _BaseModel.default {
358
534
  const {
359
535
  spacing = 2,
360
536
  textAnchor = 'center',
361
- textOffset
537
+ textOffset,
538
+ backgroundColor,
539
+ backgroundPadding = [0, 0],
540
+ backgroundShape = 'rect'
362
541
  } = this.layer.getLayerConfig();
363
542
  const data = this.rawEncodeData;
364
543
  this.glyphInfo = data.map(feature => {
@@ -375,6 +554,7 @@ class TextModel extends _BaseModel.default {
375
554
  //
376
555
  iconfont);
377
556
  const glyphQuads = (0, _symbolLayout.getGlyphQuads)(shaping, offset, false);
557
+ const backgroundQuad = hasBackground(backgroundColor) ? getBackgroundQuad(glyphQuads, normalizePadding(backgroundPadding), backgroundShape) : undefined;
378
558
  feature.shaping = shaping;
379
559
  feature.glyphQuads = glyphQuads;
380
560
  // feature.centroid = calculteCentroid(coordinates);
@@ -383,6 +563,7 @@ class TextModel extends _BaseModel.default {
383
563
  this.glyphInfoMap[id] = {
384
564
  shaping,
385
565
  glyphQuads,
566
+ backgroundQuad,
386
567
  centroid: (0, _l7Utils.calculateCentroid)(feature.coordinates)
387
568
  };
388
569
  return feature;
@@ -410,12 +591,16 @@ class TextModel extends _BaseModel.default {
410
591
  filterGlyphs() {
411
592
  const {
412
593
  padding = [0, 0],
594
+ backgroundColor,
595
+ backgroundPadding = [0, 0],
413
596
  textAllowOverlap = false
414
597
  } = this.layer.getLayerConfig();
415
598
  if (textAllowOverlap) {
416
599
  // 如果允许文本覆盖
417
600
  return;
418
601
  }
602
+ const collisionPadding = normalizePadding(backgroundPadding);
603
+ const extraPadding = hasBackground(backgroundColor) ? collisionPadding : [0, 0];
419
604
  this.glyphInfoMap = {};
420
605
  this.currentZoom = this.mapService.getZoom();
421
606
  this.extent = this.textExtent();
@@ -436,10 +621,10 @@ class TextModel extends _BaseModel.default {
436
621
  const {
437
622
  box
438
623
  } = collisionIndex.placeCollisionBox({
439
- x1: shaping.left * fontScale - padding[0],
440
- x2: shaping.right * fontScale + padding[0],
441
- y1: shaping.top * fontScale - padding[1],
442
- y2: shaping.bottom * fontScale + padding[1],
624
+ x1: shaping.left * fontScale - padding[0] - extraPadding[0],
625
+ x2: shaping.right * fontScale + padding[0] + extraPadding[0],
626
+ y1: shaping.top * fontScale - padding[1] - extraPadding[1],
627
+ y2: shaping.bottom * fontScale + padding[1] + extraPadding[1],
443
628
  anchorPointX: pixels.x,
444
629
  anchorPointY: pixels.y
445
630
  });
@@ -492,12 +677,31 @@ class TextModel extends _BaseModel.default {
492
677
  reBuildModel() {
493
678
  var _this5 = this;
494
679
  return (0, _asyncToGenerator2.default)(function* () {
680
+ const {
681
+ backgroundColor
682
+ } = _this5.layer.getLayerConfig();
683
+ _this5.rawEncodeData = _this5.layer.getEncodedData();
495
684
  _this5.filterGlyphs();
496
- const model = yield _this5.layer.buildLayerModel({
685
+ const textModel = yield _this5.layer.buildLayerModel({
686
+ moduleName: 'pointText',
687
+ vertexShader: textVert,
688
+ fragmentShader: textFrag,
689
+ triangulation: TextGlyphTrianglation.bind(_this5),
690
+ defines: _this5.getDefines(),
691
+ inject: _this5.getInject(),
692
+ depth: {
693
+ enable: false
694
+ }
695
+ });
696
+ if (!hasBackground(backgroundColor)) {
697
+ _this5.layer.models = [textModel];
698
+ return;
699
+ }
700
+ const backgroundModel = yield _this5.layer.buildLayerModel({
497
701
  moduleName: 'pointText',
498
702
  vertexShader: textVert,
499
703
  fragmentShader: textFrag,
500
- triangulation: TextTrianglation.bind(_this5),
704
+ triangulation: TextBackgroundTrianglation.bind(_this5),
501
705
  defines: _this5.getDefines(),
502
706
  inject: _this5.getInject(),
503
707
  depth: {
@@ -505,7 +709,7 @@ class TextModel extends _BaseModel.default {
505
709
  }
506
710
  });
507
711
  // TODO 渲染流程待修改
508
- _this5.layer.models = [model];
712
+ _this5.layer.models = [backgroundModel, textModel];
509
713
  })();
510
714
  }
511
715
  }
@@ -27,6 +27,7 @@ vec2 applyAnchorPoint(float anchor, float pointSize) {
27
27
  }
28
28
 
29
29
  vec2 offset = vec2(0.0);
30
+ float gap = 2.0 * u_DevicePixelRatio; // 2px 间隔,考虑设备像素比
30
31
 
31
32
  // horizontal alignment: 左边缘对准坐标 -> 向右移; 右边缘对准坐标 -> 向左移
32
33
  if (anchor == 2.0 || anchor == 3.0 || anchor == 4.0) {
@@ -36,10 +37,11 @@ vec2 applyAnchorPoint(float anchor, float pointSize) {
36
37
  }
37
38
 
38
39
  // vertical alignment: 上边缘对准坐标 -> 向下移(图形在坐标下方); 下边缘对准坐标 -> 向上移(图形在坐标上方)
40
+ // bottom 和 top 增加 2px 间隔,避免图形紧贴参考点
39
41
  if (anchor == 1.0 || anchor == 2.0 || anchor == 8.0) {
40
- offset.y = -pointSize * 0.5;
42
+ offset.y = -pointSize * 0.5 - gap; // top: 图形在坐标下方,额外向下移 2px
41
43
  } else if (anchor == 4.0 || anchor == 5.0 || anchor == 6.0 || anchor == 9.0) {
42
- offset.y = pointSize * 0.5;
44
+ offset.y = pointSize * 0.5 + gap; // bottom: 图形在坐标上方,额外向上移 2px
43
45
  }
44
46
 
45
47
  return offset;
@@ -25,6 +25,7 @@ vec2 applyAnchorPoint(float anchor, float pointSize) {
25
25
  }
26
26
 
27
27
  vec2 offset = vec2(0.0);
28
+ float gap = 2.0 * u_DevicePixelRatio; // 2px 间隔,考虑设备像素比
28
29
 
29
30
  // horizontal alignment: 左边缘对准坐标 -> 向右移; 右边缘对准坐标 -> 向左移
30
31
  if (anchor == 2.0 || anchor == 3.0 || anchor == 4.0) {
@@ -34,10 +35,11 @@ vec2 applyAnchorPoint(float anchor, float pointSize) {
34
35
  }
35
36
 
36
37
  // vertical alignment: 上边缘对准坐标 -> 向下移(图形在坐标下方); 下边缘对准坐标 -> 向上移(图形在坐标上方)
38
+ // bottom 和 top 增加 2px 间隔,避免图形紧贴参考点
37
39
  if (anchor == 1.0 || anchor == 2.0 || anchor == 8.0) {
38
- offset.y = -pointSize * 0.5;
40
+ offset.y = -pointSize * 0.5 - gap; // top: 图形在坐标下方,额外向下移 2px
39
41
  } else if (anchor == 4.0 || anchor == 5.0 || anchor == 6.0 || anchor == 9.0) {
40
- offset.y = pointSize * 0.5;
42
+ offset.y = pointSize * 0.5 + gap; // bottom: 图形在坐标上方,额外向上移 2px
41
43
  }
42
44
 
43
45
  return offset;
@@ -20,6 +20,7 @@ vec2 applyAnchorPoint(float anchor, float pointSize) {
20
20
  }
21
21
 
22
22
  vec2 offset = vec2(0.0);
23
+ float gap = 2.0 * u_DevicePixelRatio; // 2px 间隔,考虑设备像素比
23
24
 
24
25
  // horizontal alignment: 左边缘对准坐标 -> 向右移; 右边缘对准坐标 -> 向左移
25
26
  if (anchor == 2.0 || anchor == 3.0 || anchor == 4.0) {
@@ -29,10 +30,11 @@ vec2 applyAnchorPoint(float anchor, float pointSize) {
29
30
  }
30
31
 
31
32
  // vertical alignment: 上边缘对准坐标 -> 向下移(图形在坐标下方); 下边缘对准坐标 -> 向上移(图形在坐标上方)
33
+ // bottom 和 top 增加 2px 间隔,避免图形紧贴参考点
32
34
  if (anchor == 1.0 || anchor == 2.0 || anchor == 8.0) {
33
- offset.y = -pointSize * 0.5;
35
+ offset.y = -pointSize * 0.5 - gap; // top: 图形在坐标下方,额外向下移 2px
34
36
  } else if (anchor == 4.0 || anchor == 5.0 || anchor == 6.0 || anchor == 9.0) {
35
- offset.y = pointSize * 0.5;
37
+ offset.y = pointSize * 0.5 + gap; // bottom: 图形在坐标上方,额外向上移 2px
36
38
  }
37
39
 
38
40
  return offset;
@@ -5,17 +5,24 @@
5
5
  uniform sampler2D u_sdf_map;
6
6
  layout(std140) uniform commonUniforms {
7
7
  vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];
8
+ vec4 u_background_color : [0.0, 0.0, 0.0, 0.0];
8
9
  vec2 u_sdf_map_size;
9
10
  float u_raisingHeight: 0.0;
10
11
  float u_stroke_width : 2;
12
+ float u_background_radius : 0.0;
13
+ float u_background_shape : 0.0;
11
14
  float u_gamma_scale : 0.5;
12
15
  float u_halo_blur : 0.5;
13
16
  };
14
17
 
15
18
  in vec2 v_uv;
19
+ in vec2 v_backgroundUV;
20
+ in vec2 v_backgroundSize;
16
21
  in float v_gamma_scale;
22
+ in float v_textQuadType;
17
23
  in vec4 v_color;
18
24
  in vec4 v_stroke_color;
25
+ in vec4 v_background_color;
19
26
  in float v_fontScale;
20
27
 
21
28
  out vec4 outputColor;
@@ -24,21 +31,54 @@ out vec4 outputColor;
24
31
  void main() {
25
32
  // get style data mapping
26
33
 
34
+ if (v_textQuadType > 0.5) {
35
+ vec2 halfSize = v_backgroundSize * 0.5;
36
+ float radius = clamp(u_background_radius, 0.0, min(halfSize.x, halfSize.y));
37
+ if (u_background_shape > 0.5) {
38
+ radius = min(halfSize.x, halfSize.y);
39
+ }
40
+
41
+ vec2 centered = (v_backgroundUV - 0.5) * v_backgroundSize;
42
+ vec2 q = abs(centered) - (halfSize - vec2(radius));
43
+ float signedDistance = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius;
44
+ float aa = max(fwidth(signedDistance), 1.0);
45
+ float backgroundAlpha = (1.0 - smoothstep(0.0, aa, signedDistance)) * v_background_color.a;
46
+ outputColor = vec4(v_background_color.rgb, backgroundAlpha);
47
+ if (outputColor.a < 0.01) {
48
+ discard;
49
+ }
50
+ outputColor = filterColor(outputColor);
51
+ return;
52
+ }
53
+
27
54
  // get sdf from atlas
28
55
  float dist = texture(SAMPLER_2D(u_sdf_map), v_uv).a;
29
56
 
30
- lowp float buff = (6.0 - u_stroke_width / v_fontScale) / SDF_PX;
57
+ lowp float fill_buff = 6.0 / SDF_PX;
58
+ lowp float stroke_buff = (6.0 - u_stroke_width / v_fontScale) / SDF_PX;
31
59
  highp float gamma = (u_halo_blur * 1.19 / SDF_PX + EDGE_GAMMA) / (v_fontScale * u_gamma_scale) / 1.0;
32
60
 
33
61
  highp float gamma_scaled = gamma * v_gamma_scale;
34
62
 
35
- highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);
63
+ highp float fill_alpha = smoothstep(
64
+ fill_buff - gamma_scaled,
65
+ fill_buff + gamma_scaled,
66
+ dist
67
+ ) * v_color.a;
68
+ highp float outer_alpha = smoothstep(
69
+ stroke_buff - gamma_scaled,
70
+ stroke_buff + gamma_scaled,
71
+ dist
72
+ );
73
+ highp float stroke_alpha = max(outer_alpha - fill_alpha / max(v_color.a, 0.0001), 0.0) * v_stroke_color.a;
36
74
 
37
- // 根据 stroke alpha 值调整混合权重,避免透明 stroke 影响文本颜色
38
- float stroke_mix_factor = smoothstep(0., 0.5, 1.- dist) * v_stroke_color.a;
39
- outputColor = mix(v_color, v_stroke_color, stroke_mix_factor);
75
+ float out_alpha = clamp(fill_alpha + stroke_alpha, 0.0, 1.0);
76
+ vec3 out_rgb = vec3(0.0);
77
+ if (out_alpha > 0.0) {
78
+ out_rgb = (v_color.rgb * fill_alpha + v_stroke_color.rgb * stroke_alpha) / out_alpha;
79
+ }
40
80
 
41
- outputColor.a *= alpha;
81
+ outputColor = vec4(out_rgb, out_alpha);
42
82
  // 作为 mask 模板时需要丢弃透明的像素
43
83
  if (outputColor.a < 0.01) {
44
84
  discard;
@@ -8,20 +8,30 @@ layout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;
8
8
  layout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;
9
9
  layout(location = ATTRIBUTE_LOCATION_TEXT_OFFSETS) in vec2 a_textOffsets;
10
10
  layout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_tex;
11
+ layout(location = ATTRIBUTE_LOCATION_TEXT_QUAD_TYPE) in float a_textQuadType;
12
+ layout(location = ATTRIBUTE_LOCATION_TEXT_BACKGROUND_UV) in vec2 a_backgroundUV;
13
+ layout(location = ATTRIBUTE_LOCATION_TEXT_BACKGROUND_SIZE) in vec2 a_backgroundSize;
11
14
 
12
15
  layout(std140) uniform commonUniforms {
13
16
  vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];
17
+ vec4 u_background_color : [0.0, 0.0, 0.0, 0.0];
14
18
  vec2 u_sdf_map_size;
15
19
  float u_raisingHeight: 0.0;
16
20
  float u_stroke_width : 2;
21
+ float u_background_radius : 0.0;
22
+ float u_background_shape : 0.0;
17
23
  float u_gamma_scale : 0.5;
18
24
  float u_halo_blur : 0.5;
19
25
  };
20
26
 
21
27
  out vec2 v_uv;
28
+ out vec2 v_backgroundUV;
29
+ out vec2 v_backgroundSize;
22
30
  out float v_gamma_scale;
31
+ out float v_textQuadType;
23
32
  out vec4 v_color;
24
33
  out vec4 v_stroke_color;
34
+ out vec4 v_background_color;
25
35
  out float v_fontScale;
26
36
 
27
37
  #pragma include "projection"
@@ -32,11 +42,15 @@ void main() {
32
42
  // cal style mapping - 数据纹理映射部分的计算
33
43
 
34
44
  v_uv = a_tex / u_sdf_map_size;
45
+ v_backgroundUV = a_backgroundUV;
46
+ v_backgroundSize = a_backgroundSize;
47
+ v_textQuadType = a_textQuadType;
35
48
 
36
49
 
37
50
 
38
51
  v_color = vec4(a_Color.xyz, a_Color.w * opacity);
39
52
  v_stroke_color = vec4(u_stroke_color.xyz, u_stroke_color.w * opacity);
53
+ v_background_color = vec4(u_background_color.xyz, u_background_color.w * opacity);
40
54
 
41
55
  // 文本缩放比例
42
56
  float fontScale = a_Size / FONT_SIZE;
@@ -59,7 +73,7 @@ void main() {
59
73
 
60
74
  gl_Position = vec4(
61
75
  projected_position.xy / projected_position.w + offset * fontScale / u_ViewportSize * 2.0 * u_DevicePixelRatio, 0.0, 1.0);
62
- v_gamma_scale = gl_Position.w;
76
+ v_gamma_scale = projected_position.w;
63
77
  setPickingColor(a_PickingColor);
64
78
 
65
79
  }
@@ -85,7 +85,7 @@ export default abstract class Tile extends EventEmitter implements ITile {
85
85
  pickBufferScale?: number | undefined;
86
86
  stencil?: boolean | undefined;
87
87
  debug?: boolean | undefined;
88
- renderer?: "device" | "regl" | undefined;
88
+ renderer?: "regl" | "device" | undefined;
89
89
  antialias?: boolean | undefined;
90
90
  preserveDrawingBuffer?: boolean | undefined;
91
91
  enableWebGPU?: boolean | undefined;