@antv/l7-layers 2.9.23 → 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.
Files changed (166) hide show
  1. package/es/Geometry/models/plane.d.ts +1 -0
  2. package/es/citybuliding/building.js +1 -1
  3. package/es/core/BaseLayer.js +10 -3
  4. package/es/core/interface.d.ts +26 -48
  5. package/es/core/interface.js +3 -0
  6. package/es/core/schema.d.ts +3 -3
  7. package/es/core/triangulation.d.ts +4 -3
  8. package/es/core/triangulation.js +54 -39
  9. package/es/heatmap/models/heatmap.js +1 -1
  10. package/es/image/models/image.js +7 -1
  11. package/es/line/index.js +4 -1
  12. package/es/line/models/arc.js +1 -1
  13. package/es/line/models/simpleLine.js +1 -1
  14. package/es/line/shaders/line_arc_vert.glsl +5 -3
  15. package/es/line/shaders/simple/simpleline_vert.glsl +1 -0
  16. package/es/plugins/FeatureScalePlugin.js +0 -1
  17. package/es/point/index.js +3 -1
  18. package/es/point/models/fill.js +5 -2
  19. package/es/point/models/fillmage.js +9 -3
  20. package/es/point/models/image.js +8 -2
  21. package/es/point/models/radar.js +2 -3
  22. package/es/point/models/tile.js +1 -1
  23. package/es/point/shaders/fill_vert.glsl +13 -6
  24. package/es/point/shaders/image/fillImage_vert.glsl +13 -5
  25. package/es/point/shaders/image_vert.glsl +17 -8
  26. package/es/polygon/index.js +4 -1
  27. package/es/raster/index.js +3 -1
  28. package/es/tile/manager/tileLayerManager.d.ts +3 -2
  29. package/es/tile/manager/tileLayerManager.js +5 -2
  30. package/es/tile/models/tileModel.js +4 -3
  31. package/es/tile/tileFactory/base.d.ts +1 -1
  32. package/es/tile/tileFactory/base.js +32 -5
  33. package/es/tile/tileFactory/vectorLayer.d.ts +3 -1
  34. package/es/tile/tileFactory/vectorLayer.js +22 -1
  35. package/es/tile/tileLayer/baseTileLayer.d.ts +1 -1
  36. package/es/tile/tileLayer/baseTileLayer.js +3 -2
  37. package/es/tile/utils.d.ts +2 -0
  38. package/es/tile/utils.js +5 -1
  39. package/lib/Geometry/index.js +114 -77
  40. package/lib/Geometry/models/billboard.js +232 -181
  41. package/lib/Geometry/models/index.js +18 -34
  42. package/lib/Geometry/models/plane.js +407 -278
  43. package/lib/Geometry/models/sprite.js +291 -189
  44. package/lib/canvas/index.js +101 -66
  45. package/lib/canvas/models/canvas.js +207 -140
  46. package/lib/canvas/models/index.js +12 -30
  47. package/lib/citybuliding/building.js +98 -63
  48. package/lib/citybuliding/models/build.js +192 -146
  49. package/lib/core/BaseLayer.js +1331 -809
  50. package/lib/core/BaseModel.js +457 -279
  51. package/lib/core/interface.js +40 -53
  52. package/lib/core/schema.js +21 -39
  53. package/lib/core/shape/Path.js +67 -79
  54. package/lib/core/shape/extrude.js +132 -91
  55. package/lib/core/triangulation.js +412 -213
  56. package/lib/earth/index.js +100 -62
  57. package/lib/earth/models/atmosphere.js +146 -112
  58. package/lib/earth/models/base.js +210 -150
  59. package/lib/earth/models/bloomsphere.js +146 -112
  60. package/lib/earth/utils.js +111 -91
  61. package/lib/heatmap/index.js +149 -92
  62. package/lib/heatmap/models/grid.js +118 -91
  63. package/lib/heatmap/models/grid3d.js +155 -123
  64. package/lib/heatmap/models/heatmap.js +475 -338
  65. package/lib/heatmap/models/hexagon.js +121 -92
  66. package/lib/heatmap/models/index.js +22 -37
  67. package/lib/heatmap/triangulation.js +31 -47
  68. package/lib/image/index.js +111 -74
  69. package/lib/image/models/dataImage.js +232 -174
  70. package/lib/image/models/image.js +175 -123
  71. package/lib/image/models/index.js +15 -32
  72. package/lib/index.js +263 -97
  73. package/lib/line/index.js +131 -83
  74. package/lib/line/models/arc.js +352 -237
  75. package/lib/line/models/arc_3d.js +334 -228
  76. package/lib/line/models/earthArc_3d.js +336 -228
  77. package/lib/line/models/great_circle.js +291 -200
  78. package/lib/line/models/half.js +286 -201
  79. package/lib/line/models/index.js +42 -50
  80. package/lib/line/models/line.js +428 -299
  81. package/lib/line/models/linearline.js +277 -203
  82. package/lib/line/models/simpleLine.js +239 -175
  83. package/lib/line/models/tile.js +348 -237
  84. package/lib/line/models/wall.js +327 -235
  85. package/lib/line/shaders/line_arc_vert.glsl +5 -3
  86. package/lib/line/shaders/simple/simpleline_vert.glsl +1 -0
  87. package/lib/mask/index.js +92 -59
  88. package/lib/mask/models/fill.js +134 -82
  89. package/lib/mask/models/index.js +12 -30
  90. package/lib/plugins/DataMappingPlugin.js +342 -224
  91. package/lib/plugins/DataSourcePlugin.js +102 -87
  92. package/lib/plugins/FeatureScalePlugin.js +330 -241
  93. package/lib/plugins/LayerAnimateStylePlugin.js +61 -55
  94. package/lib/plugins/LayerModelPlugin.js +80 -73
  95. package/lib/plugins/LayerStylePlugin.js +48 -51
  96. package/lib/plugins/LightingPlugin.js +80 -68
  97. package/lib/plugins/MultiPassRendererPlugin.js +91 -65
  98. package/lib/plugins/PixelPickingPlugin.js +150 -109
  99. package/lib/plugins/RegisterStyleAttributePlugin.js +110 -110
  100. package/lib/plugins/ShaderUniformPlugin.js +118 -99
  101. package/lib/plugins/UpdateModelPlugin.js +40 -47
  102. package/lib/plugins/UpdateStyleAttributePlugin.js +93 -75
  103. package/lib/point/index.js +226 -148
  104. package/lib/point/models/earthExtrude.js +279 -201
  105. package/lib/point/models/earthFill.js +287 -202
  106. package/lib/point/models/extrude.js +299 -203
  107. package/lib/point/models/fill.js +406 -273
  108. package/lib/point/models/fillmage.js +365 -252
  109. package/lib/point/models/image.js +241 -164
  110. package/lib/point/models/index.js +46 -52
  111. package/lib/point/models/normal.js +183 -134
  112. package/lib/point/models/radar.js +304 -212
  113. package/lib/point/models/simplePoint.js +194 -142
  114. package/lib/point/models/text.js +608 -385
  115. package/lib/point/models/tile.js +314 -223
  116. package/lib/point/shaders/fill_vert.glsl +13 -6
  117. package/lib/point/shaders/image/fillImage_vert.glsl +13 -5
  118. package/lib/point/shaders/image_vert.glsl +17 -8
  119. package/lib/point/shape/extrude.js +56 -52
  120. package/lib/polygon/index.js +154 -100
  121. package/lib/polygon/models/extrude.js +311 -223
  122. package/lib/polygon/models/fill.js +215 -153
  123. package/lib/polygon/models/index.js +46 -52
  124. package/lib/polygon/models/ocean.js +244 -173
  125. package/lib/polygon/models/tile.js +144 -100
  126. package/lib/polygon/models/water.js +222 -153
  127. package/lib/raster/buffers/triangulation.js +27 -40
  128. package/lib/raster/index.js +115 -74
  129. package/lib/raster/models/index.js +16 -33
  130. package/lib/raster/models/raster.js +178 -135
  131. package/lib/raster/raster.js +187 -132
  132. package/lib/tile/interface.js +4 -16
  133. package/lib/tile/manager/tileConfigManager.js +125 -86
  134. package/lib/tile/manager/tileLayerManager.js +314 -227
  135. package/lib/tile/manager/tilePickerManager.js +192 -123
  136. package/lib/tile/models/tileModel.js +71 -51
  137. package/lib/tile/tileFactory/base.js +433 -292
  138. package/lib/tile/tileFactory/index.js +51 -49
  139. package/lib/tile/tileFactory/line.js +65 -50
  140. package/lib/tile/tileFactory/point.js +65 -50
  141. package/lib/tile/tileFactory/polygon.js +65 -50
  142. package/lib/tile/tileFactory/raster.js +66 -54
  143. package/lib/tile/tileFactory/rasterData.js +88 -76
  144. package/lib/tile/tileFactory/rasterDataLayer.js +97 -62
  145. package/lib/tile/tileFactory/vectorLayer.js +169 -95
  146. package/lib/tile/tileLayer/baseTileLayer.js +420 -220
  147. package/lib/tile/tmsTileLayer.js +110 -67
  148. package/lib/tile/utils.js +113 -87
  149. package/lib/utils/blend.js +59 -79
  150. package/lib/utils/collision-index.js +107 -64
  151. package/lib/utils/dataMappingStyle.js +105 -60
  152. package/lib/utils/extrude_polyline.js +600 -398
  153. package/lib/utils/grid-index.js +163 -111
  154. package/lib/utils/layerData.js +130 -99
  155. package/lib/utils/multiPassRender.js +49 -41
  156. package/lib/utils/polylineNormal.js +148 -96
  157. package/lib/utils/simpleLine.js +100 -85
  158. package/lib/utils/symbol-layout.js +219 -116
  159. package/lib/utils/updateShape.js +15 -41
  160. package/lib/wind/index.js +109 -71
  161. package/lib/wind/models/index.js +12 -30
  162. package/lib/wind/models/utils.js +144 -105
  163. package/lib/wind/models/wind.js +333 -224
  164. package/lib/wind/models/windRender.js +329 -218
  165. package/lib/wind/models/windShader.js +23 -181
  166. package/package.json +7 -6
