@antv/l7-layers 2.15.1 → 2.15.3
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.
- package/es/Geometry/index.js +9 -31
- package/es/Geometry/models/billboard.js +51 -89
- package/es/Geometry/models/plane.js +81 -143
- package/es/Geometry/models/sprite.js +60 -118
- package/es/canvas/index.js +10 -33
- package/es/canvas/models/canvas.js +41 -97
- package/es/citybuliding/building.js +8 -27
- package/es/citybuliding/models/build.js +57 -82
- package/es/core/BaseLayer.js +320 -484
- package/es/core/BaseModel.js +97 -126
- package/es/core/LayerPickService.js +21 -32
- package/es/core/TextureService.js +0 -13
- package/es/core/interface.js +17 -24
- package/es/core/shape/Path.js +13 -20
- package/es/core/shape/extrude.js +10 -31
- package/es/core/triangulation.js +54 -114
- package/es/earth/index.js +9 -33
- package/es/earth/models/atmosphere.js +30 -54
- package/es/earth/models/base.js +47 -85
- package/es/earth/models/bloomsphere.js +30 -54
- package/es/earth/utils.js +9 -13
- package/es/heatmap/index.js +10 -40
- package/es/heatmap/models/grid.js +28 -52
- package/es/heatmap/models/grid3d.js +28 -52
- package/es/heatmap/models/heatmap.js +91 -146
- package/es/heatmap/models/hexagon.js +28 -52
- package/es/heatmap/triangulation.js +0 -4
- package/es/image/index.js +9 -28
- package/es/image/models/image.js +66 -100
- package/es/index.js +9 -17
- package/es/line/index.js +9 -34
- package/es/line/models/arc.js +66 -118
- package/es/line/models/arc_3d.js +60 -108
- package/es/line/models/earthArc_3d.js +63 -111
- package/es/line/models/great_circle.js +56 -100
- package/es/line/models/half.js +46 -77
- package/es/line/models/line.js +94 -148
- package/es/line/models/linearline.js +45 -80
- package/es/line/models/simpleLine.js +41 -74
- package/es/line/models/wall.js +52 -92
- package/es/mask/index.js +9 -28
- package/es/mask/models/fill.js +29 -54
- package/es/plugins/DataMappingPlugin.js +80 -117
- package/es/plugins/DataSourcePlugin.js +45 -68
- package/es/plugins/FeatureScalePlugin.js +67 -122
- package/es/plugins/LayerAnimateStylePlugin.js +0 -5
- package/es/plugins/LayerMaskPlugin.js +3 -11
- package/es/plugins/LayerModelPlugin.js +67 -104
- package/es/plugins/LayerStylePlugin.js +3 -9
- package/es/plugins/LightingPlugin.js +12 -18
- package/es/plugins/MultiPassRendererPlugin.js +11 -16
- package/es/plugins/PixelPickingPlugin.js +12 -21
- package/es/plugins/RegisterStyleAttributePlugin.js +5 -12
- package/es/plugins/ShaderUniformPlugin.js +13 -27
- package/es/plugins/UpdateModelPlugin.js +0 -5
- package/es/plugins/UpdateStyleAttributePlugin.js +5 -11
- package/es/point/index.js +26 -77
- package/es/point/models/earthExtrude.js +61 -102
- package/es/point/models/earthFill.js +57 -87
- package/es/point/models/extrude.js +60 -101
- package/es/point/models/fill.js +70 -100
- package/es/point/models/fillmage.js +63 -107
- package/es/point/models/image.js +48 -88
- package/es/point/models/index.js +2 -2
- package/es/point/models/normal.js +30 -54
- package/es/point/models/radar.js +40 -64
- package/es/point/models/simplePoint.js +41 -69
- package/es/point/models/text.d.ts +2 -0
- package/es/point/models/text.js +214 -295
- package/es/point/shape/extrude.js +4 -13
- package/es/polygon/index.js +11 -40
- package/es/polygon/models/extrude.js +48 -92
- package/es/polygon/models/fill.js +54 -88
- package/es/polygon/models/index.js +3 -2
- package/es/polygon/models/ocean.js +42 -76
- package/es/polygon/models/water.js +37 -71
- package/es/raster/buffers/triangulation.js +2 -4
- package/es/raster/index.js +9 -32
- package/es/raster/models/raster.js +80 -116
- package/es/raster/models/rasterRgb.js +84 -127
- package/es/raster/models/rasterTerrainRgb.js +56 -84
- package/es/tile/interaction/getRasterData.js +14 -20
- package/es/tile/interaction/utils.js +7 -9
- package/es/tile/manager/base.js +63 -96
- package/es/tile/service/TileLayerService.js +30 -52
- package/es/tile/service/TilePickService.js +26 -40
- package/es/tile/service/TileSourceService.js +3 -7
- package/es/tile/tileFactory/DebugTile.js +28 -45
- package/es/tile/tileFactory/ImageTile.js +20 -38
- package/es/tile/tileFactory/MaskTile.js +22 -43
- package/es/tile/tileFactory/RasterRGBTile.js +22 -42
- package/es/tile/tileFactory/RasterTerrainRGBTile.js +20 -38
- package/es/tile/tileFactory/RasterTile.js +30 -53
- package/es/tile/tileFactory/Tile.js +63 -97
- package/es/tile/tileFactory/VectorTile.js +41 -68
- package/es/tile/tileFactory/index.js +0 -11
- package/es/tile/tileFactory/layers/TileDebugLayer.js +6 -27
- package/es/tile/tileFactory/util.js +0 -3
- package/es/tile/tileLayer/BaseLayer.js +105 -146
- package/es/tile/utils.js +1 -1
- package/es/utils/blend.js +0 -2
- package/es/utils/collision-index.js +9 -16
- package/es/utils/dataMappingStyle.js +8 -18
- package/es/utils/extrude_polyline.js +101 -149
- package/es/utils/grid-index.js +2 -27
- package/es/utils/identityScale.js +0 -8
- package/es/utils/layerData.js +30 -44
- package/es/utils/multiPassRender.js +11 -13
- package/es/utils/polylineNormal.js +31 -37
- package/es/utils/simpleLine.js +2 -16
- package/es/utils/stencil.js +2 -3
- package/es/utils/symbol-layout.js +27 -53
- package/es/wind/index.js +9 -29
- package/es/wind/models/utils.js +26 -51
- package/es/wind/models/wind.js +101 -147
- package/es/wind/models/windRender.js +53 -66
- package/lib/Geometry/index.js +9 -38
- package/lib/Geometry/models/billboard.js +51 -97
- package/lib/Geometry/models/index.js +0 -5
- package/lib/Geometry/models/plane.js +79 -151
- package/lib/Geometry/models/sprite.js +60 -127
- package/lib/canvas/index.js +10 -40
- package/lib/canvas/models/canvas.js +41 -101
- package/lib/canvas/models/index.js +0 -3
- package/lib/citybuliding/building.js +8 -35
- package/lib/citybuliding/models/build.js +57 -92
- package/lib/core/BaseLayer.js +320 -478
- package/lib/core/BaseModel.js +97 -139
- package/lib/core/LayerPickService.js +21 -37
- package/lib/core/TextureService.js +0 -16
- package/lib/core/interface.js +21 -31
- package/lib/core/schema.js +0 -1
- package/lib/core/shape/Path.js +14 -31
- package/lib/core/shape/extrude.js +10 -54
- package/lib/core/triangulation.js +53 -153
- package/lib/earth/index.js +9 -43
- package/lib/earth/models/atmosphere.js +30 -63
- package/lib/earth/models/base.js +47 -90
- package/lib/earth/models/bloomsphere.js +30 -63
- package/lib/earth/utils.js +7 -31
- package/lib/heatmap/index.js +10 -48
- package/lib/heatmap/models/grid.js +28 -60
- package/lib/heatmap/models/grid3d.js +28 -60
- package/lib/heatmap/models/heatmap.js +91 -162
- package/lib/heatmap/models/hexagon.js +28 -60
- package/lib/heatmap/models/index.js +0 -6
- package/lib/heatmap/triangulation.js +0 -5
- package/lib/image/index.js +9 -36
- package/lib/image/models/image.js +66 -109
- package/lib/image/models/index.js +0 -3
- package/lib/index.js +7 -61
- package/lib/line/index.js +9 -40
- package/lib/line/models/arc.js +64 -128
- package/lib/line/models/arc_3d.js +58 -119
- package/lib/line/models/earthArc_3d.js +61 -122
- package/lib/line/models/great_circle.js +56 -111
- package/lib/line/models/half.js +46 -87
- package/lib/line/models/index.js +0 -11
- package/lib/line/models/line.js +92 -156
- package/lib/line/models/linearline.js +45 -92
- package/lib/line/models/simpleLine.js +41 -84
- package/lib/line/models/wall.js +52 -103
- package/lib/mask/index.js +9 -36
- package/lib/mask/models/fill.js +29 -63
- package/lib/mask/models/index.js +0 -3
- package/lib/plugins/DataMappingPlugin.js +80 -128
- package/lib/plugins/DataSourcePlugin.js +45 -76
- package/lib/plugins/FeatureScalePlugin.js +67 -138
- package/lib/plugins/LayerAnimateStylePlugin.js +0 -10
- package/lib/plugins/LayerMaskPlugin.js +4 -17
- package/lib/plugins/LayerModelPlugin.js +68 -113
- package/lib/plugins/LayerStylePlugin.js +4 -14
- package/lib/plugins/LightingPlugin.js +12 -25
- package/lib/plugins/MultiPassRendererPlugin.js +11 -22
- package/lib/plugins/PixelPickingPlugin.js +12 -27
- package/lib/plugins/RegisterStyleAttributePlugin.js +5 -19
- package/lib/plugins/ShaderUniformPlugin.js +13 -34
- package/lib/plugins/UpdateModelPlugin.js +1 -10
- package/lib/plugins/UpdateStyleAttributePlugin.js +5 -16
- package/lib/point/index.js +26 -83
- package/lib/point/models/earthExtrude.js +61 -113
- package/lib/point/models/earthFill.js +57 -117
- package/lib/point/models/extrude.js +60 -111
- package/lib/point/models/fill.js +68 -109
- package/lib/point/models/fillmage.js +61 -115
- package/lib/point/models/image.js +48 -98
- package/lib/point/models/index.js +1 -12
- package/lib/point/models/normal.js +30 -64
- package/lib/point/models/radar.js +40 -74
- package/lib/point/models/simplePoint.js +41 -79
- package/lib/point/models/text.js +214 -303
- package/lib/point/shape/extrude.js +4 -20
- package/lib/polygon/index.js +11 -48
- package/lib/polygon/models/extrude.js +48 -103
- package/lib/polygon/models/fill.js +54 -98
- package/lib/polygon/models/index.js +2 -14
- package/lib/polygon/models/ocean.js +42 -88
- package/lib/polygon/models/water.js +37 -82
- package/lib/raster/buffers/triangulation.js +3 -7
- package/lib/raster/index.js +9 -40
- package/lib/raster/models/index.js +0 -5
- package/lib/raster/models/raster.js +80 -125
- package/lib/raster/models/rasterRgb.js +84 -139
- package/lib/raster/models/rasterTerrainRgb.js +56 -93
- package/lib/tile/interaction/getRasterData.js +14 -25
- package/lib/tile/interaction/utils.js +7 -19
- package/lib/tile/manager/base.js +63 -104
- package/lib/tile/service/TileLayerService.js +30 -57
- package/lib/tile/service/TilePickService.js +26 -48
- package/lib/tile/service/TileSourceService.js +2 -16
- package/lib/tile/style/utils.js +0 -3
- package/lib/tile/tileFactory/DebugTile.js +28 -53
- package/lib/tile/tileFactory/ImageTile.js +20 -46
- package/lib/tile/tileFactory/MaskTile.js +22 -51
- package/lib/tile/tileFactory/RasterRGBTile.js +22 -50
- package/lib/tile/tileFactory/RasterTerrainRGBTile.js +20 -46
- package/lib/tile/tileFactory/RasterTile.js +30 -63
- package/lib/tile/tileFactory/Tile.js +63 -102
- package/lib/tile/tileFactory/VectorTile.js +41 -76
- package/lib/tile/tileFactory/index.js +0 -25
- package/lib/tile/tileFactory/layers/TileDebugLayer.js +6 -32
- package/lib/tile/tileFactory/util.js +0 -9
- package/lib/tile/tileLayer/BaseLayer.js +105 -153
- package/lib/tile/utils.js +1 -5
- package/lib/utils/blend.js +0 -5
- package/lib/utils/collision-index.js +9 -25
- package/lib/utils/dataMappingStyle.js +8 -19
- package/lib/utils/extrude_polyline.js +101 -181
- package/lib/utils/grid-index.js +2 -28
- package/lib/utils/identityScale.js +0 -9
- package/lib/utils/layerData.js +30 -49
- package/lib/utils/multiPassRender.js +11 -16
- package/lib/utils/polylineNormal.js +31 -66
- package/lib/utils/simpleLine.js +2 -21
- package/lib/utils/stencil.js +0 -4
- package/lib/utils/symbol-layout.js +27 -55
- package/lib/wind/index.js +9 -37
- package/lib/wind/models/index.js +0 -3
- package/lib/wind/models/utils.js +26 -62
- package/lib/wind/models/wind.js +101 -157
- package/lib/wind/models/windRender.js +53 -71
- package/lib/wind/models/windShader.js +0 -1
- package/package.json +7 -7
package/es/point/models/text.js
CHANGED
|
@@ -7,29 +7,20 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConst
|
|
|
7
7
|
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
8
8
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
9
9
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
10
|
-
|
|
11
10
|
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; } } }; }
|
|
12
|
-
|
|
13
11
|
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); }
|
|
14
|
-
|
|
15
|
-
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; }
|
|
16
|
-
|
|
12
|
+
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; }
|
|
17
13
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
18
|
-
|
|
19
14
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
20
|
-
|
|
21
15
|
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; } }
|
|
22
|
-
|
|
23
16
|
import { AttributeType, gl } from '@antv/l7-core';
|
|
24
17
|
import { boundsContains, calculateCentroid, padBounds } from '@antv/l7-utils';
|
|
25
18
|
import { isEqual, isNumber } from 'lodash';
|
|
26
19
|
import BaseModel from "../../core/BaseModel";
|
|
27
20
|
import CollisionIndex from "../../utils/collision-index";
|
|
28
21
|
import { getGlyphQuads, shapeText } from "../../utils/symbol-layout";
|
|
29
|
-
|
|
30
22
|
/* babel-plugin-inline-import '../shaders/text_frag.glsl' */
|
|
31
23
|
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 // \u4F5C\u4E3A mask \u6A21\u677F\u65F6\u9700\u8981\u4E22\u5F03\u900F\u660E\u7684\u50CF\u7D20\n if (gl_FragColor.a < 0.01) {\n discard;\n }\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
|
|
32
|
-
|
|
33
24
|
/* babel-plugin-inline-import '../shaders/text_vert.glsl' */
|
|
34
25
|
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";
|
|
35
26
|
export function TextTriangulation(feature) {
|
|
@@ -38,7 +29,6 @@ export function TextTriangulation(feature) {
|
|
|
38
29
|
var id = feature.id;
|
|
39
30
|
var vertices = [];
|
|
40
31
|
var indices = [];
|
|
41
|
-
|
|
42
32
|
if (!that.glyphInfoMap || !that.glyphInfoMap[id]) {
|
|
43
33
|
return {
|
|
44
34
|
vertices: [],
|
|
@@ -47,9 +37,7 @@ export function TextTriangulation(feature) {
|
|
|
47
37
|
size: 7
|
|
48
38
|
};
|
|
49
39
|
}
|
|
50
|
-
|
|
51
40
|
var centroid = that.glyphInfoMap[id].centroid; // 计算中心点
|
|
52
|
-
|
|
53
41
|
var coord = centroid.length === 2 ? [centroid[0], centroid[1], 0] : centroid;
|
|
54
42
|
that.glyphInfoMap[id].glyphQuads.forEach(function (quad, index) {
|
|
55
43
|
vertices.push.apply(vertices, _toConsumableArray(coord).concat([quad.tex.x, quad.tex.y + quad.tex.height, quad.tl.x, quad.tl.y], _toConsumableArray(coord), [quad.tex.x + quad.tex.width, quad.tex.y + quad.tex.height, quad.tr.x, quad.tr.y], _toConsumableArray(coord), [quad.tex.x + quad.tex.width, quad.tex.y, quad.br.x, quad.br.y], _toConsumableArray(coord), [quad.tex.x, quad.tex.y, quad.bl.x, quad.bl.y]));
|
|
@@ -62,85 +50,60 @@ export function TextTriangulation(feature) {
|
|
|
62
50
|
size: 7
|
|
63
51
|
};
|
|
64
52
|
}
|
|
65
|
-
|
|
66
53
|
var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
67
54
|
_inherits(TextModel, _BaseModel);
|
|
68
|
-
|
|
69
55
|
var _super = _createSuper(TextModel);
|
|
70
|
-
|
|
71
56
|
function TextModel() {
|
|
72
57
|
var _this;
|
|
73
|
-
|
|
74
58
|
_classCallCheck(this, TextModel);
|
|
75
|
-
|
|
76
59
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
77
60
|
args[_key] = arguments[_key];
|
|
78
61
|
}
|
|
79
|
-
|
|
80
62
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
81
|
-
|
|
82
63
|
_defineProperty(_assertThisInitialized(_this), "glyphInfoMap", {});
|
|
83
|
-
|
|
84
64
|
_defineProperty(_assertThisInitialized(_this), "currentZoom", -1);
|
|
85
|
-
|
|
86
65
|
_defineProperty(_assertThisInitialized(_this), "textureHeight", 0);
|
|
87
|
-
|
|
88
66
|
_defineProperty(_assertThisInitialized(_this), "textCount", 0);
|
|
89
|
-
|
|
90
67
|
_defineProperty(_assertThisInitialized(_this), "preTextStyle", {});
|
|
91
|
-
|
|
92
68
|
_defineProperty(_assertThisInitialized(_this), "mapping", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
93
69
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
94
|
-
while (1) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return _this.reBuildModel();
|
|
104
|
-
|
|
105
|
-
case 4:
|
|
106
|
-
case "end":
|
|
107
|
-
return _context.stop();
|
|
108
|
-
}
|
|
70
|
+
while (1) switch (_context.prev = _context.next) {
|
|
71
|
+
case 0:
|
|
72
|
+
_this.initGlyph(); //
|
|
73
|
+
_this.updateTexture();
|
|
74
|
+
_context.next = 4;
|
|
75
|
+
return _this.reBuildModel();
|
|
76
|
+
case 4:
|
|
77
|
+
case "end":
|
|
78
|
+
return _context.stop();
|
|
109
79
|
}
|
|
110
80
|
}, _callee);
|
|
111
81
|
})));
|
|
112
|
-
|
|
113
82
|
return _this;
|
|
114
83
|
}
|
|
115
|
-
|
|
116
84
|
_createClass(TextModel, [{
|
|
117
85
|
key: "getUninforms",
|
|
118
86
|
value: function getUninforms() {
|
|
119
87
|
var _ref2 = this.layer.getLayerConfig(),
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
var
|
|
134
|
-
canvas = _this$fontService.canvas,
|
|
135
|
-
mapping = _this$fontService.mapping;
|
|
136
|
-
|
|
88
|
+
_ref2$opacity = _ref2.opacity,
|
|
89
|
+
opacity = _ref2$opacity === void 0 ? 1.0 : _ref2$opacity,
|
|
90
|
+
_ref2$stroke = _ref2.stroke,
|
|
91
|
+
stroke = _ref2$stroke === void 0 ? '#fff' : _ref2$stroke,
|
|
92
|
+
_ref2$strokeWidth = _ref2.strokeWidth,
|
|
93
|
+
strokeWidth = _ref2$strokeWidth === void 0 ? 0 : _ref2$strokeWidth,
|
|
94
|
+
_ref2$halo = _ref2.halo,
|
|
95
|
+
halo = _ref2$halo === void 0 ? 0.5 : _ref2$halo,
|
|
96
|
+
_ref2$gamma = _ref2.gamma,
|
|
97
|
+
gamma = _ref2$gamma === void 0 ? 2.0 : _ref2$gamma,
|
|
98
|
+
_ref2$raisingHeight = _ref2.raisingHeight,
|
|
99
|
+
raisingHeight = _ref2$raisingHeight === void 0 ? 0 : _ref2$raisingHeight;
|
|
100
|
+
var mapping = this.getFontServiceMapping();
|
|
101
|
+
var canvas = this.getFontServiceCanvas();
|
|
137
102
|
if (mapping && Object.keys(mapping).length !== this.textCount && canvas) {
|
|
138
103
|
this.updateTexture();
|
|
139
104
|
this.textCount = Object.keys(mapping).length;
|
|
140
105
|
}
|
|
141
|
-
|
|
142
106
|
this.preTextStyle = this.getTextStyle();
|
|
143
|
-
|
|
144
107
|
if (this.dataTextureTest && this.dataTextureNeedUpdate({
|
|
145
108
|
opacity: opacity,
|
|
146
109
|
strokeWidth: strokeWidth,
|
|
@@ -152,12 +115,10 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
152
115
|
stroke: stroke
|
|
153
116
|
});
|
|
154
117
|
var encodeData = this.layer.getEncodedData();
|
|
155
|
-
|
|
156
118
|
var _this$calDataFrame = this.calDataFrame(this.cellLength, encodeData, this.cellProperties),
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
119
|
+
data = _this$calDataFrame.data,
|
|
120
|
+
width = _this$calDataFrame.width,
|
|
121
|
+
height = _this$calDataFrame.height;
|
|
161
122
|
this.rowCount = height; // 当前数据纹理有多少行
|
|
162
123
|
|
|
163
124
|
this.dataTexture = this.cellLength > 0 && data.length > 0 ? this.createTexture2D({
|
|
@@ -176,7 +137,6 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
176
137
|
height: 1
|
|
177
138
|
});
|
|
178
139
|
}
|
|
179
|
-
|
|
180
140
|
return {
|
|
181
141
|
u_dataTexture: this.dataTexture,
|
|
182
142
|
// 数据纹理 - 有数据映射的时候纹理中带数据,若没有任何数据映射时纹理是 [1]
|
|
@@ -196,27 +156,22 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
196
156
|
value: function () {
|
|
197
157
|
var _initModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
198
158
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
199
|
-
while (1) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
case "end":
|
|
210
|
-
return _context2.stop();
|
|
211
|
-
}
|
|
159
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
160
|
+
case 0:
|
|
161
|
+
// 绑定事件
|
|
162
|
+
this.bindEvent();
|
|
163
|
+
this.extent = this.textExtent();
|
|
164
|
+
this.preTextStyle = this.getTextStyle();
|
|
165
|
+
return _context2.abrupt("return", this.buildModels());
|
|
166
|
+
case 4:
|
|
167
|
+
case "end":
|
|
168
|
+
return _context2.stop();
|
|
212
169
|
}
|
|
213
170
|
}, _callee2, this);
|
|
214
171
|
}));
|
|
215
|
-
|
|
216
172
|
function initModels() {
|
|
217
173
|
return _initModels.apply(this, arguments);
|
|
218
174
|
}
|
|
219
|
-
|
|
220
175
|
return initModels;
|
|
221
176
|
}()
|
|
222
177
|
}, {
|
|
@@ -224,48 +179,37 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
224
179
|
value: function () {
|
|
225
180
|
var _buildModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
226
181
|
var _ref3, _ref3$textAllowOverla, textAllowOverlap, model;
|
|
227
|
-
|
|
228
182
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
229
|
-
while (1) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
183
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
184
|
+
case 0:
|
|
185
|
+
_ref3 = this.layer.getLayerConfig(), _ref3$textAllowOverla = _ref3.textAllowOverlap, textAllowOverlap = _ref3$textAllowOverla === void 0 ? false : _ref3$textAllowOverla; // this.mapping(); 重复调用
|
|
186
|
+
this.initGlyph(); //
|
|
187
|
+
this.updateTexture();
|
|
188
|
+
if (!textAllowOverlap) {
|
|
189
|
+
this.filterGlyphs();
|
|
190
|
+
}
|
|
191
|
+
_context3.next = 6;
|
|
192
|
+
return this.layer.buildLayerModel({
|
|
193
|
+
moduleName: 'pointText',
|
|
194
|
+
vertexShader: textVert,
|
|
195
|
+
fragmentShader: textFrag,
|
|
196
|
+
triangulation: TextTriangulation.bind(this),
|
|
197
|
+
depth: {
|
|
198
|
+
enable: false
|
|
240
199
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
depth: {
|
|
249
|
-
enable: false
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
case 6:
|
|
254
|
-
model = _context3.sent;
|
|
255
|
-
return _context3.abrupt("return", [model]);
|
|
256
|
-
|
|
257
|
-
case 8:
|
|
258
|
-
case "end":
|
|
259
|
-
return _context3.stop();
|
|
260
|
-
}
|
|
200
|
+
});
|
|
201
|
+
case 6:
|
|
202
|
+
model = _context3.sent;
|
|
203
|
+
return _context3.abrupt("return", [model]);
|
|
204
|
+
case 8:
|
|
205
|
+
case "end":
|
|
206
|
+
return _context3.stop();
|
|
261
207
|
}
|
|
262
208
|
}, _callee3, this);
|
|
263
209
|
}));
|
|
264
|
-
|
|
265
210
|
function buildModels() {
|
|
266
211
|
return _buildModels.apply(this, arguments);
|
|
267
212
|
}
|
|
268
|
-
|
|
269
213
|
return buildModels;
|
|
270
214
|
}() // 需要更新的场景
|
|
271
215
|
// 1. 文本偏移量发生改变
|
|
@@ -273,80 +217,62 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
273
217
|
// 3. 文本允许重叠发生改变
|
|
274
218
|
// 4. 文本字体发生改变
|
|
275
219
|
// 5. 文本字体粗细发生改变
|
|
276
|
-
|
|
277
220
|
}, {
|
|
278
221
|
key: "needUpdate",
|
|
279
222
|
value: function () {
|
|
280
223
|
var _needUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
281
224
|
var _ref4, _ref4$textAllowOverla, textAllowOverlap, _ref4$textAnchor, textAnchor, textOffset, padding, fontFamily, fontWeight, zoom, extent, flag;
|
|
282
|
-
|
|
283
225
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
284
|
-
while (1) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
_context4.next = 13;
|
|
320
|
-
return this.reBuildModel();
|
|
321
|
-
|
|
322
|
-
case 13:
|
|
323
|
-
return _context4.abrupt("return", true);
|
|
324
|
-
|
|
325
|
-
case 14:
|
|
326
|
-
return _context4.abrupt("return", false);
|
|
327
|
-
|
|
328
|
-
case 15:
|
|
329
|
-
case "end":
|
|
330
|
-
return _context4.stop();
|
|
331
|
-
}
|
|
226
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
227
|
+
case 0:
|
|
228
|
+
_ref4 = this.getTextStyle(), _ref4$textAllowOverla = _ref4.textAllowOverlap, textAllowOverlap = _ref4$textAllowOverla === void 0 ? false : _ref4$textAllowOverla, _ref4$textAnchor = _ref4.textAnchor, textAnchor = _ref4$textAnchor === void 0 ? 'center' : _ref4$textAnchor, textOffset = _ref4.textOffset, padding = _ref4.padding, fontFamily = _ref4.fontFamily, fontWeight = _ref4.fontWeight;
|
|
229
|
+
if (!(!isEqual(padding, this.preTextStyle.padding) || !isEqual(textOffset, this.preTextStyle.textOffset) || !isEqual(textAnchor, this.preTextStyle.textAnchor) || !isEqual(fontFamily, this.preTextStyle.fontFamily) || !isEqual(fontWeight, this.preTextStyle.fontWeight))) {
|
|
230
|
+
_context4.next = 5;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
_context4.next = 4;
|
|
234
|
+
return this.mapping();
|
|
235
|
+
case 4:
|
|
236
|
+
return _context4.abrupt("return", true);
|
|
237
|
+
case 5:
|
|
238
|
+
if (!textAllowOverlap) {
|
|
239
|
+
_context4.next = 7;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
return _context4.abrupt("return", false);
|
|
243
|
+
case 7:
|
|
244
|
+
// textAllowOverlap 发生改变
|
|
245
|
+
zoom = this.mapService.getZoom();
|
|
246
|
+
extent = this.mapService.getBounds();
|
|
247
|
+
flag = boundsContains(this.extent, extent); // 文本不能压盖则进行过滤
|
|
248
|
+
if (!(Math.abs(this.currentZoom - zoom) > 0.5 || !flag || textAllowOverlap !== this.preTextStyle.textAllowOverlap)) {
|
|
249
|
+
_context4.next = 14;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
_context4.next = 13;
|
|
253
|
+
return this.reBuildModel();
|
|
254
|
+
case 13:
|
|
255
|
+
return _context4.abrupt("return", true);
|
|
256
|
+
case 14:
|
|
257
|
+
return _context4.abrupt("return", false);
|
|
258
|
+
case 15:
|
|
259
|
+
case "end":
|
|
260
|
+
return _context4.stop();
|
|
332
261
|
}
|
|
333
262
|
}, _callee4, this);
|
|
334
263
|
}));
|
|
335
|
-
|
|
336
264
|
function needUpdate() {
|
|
337
265
|
return _needUpdate.apply(this, arguments);
|
|
338
266
|
}
|
|
339
|
-
|
|
340
267
|
return needUpdate;
|
|
341
268
|
}()
|
|
342
269
|
}, {
|
|
343
270
|
key: "clearModels",
|
|
344
271
|
value: function clearModels() {
|
|
345
272
|
var _this$texture, _this$dataTexture;
|
|
346
|
-
|
|
347
273
|
(_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy();
|
|
348
|
-
(_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy();
|
|
349
|
-
|
|
274
|
+
(_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy();
|
|
275
|
+
// TODO this.mapping
|
|
350
276
|
this.layer.off('remapping', this.mapping);
|
|
351
277
|
}
|
|
352
278
|
}, {
|
|
@@ -365,7 +291,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
365
291
|
size: 1,
|
|
366
292
|
update: function update(feature) {
|
|
367
293
|
var _feature$rotate = feature.rotate,
|
|
368
|
-
|
|
294
|
+
rotate = _feature$rotate === void 0 ? 0 : _feature$rotate;
|
|
369
295
|
return Array.isArray(rotate) ? [rotate[0]] : [rotate];
|
|
370
296
|
}
|
|
371
297
|
}
|
|
@@ -386,8 +312,9 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
386
312
|
return [vertex[5], vertex[6]];
|
|
387
313
|
}
|
|
388
314
|
}
|
|
389
|
-
});
|
|
315
|
+
});
|
|
390
316
|
|
|
317
|
+
// point layer size;
|
|
391
318
|
this.styleAttributeService.registerStyleAttribute({
|
|
392
319
|
name: 'size',
|
|
393
320
|
type: AttributeType.Attribute,
|
|
@@ -402,7 +329,7 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
402
329
|
size: 1,
|
|
403
330
|
update: function update(feature) {
|
|
404
331
|
var _feature$size = feature.size,
|
|
405
|
-
|
|
332
|
+
size = _feature$size === void 0 ? 12 : _feature$size;
|
|
406
333
|
return Array.isArray(size) ? [size[0]] : [size];
|
|
407
334
|
}
|
|
408
335
|
}
|
|
@@ -441,28 +368,23 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
441
368
|
/**
|
|
442
369
|
* 生成文字纹理(生成文字纹理字典)
|
|
443
370
|
*/
|
|
444
|
-
|
|
445
371
|
}, {
|
|
446
372
|
key: "initTextFont",
|
|
447
373
|
value: function initTextFont() {
|
|
448
374
|
var _this$getTextStyle = this.getTextStyle(),
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
375
|
+
fontWeight = _this$getTextStyle.fontWeight,
|
|
376
|
+
fontFamily = _this$getTextStyle.fontFamily;
|
|
452
377
|
var data = this.layer.getEncodedData();
|
|
453
378
|
var characterSet = [];
|
|
454
379
|
data.forEach(function (item) {
|
|
455
380
|
var _item$shape = item.shape,
|
|
456
|
-
|
|
381
|
+
shape = _item$shape === void 0 ? '' : _item$shape;
|
|
457
382
|
shape = shape.toString();
|
|
458
|
-
|
|
459
383
|
var _iterator = _createForOfIteratorHelper(shape),
|
|
460
|
-
|
|
461
|
-
|
|
384
|
+
_step;
|
|
462
385
|
try {
|
|
463
386
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
464
387
|
var char = _step.value;
|
|
465
|
-
|
|
466
388
|
// 去重
|
|
467
389
|
if (characterSet.indexOf(char) === -1) {
|
|
468
390
|
characterSet.push(char);
|
|
@@ -481,24 +403,22 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
481
403
|
iconfont: false
|
|
482
404
|
});
|
|
483
405
|
}
|
|
406
|
+
|
|
484
407
|
/**
|
|
485
408
|
* 生成 iconfont 纹理字典
|
|
486
409
|
*/
|
|
487
|
-
|
|
488
410
|
}, {
|
|
489
411
|
key: "initIconFontTex",
|
|
490
412
|
value: function initIconFontTex() {
|
|
491
413
|
var _this$getTextStyle2 = this.getTextStyle(),
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
414
|
+
fontWeight = _this$getTextStyle2.fontWeight,
|
|
415
|
+
fontFamily = _this$getTextStyle2.fontFamily;
|
|
495
416
|
var data = this.layer.getEncodedData();
|
|
496
417
|
var characterSet = [];
|
|
497
418
|
data.forEach(function (item) {
|
|
498
419
|
var _item$shape2 = item.shape,
|
|
499
|
-
|
|
420
|
+
shape = _item$shape2 === void 0 ? '' : _item$shape2;
|
|
500
421
|
shape = "".concat(shape);
|
|
501
|
-
|
|
502
422
|
if (characterSet.indexOf(shape) === -1) {
|
|
503
423
|
characterSet.push(shape);
|
|
504
424
|
}
|
|
@@ -514,27 +434,26 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
514
434
|
key: "getTextStyle",
|
|
515
435
|
value: function getTextStyle() {
|
|
516
436
|
var _ref5 = this.layer.getLayerConfig(),
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
437
|
+
_ref5$fontWeight = _ref5.fontWeight,
|
|
438
|
+
fontWeight = _ref5$fontWeight === void 0 ? '400' : _ref5$fontWeight,
|
|
439
|
+
_ref5$fontFamily = _ref5.fontFamily,
|
|
440
|
+
fontFamily = _ref5$fontFamily === void 0 ? 'sans-serif' : _ref5$fontFamily,
|
|
441
|
+
_ref5$textAllowOverla = _ref5.textAllowOverlap,
|
|
442
|
+
textAllowOverlap = _ref5$textAllowOverla === void 0 ? false : _ref5$textAllowOverla,
|
|
443
|
+
_ref5$padding = _ref5.padding,
|
|
444
|
+
padding = _ref5$padding === void 0 ? [0, 0] : _ref5$padding,
|
|
445
|
+
_ref5$textAnchor = _ref5.textAnchor,
|
|
446
|
+
textAnchor = _ref5$textAnchor === void 0 ? 'center' : _ref5$textAnchor,
|
|
447
|
+
_ref5$textOffset = _ref5.textOffset,
|
|
448
|
+
textOffset = _ref5$textOffset === void 0 ? [0, 0] : _ref5$textOffset,
|
|
449
|
+
_ref5$opacity = _ref5.opacity,
|
|
450
|
+
opacity = _ref5$opacity === void 0 ? 1 : _ref5$opacity,
|
|
451
|
+
_ref5$strokeOpacity = _ref5.strokeOpacity,
|
|
452
|
+
strokeOpacity = _ref5$strokeOpacity === void 0 ? 1 : _ref5$strokeOpacity,
|
|
453
|
+
_ref5$strokeWidth = _ref5.strokeWidth,
|
|
454
|
+
strokeWidth = _ref5$strokeWidth === void 0 ? 0 : _ref5$strokeWidth,
|
|
455
|
+
_ref5$stroke = _ref5.stroke,
|
|
456
|
+
stroke = _ref5$stroke === void 0 ? '#000' : _ref5$stroke;
|
|
538
457
|
return {
|
|
539
458
|
fontWeight: fontWeight,
|
|
540
459
|
fontFamily: fontFamily,
|
|
@@ -548,40 +467,39 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
548
467
|
stroke: stroke
|
|
549
468
|
};
|
|
550
469
|
}
|
|
470
|
+
|
|
551
471
|
/**
|
|
552
472
|
* 生成文字布局(对照文字纹理字典提取对应文字的位置很好信息)
|
|
553
473
|
*/
|
|
554
|
-
|
|
555
474
|
}, {
|
|
556
475
|
key: "generateGlyphLayout",
|
|
557
476
|
value: function generateGlyphLayout(iconfont) {
|
|
558
477
|
var _this2 = this;
|
|
559
|
-
|
|
560
|
-
// 更新文字布局
|
|
561
|
-
var mapping = this.fontService.mapping;
|
|
562
|
-
|
|
478
|
+
var mapping = this.getFontServiceMapping();
|
|
563
479
|
var _ref6 = this.layer.getLayerConfig(),
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
480
|
+
_ref6$spacing = _ref6.spacing,
|
|
481
|
+
spacing = _ref6$spacing === void 0 ? 2 : _ref6$spacing,
|
|
482
|
+
_ref6$textAnchor = _ref6.textAnchor,
|
|
483
|
+
textAnchor = _ref6$textAnchor === void 0 ? 'center' : _ref6$textAnchor,
|
|
484
|
+
textOffset = _ref6.textOffset;
|
|
570
485
|
var data = this.layer.getEncodedData();
|
|
571
486
|
this.glyphInfo = data.map(function (feature) {
|
|
572
487
|
var _feature$shape = feature.shape,
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
var shaping = shapeText(shape.toString(), mapping,
|
|
488
|
+
shape = _feature$shape === void 0 ? '' : _feature$shape,
|
|
489
|
+
id = feature.id,
|
|
490
|
+
_feature$size2 = feature.size,
|
|
491
|
+
size = _feature$size2 === void 0 ? 1 : _feature$size2;
|
|
492
|
+
var shaping = shapeText(shape.toString(), mapping,
|
|
493
|
+
// @ts-ignore
|
|
578
494
|
size, textAnchor, 'left', spacing, textOffset || feature.textOffset || [0, 0], iconfont);
|
|
579
495
|
var glyphQuads = getGlyphQuads(shaping, textOffset, false);
|
|
580
496
|
feature.shaping = shaping;
|
|
581
|
-
feature.glyphQuads = glyphQuads;
|
|
497
|
+
feature.glyphQuads = glyphQuads;
|
|
498
|
+
// feature.centroid = calculteCentroid(coordinates);
|
|
582
499
|
|
|
583
|
-
feature.centroid = calculateCentroid(feature.coordinates);
|
|
500
|
+
feature.centroid = calculateCentroid(feature.coordinates);
|
|
584
501
|
|
|
502
|
+
// 此时地图高德2.0 originCentroid == centroid
|
|
585
503
|
feature.originCentroid = feature.version === 'GAODE2.x' ? calculateCentroid(feature.originCoordinates) : feature.originCentroid = feature.centroid;
|
|
586
504
|
_this2.glyphInfoMap[id] = {
|
|
587
505
|
shaping: shaping,
|
|
@@ -591,57 +509,70 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
591
509
|
return feature;
|
|
592
510
|
});
|
|
593
511
|
}
|
|
512
|
+
}, {
|
|
513
|
+
key: "getFontServiceMapping",
|
|
514
|
+
value: function getFontServiceMapping() {
|
|
515
|
+
var _ref7 = this.layer.getLayerConfig(),
|
|
516
|
+
_ref7$fontWeight = _ref7.fontWeight,
|
|
517
|
+
fontWeight = _ref7$fontWeight === void 0 ? '400' : _ref7$fontWeight,
|
|
518
|
+
_ref7$fontFamily = _ref7.fontFamily,
|
|
519
|
+
fontFamily = _ref7$fontFamily === void 0 ? 'sans-serif' : _ref7$fontFamily;
|
|
520
|
+
return this.fontService.getMappingByKey("".concat(fontFamily, "_").concat(fontWeight));
|
|
521
|
+
}
|
|
522
|
+
}, {
|
|
523
|
+
key: "getFontServiceCanvas",
|
|
524
|
+
value: function getFontServiceCanvas() {
|
|
525
|
+
var _ref8 = this.layer.getLayerConfig(),
|
|
526
|
+
_ref8$fontWeight = _ref8.fontWeight,
|
|
527
|
+
fontWeight = _ref8$fontWeight === void 0 ? '400' : _ref8$fontWeight,
|
|
528
|
+
_ref8$fontFamily = _ref8.fontFamily,
|
|
529
|
+
fontFamily = _ref8$fontFamily === void 0 ? 'sans-serif' : _ref8$fontFamily;
|
|
530
|
+
// 更新文字布局
|
|
531
|
+
return this.fontService.getCanvasByKey("".concat(fontFamily, "_").concat(fontWeight));
|
|
532
|
+
}
|
|
533
|
+
|
|
594
534
|
/**
|
|
595
535
|
* 文字避让 depend on originCentorid
|
|
596
536
|
*/
|
|
597
|
-
|
|
598
537
|
}, {
|
|
599
538
|
key: "filterGlyphs",
|
|
600
539
|
value: function filterGlyphs() {
|
|
601
540
|
var _this3 = this;
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
textAllowOverlap = _ref7$textAllowOverla === void 0 ? false : _ref7$textAllowOverla;
|
|
608
|
-
|
|
541
|
+
var _ref9 = this.layer.getLayerConfig(),
|
|
542
|
+
_ref9$padding = _ref9.padding,
|
|
543
|
+
padding = _ref9$padding === void 0 ? [0, 0] : _ref9$padding,
|
|
544
|
+
_ref9$textAllowOverla = _ref9.textAllowOverlap,
|
|
545
|
+
textAllowOverlap = _ref9$textAllowOverla === void 0 ? false : _ref9$textAllowOverla;
|
|
609
546
|
if (textAllowOverlap) {
|
|
610
547
|
// 如果允许文本覆盖
|
|
611
548
|
return;
|
|
612
549
|
}
|
|
613
|
-
|
|
614
550
|
this.glyphInfoMap = {};
|
|
615
551
|
this.currentZoom = this.mapService.getZoom();
|
|
616
552
|
this.extent = this.textExtent();
|
|
617
|
-
|
|
618
553
|
var _this$rendererService = this.rendererService.getViewportSize(),
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
554
|
+
width = _this$rendererService.width,
|
|
555
|
+
height = _this$rendererService.height;
|
|
622
556
|
var collisionIndex = new CollisionIndex(width, height);
|
|
623
557
|
var filterData = this.glyphInfo.filter(function (feature) {
|
|
624
558
|
var shaping = feature.shaping,
|
|
625
|
-
|
|
626
|
-
|
|
559
|
+
_feature$id = feature.id,
|
|
560
|
+
id = _feature$id === void 0 ? 0 : _feature$id;
|
|
561
|
+
// const centroid = feature.centroid as [number, number];
|
|
627
562
|
// const centroid = feature.originCentroid as [number, number];
|
|
628
|
-
|
|
629
563
|
var centroid = feature.version === 'GAODE2.x' ? feature.originCentroid : feature.centroid;
|
|
630
564
|
var size = feature.size;
|
|
631
565
|
var fontScale = size / 16;
|
|
632
|
-
|
|
633
566
|
var pixels = _this3.mapService.lngLatToContainer(centroid);
|
|
634
|
-
|
|
635
567
|
var _collisionIndex$place = collisionIndex.placeCollisionBox({
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
568
|
+
x1: shaping.left * fontScale - padding[0],
|
|
569
|
+
x2: shaping.right * fontScale + padding[0],
|
|
570
|
+
y1: shaping.top * fontScale - padding[1],
|
|
571
|
+
y2: shaping.bottom * fontScale + padding[1],
|
|
572
|
+
anchorPointX: pixels.x,
|
|
573
|
+
anchorPointY: pixels.y
|
|
574
|
+
}),
|
|
575
|
+
box = _collisionIndex$place.box;
|
|
645
576
|
if (box && box.length) {
|
|
646
577
|
collisionIndex.insertCollisionBox(box, id);
|
|
647
578
|
return true;
|
|
@@ -652,39 +583,35 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
652
583
|
filterData.forEach(function (item) {
|
|
653
584
|
// @ts-ignore
|
|
654
585
|
_this3.glyphInfoMap[item.id] = item;
|
|
655
|
-
});
|
|
586
|
+
});
|
|
587
|
+
// this.layer.setEncodedData(filterData);
|
|
656
588
|
}
|
|
657
589
|
/**
|
|
658
590
|
* 初始化文字布局
|
|
659
591
|
*/
|
|
660
|
-
|
|
661
592
|
}, {
|
|
662
593
|
key: "initGlyph",
|
|
663
594
|
value: function initGlyph() {
|
|
664
595
|
var _this$layer$getLayerC = this.layer.getLayerConfig(),
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
596
|
+
_this$layer$getLayerC2 = _this$layer$getLayerC.iconfont,
|
|
597
|
+
iconfont = _this$layer$getLayerC2 === void 0 ? false : _this$layer$getLayerC2;
|
|
598
|
+
// 1.生成文字纹理(或是生成 iconfont)
|
|
599
|
+
iconfont ? this.initIconFontTex() : this.initTextFont();
|
|
600
|
+
// 2.生成文字布局
|
|
671
601
|
this.generateGlyphLayout(iconfont);
|
|
672
602
|
}
|
|
673
603
|
/**
|
|
674
604
|
* 更新文字纹理
|
|
675
605
|
*/
|
|
676
|
-
|
|
677
606
|
}, {
|
|
678
607
|
key: "updateTexture",
|
|
679
608
|
value: function updateTexture() {
|
|
680
609
|
var createTexture2D = this.rendererService.createTexture2D;
|
|
681
|
-
var canvas = this.
|
|
610
|
+
var canvas = this.getFontServiceCanvas();
|
|
682
611
|
this.textureHeight = canvas.height;
|
|
683
|
-
|
|
684
612
|
if (this.texture) {
|
|
685
613
|
this.texture.destroy();
|
|
686
614
|
}
|
|
687
|
-
|
|
688
615
|
this.texture = createTexture2D({
|
|
689
616
|
data: canvas,
|
|
690
617
|
mag: gl.LINEAR,
|
|
@@ -699,43 +626,35 @@ var TextModel = /*#__PURE__*/function (_BaseModel) {
|
|
|
699
626
|
var _reBuildModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
700
627
|
var model;
|
|
701
628
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
702
|
-
while (1) {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
case 5:
|
|
723
|
-
case "end":
|
|
724
|
-
return _context5.stop();
|
|
725
|
-
}
|
|
629
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
630
|
+
case 0:
|
|
631
|
+
this.filterGlyphs();
|
|
632
|
+
_context5.next = 3;
|
|
633
|
+
return this.layer.buildLayerModel({
|
|
634
|
+
moduleName: 'pointText',
|
|
635
|
+
vertexShader: textVert,
|
|
636
|
+
fragmentShader: textFrag,
|
|
637
|
+
triangulation: TextTriangulation.bind(this),
|
|
638
|
+
depth: {
|
|
639
|
+
enable: false
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
case 3:
|
|
643
|
+
model = _context5.sent;
|
|
644
|
+
// TODO 渲染流程待修改
|
|
645
|
+
this.layer.models = [model];
|
|
646
|
+
case 5:
|
|
647
|
+
case "end":
|
|
648
|
+
return _context5.stop();
|
|
726
649
|
}
|
|
727
650
|
}, _callee5, this);
|
|
728
651
|
}));
|
|
729
|
-
|
|
730
652
|
function reBuildModel() {
|
|
731
653
|
return _reBuildModel.apply(this, arguments);
|
|
732
654
|
}
|
|
733
|
-
|
|
734
655
|
return reBuildModel;
|
|
735
656
|
}()
|
|
736
657
|
}]);
|
|
737
|
-
|
|
738
658
|
return TextModel;
|
|
739
659
|
}(BaseModel);
|
|
740
|
-
|
|
741
660
|
export { TextModel as default };
|