@antv/l7-layers 2.9.26-alpha.2 → 2.9.27-alpha.1

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 (47) hide show
  1. package/es/core/BaseLayer.d.ts +4 -0
  2. package/es/image/models/image.js +1 -1
  3. package/es/index.d.ts +2 -1
  4. package/es/index.js +3 -2
  5. package/es/line/index.d.ts +17 -0
  6. package/es/line/index.js +18 -0
  7. package/es/mask/index.d.ts +8 -0
  8. package/es/plugins/DataSourcePlugin.js +4 -10
  9. package/es/plugins/FeatureScalePlugin.d.ts +1 -0
  10. package/es/plugins/FeatureScalePlugin.js +80 -24
  11. package/es/point/index.d.ts +11 -1
  12. package/es/point/index.js +13 -3
  13. package/es/point/models/index.d.ts +1 -1
  14. package/es/point/models/index.js +2 -0
  15. package/es/point/models/tileText.d.ts +56 -0
  16. package/es/point/models/tileText.js +598 -0
  17. package/es/polygon/index.d.ts +8 -0
  18. package/es/tile/manager/tileLayerManager.d.ts +1 -0
  19. package/es/tile/manager/tileLayerManager.js +12 -1
  20. package/es/tile/models/tileModel.d.ts +1 -1
  21. package/es/tile/models/tileModel.js +8 -8
  22. package/es/tile/tileFactory/base.d.ts +1 -1
  23. package/es/tile/tileFactory/index.d.ts +1 -1
  24. package/es/tile/tileFactory/index.js +4 -0
  25. package/es/tile/tileFactory/test.d.ts +12 -0
  26. package/es/tile/tileFactory/test.js +82 -0
  27. package/es/tile/tileFactory/vectorLayer.d.ts +1 -1
  28. package/es/tile/tileFactory/vectorLayer.js +1 -1
  29. package/es/tile/tileTest.d.ts +14 -0
  30. package/es/tile/tileTest.js +63 -0
  31. package/es/tile/utils.js +1 -1
  32. package/lib/image/models/image.js +1 -1
  33. package/lib/index.js +10 -1
  34. package/lib/line/index.js +17 -0
  35. package/lib/plugins/DataSourcePlugin.js +4 -16
  36. package/lib/plugins/FeatureScalePlugin.js +80 -24
  37. package/lib/point/index.js +12 -3
  38. package/lib/point/models/index.js +3 -0
  39. package/lib/point/models/tileText.js +613 -0
  40. package/lib/tile/manager/tileLayerManager.js +12 -1
  41. package/lib/tile/models/tileModel.js +8 -8
  42. package/lib/tile/tileFactory/index.js +5 -0
  43. package/lib/tile/tileFactory/test.js +95 -0
  44. package/lib/tile/tileFactory/vectorLayer.js +2 -2
  45. package/lib/tile/tileTest.js +75 -0
  46. package/lib/tile/utils.js +1 -1
  47. package/package.json +6 -7
