@antv/l7-layers 2.9.25-alpha.0 → 2.9.25
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/heatmap/models/heatmap.js +1 -1
- package/es/tile/utils.js +1 -1
- package/lib/Geometry/index.js +114 -77
- package/lib/Geometry/models/billboard.js +232 -181
- package/lib/Geometry/models/index.js +18 -34
- package/lib/Geometry/models/plane.js +407 -278
- package/lib/Geometry/models/sprite.js +291 -189
- package/lib/canvas/index.js +101 -66
- package/lib/canvas/models/canvas.js +207 -140
- package/lib/canvas/models/index.js +12 -30
- package/lib/citybuliding/building.js +98 -63
- package/lib/citybuliding/models/build.js +192 -146
- package/lib/core/BaseLayer.js +1331 -814
- package/lib/core/BaseModel.js +457 -279
- package/lib/core/interface.js +40 -53
- package/lib/core/schema.js +21 -39
- package/lib/core/shape/Path.js +67 -79
- package/lib/core/shape/extrude.js +132 -91
- package/lib/core/triangulation.js +378 -196
- package/lib/earth/index.js +100 -62
- package/lib/earth/models/atmosphere.js +146 -112
- package/lib/earth/models/base.js +210 -150
- package/lib/earth/models/bloomsphere.js +146 -112
- package/lib/earth/utils.js +111 -91
- package/lib/heatmap/index.js +149 -92
- package/lib/heatmap/models/grid.js +118 -91
- package/lib/heatmap/models/grid3d.js +155 -123
- package/lib/heatmap/models/heatmap.js +475 -338
- package/lib/heatmap/models/hexagon.js +121 -92
- package/lib/heatmap/models/index.js +22 -37
- package/lib/heatmap/triangulation.js +31 -47
- package/lib/image/index.js +111 -74
- package/lib/image/models/dataImage.js +232 -174
- package/lib/image/models/image.js +175 -128
- package/lib/image/models/index.js +15 -32
- package/lib/index.js +263 -97
- package/lib/line/index.js +131 -85
- package/lib/line/models/arc.js +352 -237
- package/lib/line/models/arc_3d.js +334 -228
- package/lib/line/models/earthArc_3d.js +336 -228
- package/lib/line/models/great_circle.js +291 -200
- package/lib/line/models/half.js +286 -201
- package/lib/line/models/index.js +42 -50
- package/lib/line/models/line.js +428 -299
- package/lib/line/models/linearline.js +277 -203
- package/lib/line/models/simpleLine.js +239 -175
- package/lib/line/models/tile.js +348 -237
- package/lib/line/models/wall.js +327 -235
- package/lib/mask/index.js +92 -59
- package/lib/mask/models/fill.js +134 -82
- package/lib/mask/models/index.js +12 -30
- package/lib/plugins/DataMappingPlugin.js +342 -224
- package/lib/plugins/DataSourcePlugin.js +102 -87
- package/lib/plugins/FeatureScalePlugin.js +330 -240
- package/lib/plugins/LayerAnimateStylePlugin.js +61 -55
- package/lib/plugins/LayerModelPlugin.js +80 -73
- package/lib/plugins/LayerStylePlugin.js +48 -51
- package/lib/plugins/LightingPlugin.js +80 -68
- package/lib/plugins/MultiPassRendererPlugin.js +91 -65
- package/lib/plugins/PixelPickingPlugin.js +150 -109
- package/lib/plugins/RegisterStyleAttributePlugin.js +110 -110
- package/lib/plugins/ShaderUniformPlugin.js +118 -99
- package/lib/plugins/UpdateModelPlugin.js +40 -47
- package/lib/plugins/UpdateStyleAttributePlugin.js +93 -75
- package/lib/point/index.js +226 -150
- package/lib/point/models/earthExtrude.js +279 -201
- package/lib/point/models/earthFill.js +287 -202
- package/lib/point/models/extrude.js +299 -203
- package/lib/point/models/fill.js +406 -275
- package/lib/point/models/fillmage.js +365 -256
- package/lib/point/models/image.js +241 -168
- package/lib/point/models/index.js +46 -52
- package/lib/point/models/normal.js +183 -134
- package/lib/point/models/radar.js +304 -211
- package/lib/point/models/simplePoint.js +194 -142
- package/lib/point/models/text.js +608 -385
- package/lib/point/models/tile.js +314 -223
- package/lib/point/shape/extrude.js +56 -52
- package/lib/polygon/index.js +154 -102
- package/lib/polygon/models/extrude.js +311 -223
- package/lib/polygon/models/fill.js +215 -153
- package/lib/polygon/models/index.js +46 -52
- package/lib/polygon/models/ocean.js +244 -173
- package/lib/polygon/models/tile.js +144 -100
- package/lib/polygon/models/water.js +222 -153
- package/lib/raster/buffers/triangulation.js +27 -40
- package/lib/raster/index.js +115 -75
- package/lib/raster/models/index.js +16 -33
- package/lib/raster/models/raster.js +178 -135
- package/lib/raster/raster.js +187 -132
- package/lib/tile/interface.js +4 -16
- package/lib/tile/manager/tileConfigManager.js +125 -86
- package/lib/tile/manager/tileLayerManager.js +313 -229
- package/lib/tile/manager/tilePickerManager.js +192 -123
- package/lib/tile/models/tileModel.js +71 -52
- package/lib/tile/tileFactory/base.js +432 -309
- package/lib/tile/tileFactory/index.js +51 -49
- package/lib/tile/tileFactory/line.js +65 -50
- package/lib/tile/tileFactory/point.js +65 -50
- package/lib/tile/tileFactory/polygon.js +65 -50
- package/lib/tile/tileFactory/raster.js +66 -54
- package/lib/tile/tileFactory/rasterData.js +88 -76
- package/lib/tile/tileFactory/rasterDataLayer.js +97 -62
- package/lib/tile/tileFactory/vectorLayer.js +168 -109
- package/lib/tile/tileLayer/baseTileLayer.js +420 -221
- package/lib/tile/tmsTileLayer.js +110 -67
- package/lib/tile/utils.js +110 -92
- package/lib/utils/blend.js +59 -79
- package/lib/utils/collision-index.js +107 -64
- package/lib/utils/dataMappingStyle.js +105 -60
- package/lib/utils/extrude_polyline.js +600 -398
- package/lib/utils/grid-index.js +163 -111
- package/lib/utils/layerData.js +130 -99
- package/lib/utils/multiPassRender.js +49 -41
- package/lib/utils/polylineNormal.js +148 -96
- package/lib/utils/simpleLine.js +100 -85
- package/lib/utils/symbol-layout.js +219 -116
- package/lib/utils/updateShape.js +15 -41
- package/lib/wind/index.js +109 -71
- package/lib/wind/models/index.js +12 -30
- package/lib/wind/models/utils.js +144 -105
- package/lib/wind/models/wind.js +333 -224
- package/lib/wind/models/windRender.js +329 -218
- package/lib/wind/models/windShader.js +23 -181
- package/package.json +6 -6
package/lib/utils/grid-index.js
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/utils/grid-index.ts
|
|
20
|
-
var grid_index_exports = {};
|
|
21
|
-
__export(grid_index_exports, {
|
|
22
|
-
default: () => grid_index_default
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
23
7
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
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; } } }; }
|
|
17
|
+
|
|
18
|
+
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); }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 网格索引,相比 @mapbox/grid-index,在简单计算碰撞检测结果时效率更高
|
|
24
|
+
* @see https://zhuanlan.zhihu.com/p/74373214
|
|
25
|
+
*/
|
|
26
|
+
var GridIndex = /*#__PURE__*/function () {
|
|
27
|
+
function GridIndex(width, height, cellSize) {
|
|
28
|
+
(0, _classCallCheck2.default)(this, GridIndex);
|
|
29
|
+
(0, _defineProperty2.default)(this, "boxCells", []);
|
|
30
|
+
var boxCells = this.boxCells;
|
|
29
31
|
this.xCellCount = Math.ceil(width / cellSize);
|
|
30
32
|
this.yCellCount = Math.ceil(height / cellSize);
|
|
31
|
-
|
|
33
|
+
|
|
34
|
+
for (var i = 0; i < this.xCellCount * this.yCellCount; i++) {
|
|
32
35
|
boxCells.push([]);
|
|
33
36
|
}
|
|
37
|
+
|
|
34
38
|
this.boxKeys = [];
|
|
35
39
|
this.bboxes = [];
|
|
36
40
|
this.width = width;
|
|
@@ -39,98 +43,146 @@ var GridIndex = class {
|
|
|
39
43
|
this.yScale = this.yCellCount / height;
|
|
40
44
|
this.boxUid = 0;
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.boxCells[cellIndex].push(uid);
|
|
58
|
-
}
|
|
59
|
-
queryHitTest(x1, y1, x2, y2, hitTest, predicate) {
|
|
60
|
-
if (x2 < 0 || x1 > this.width || y2 < 0 || y1 > this.height) {
|
|
61
|
-
return hitTest ? false : [];
|
|
46
|
+
|
|
47
|
+
(0, _createClass2.default)(GridIndex, [{
|
|
48
|
+
key: "insert",
|
|
49
|
+
value: function insert(key, x1, y1, x2, y2) {
|
|
50
|
+
this.forEachCell(x1, y1, x2, y2, this.insertBoxCell, this.boxUid++);
|
|
51
|
+
this.boxKeys.push(key);
|
|
52
|
+
this.bboxes.push(x1);
|
|
53
|
+
this.bboxes.push(y1);
|
|
54
|
+
this.bboxes.push(x2);
|
|
55
|
+
this.bboxes.push(y2);
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "query",
|
|
59
|
+
value: function query(x1, y1, x2, y2, predicate) {
|
|
60
|
+
return this.queryHitTest(x1, y1, x2, y2, false, predicate);
|
|
62
61
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
}, {
|
|
63
|
+
key: "hitTest",
|
|
64
|
+
value: function hitTest(x1, y1, x2, y2, predicate) {
|
|
65
|
+
return this.queryHitTest(x1, y1, x2, y2, true, predicate);
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "insertBoxCell",
|
|
69
|
+
value: function insertBoxCell(x1, y1, x2, y2, cellIndex, uid) {
|
|
70
|
+
this.boxCells[cellIndex].push(uid);
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "queryHitTest",
|
|
74
|
+
value: function queryHitTest(x1, y1, x2, y2, hitTest, predicate) {
|
|
75
|
+
if (x2 < 0 || x1 > this.width || y2 < 0 || y1 > this.height) {
|
|
76
|
+
return hitTest ? false : [];
|
|
67
77
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
78
|
+
|
|
79
|
+
var result = [];
|
|
80
|
+
|
|
81
|
+
if (x1 <= 0 && y1 <= 0 && this.width <= x2 && this.height <= y2) {
|
|
82
|
+
// 这一步是高效的关键,后续精确碰撞检测结果在计算文本可见性时并不需要
|
|
83
|
+
if (hitTest) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
for (var boxUid = 0; boxUid < this.boxKeys.length; boxUid++) {
|
|
88
|
+
result.push({
|
|
89
|
+
key: this.boxKeys[boxUid],
|
|
90
|
+
x1: this.bboxes[boxUid * 4],
|
|
91
|
+
y1: this.bboxes[boxUid * 4 + 1],
|
|
92
|
+
x2: this.bboxes[boxUid * 4 + 2],
|
|
93
|
+
y2: this.bboxes[boxUid * 4 + 3]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return predicate ? result.filter(predicate) : result;
|
|
76
98
|
}
|
|
77
|
-
|
|
99
|
+
|
|
100
|
+
var queryArgs = {
|
|
101
|
+
hitTest: hitTest,
|
|
102
|
+
seenUids: {
|
|
103
|
+
box: {},
|
|
104
|
+
circle: {}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
this.forEachCell(x1, y1, x2, y2, this.queryCell, result, queryArgs, predicate);
|
|
108
|
+
return hitTest ? result.length > 0 : result;
|
|
78
109
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
}, {
|
|
111
|
+
key: "queryCell",
|
|
112
|
+
value: function queryCell(x1, y1, x2, y2, cellIndex, result, queryArgs, predicate) {
|
|
113
|
+
var seenUids = queryArgs.seenUids;
|
|
114
|
+
var boxCell = this.boxCells[cellIndex];
|
|
115
|
+
|
|
116
|
+
if (boxCell !== null) {
|
|
117
|
+
var bboxes = this.bboxes;
|
|
118
|
+
|
|
119
|
+
var _iterator = _createForOfIteratorHelper(boxCell),
|
|
120
|
+
_step;
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
124
|
+
var boxUid = _step.value;
|
|
125
|
+
|
|
126
|
+
if (!seenUids.box[boxUid]) {
|
|
127
|
+
seenUids.box[boxUid] = true;
|
|
128
|
+
var offset = boxUid * 4;
|
|
129
|
+
|
|
130
|
+
if (x1 <= bboxes[offset + 2] && y1 <= bboxes[offset + 3] && x2 >= bboxes[offset + 0] && y2 >= bboxes[offset + 1] && (!predicate || predicate(this.boxKeys[boxUid]))) {
|
|
131
|
+
if (queryArgs.hitTest) {
|
|
132
|
+
result.push(true);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
result.push({
|
|
137
|
+
key: this.boxKeys[boxUid],
|
|
138
|
+
x1: bboxes[offset],
|
|
139
|
+
y1: bboxes[offset + 1],
|
|
140
|
+
x2: bboxes[offset + 2],
|
|
141
|
+
y2: bboxes[offset + 3]
|
|
142
|
+
});
|
|
143
|
+
}
|
|
99
144
|
}
|
|
100
|
-
result.push({
|
|
101
|
-
key: this.boxKeys[boxUid],
|
|
102
|
-
x1: bboxes[offset],
|
|
103
|
-
y1: bboxes[offset + 1],
|
|
104
|
-
x2: bboxes[offset + 2],
|
|
105
|
-
y2: bboxes[offset + 3]
|
|
106
|
-
});
|
|
107
145
|
}
|
|
146
|
+
} catch (err) {
|
|
147
|
+
_iterator.e(err);
|
|
148
|
+
} finally {
|
|
149
|
+
_iterator.f();
|
|
108
150
|
}
|
|
109
151
|
}
|
|
152
|
+
|
|
153
|
+
return false;
|
|
110
154
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
for (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
155
|
+
}, {
|
|
156
|
+
key: "forEachCell",
|
|
157
|
+
value: function forEachCell(x1, y1, x2, y2, fn, arg1, arg2, predicate) {
|
|
158
|
+
var cx1 = this.convertToXCellCoord(x1);
|
|
159
|
+
var cy1 = this.convertToYCellCoord(y1);
|
|
160
|
+
var cx2 = this.convertToXCellCoord(x2);
|
|
161
|
+
var cy2 = this.convertToYCellCoord(y2);
|
|
162
|
+
|
|
163
|
+
for (var x = cx1; x <= cx2; x++) {
|
|
164
|
+
for (var y = cy1; y <= cy2; y++) {
|
|
165
|
+
var cellIndex = this.xCellCount * y + x;
|
|
166
|
+
|
|
167
|
+
if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, predicate)) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
123
170
|
}
|
|
124
171
|
}
|
|
125
172
|
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
173
|
+
}, {
|
|
174
|
+
key: "convertToXCellCoord",
|
|
175
|
+
value: function convertToXCellCoord(x) {
|
|
176
|
+
return Math.max(0, Math.min(this.xCellCount - 1, Math.floor(x * this.xScale)));
|
|
177
|
+
}
|
|
178
|
+
}, {
|
|
179
|
+
key: "convertToYCellCoord",
|
|
180
|
+
value: function convertToYCellCoord(y) {
|
|
181
|
+
return Math.max(0, Math.min(this.yCellCount - 1, Math.floor(y * this.yScale)));
|
|
182
|
+
}
|
|
183
|
+
}]);
|
|
184
|
+
return GridIndex;
|
|
185
|
+
}();
|
|
186
|
+
|
|
187
|
+
var _default = GridIndex;
|
|
188
|
+
exports.default = _default;
|
package/lib/utils/layerData.js
CHANGED
|
@@ -1,62 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
|
|
22
|
-
// src/utils/layerData.ts
|
|
23
|
-
var layerData_exports = {};
|
|
24
|
-
__export(layerData_exports, {
|
|
25
|
-
calculateData: () => calculateData
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
26
7
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
|
|
8
|
+
exports.calculateData = calculateData;
|
|
9
|
+
|
|
10
|
+
var _l7Maps = require("@antv/l7-maps");
|
|
11
|
+
|
|
12
|
+
var _l7Source = _interopRequireDefault(require("@antv/l7-source"));
|
|
13
|
+
|
|
14
|
+
var _l7Utils = require("@antv/l7-utils");
|
|
15
|
+
|
|
31
16
|
function getArrowPoints(p1, p2) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
p1[0] + normalizeDir[0] * 1e-4,
|
|
36
|
-
p1[1] + normalizeDir[1] * 1e-4
|
|
37
|
-
];
|
|
17
|
+
var dir = [p2[0] - p1[0], p2[1] - p1[1]];
|
|
18
|
+
var normalizeDir = (0, _l7Utils.normalize)(dir);
|
|
19
|
+
var arrowPoint = [p1[0] + normalizeDir[0] * 0.0001, p1[1] + normalizeDir[1] * 0.0001];
|
|
38
20
|
return arrowPoint;
|
|
39
21
|
}
|
|
22
|
+
|
|
40
23
|
function adjustData2Amap2Coordinates(mappedData, mapService) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
24
|
+
var _this = this;
|
|
25
|
+
|
|
26
|
+
// 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移
|
|
27
|
+
if (mappedData.length > 0 && mapService.version === _l7Maps.Version['GAODE2.x']) {
|
|
28
|
+
if (typeof mappedData[0].coordinates[0] === 'number') {
|
|
29
|
+
// 单个的点数据
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
mappedData // TODO: 避免经纬度被重复计算导致坐标位置偏移
|
|
32
|
+
.filter(function (d) {
|
|
33
|
+
return !d.originCoordinates;
|
|
34
|
+
}).map(function (d) {
|
|
35
|
+
d.version = _l7Maps.Version['GAODE2.x']; // @ts-ignore
|
|
36
|
+
|
|
37
|
+
d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
|
|
40
|
+
d.coordinates = _this.mapService.lngLatToCoord(d.coordinates);
|
|
47
41
|
});
|
|
48
42
|
} else {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
// 连续的线、面数据
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
mappedData // TODO: 避免经纬度被重复计算导致坐标位置偏移
|
|
46
|
+
.filter(function (d) {
|
|
47
|
+
return !d.originCoordinates;
|
|
48
|
+
}).map(function (d) {
|
|
49
|
+
d.version = _l7Maps.Version['GAODE2.x']; // @ts-ignore
|
|
50
|
+
|
|
51
|
+
d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
|
|
54
|
+
d.coordinates = _this.mapService.lngLatToCoords(d.coordinates);
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
}
|
|
59
|
+
|
|
57
60
|
function adjustData2SimpleCoordinates(mappedData, mapService) {
|
|
58
|
-
if (mappedData.length > 0 && mapService.version ===
|
|
59
|
-
mappedData.map((d)
|
|
61
|
+
if (mappedData.length > 0 && mapService.version === _l7Maps.Version.SIMPLE) {
|
|
62
|
+
mappedData.map(function (d) {
|
|
60
63
|
if (!d.simpleCoordinate) {
|
|
61
64
|
d.coordinates = unProjectCoordinates(d.coordinates, mapService);
|
|
62
65
|
d.simpleCoordinate = true;
|
|
@@ -64,93 +67,121 @@ function adjustData2SimpleCoordinates(mappedData, mapService) {
|
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
69
|
}
|
|
70
|
+
|
|
67
71
|
function unProjectCoordinates(coordinates, mapService) {
|
|
68
|
-
if (typeof coordinates[0] ===
|
|
72
|
+
if (typeof coordinates[0] === 'number') {
|
|
69
73
|
return mapService.simpleMapCoord.unproject(coordinates);
|
|
70
74
|
}
|
|
75
|
+
|
|
71
76
|
if (coordinates[0] && coordinates[0][0] instanceof Array) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
var coords = [];
|
|
79
|
+
coordinates.map(function (coord) {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
var c1 = [];
|
|
82
|
+
coord.map(function (co) {
|
|
76
83
|
c1.push(mapService.simpleMapCoord.unproject(co));
|
|
77
|
-
});
|
|
84
|
+
}); // @ts-ignore
|
|
85
|
+
|
|
78
86
|
coords.push(c1);
|
|
79
|
-
});
|
|
87
|
+
}); // @ts-ignore
|
|
88
|
+
|
|
80
89
|
return coords;
|
|
81
90
|
} else {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
var _coords = []; // @ts-ignore
|
|
93
|
+
|
|
94
|
+
coordinates.map(function (coord) {
|
|
95
|
+
_coords.push(mapService.simpleMapCoord.unproject(coord));
|
|
96
|
+
}); // @ts-ignore
|
|
97
|
+
|
|
98
|
+
return _coords;
|
|
87
99
|
}
|
|
88
100
|
}
|
|
101
|
+
|
|
89
102
|
function applyAttributeMapping(attribute, record, minimumColor) {
|
|
90
|
-
var
|
|
103
|
+
var _attribute$scale;
|
|
104
|
+
|
|
91
105
|
if (!attribute.scale) {
|
|
92
106
|
return [];
|
|
93
107
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
108
|
+
|
|
109
|
+
var scalers = (attribute === null || attribute === void 0 ? void 0 : (_attribute$scale = attribute.scale) === null || _attribute$scale === void 0 ? void 0 : _attribute$scale.scalers) || [];
|
|
110
|
+
var params = [];
|
|
111
|
+
scalers.forEach(function (_ref) {
|
|
112
|
+
var _attribute$scale2;
|
|
113
|
+
|
|
114
|
+
var field = _ref.field;
|
|
115
|
+
|
|
116
|
+
if (record.hasOwnProperty(field) || ((_attribute$scale2 = attribute.scale) === null || _attribute$scale2 === void 0 ? void 0 : _attribute$scale2.type) === 'variable') {
|
|
117
|
+
// TODO:多字段,常量
|
|
99
118
|
params.push(record[field]);
|
|
100
119
|
}
|
|
101
120
|
});
|
|
102
|
-
|
|
103
|
-
|
|
121
|
+
var mappingResult = attribute.mapping ? attribute.mapping(params) : [];
|
|
122
|
+
|
|
123
|
+
if (attribute.name === 'color' && !(0, _l7Utils.isColor)(mappingResult[0])) {
|
|
104
124
|
return [minimumColor];
|
|
105
125
|
}
|
|
126
|
+
|
|
106
127
|
return mappingResult;
|
|
107
128
|
}
|
|
129
|
+
|
|
108
130
|
function mapping(attributes, data, fontService, mapService, minimumColor, layer) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
var _ref2 = layer === null || layer === void 0 ? void 0 : layer.getLayerConfig(),
|
|
132
|
+
_ref2$arrow = _ref2.arrow,
|
|
133
|
+
arrow = _ref2$arrow === void 0 ? {
|
|
134
|
+
enable: false
|
|
135
|
+
} : _ref2$arrow;
|
|
136
|
+
|
|
137
|
+
var mappedData = data.map(function (record) {
|
|
138
|
+
var encodeRecord = {
|
|
116
139
|
id: record._id,
|
|
117
140
|
coordinates: record.coordinates
|
|
118
141
|
};
|
|
119
|
-
attributes.filter(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
142
|
+
attributes.filter(function (attribute) {
|
|
143
|
+
return attribute.scale !== undefined;
|
|
144
|
+
}).forEach(function (attribute) {
|
|
145
|
+
var values = applyAttributeMapping(attribute, record, minimumColor);
|
|
146
|
+
attribute.needRemapping = false; // TODO: 支持每个属性配置 postprocess
|
|
147
|
+
|
|
148
|
+
if (attribute.name === 'color') {
|
|
149
|
+
values = values.map(function (c) {
|
|
150
|
+
return (0, _l7Utils.rgb2arr)(c);
|
|
125
151
|
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
152
|
+
} // @ts-ignore
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
encodeRecord[attribute.name] = Array.isArray(values) && values.length === 1 ? values[0] : values; // 增加对 layer/text/iconfont unicode 映射的解析
|
|
156
|
+
|
|
157
|
+
if (attribute.name === 'shape') {
|
|
129
158
|
encodeRecord.shape = fontService.getIconFontKey(encodeRecord[attribute.name]);
|
|
130
159
|
}
|
|
131
160
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
161
|
+
|
|
162
|
+
if (encodeRecord.shape === 'line' && arrow.enable) {
|
|
163
|
+
// 只有在线图层且支持配置箭头的时候进行插入顶点的处理
|
|
164
|
+
var coords = encodeRecord.coordinates;
|
|
165
|
+
var arrowPoint = getArrowPoints(coords[0], coords[1]);
|
|
135
166
|
encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);
|
|
136
167
|
}
|
|
168
|
+
|
|
137
169
|
return encodeRecord;
|
|
138
|
-
});
|
|
139
|
-
|
|
170
|
+
}); // 调整数据兼容 Amap2.0
|
|
171
|
+
|
|
172
|
+
adjustData2Amap2Coordinates(mappedData, mapService); // 调整数据兼容 SimpleCoordinates
|
|
173
|
+
|
|
140
174
|
adjustData2SimpleCoordinates(mappedData, mapService);
|
|
141
175
|
return mappedData;
|
|
142
176
|
}
|
|
177
|
+
|
|
143
178
|
function calculateData(layer, fontService, mapService, styleAttributeService, data, options) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
179
|
+
var source = new _l7Source.default(data, options);
|
|
180
|
+
var bottomColor = layer.getBottomColor();
|
|
181
|
+
var attributes = styleAttributeService.getLayerStyleAttributes() || [];
|
|
182
|
+
var dataArray = source.data.dataArray;
|
|
183
|
+
var filterData = dataArray;
|
|
184
|
+
var mappedEncodeData = mapping(attributes, filterData, fontService, mapService, bottomColor, layer);
|
|
150
185
|
source.destroy();
|
|
151
186
|
return mappedEncodeData;
|
|
152
|
-
}
|
|
153
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
-
0 && (module.exports = {
|
|
155
|
-
calculateData
|
|
156
|
-
});
|
|
187
|
+
}
|