@@ -1,242 +1,360 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
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
- var __decorateClass = (decorators, target, key, kind) => {
19
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
- if (decorator = decorators[i])
22
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
- if (kind && result)
24
- __defProp(target, key, result);
25
- return result;
26
- };
27
-
28
- // src/plugins/DataMappingPlugin.ts
29
- var DataMappingPlugin_exports = {};
30
- __export(DataMappingPlugin_exports, {
31
- default: () => DataMappingPlugin
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
32
7
  });
33
- module.exports = __toCommonJS(DataMappingPlugin_exports);
34
- var import_l7_core = require("@antv/l7-core");
35
- var import_l7_maps = require("@antv/l7-maps");
36
- var import_l7_utils = require("@antv/l7-utils");
37
- var import_inversify = require("inversify");
38
- var import_lodash = require("lodash");
39
- var import_reflect_metadata = require("reflect-metadata");
40
- var DataMappingPlugin = class {
41
- apply(layer, {
42
- styleAttributeService
43
- }) {
44
- layer.hooks.init.tap("DataMappingPlugin", () => {
45
- const source = layer.getSource();
46
- if (source.inited) {
47
- this.generateMaping(layer, { styleAttributeService });
48
- } else {
49
- source.once("sourceUpdate", () => {
50
- this.generateMaping(layer, { styleAttributeService });
51
- });
52
- }
53
- });
54
- layer.hooks.beforeRenderData.tap("DataMappingPlugin", () => {
55
- layer.dataState.dataMappingNeedUpdate = false;
56
- const source = layer.getSource();
57
- if (source.inited) {
58
- this.generateMaping(layer, { styleAttributeService });
59
- } else {
60
- source.once("sourceUpdate", () => {
61
- this.generateMaping(layer, { styleAttributeService });
62
- });
63
- }
64
- return true;
65
- });
66
- layer.hooks.beforeRender.tap("DataMappingPlugin", () => {
67
- const source = layer.getSource();
68
- if (layer.layerModelNeedUpdate || !source || !source.inited) {
69
- return;
70
- }
71
- const bottomColor = layer.getBottomColor();
72
- const attributes = styleAttributeService.getLayerStyleAttributes() || [];
73
- const filter = styleAttributeService.getLayerStyleAttribute("filter");
74
- const { dataArray } = source.data;
75
- const attributesToRemapping = attributes.filter((attribute) => attribute.needRemapping);
76
- let filterData = dataArray;
77
- if ((filter == null ? void 0 : filter.needRemapping) && (filter == null ? void 0 : filter.scale)) {
78
- filterData = dataArray.filter((record) => {
79
- return this.applyAttributeMapping(filter, record, bottomColor)[0];
80
- });
81
- }
82
- if (attributesToRemapping.length) {
83
- if (filter == null ? void 0 : filter.needRemapping) {
84
- layer.setEncodedData(this.mapping(layer, attributes, filterData, void 0, bottomColor));
85
- filter.needRemapping = false;
86
- } else {
87
- layer.setEncodedData(this.mapping(layer, attributesToRemapping, filterData, layer.getEncodedData(), bottomColor));
88
- }
89
- layer.emit("remapping", null);
90
- }
91
- });
8
+ exports.default = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
+
20
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
21
+
22
+ var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
23
+
24
+ var _l7Core = require("@antv/l7-core");
25
+
26
+ var _l7Maps = require("@antv/l7-maps");
27
+
28
+ var _l7Utils = require("@antv/l7-utils");
29
+
30
+ var _inversify = require("inversify");
31
+
32
+ var _lodash = require("lodash");
33
+
34
+ require("reflect-metadata");
35
+
36
+ var _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3;
37
+
38
+ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_l7Core.TYPES.IGlobalConfigService), _dec3 = (0, _inversify.inject)(_l7Core.TYPES.IMapService), _dec4 = (0, _inversify.inject)(_l7Core.TYPES.IFontService), _dec(_class = (_class2 = /*#__PURE__*/function () {
39
+ function DataMappingPlugin() {
40
+ (0, _classCallCheck2.default)(this, DataMappingPlugin);
41
+ (0, _initializerDefineProperty2.default)(this, "configService", _descriptor, this);
42
+ (0, _initializerDefineProperty2.default)(this, "mapService", _descriptor2, this);
43
+ (0, _initializerDefineProperty2.default)(this, "fontService", _descriptor3, this);
92
44
  }
93
- generateMaping(layer, {
94
- styleAttributeService
95
- }) {
96
- const bottomColor = layer.getBottomColor();
97
- const attributes = styleAttributeService.getLayerStyleAttributes() || [];
98
- const filter = styleAttributeService.getLayerStyleAttribute("filter");
99
- const { dataArray } = layer.getSource().data;
100
- let filterData = dataArray;
101
- if (filter == null ? void 0 : filter.scale) {
102
- filterData = dataArray.filter((record) => {
103
- return this.applyAttributeMapping(filter, record, bottomColor)[0];
45
+
46
+ (0, _createClass2.default)(DataMappingPlugin, [{
47
+ key: "apply",
48
+ value: function apply(layer, _ref) {
49
+ var _this = this;
50
+
51
+ var styleAttributeService = _ref.styleAttributeService;
52
+ layer.hooks.init.tap('DataMappingPlugin', function () {
53
+ // 初始化重新生成 map
54
+ var source = layer.getSource();
55
+
56
+ if (source.inited) {
57
+ _this.generateMaping(layer, {
58
+ styleAttributeService: styleAttributeService
59
+ });
60
+ } else {
61
+ source.once('sourceUpdate', function () {
62
+ _this.generateMaping(layer, {
63
+ styleAttributeService: styleAttributeService
64
+ });
65
+ });
66
+ } // this.generateMaping(layer, { styleAttributeService });
67
+
104
68
  });
105
- }
106
- layer.setEncodedData(this.mapping(layer, attributes, filterData, void 0, bottomColor));
107
- layer.emit("dataUpdate", null);
108
- }
109
- getArrowPoints(p1, p2) {
110
- const dir = [p2[0] - p1[0], p2[1] - p1[1]];
111
- const normalizeDir = (0, import_l7_utils.normalize)(dir);
112
- const arrowPoint = [
113
- p1[0] + normalizeDir[0] * 1e-4,
114
- p1[1] + normalizeDir[1] * 1e-4
115
- ];
116
- return arrowPoint;
117
- }
118
- mapping(layer, attributes, data, predata, minimumColor) {
119
- const {
120
- arrow = {
121
- enable: false
122
- }
123
- } = layer.getLayerConfig();
124
- const mappedData = data.map((record, i) => {
125
- const preRecord = predata ? predata[i] : {};
126
- const encodeRecord = {
127
- id: record._id,
128
- coordinates: record.coordinates,
129
- ...preRecord
130
- };
131
- attributes.filter((attribute) => attribute.scale !== void 0).forEach((attribute) => {
132
- let values = this.applyAttributeMapping(attribute, record, minimumColor);
133
- attribute.needRemapping = false;
134
- if (attribute.name === "color") {
135
- values = values.map((c) => {
136
- return (0, import_l7_utils.rgb2arr)(c);
69
+ layer.hooks.beforeRenderData.tap('DataMappingPlugin', function () {
70
+ layer.dataState.dataMappingNeedUpdate = false;
71
+ var source = layer.getSource();
72
+
73
+ if (source.inited) {
74
+ _this.generateMaping(layer, {
75
+ styleAttributeService: styleAttributeService
76
+ });
77
+ } else {
78
+ source.once('sourceUpdate', function () {
79
+ _this.generateMaping(layer, {
80
+ styleAttributeService: styleAttributeService
81
+ });
82
+ });
83
+ } // this.generateMaping(layer, { styleAttributeService });
84
+
85
+
86
+ return true;
87
+ }); // remapping before render
88
+
89
+ layer.hooks.beforeRender.tap('DataMappingPlugin', function () {
90
+ var source = layer.getSource();
91
+
92
+ if (layer.layerModelNeedUpdate || !source || !source.inited) {
93
+ return;
94
+ }
95
+
96
+ var bottomColor = layer.getBottomColor();
97
+ var attributes = styleAttributeService.getLayerStyleAttributes() || [];
98
+ var filter = styleAttributeService.getLayerStyleAttribute('filter');
99
+ var dataArray = source.data.dataArray;
100
+ var attributesToRemapping = attributes.filter(function (attribute) {
101
+ return attribute.needRemapping;
102
+ } // 如果filter变化
103
+ );
104
+ var filterData = dataArray; // 数据过滤完 再执行数据映射
105
+
106
+ if (filter !== null && filter !== void 0 && filter.needRemapping && filter !== null && filter !== void 0 && filter.scale) {
107
+ filterData = dataArray.filter(function (record) {
108
+ return _this.applyAttributeMapping(filter, record, bottomColor)[0];
137
109
  });
138
110
  }
139
- encodeRecord[attribute.name] = Array.isArray(values) && values.length === 1 ? values[0] : values;
140
- if (attribute.name === "shape") {
141
- encodeRecord.shape = this.fontService.getIconFontKey(encodeRecord[attribute.name]);
111
+
112
+ if (attributesToRemapping.length) {
113
+ // 过滤数据
114
+ if (filter !== null && filter !== void 0 && filter.needRemapping) {
115
+ layer.setEncodedData(_this.mapping(layer, attributes, filterData, undefined, bottomColor));
116
+ filter.needRemapping = false;
117
+ } else {
118
+ layer.setEncodedData(_this.mapping(layer, attributesToRemapping, filterData, layer.getEncodedData(), bottomColor));
119
+ } // 处理文本更新
120
+
121
+
122
+ layer.emit('remapping', null);
142
123
  }
143
124
  });
144
- if (arrow.enable && (encodeRecord.shape === "line" || encodeRecord.shape === "halfLine")) {
145
- const coords = encodeRecord.coordinates;
146
- const arrowPoint = this.getArrowPoints(coords[0], coords[1]);
147
- encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);
148
- }
149
- return encodeRecord;
150
- });
151
- this.adjustData2Amap2Coordinates(mappedData, layer);
152
- this.adjustData2SimpleCoordinates(mappedData);
153
- return mappedData;
154
- }
155
- adjustData2Amap2Coordinates(mappedData, layer) {
156
- if (mappedData.length > 0 && this.mapService.version === import_l7_maps.Version["GAODE2.x"]) {
157
- const layerCenter = this.getLayerCenter(layer);
158
- if (typeof mappedData[0].coordinates[0] === "number") {
159
- mappedData.filter((d) => !d.originCoordinates).map((d) => {
160
- d.version = import_l7_maps.Version["GAODE2.x"];
161
- d.originCoordinates = (0, import_lodash.cloneDeep)(d.coordinates);
162
- d.coordinates = this.mapService.lngLatToCoordByLayer(d.coordinates, layerCenter);
163
- });
164
- } else {
165
- mappedData.filter((d) => !d.originCoordinates).map((d) => {
166
- d.version = import_l7_maps.Version["GAODE2.x"];
167
- d.originCoordinates = (0, import_lodash.cloneDeep)(d.coordinates);
168
- d.coordinates = this.mapService.lngLatToCoordsByLayer(d.coordinates, layerCenter);
125
+ }
126
+ }, {
127
+ key: "generateMaping",
128
+ value: function generateMaping(layer, _ref2) {
129
+ var _this2 = this;
130
+
131
+ var styleAttributeService = _ref2.styleAttributeService;
132
+ var bottomColor = layer.getBottomColor();
133
+ var attributes = styleAttributeService.getLayerStyleAttributes() || [];
134
+ var filter = styleAttributeService.getLayerStyleAttribute('filter');
135
+ var dataArray = layer.getSource().data.dataArray;
136
+ var filterData = dataArray; // 数据过滤完 再执行数据映射
137
+
138
+ if (filter !== null && filter !== void 0 && filter.scale) {
139
+ filterData = dataArray.filter(function (record) {
140
+ return _this2.applyAttributeMapping(filter, record, bottomColor)[0];
169
141
  });
170
142
  }
143
+
144
+ layer.setEncodedData(this.mapping(layer, attributes, filterData, undefined, bottomColor)); // 对外暴露事件
145
+
146
+ layer.emit('dataUpdate', null);
171
147
  }
172
- }
173
- getLayerCenter(layer) {
174
- const source = layer.getSource();
175
- return source.center;
176
- }
177
- adjustData2SimpleCoordinates(mappedData) {
178
- if (mappedData.length > 0 && this.mapService.version === import_l7_maps.Version.SIMPLE) {
179
- mappedData.map((d) => {
180
- if (!d.simpleCoordinate) {
181
- d.coordinates = this.unProjectCoordinates(d.coordinates);
182
- d.simpleCoordinate = true;
148
+ }, {
149
+ key: "getArrowPoints",
150
+ value: function getArrowPoints(p1, p2) {
151
+ var dir = [p2[0] - p1[0], p2[1] - p1[1]];
152
+ var normalizeDir = (0, _l7Utils.normalize)(dir);
153
+ var arrowPoint = [p1[0] + normalizeDir[0] * 0.0001, p1[1] + normalizeDir[1] * 0.0001];
154
+ return arrowPoint;
155
+ }
156
+ }, {
157
+ key: "mapping",
158
+ value: function mapping(layer, attributes, data, predata, minimumColor) {
159
+ var _this3 = this;
160
+
161
+ var _ref3 = layer.getLayerConfig(),
162
+ _ref3$arrow = _ref3.arrow,
163
+ arrow = _ref3$arrow === void 0 ? {
164
+ enable: false
165
+ } : _ref3$arrow;
166
+
167
+ var mappedData = data.map(function (record, i) {
168
+ var preRecord = predata ? predata[i] : {};
169
+ var encodeRecord = (0, _objectSpread2.default)({
170
+ id: record._id,
171
+ coordinates: record.coordinates
172
+ }, preRecord);
173
+ attributes.filter(function (attribute) {
174
+ return attribute.scale !== undefined;
175
+ }).forEach(function (attribute) {
176
+ // console.log('record', record)
177
+ var values = _this3.applyAttributeMapping(attribute, record, minimumColor); // console.log('values', values)
178
+
179
+
180
+ attribute.needRemapping = false; // TODO: 支持每个属性配置 postprocess
181
+
182
+ if (attribute.name === 'color') {
183
+ // console.log('attribute', attribute)
184
+ values = values.map(function (c) {
185
+ return (0, _l7Utils.rgb2arr)(c);
186
+ });
187
+ } // @ts-ignore
188
+
189
+
190
+ encodeRecord[attribute.name] = Array.isArray(values) && values.length === 1 ? values[0] : values; // 增加对 layer/text/iconfont unicode 映射的解析
191
+
192
+ if (attribute.name === 'shape') {
193
+ encodeRecord.shape = _this3.fontService.getIconFontKey(encodeRecord[attribute.name]);
194
+ }
195
+ });
196
+
197
+ if (arrow.enable && (encodeRecord.shape === 'line' || encodeRecord.shape === 'halfLine')) {
198
+ // 只有在线图层且支持配置箭头的时候进行插入顶点的处理
199
+ var coords = encodeRecord.coordinates;
200
+
201
+ var arrowPoint = _this3.getArrowPoints(coords[0], coords[1]);
202
+
203
+ encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);
183
204
  }
184
- });
205
+
206
+ return encodeRecord;
207
+ }); // console.log('mappedData', mappedData)
208
+ // 调整数据兼容 Amap2.0
209
+
210
+ this.adjustData2Amap2Coordinates(mappedData, layer); // 调整数据兼容 SimpleCoordinates
211
+
212
+ this.adjustData2SimpleCoordinates(mappedData);
213
+ return mappedData;
185
214
  }
186
- }
187
- unProjectCoordinates(coordinates) {
188
- if (typeof coordinates[0] === "number") {
189
- return this.mapService.simpleMapCoord.unproject(coordinates);
215
+ }, {
216
+ key: "adjustData2Amap2Coordinates",
217
+ value: function adjustData2Amap2Coordinates(mappedData, layer) {
218
+ var _this4 = this;
219
+
220
+ // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移
221
+ if (mappedData.length > 0 && this.mapService.version === _l7Maps.Version['GAODE2.x']) {
222
+ var layerCenter = this.getLayerCenter(layer);
223
+
224
+ if (typeof mappedData[0].coordinates[0] === 'number') {
225
+ // 单个的点数据
226
+ // @ts-ignore
227
+ mappedData // TODO: 避免经纬度被重复计算导致坐标位置偏移
228
+ .filter(function (d) {
229
+ return !d.originCoordinates;
230
+ }).map(function (d) {
231
+ d.version = _l7Maps.Version['GAODE2.x']; // @ts-ignore
232
+
233
+ d.originCoordinates = (0, _lodash.cloneDeep)(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)
234
+ // @ts-ignore
235
+ // d.coordinates = this.mapService.lngLatToCoord(d.coordinates);
236
+
237
+ d.coordinates = _this4.mapService.lngLatToCoordByLayer(d.coordinates, layerCenter);
238
+ });
239
+ } else {
240
+ // 连续的线、面数据
241
+ // @ts-ignore
242
+ mappedData // TODO: 避免经纬度被重复计算导致坐标位置偏移
243
+ .filter(function (d) {
244
+ return !d.originCoordinates;
245
+ }).map(function (d) {
246
+ d.version = _l7Maps.Version['GAODE2.x']; // @ts-ignore
247
+
248
+ d.originCoordinates = (0, _lodash.cloneDeep)(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)
249
+ // @ts-ignore
250
+ // d.coordinates = this.mapService.lngLatToCoords(d.coordinates);
251
+
252
+ d.coordinates = _this4.mapService.lngLatToCoordsByLayer(d.coordinates, layerCenter);
253
+ });
254
+ }
255
+ }
256
+ }
257
+ }, {
258
+ key: "getLayerCenter",
259
+ value: function getLayerCenter(layer) {
260
+ var source = layer.getSource();
261
+ return source.center;
190
262
  }
191
- if (coordinates[0] && coordinates[0][0] instanceof Array) {
192
- const coords = [];
193
- coordinates.map((coord) => {
194
- const c1 = [];
195
- coord.map((co) => {
196
- c1.push(this.mapService.simpleMapCoord.unproject(co));
263
+ }, {
264
+ key: "adjustData2SimpleCoordinates",
265
+ value: function adjustData2SimpleCoordinates(mappedData) {
266
+ var _this5 = this;
267
+
268
+ if (mappedData.length > 0 && this.mapService.version === _l7Maps.Version.SIMPLE) {
269
+ mappedData.map(function (d) {
270
+ if (!d.simpleCoordinate) {
271
+ d.coordinates = _this5.unProjectCoordinates(d.coordinates);
272
+ d.simpleCoordinate = true;
273
+ }
197
274
  });
198
- coords.push(c1);
199
- });
200
- return coords;
201
- } else {
202
- const coords = [];
203
- coordinates.map((coord) => {
204
- coords.push(this.mapService.simpleMapCoord.unproject(coord));
205
- });
206
- return coords;
275
+ }
207
276
  }
208
- }
209
- applyAttributeMapping(attribute, record, minimumColor) {
210
- var _a;
211
- if (!attribute.scale) {
212
- return [];
277
+ }, {
278
+ key: "unProjectCoordinates",
279
+ value: function unProjectCoordinates(coordinates) {
280
+ var _this6 = this;
281
+
282
+ if (typeof coordinates[0] === 'number') {
283
+ return this.mapService.simpleMapCoord.unproject(coordinates);
284
+ }
285
+
286
+ if (coordinates[0] && coordinates[0][0] instanceof Array) {
287
+ // @ts-ignore
288
+ var coords = [];
289
+ coordinates.map(function (coord) {
290
+ // @ts-ignore
291
+ var c1 = [];
292
+ coord.map(function (co) {
293
+ c1.push(_this6.mapService.simpleMapCoord.unproject(co));
294
+ }); // @ts-ignore
295
+
296
+ coords.push(c1);
297
+ }); // @ts-ignore
298
+
299
+ return coords;
300
+ } else {
301
+ // @ts-ignore
302
+ var _coords = []; // @ts-ignore
303
+
304
+ coordinates.map(function (coord) {
305
+ _coords.push(_this6.mapService.simpleMapCoord.unproject(coord));
306
+ }); // @ts-ignore
307
+
308
+ return _coords;
309
+ }
213
310
  }
214
- const scalers = ((_a = attribute == null ? void 0 : attribute.scale) == null ? void 0 : _a.scalers) || [];
215
- const params = [];
216
- scalers.forEach(({ field }) => {
217
- var _a2;
218
- if (record.hasOwnProperty(field) || ((_a2 = attribute.scale) == null ? void 0 : _a2.type) === "variable") {
219
- params.push(record[field]);
311
+ }, {
312
+ key: "applyAttributeMapping",
313
+ value: function applyAttributeMapping(attribute, record, minimumColor) {
314
+ var _attribute$scale;
315
+
316
+ if (!attribute.scale) {
317
+ return [];
220
318
  }
221
- });
222
- const mappingResult = attribute.mapping ? attribute.mapping(params) : [];
223
- if (attribute.name === "color" && !(0, import_l7_utils.isColor)(mappingResult[0])) {
224
- return [minimumColor];
319
+
320
+ var scalers = (attribute === null || attribute === void 0 ? void 0 : (_attribute$scale = attribute.scale) === null || _attribute$scale === void 0 ? void 0 : _attribute$scale.scalers) || [];
321
+ var params = [];
322
+ scalers.forEach(function (_ref4) {
323
+ var _attribute$scale2;
324
+
325
+ var field = _ref4.field;
326
+
327
+ if (record.hasOwnProperty(field) || ((_attribute$scale2 = attribute.scale) === null || _attribute$scale2 === void 0 ? void 0 : _attribute$scale2.type) === 'variable') {
328
+ // TODO:多字段,常量
329
+ params.push(record[field]);
330
+ }
331
+ }); // console.log('params', params)
332
+ // console.log('attribute', attribute)
333
+
334
+ var mappingResult = attribute.mapping ? attribute.mapping(params) : [];
335
+
336
+ if (attribute.name === 'color' && !(0, _l7Utils.isColor)(mappingResult[0])) {
337
+ return [minimumColor];
338
+ }
339
+
340
+ return mappingResult; // return attribute.mapping ? attribute.mapping(params) : [];
225
341
  }
226
- return mappingResult;
227
- }
228
- };
229
- __decorateClass([
230
- (0, import_inversify.inject)(import_l7_core.TYPES.IGlobalConfigService)
231
- ], DataMappingPlugin.prototype, "configService", 2);
232
- __decorateClass([
233
- (0, import_inversify.inject)(import_l7_core.TYPES.IMapService)
234
- ], DataMappingPlugin.prototype, "mapService", 2);
235
- __decorateClass([
236
- (0, import_inversify.inject)(import_l7_core.TYPES.IFontService)
237
- ], DataMappingPlugin.prototype, "fontService", 2);
238
- DataMappingPlugin = __decorateClass([
239
- (0, import_inversify.injectable)()
240
- ], DataMappingPlugin);
241
- // Annotate the CommonJS export names for ESM import in node:
242
- 0 && (module.exports = {});
342
+ }]);
343
+ return DataMappingPlugin;
344
+ }(), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "configService", [_dec2], {
345
+ configurable: true,
346
+ enumerable: true,
347
+ writable: true,
348
+ initializer: null
349
+ }), _descriptor2 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "mapService", [_dec3], {
350
+ configurable: true,
351
+ enumerable: true,
352
+ writable: true,
353
+ initializer: null
354
+ }), _descriptor3 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "fontService", [_dec4], {
355
+ configurable: true,
356
+ enumerable: true,
357
+ writable: true,
358
+ initializer: null
359
+ })), _class2)) || _class);
360
+ exports.default = DataMappingPlugin;