@@ -0,0 +1,613 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.TextTriangulation = TextTriangulation;
9
+ exports.default = void 0;
10
+
11
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
+
13
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
+
15
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
16
+
17
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
18
+
19
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
20
+
21
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
22
+
23
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
24
+
25
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
26
+
27
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
28
+
29
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
30
+
31
+ var _l7Core = require("@antv/l7-core");
32
+
33
+ var _l7Utils = require("@antv/l7-utils");
34
+
35
+ var _lodash = require("lodash");
36
+
37
+ var _BaseModel2 = _interopRequireDefault(require("../../core/BaseModel"));
38
+
39
+ var _collisionIndex = _interopRequireDefault(require("../../utils/collision-index"));
40
+
41
+ var _symbolLayout = require("../../utils/symbol-layout");
42
+
43
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
44
+
45
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
46
+
47
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
48
+
49
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
50
+
51
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
52
+
53
+ /* babel-plugin-inline-import '../shaders/text_frag.glsl' */
54
+ var textFrag = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 48.0\nuniform sampler2D u_sdf_map;\nuniform float u_gamma_scale : 0.5;\n// uniform float u_font_size : 24.0;\nuniform float u_opacity : 1.0;\nuniform vec4 u_stroke_color : [0, 0, 0, 1];\nuniform float u_stroke_width : 2.0;\nuniform float u_halo_blur : 0.5;\nuniform float u_DevicePixelRatio;\n\nvarying vec4 v_color;\nvarying vec2 v_uv;\nvarying float v_gamma_scale;\nvarying float v_fontScale;\n\nvarying mat4 styleMappingMat; // \u4F20\u9012\u4ECE\u7247\u5143\u4E2D\u4F20\u9012\u7684\u6620\u5C04\u6570\u636E\n\n#pragma include \"picking\"\nvoid main() {\n // get style data mapping\n float opacity = styleMappingMat[0][0];\n float strokeWidth = styleMappingMat[0][2];\n vec4 textrueStroke = vec4(\n styleMappingMat[1][0],\n styleMappingMat[1][1],\n styleMappingMat[1][2],\n styleMappingMat[1][3]\n );\n\n // get sdf from atlas\n float dist = texture2D(u_sdf_map, v_uv).a;\n\n // float fontScale = u_font_size / FONT_SIZE;\n\n // lowp float buff = (6.0 - u_stroke_width / v_fontScale) / SDF_PX;\n lowp float buff = (6.0 - strokeWidth / 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 // gl_FragColor = mix(vec4(v_color.rgb, v_color.a * u_opacity), vec4(u_stroke_color.rgb, u_stroke_color.a * u_opacity), smoothstep(0., 0.5, 1. - dist));\n gl_FragColor = mix(vec4(v_color.rgb, v_color.a * opacity), vec4(textrueStroke.rgb, textrueStroke.a * opacity), smoothstep(0., 0.5, 1. - dist));\n gl_FragColor.a= gl_FragColor.a * alpha;\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
55
+
56
+ /* babel-plugin-inline-import '../shaders/text_vert.glsl' */
57
+ var textVert = "#define SDF_PX 8.0\n#define EDGE_GAMMA 0.105\n#define FONT_SIZE 24.0\nattribute vec3 a_Position;\nattribute vec2 a_tex;\nattribute vec2 a_textOffsets;\nattribute vec4 a_Color;\nattribute float a_Size;\nattribute float a_Rotate;\n\nuniform vec2 u_sdf_map_size;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\nuniform float u_raisingHeight: 0.0;\n\nvarying vec2 v_uv;\nvarying float v_gamma_scale;\nvarying vec4 v_color;\nvarying float v_fontScale;\n\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\nuniform float u_opacity : 1;\nuniform float u_stroke_width : 2;\nuniform vec4 u_stroke_color : [0.0, 0.0, 0.0, 0.0];\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n#pragma include \"styleMappingCalStrokeWidth\"\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - strokeWidth - empty\n 0.0, 0.0, 0.0, 0.0, // strokeR - strokeG - strokeB - strokeA\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]\n 0.0, 0.0, 0.0, 0.0\n );\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n\n vec2 strokeWidthAndOffset = calStrokeWidthAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][2] = strokeWidthAndOffset.r;\n textureOffset = strokeWidthAndOffset.g;\n\n vec4 textrueStroke = vec4(-1.0, -1.0, -1.0, -1.0);\n if(hasStroke()) {\n vec2 valueRPos = nextPos(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset);\n styleMappingMat[1][0] = pos2value(valueRPos, columnWidth, rowHeight); // R\n textureOffset += 1.0;\n\n vec2 valueGPos = nextPos(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset);\n styleMappingMat[1][1] = pos2value(valueGPos, columnWidth, rowHeight); // G\n textureOffset += 1.0;\n\n vec2 valueBPos = nextPos(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset);\n styleMappingMat[1][2] = pos2value(valueBPos, columnWidth, rowHeight); // B\n textureOffset += 1.0;\n\n vec2 valueAPos = nextPos(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset);\n styleMappingMat[1][3] = pos2value(valueAPos, columnWidth, rowHeight); // A\n textureOffset += 1.0;\n } else {\n if(u_stroke_color == vec4(0.0)) {\n styleMappingMat[1][0] = v_color.r;\n styleMappingMat[1][1] = v_color.g;\n styleMappingMat[1][2] = v_color.b;\n styleMappingMat[1][3] = v_color.a;\n } else {\n styleMappingMat[1][0] = u_stroke_color.r;\n styleMappingMat[1][1] = u_stroke_color.g;\n styleMappingMat[1][2] = u_stroke_color.b;\n styleMappingMat[1][3] = u_stroke_color.a;\n }\n }\n \n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n v_color = a_Color;\n v_uv = a_tex / u_sdf_map_size;\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));\n // vec4 projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n highp float angle_sin = sin(a_Rotate);\n highp float angle_cos = cos(a_Rotate);\n mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);\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;\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n projected_position = u_Mvp * (vec4(a_Position.xyz + vec3(0.0, 0.0, raiseHeight), 1.0));\n } else { // else\n projected_position = project_common_position_to_clipspace(vec4(project_pos.xyz + vec3(0.0, 0.0, raiseHeight), 1.0));\n }\n\n gl_Position = vec4(\n projected_position.xy / projected_position.w + rotation_matrix * a_textOffsets * 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";
58
+
59
+ function TextTriangulation(feature) {
60
+ // @ts-ignore
61
+ var that = this;
62
+ var id = feature.id;
63
+ var vertices = [];
64
+ var indices = [];
65
+
66
+ if (!that.glyphInfoMap || !that.glyphInfoMap[id]) {
67
+ return {
68
+ vertices: [],
69
+ // [ x, y, z, tex.x,tex.y, offset.x. offset.y]
70
+ indices: [],
71
+ size: 7
72
+ };
73
+ }
74
+
75
+ var centroid = that.glyphInfoMap[id].centroid; // 计算中心点
76
+
77
+ var coord = centroid.length === 2 ? [centroid[0], centroid[1], 0] : centroid;
78
+ that.glyphInfoMap[id].glyphQuads.forEach(function (quad, index) {
79
+ vertices.push.apply(vertices, (0, _toConsumableArray2.default)(coord).concat([quad.tex.x, quad.tex.y + quad.tex.height, quad.tl.x, quad.tl.y], (0, _toConsumableArray2.default)(coord), [quad.tex.x + quad.tex.width, quad.tex.y + quad.tex.height, quad.tr.x, quad.tr.y], (0, _toConsumableArray2.default)(coord), [quad.tex.x + quad.tex.width, quad.tex.y, quad.br.x, quad.br.y], (0, _toConsumableArray2.default)(coord), [quad.tex.x, quad.tex.y, quad.bl.x, quad.bl.y]));
80
+ indices.push(0 + index * 4, 1 + index * 4, 2 + index * 4, 2 + index * 4, 3 + index * 4, 0 + index * 4);
81
+ });
82
+ return {
83
+ vertices: vertices,
84
+ // [ x, y, z, tex.x,tex.y, offset.x. offset.y]
85
+ indices: indices,
86
+ size: 7
87
+ };
88
+ }
89
+
90
+ var TextModel = /*#__PURE__*/function (_BaseModel) {
91
+ (0, _inherits2.default)(TextModel, _BaseModel);
92
+
93
+ var _super = _createSuper(TextModel);
94
+
95
+ function TextModel() {
96
+ var _this;
97
+
98
+ (0, _classCallCheck2.default)(this, TextModel);
99
+
100
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
101
+ args[_key] = arguments[_key];
102
+ }
103
+
104
+ _this = _super.call.apply(_super, [this].concat(args));
105
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "glyphInfoMap", {});
106
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "currentZoom", -1);
107
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "textureHeight", 0);
108
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "textCount", 0);
109
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "preTextStyle", {});
110
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "buildModels", /*#__PURE__*/function () {
111
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(callbackModel) {
112
+ var _ref2, _ref2$mask, mask, _ref2$maskInside, maskInside;
113
+
114
+ return _regenerator.default.wrap(function _callee$(_context) {
115
+ while (1) {
116
+ switch (_context.prev = _context.next) {
117
+ case 0:
118
+ _ref2 = _this.layer.getLayerConfig(), _ref2$mask = _ref2.mask, mask = _ref2$mask === void 0 ? false : _ref2$mask, _ref2$maskInside = _ref2.maskInside, maskInside = _ref2$maskInside === void 0 ? true : _ref2$maskInside;
119
+
120
+ _this.mapping();
121
+
122
+ _this.layer.buildLayerModel({
123
+ moduleName: 'pointText',
124
+ vertexShader: textVert,
125
+ fragmentShader: textFrag,
126
+ triangulation: TextTriangulation.bind((0, _assertThisInitialized2.default)(_this)),
127
+ depth: {
128
+ enable: false
129
+ },
130
+ blend: _this.getBlend(),
131
+ stencil: (0, _l7Utils.getMask)(mask, maskInside)
132
+ }).then(function (model) {
133
+ callbackModel([model]);
134
+ }).catch(function (err) {
135
+ console.warn(err);
136
+ callbackModel([]);
137
+ });
138
+
139
+ case 3:
140
+ case "end":
141
+ return _context.stop();
142
+ }
143
+ }
144
+ }, _callee);
145
+ }));
146
+
147
+ return function (_x) {
148
+ return _ref.apply(this, arguments);
149
+ };
150
+ }());
151
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "mapping", function () {
152
+ _this.initGlyph();
153
+
154
+ _this.updateTexture();
155
+
156
+ _this.filterGlyphs();
157
+
158
+ _this.reBuildModel();
159
+ });
160
+ return _this;
161
+ }
162
+
163
+ (0, _createClass2.default)(TextModel, [{
164
+ key: "getUninforms",
165
+ value: function getUninforms() {
166
+ var _ref3 = this.layer.getLayerConfig(),
167
+ _ref3$opacity = _ref3.opacity,
168
+ opacity = _ref3$opacity === void 0 ? 1.0 : _ref3$opacity,
169
+ _ref3$stroke = _ref3.stroke,
170
+ stroke = _ref3$stroke === void 0 ? '#fff' : _ref3$stroke,
171
+ _ref3$strokeWidth = _ref3.strokeWidth,
172
+ strokeWidth = _ref3$strokeWidth === void 0 ? 0 : _ref3$strokeWidth,
173
+ _ref3$textAnchor = _ref3.textAnchor,
174
+ textAnchor = _ref3$textAnchor === void 0 ? 'center' : _ref3$textAnchor,
175
+ _ref3$textAllowOverla = _ref3.textAllowOverlap,
176
+ textAllowOverlap = _ref3$textAllowOverla === void 0 ? false : _ref3$textAllowOverla,
177
+ _ref3$halo = _ref3.halo,
178
+ halo = _ref3$halo === void 0 ? 0.5 : _ref3$halo,
179
+ _ref3$gamma = _ref3.gamma,
180
+ gamma = _ref3$gamma === void 0 ? 2.0 : _ref3$gamma,
181
+ _ref3$raisingHeight = _ref3.raisingHeight,
182
+ raisingHeight = _ref3$raisingHeight === void 0 ? 0 : _ref3$raisingHeight;
183
+
184
+ var _this$fontService = this.fontService,
185
+ canvas = _this$fontService.canvas,
186
+ mapping = _this$fontService.mapping;
187
+
188
+ if (Object.keys(mapping).length !== this.textCount) {
189
+ this.updateTexture();
190
+ this.textCount = Object.keys(mapping).length;
191
+ }
192
+
193
+ this.preTextStyle = {
194
+ textAnchor: textAnchor,
195
+ textAllowOverlap: textAllowOverlap
196
+ };
197
+
198
+ if (this.dataTextureTest && this.dataTextureNeedUpdate({
199
+ opacity: opacity,
200
+ strokeWidth: strokeWidth,
201
+ stroke: stroke
202
+ })) {
203
+ this.judgeStyleAttributes({
204
+ opacity: opacity,
205
+ strokeWidth: strokeWidth,
206
+ stroke: stroke
207
+ });
208
+ var encodeData = this.layer.getEncodedData();
209
+
210
+ var _this$calDataFrame = this.calDataFrame(this.cellLength, encodeData, this.cellProperties),
211
+ data = _this$calDataFrame.data,
212
+ width = _this$calDataFrame.width,
213
+ height = _this$calDataFrame.height;
214
+
215
+ this.rowCount = height; // 当前数据纹理有多少行
216
+
217
+ this.dataTexture = this.cellLength > 0 && data.length > 0 ? this.createTexture2D({
218
+ flipY: true,
219
+ data: data,
220
+ format: _l7Core.gl.LUMINANCE,
221
+ type: _l7Core.gl.FLOAT,
222
+ width: width,
223
+ height: height
224
+ }) : this.createTexture2D({
225
+ flipY: true,
226
+ data: [1],
227
+ format: _l7Core.gl.LUMINANCE,
228
+ type: _l7Core.gl.FLOAT,
229
+ width: 1,
230
+ height: 1
231
+ });
232
+ }
233
+
234
+ return {
235
+ u_dataTexture: this.dataTexture,
236
+ // 数据纹理 - 有数据映射的时候纹理中带数据,若没有任何数据映射时纹理是 [1]
237
+ u_cellTypeLayout: this.getCellTypeLayout(),
238
+ u_raisingHeight: Number(raisingHeight),
239
+ u_opacity: (0, _lodash.isNumber)(opacity) ? opacity : 1.0,
240
+ u_stroke_width: (0, _lodash.isNumber)(strokeWidth) ? strokeWidth : 1.0,
241
+ u_stroke_color: this.getStrokeColor(stroke),
242
+ u_sdf_map: this.texture,
243
+ u_halo_blur: halo,
244
+ u_gamma_scale: gamma,
245
+ u_sdf_map_size: [canvas.width, canvas.height]
246
+ };
247
+ }
248
+ }, {
249
+ key: "initModels",
250
+ value: function initModels(callbackModel) {
251
+ this.layer.on('remapping', this.mapping);
252
+ this.extent = this.textExtent();
253
+
254
+ var _ref4 = this.layer.getLayerConfig(),
255
+ _ref4$textAnchor = _ref4.textAnchor,
256
+ textAnchor = _ref4$textAnchor === void 0 ? 'center' : _ref4$textAnchor,
257
+ _ref4$textAllowOverla = _ref4.textAllowOverlap,
258
+ textAllowOverlap = _ref4$textAllowOverla === void 0 ? true : _ref4$textAllowOverla;
259
+
260
+ this.preTextStyle = {
261
+ textAnchor: textAnchor,
262
+ textAllowOverlap: textAllowOverlap
263
+ };
264
+ this.buildModels(callbackModel);
265
+ }
266
+ }, {
267
+ key: "clearModels",
268
+ value: function clearModels() {
269
+ var _this$texture, _this$dataTexture;
270
+
271
+ (_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy();
272
+ (_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy();
273
+ this.layer.off('remapping', this.mapping);
274
+ }
275
+ }, {
276
+ key: "registerBuiltinAttributes",
277
+ value: function registerBuiltinAttributes() {
278
+ this.styleAttributeService.registerStyleAttribute({
279
+ name: 'rotate',
280
+ type: _l7Core.AttributeType.Attribute,
281
+ descriptor: {
282
+ name: 'a_Rotate',
283
+ buffer: {
284
+ usage: _l7Core.gl.DYNAMIC_DRAW,
285
+ data: [],
286
+ type: _l7Core.gl.FLOAT
287
+ },
288
+ size: 1,
289
+ update: function update(feature, featureIdx, vertex, attributeIdx) {
290
+ var _feature$rotate = feature.rotate,
291
+ rotate = _feature$rotate === void 0 ? 0 : _feature$rotate;
292
+ return Array.isArray(rotate) ? [rotate[0]] : [rotate];
293
+ }
294
+ }
295
+ });
296
+ this.styleAttributeService.registerStyleAttribute({
297
+ name: 'textOffsets',
298
+ type: _l7Core.AttributeType.Attribute,
299
+ descriptor: {
300
+ name: 'a_textOffsets',
301
+ buffer: {
302
+ // give the WebGL driver a hint that this buffer may change
303
+ usage: _l7Core.gl.STATIC_DRAW,
304
+ data: [],
305
+ type: _l7Core.gl.FLOAT
306
+ },
307
+ size: 2,
308
+ update: function update(feature, featureIdx, vertex, attributeIdx) {
309
+ return [vertex[5], vertex[6]];
310
+ }
311
+ }
312
+ }); // point layer size;
313
+
314
+ this.styleAttributeService.registerStyleAttribute({
315
+ name: 'size',
316
+ type: _l7Core.AttributeType.Attribute,
317
+ descriptor: {
318
+ name: 'a_Size',
319
+ buffer: {
320
+ // give the WebGL driver a hint that this buffer may change
321
+ usage: _l7Core.gl.DYNAMIC_DRAW,
322
+ data: [],
323
+ type: _l7Core.gl.FLOAT
324
+ },
325
+ size: 1,
326
+ update: function update(feature, featureIdx, vertex, attributeIdx) {
327
+ var _feature$size = feature.size,
328
+ size = _feature$size === void 0 ? 12 : _feature$size;
329
+ return Array.isArray(size) ? [size[0]] : [size];
330
+ }
331
+ }
332
+ }); // point layer size;
333
+
334
+ this.styleAttributeService.registerStyleAttribute({
335
+ name: 'textUv',
336
+ type: _l7Core.AttributeType.Attribute,
337
+ descriptor: {
338
+ name: 'a_tex',
339
+ buffer: {
340
+ // give the WebGL driver a hint that this buffer may change
341
+ usage: _l7Core.gl.DYNAMIC_DRAW,
342
+ data: [],
343
+ type: _l7Core.gl.FLOAT
344
+ },
345
+ size: 2,
346
+ update: function update(feature, featureIdx, vertex, attributeIdx) {
347
+ return [vertex[3], vertex[4]];
348
+ }
349
+ }
350
+ });
351
+ }
352
+ }, {
353
+ key: "textExtent",
354
+ value: function textExtent() {
355
+ var bounds = this.mapService.getBounds();
356
+ return (0, _l7Utils.padBounds)(bounds, 0.5);
357
+ }
358
+ /**
359
+ * 生成文字纹理(生成文字纹理字典)
360
+ */
361
+
362
+ }, {
363
+ key: "initTextFont",
364
+ value: function initTextFont() {
365
+ var _ref5 = this.layer.getLayerConfig(),
366
+ _ref5$fontWeight = _ref5.fontWeight,
367
+ fontWeight = _ref5$fontWeight === void 0 ? '400' : _ref5$fontWeight,
368
+ _ref5$fontFamily = _ref5.fontFamily,
369
+ fontFamily = _ref5$fontFamily === void 0 ? 'sans-serif' : _ref5$fontFamily;
370
+
371
+ var data = this.layer.getEncodedData();
372
+ var characterSet = [];
373
+ data.forEach(function (item) {
374
+ var _item$shape = item.shape,
375
+ shape = _item$shape === void 0 ? '' : _item$shape;
376
+ shape = shape.toString();
377
+
378
+ var _iterator = _createForOfIteratorHelper(shape),
379
+ _step;
380
+
381
+ try {
382
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
383
+ var char = _step.value;
384
+
385
+ // 去重
386
+ if (characterSet.indexOf(char) === -1) {
387
+ characterSet.push(char);
388
+ }
389
+ }
390
+ } catch (err) {
391
+ _iterator.e(err);
392
+ } finally {
393
+ _iterator.f();
394
+ }
395
+ });
396
+ this.fontService.setFontOptions({
397
+ characterSet: characterSet,
398
+ fontWeight: fontWeight,
399
+ fontFamily: fontFamily,
400
+ iconfont: false
401
+ });
402
+ }
403
+ /**
404
+ * 生成 iconfont 纹理字典
405
+ */
406
+
407
+ }, {
408
+ key: "initIconFontTex",
409
+ value: function initIconFontTex() {
410
+ var _ref6 = this.layer.getLayerConfig(),
411
+ _ref6$fontWeight = _ref6.fontWeight,
412
+ fontWeight = _ref6$fontWeight === void 0 ? '400' : _ref6$fontWeight,
413
+ _ref6$fontFamily = _ref6.fontFamily,
414
+ fontFamily = _ref6$fontFamily === void 0 ? 'sans-serif' : _ref6$fontFamily;
415
+
416
+ var data = this.layer.getEncodedData();
417
+ var characterSet = [];
418
+ data.forEach(function (item) {
419
+ var _item$shape2 = item.shape,
420
+ shape = _item$shape2 === void 0 ? '' : _item$shape2;
421
+ shape = "".concat(shape);
422
+
423
+ if (characterSet.indexOf(shape) === -1) {
424
+ characterSet.push(shape);
425
+ }
426
+ });
427
+ this.fontService.setFontOptions({
428
+ characterSet: characterSet,
429
+ fontWeight: fontWeight,
430
+ fontFamily: fontFamily,
431
+ iconfont: true
432
+ });
433
+ }
434
+ /**
435
+ * 生成文字布局(对照文字纹理字典提取对应文字的位置很好信息)
436
+ */
437
+
438
+ }, {
439
+ key: "generateGlyphLayout",
440
+ value: function generateGlyphLayout(iconfont) {
441
+ var _this2 = this;
442
+
443
+ // TODO:更新文字布局
444
+ var mapping = this.fontService.mapping;
445
+
446
+ var _ref7 = this.layer.getLayerConfig(),
447
+ _ref7$spacing = _ref7.spacing,
448
+ spacing = _ref7$spacing === void 0 ? 2 : _ref7$spacing,
449
+ _ref7$textAnchor = _ref7.textAnchor,
450
+ textAnchor = _ref7$textAnchor === void 0 ? 'center' : _ref7$textAnchor;
451
+
452
+ var data = this.layer.getEncodedData();
453
+ this.glyphInfo = data.map(function (feature) {
454
+ var _feature$shape = feature.shape,
455
+ shape = _feature$shape === void 0 ? '' : _feature$shape,
456
+ id = feature.id,
457
+ _feature$size2 = feature.size,
458
+ size = _feature$size2 === void 0 ? 1 : _feature$size2,
459
+ _feature$textOffset = feature.textOffset,
460
+ textOffset = _feature$textOffset === void 0 ? [0, 0] : _feature$textOffset;
461
+ var shaping = (0, _symbolLayout.shapeText)(shape.toString(), mapping, // @ts-ignore
462
+ size, textAnchor, 'left', spacing, textOffset, iconfont);
463
+ var glyphQuads = (0, _symbolLayout.getGlyphQuads)(shaping, textOffset, false);
464
+ feature.shaping = shaping;
465
+ feature.glyphQuads = glyphQuads;
466
+ feature.centroid = (0, _l7Utils.calculateCentroid)(feature.coordinates); // 此时地图高德2.0 originCentroid == centroid
467
+
468
+ feature.originCentroid = feature.version === 'GAODE2.x' ? (0, _l7Utils.calculateCentroid)(feature.originCoordinates) : feature.originCentroid = feature.centroid;
469
+ _this2.glyphInfoMap[id] = {
470
+ shaping: shaping,
471
+ glyphQuads: glyphQuads,
472
+ centroid: (0, _l7Utils.calculateCentroid)(feature.coordinates)
473
+ };
474
+ return feature;
475
+ });
476
+ }
477
+ /**
478
+ * 文字避让 depend on originCentorid
479
+ */
480
+
481
+ }, {
482
+ key: "filterGlyphs",
483
+ value: function filterGlyphs() {
484
+ var _this3 = this;
485
+
486
+ var _ref8 = this.layer.getLayerConfig(),
487
+ _ref8$padding = _ref8.padding,
488
+ padding = _ref8$padding === void 0 ? [4, 4] : _ref8$padding,
489
+ _ref8$textAllowOverla = _ref8.textAllowOverlap,
490
+ textAllowOverlap = _ref8$textAllowOverla === void 0 ? false : _ref8$textAllowOverla;
491
+
492
+ if (textAllowOverlap) {
493
+ // 如果允许文本覆盖
494
+ return;
495
+ }
496
+
497
+ this.glyphInfoMap = {};
498
+ this.currentZoom = this.mapService.getZoom();
499
+ this.extent = this.textExtent();
500
+
501
+ var _this$rendererService = this.rendererService.getViewportSize(),
502
+ width = _this$rendererService.width,
503
+ height = _this$rendererService.height;
504
+
505
+ var collisionIndex = new _collisionIndex.default(width, height);
506
+ var filterData = this.glyphInfo.filter(function (feature) {
507
+ var shaping = feature.shaping,
508
+ _feature$id = feature.id,
509
+ id = _feature$id === void 0 ? 0 : _feature$id;
510
+ var centroid = feature.version === 'GAODE2.x' ? feature.originCentroid : feature.centroid;
511
+ var size = feature.size;
512
+ var fontScale = size / 24;
513
+
514
+ var pixels = _this3.mapService.lngLatToContainer(centroid);
515
+
516
+ var _collisionIndex$place = collisionIndex.placeCollisionBox({
517
+ x1: shaping.left * fontScale - padding[0],
518
+ x2: shaping.right * fontScale + padding[0],
519
+ y1: shaping.top * fontScale - padding[1],
520
+ y2: shaping.bottom * fontScale + padding[1],
521
+ anchorPointX: pixels.x,
522
+ anchorPointY: pixels.y
523
+ }),
524
+ box = _collisionIndex$place.box;
525
+
526
+ if (box && box.length) {
527
+ // TODO:featureIndex
528
+ collisionIndex.insertCollisionBox(box, id);
529
+ return true;
530
+ } else {
531
+ return false;
532
+ }
533
+ });
534
+ filterData.forEach(function (item) {
535
+ // @ts-ignore
536
+ _this3.glyphInfoMap[item.id] = item;
537
+ });
538
+ }
539
+ /**
540
+ * 初始化文字布局
541
+ */
542
+
543
+ }, {
544
+ key: "initGlyph",
545
+ value: function initGlyph() {
546
+ var _this$layer$getLayerC = this.layer.getLayerConfig(),
547
+ _this$layer$getLayerC2 = _this$layer$getLayerC.iconfont,
548
+ iconfont = _this$layer$getLayerC2 === void 0 ? false : _this$layer$getLayerC2; // 1.生成文字纹理(或是生成 iconfont)
549
+
550
+
551
+ iconfont ? this.initIconFontTex() : this.initTextFont(); // 2.生成文字布局
552
+
553
+ this.generateGlyphLayout(iconfont);
554
+ }
555
+ /**
556
+ * 更新文字纹理
557
+ */
558
+
559
+ }, {
560
+ key: "updateTexture",
561
+ value: function updateTexture() {
562
+ var createTexture2D = this.rendererService.createTexture2D;
563
+ var canvas = this.fontService.canvas;
564
+ this.textureHeight = canvas.height;
565
+
566
+ if (this.texture) {
567
+ this.texture.destroy();
568
+ }
569
+
570
+ this.texture = createTexture2D({
571
+ data: canvas,
572
+ mag: _l7Core.gl.LINEAR,
573
+ min: _l7Core.gl.LINEAR,
574
+ width: canvas.width,
575
+ height: canvas.height
576
+ });
577
+ }
578
+ }, {
579
+ key: "reBuildModel",
580
+ value: function reBuildModel() {
581
+ var _this4 = this;
582
+
583
+ var _ref9 = this.layer.getLayerConfig(),
584
+ _ref9$mask = _ref9.mask,
585
+ mask = _ref9$mask === void 0 ? false : _ref9$mask,
586
+ _ref9$maskInside = _ref9.maskInside,
587
+ maskInside = _ref9$maskInside === void 0 ? true : _ref9$maskInside;
588
+
589
+ this.filterGlyphs();
590
+ this.layer.buildLayerModel({
591
+ moduleName: 'pointTileText',
592
+ vertexShader: textVert,
593
+ fragmentShader: textFrag,
594
+ triangulation: TextTriangulation.bind(this),
595
+ depth: {
596
+ enable: false
597
+ },
598
+ blend: this.getBlend(),
599
+ stencil: (0, _l7Utils.getMask)(mask, maskInside)
600
+ }).then(function (model) {
601
+ _this4.layer.models = [model];
602
+
603
+ _this4.layer.renderLayers();
604
+ }).catch(function (err) {
605
+ console.warn(err);
606
+ _this4.layer.models = [];
607
+ });
608
+ }
609
+ }]);
610
+ return TextModel;
611
+ }(_BaseModel2.default);
612
+
613
+ exports.default = TextModel;
@@ -204,7 +204,7 @@ var TileLayerManager = /*#__PURE__*/function () {
204
204
  shape: layerShape,
205
205
  zIndex: zIndex,
206
206
  opacity: opacity,
207
- sourceLayer: parentParserType === 'geojsonvt' ? 'geojsonvt' : sourceLayer,
207
+ sourceLayer: this.getSourceLayer(parentParserType, sourceLayer),
208
208
  coords: coords,
209
209
  featureId: featureId,
210
210
  color: colorValue,
@@ -228,6 +228,17 @@ var TileLayerManager = /*#__PURE__*/function () {
228
228
  pixelConstantRGB: pixelConstantRGB
229
229
  };
230
230
  }
231
+ }, {
232
+ key: "getSourceLayer",
233
+ value: function getSourceLayer(parentParserType, sourceLayer) {
234
+ if (parentParserType === 'geojsonvt') {
235
+ return 'geojsonvt';
236
+ } else if (parentParserType === 'testTile') {
237
+ return 'testTile';
238
+ } else {
239
+ return sourceLayer;
240
+ }
241
+ }
231
242
  }, {
232
243
  key: "setConfigListener",
233
244
  value: function setConfigListener() {
@@ -25,17 +25,17 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
25
25
 
26
26
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
27
27
 
28
- var RasterTileModel = /*#__PURE__*/function (_BaseModel) {
29
- (0, _inherits2.default)(RasterTileModel, _BaseModel);
28
+ var TileModel = /*#__PURE__*/function (_BaseModel) {
29
+ (0, _inherits2.default)(TileModel, _BaseModel);
30
30
 
31
- var _super = _createSuper(RasterTileModel);
31
+ var _super = _createSuper(TileModel);
32
32
 
33
- function RasterTileModel() {
34
- (0, _classCallCheck2.default)(this, RasterTileModel);
33
+ function TileModel() {
34
+ (0, _classCallCheck2.default)(this, TileModel);
35
35
  return _super.apply(this, arguments);
36
36
  }
37
37
 
38
- (0, _createClass2.default)(RasterTileModel, [{
38
+ (0, _createClass2.default)(TileModel, [{
39
39
  key: "getUninforms",
40
40
  value: function getUninforms() {
41
41
  return {};
@@ -68,7 +68,7 @@ var RasterTileModel = /*#__PURE__*/function (_BaseModel) {
68
68
  value: function registerBuiltinAttributes() {//
69
69
  }
70
70
  }]);
71
- return RasterTileModel;
71
+ return TileModel;
72
72
  }(_BaseModel2.default);
73
73
 
74
- exports.default = RasterTileModel;
74
+ exports.default = TileModel;