@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,259 +1,348 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
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
- var __decorateClass = (decorators, target, key, kind) => {
22
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
23
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
24
- if (decorator = decorators[i])
25
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
26
- if (kind && result)
27
- __defProp(target, key, result);
28
- return result;
29
- };
30
-
31
- // src/plugins/FeatureScalePlugin.ts
32
- var FeatureScalePlugin_exports = {};
33
- __export(FeatureScalePlugin_exports, {
34
- default: () => FeatureScalePlugin
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
35
9
  });
36
- module.exports = __toCommonJS(FeatureScalePlugin_exports);
37
- var import_l7_core = require("@antv/l7-core");
38
- var import_d3_array = require("d3-array");
39
- var d3interpolate = __toESM(require("d3-interpolate"));
40
- var d3 = __toESM(require("d3-scale"));
41
- var import_inversify = require("inversify");
42
- var import_lodash = require("lodash");
43
- var import_reflect_metadata = require("reflect-metadata");
10
+ exports.default = void 0;
11
+
12
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
+
14
+ var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
15
+
16
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
17
+
18
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
19
+
20
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
21
+
22
+ var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
23
+
24
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
+
26
+ var _l7Core = require("@antv/l7-core");
27
+
28
+ var _d3Array = require("d3-array");
29
+
30
+ var d3interpolate = _interopRequireWildcard(require("d3-interpolate"));
31
+
32
+ var d3 = _interopRequireWildcard(require("d3-scale"));
33
+
34
+ var _inversify = require("inversify");
35
+
36
+ var _lodash = require("lodash");
37
+
38
+ require("reflect-metadata");
39
+
40
+ var _scaleMap, _dec, _dec2, _class, _class2, _descriptor;
41
+
42
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
43
+
44
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
45
+
44
46
  var dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2\2(?:29))(\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;
45
- var scaleMap = {
46
- [import_l7_core.ScaleTypes.LINEAR]: d3.scaleLinear,
47
- [import_l7_core.ScaleTypes.POWER]: d3.scalePow,
48
- [import_l7_core.ScaleTypes.LOG]: d3.scaleLog,
49
- [import_l7_core.ScaleTypes.IDENTITY]: d3.scaleIdentity,
50
- [import_l7_core.ScaleTypes.SEQUENTIAL]: d3.scaleSequential,
51
- [import_l7_core.ScaleTypes.TIME]: d3.scaleTime,
52
- [import_l7_core.ScaleTypes.QUANTILE]: d3.scaleQuantile,
53
- [import_l7_core.ScaleTypes.QUANTIZE]: d3.scaleQuantize,
54
- [import_l7_core.ScaleTypes.THRESHOLD]: d3.scaleThreshold,
55
- [import_l7_core.ScaleTypes.CAT]: d3.scaleOrdinal,
56
- [import_l7_core.ScaleTypes.DIVERGING]: d3.scaleDiverging
57
- };
58
- var FeatureScalePlugin = class {
59
- constructor() {
60
- this.scaleCache = {};
61
- this.scaleOptions = {};
47
+ var scaleMap = (_scaleMap = {}, (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.LINEAR, d3.scaleLinear), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.POWER, d3.scalePow), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.LOG, d3.scaleLog), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.IDENTITY, d3.scaleIdentity), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.SEQUENTIAL, d3.scaleSequential), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.TIME, d3.scaleTime), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.QUANTILE, d3.scaleQuantile), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.QUANTIZE, d3.scaleQuantize), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.THRESHOLD, d3.scaleThreshold), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.CAT, d3.scaleOrdinal), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.DIVERGING, d3.scaleDiverging), _scaleMap);
48
+ /**
49
+ * 根据 Source 原始数据为指定字段创建 Scale,保存在 StyleAttribute 上,供下游插件使用
50
+ */
51
+
52
+ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_l7Core.TYPES.IGlobalConfigService), _dec(_class = (_class2 = /*#__PURE__*/function () {
53
+ function FeatureScalePlugin() {
54
+ (0, _classCallCheck2.default)(this, FeatureScalePlugin);
55
+ (0, _initializerDefineProperty2.default)(this, "configService", _descriptor, this);
56
+ (0, _defineProperty2.default)(this, "scaleCache", {});
57
+ (0, _defineProperty2.default)(this, "scaleOptions", {});
62
58
  }
63
- apply(layer, {
64
- styleAttributeService
65
- }) {
66
- layer.hooks.init.tap("FeatureScalePlugin", () => {
67
- this.scaleOptions = layer.getScaleOptions();
68
- const attributes = styleAttributeService.getLayerStyleAttributes();
69
- const { dataArray } = layer.getSource().data;
70
- if (dataArray.length === 0) {
71
- return;
72
- }
73
- this.caculateScalesForAttributes(attributes || [], dataArray);
74
- });
75
- layer.hooks.beforeRenderData.tap("FeatureScalePlugin", () => {
76
- this.scaleOptions = layer.getScaleOptions();
77
- const attributes = styleAttributeService.getLayerStyleAttributes();
78
- const { dataArray } = layer.getSource().data;
79
- this.caculateScalesForAttributes(attributes || [], dataArray);
80
- layer.layerModelNeedUpdate = true;
81
- return true;
82
- });
83
- layer.hooks.beforeRender.tap("FeatureScalePlugin", () => {
84
- if (layer.layerModelNeedUpdate) {
85
- return;
86
- }
87
- this.scaleOptions = layer.getScaleOptions();
88
- const attributes = styleAttributeService.getLayerStyleAttributes();
89
- if (attributes) {
90
- const { dataArray } = layer.getSource().data;
59
+
60
+ (0, _createClass2.default)(FeatureScalePlugin, [{
61
+ key: "apply",
62
+ value: function apply(layer, _ref) {
63
+ var _this = this;
64
+
65
+ var styleAttributeService = _ref.styleAttributeService;
66
+ layer.hooks.init.tap('FeatureScalePlugin', function () {
67
+ _this.scaleOptions = layer.getScaleOptions();
68
+ var attributes = styleAttributeService.getLayerStyleAttributes();
69
+ var dataArray = layer.getSource().data.dataArray;
70
+
91
71
  if (dataArray.length === 0) {
92
72
  return;
93
73
  }
94
- const attributesToRescale = attributes.filter((attribute) => attribute.needRescale);
95
- if (attributesToRescale.length) {
96
- this.caculateScalesForAttributes(attributesToRescale, dataArray);
74
+
75
+ _this.caculateScalesForAttributes(attributes || [], dataArray);
76
+ }); // 检测数据是否需要更新
77
+
78
+ layer.hooks.beforeRenderData.tap('FeatureScalePlugin', function () {
79
+ _this.scaleOptions = layer.getScaleOptions();
80
+ var attributes = styleAttributeService.getLayerStyleAttributes();
81
+ var dataArray = layer.getSource().data.dataArray;
82
+
83
+ _this.caculateScalesForAttributes(attributes || [], dataArray);
84
+
85
+ layer.layerModelNeedUpdate = true;
86
+ return true;
87
+ });
88
+ layer.hooks.beforeRender.tap('FeatureScalePlugin', function () {
89
+ if (layer.layerModelNeedUpdate) {
90
+ return;
97
91
  }
98
- }
99
- });
100
- }
101
- isNumber(n) {
102
- return !isNaN(parseFloat(n)) && isFinite(n);
103
- }
104
- caculateScalesForAttributes(attributes, dataArray) {
105
- this.scaleCache = {};
106
- attributes.forEach((attribute) => {
107
- if (attribute.scale) {
108
- const attributeScale = attribute.scale;
109
- const type = attribute.name;
110
- attributeScale.names = this.parseFields(attribute.scale.field || []);
111
- const scales = [];
112
- attributeScale.names.forEach((field) => {
113
- var _a;
114
- scales.push(this.createScale(field, attribute.name, (_a = attribute.scale) == null ? void 0 : _a.values, dataArray));
115
- });
116
- if (scales.some((scale) => scale.type === import_l7_core.StyleScaleType.VARIABLE)) {
117
- attributeScale.type = import_l7_core.StyleScaleType.VARIABLE;
118
- scales.forEach((scale) => {
119
- var _a, _b;
120
- if (!attributeScale.callback && attributeScale.values !== "text") {
121
- switch ((_a = scale.option) == null ? void 0 : _a.type) {
122
- case import_l7_core.ScaleTypes.LOG:
123
- case import_l7_core.ScaleTypes.LINEAR:
124
- case import_l7_core.ScaleTypes.POWER:
125
- if (attributeScale.values && attributeScale.values.length > 2) {
126
- const tick = scale.scale.ticks(attributeScale.values.length);
127
- scale.scale.domain(tick);
128
- }
129
- attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
130
- break;
131
- case import_l7_core.ScaleTypes.QUANTILE:
132
- case import_l7_core.ScaleTypes.QUANTIZE:
133
- case import_l7_core.ScaleTypes.THRESHOLD:
134
- scale.scale.range(attributeScale.values);
135
- break;
136
- case import_l7_core.ScaleTypes.CAT:
137
- attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
138
- break;
139
- case import_l7_core.ScaleTypes.DIVERGING:
140
- case import_l7_core.ScaleTypes.SEQUENTIAL:
141
- scale.scale.interpolator(d3interpolate.interpolateRgbBasis(attributeScale.values));
142
- break;
143
- }
144
- }
145
- if (attributeScale.values === "text") {
146
- scale.scale.range((_b = scale.option) == null ? void 0 : _b.domain);
147
- }
92
+
93
+ _this.scaleOptions = layer.getScaleOptions();
94
+ var attributes = styleAttributeService.getLayerStyleAttributes();
95
+
96
+ if (attributes) {
97
+ var dataArray = layer.getSource().data.dataArray;
98
+
99
+ if (dataArray.length === 0) {
100
+ return;
101
+ }
102
+
103
+ var attributesToRescale = attributes.filter(function (attribute) {
104
+ return attribute.needRescale;
148
105
  });
149
- } else {
150
- attributeScale.type = import_l7_core.StyleScaleType.CONSTANT;
151
- attributeScale.defaultValues = scales.map((scale, index) => {
152
- return scale.scale(attributeScale.names[index]);
106
+
107
+ if (attributesToRescale.length) {
108
+ _this.caculateScalesForAttributes(attributesToRescale, dataArray);
109
+ }
110
+ }
111
+ });
112
+ }
113
+ }, {
114
+ key: "isNumber",
115
+ value: function isNumber(n) {
116
+ return !isNaN(parseFloat(n)) && isFinite(n);
117
+ }
118
+ }, {
119
+ key: "caculateScalesForAttributes",
120
+ value: function caculateScalesForAttributes(attributes, dataArray) {
121
+ var _this2 = this;
122
+
123
+ this.scaleCache = {};
124
+ attributes.forEach(function (attribute) {
125
+ if (attribute.scale) {
126
+ // 创建Scale
127
+ var attributeScale = attribute.scale;
128
+ attributeScale.names = _this2.parseFields(attribute.scale.field || []);
129
+ var scales = []; // 为每个字段创建 Scale
130
+
131
+ attributeScale.names.forEach(function (field) {
132
+ var _attribute$scale;
133
+
134
+ scales.push(_this2.createScale(field, attribute.name, (_attribute$scale = attribute.scale) === null || _attribute$scale === void 0 ? void 0 : _attribute$scale.values, dataArray));
135
+ }); // 为scales 设置值区间 Range
136
+
137
+ if (scales.some(function (scale) {
138
+ return scale.type === _l7Core.StyleScaleType.VARIABLE;
139
+ })) {
140
+ attributeScale.type = _l7Core.StyleScaleType.VARIABLE;
141
+ scales.forEach(function (scale) {
142
+ var _scale$option;
143
+
144
+ // 如果设置了回调, 这不需要设置range
145
+ if (!attributeScale.callback && attributeScale.values !== 'text') {
146
+ switch ((_scale$option = scale.option) === null || _scale$option === void 0 ? void 0 : _scale$option.type) {
147
+ case _l7Core.ScaleTypes.LOG:
148
+ case _l7Core.ScaleTypes.LINEAR:
149
+ case _l7Core.ScaleTypes.POWER:
150
+ if (attributeScale.values && attributeScale.values.length > 2) {
151
+ var tick = scale.scale.ticks(attributeScale.values.length);
152
+ scale.scale.domain(tick);
153
+ }
154
+
155
+ attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
156
+ break;
157
+
158
+ case _l7Core.ScaleTypes.QUANTILE:
159
+ case _l7Core.ScaleTypes.QUANTIZE:
160
+ case _l7Core.ScaleTypes.THRESHOLD:
161
+ scale.scale.range(attributeScale.values); //
162
+
163
+ break;
164
+
165
+ case _l7Core.ScaleTypes.CAT:
166
+ attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
167
+ break;
168
+
169
+ case _l7Core.ScaleTypes.DIVERGING:
170
+ case _l7Core.ScaleTypes.SEQUENTIAL:
171
+ scale.scale.interpolator( // @ts-ignore
172
+ d3interpolate.interpolateRgbBasis(attributeScale.values));
173
+ break;
174
+ }
175
+ }
176
+
177
+ if (attributeScale.values === 'text') {
178
+ var _scale$option2;
179
+
180
+ scale.scale.range((_scale$option2 = scale.option) === null || _scale$option2 === void 0 ? void 0 : _scale$option2.domain);
181
+ }
182
+ });
183
+ } else {
184
+ // 设置attribute 常量值 常量直接在value取值
185
+ attributeScale.type = _l7Core.StyleScaleType.CONSTANT;
186
+ attributeScale.defaultValues = scales.map(function (scale, index) {
187
+ return scale.scale(attributeScale.names[index]);
188
+ });
189
+ }
190
+
191
+ attributeScale.scalers = scales.map(function (scale) {
192
+ return {
193
+ field: scale.field,
194
+ func: scale.scale,
195
+ option: scale.option
196
+ };
153
197
  });
198
+ attribute.needRescale = false;
154
199
  }
155
- attributeScale.scalers = scales.map((scale) => {
156
- return {
157
- field: scale.field,
158
- func: scale.scale,
159
- option: scale.option
160
- };
161
- });
162
- attribute.needRescale = false;
163
- }
164
- });
165
- }
166
- parseFields(field) {
167
- if (Array.isArray(field)) {
168
- return field;
200
+ });
169
201
  }
170
- if ((0, import_lodash.isString)(field)) {
171
- return field.split("*");
202
+ /**
203
+ * @example
204
+ * 'w*h' => ['w', 'h']
205
+ * 'w' => ['w']
206
+ */
207
+
208
+ }, {
209
+ key: "parseFields",
210
+ value: function parseFields(field) {
211
+ if (Array.isArray(field)) {
212
+ return field;
213
+ }
214
+
215
+ if ((0, _lodash.isString)(field)) {
216
+ return field.split('*');
217
+ }
218
+
219
+ return [field];
172
220
  }
173
- return [field];
174
- }
175
- createScale(field, name, values, data) {
176
- var _a, _b;
177
- const scaleOption = this.scaleOptions[name] && ((_a = this.scaleOptions[name]) == null ? void 0 : _a.field) === field ? this.scaleOptions[name] : this.scaleOptions[field];
178
- const styleScale = {
179
- field,
180
- scale: void 0,
181
- type: import_l7_core.StyleScaleType.VARIABLE,
182
- option: scaleOption
183
- };
184
- if (!data || !data.length) {
185
- if (scaleOption && scaleOption.type) {
186
- styleScale.scale = this.createDefaultScale(scaleOption);
187
- } else {
221
+ }, {
222
+ key: "createScale",
223
+ value: function createScale(field, name, values, data) {
224
+ var _this$scaleOptions$na, _find;
225
+
226
+ // scale 支持根据视觉通道和字段
227
+ var scaleOption = this.scaleOptions[name] && ((_this$scaleOptions$na = this.scaleOptions[name]) === null || _this$scaleOptions$na === void 0 ? void 0 : _this$scaleOptions$na.field) === field ? this.scaleOptions[name] // TODO zi
228
+ : this.scaleOptions[field];
229
+ var styleScale = {
230
+ field: field,
231
+ scale: undefined,
232
+ type: _l7Core.StyleScaleType.VARIABLE,
233
+ option: scaleOption
234
+ };
235
+
236
+ if (!data || !data.length) {
237
+ if (scaleOption && scaleOption.type) {
238
+ styleScale.scale = this.createDefaultScale(scaleOption);
239
+ } else {
240
+ styleScale.scale = d3.scaleOrdinal([field]);
241
+ styleScale.type = _l7Core.StyleScaleType.CONSTANT;
242
+ }
243
+
244
+ return styleScale;
245
+ }
246
+
247
+ var firstValue = (_find = data.find(function (d) {
248
+ return !(0, _lodash.isNil)(d[field]);
249
+ })) === null || _find === void 0 ? void 0 : _find[field]; // 常量 Scale
250
+
251
+ if (this.isNumber(field) || (0, _lodash.isNil)(firstValue) && !scaleOption) {
188
252
  styleScale.scale = d3.scaleOrdinal([field]);
189
- styleScale.type = import_l7_core.StyleScaleType.CONSTANT;
253
+ styleScale.type = _l7Core.StyleScaleType.CONSTANT;
254
+ } else {
255
+ // 根据数据类型判断 默认等分位,时间,和枚举类型
256
+ var type = scaleOption && scaleOption.type || this.getDefaultType(firstValue);
257
+
258
+ if (values === 'text') {
259
+ // text 为内置变 如果是文本则为cat
260
+ type = _l7Core.ScaleTypes.CAT;
261
+ }
262
+
263
+ var cfg = this.createScaleConfig(type, field, scaleOption, data);
264
+ styleScale.scale = this.createDefaultScale(cfg);
265
+ styleScale.option = cfg;
190
266
  }
267
+
191
268
  return styleScale;
192
269
  }
193
- const firstValue = (_b = data.find((d) => !(0, import_lodash.isNil)(d[field]))) == null ? void 0 : _b[field];
194
- if (this.isNumber(field) || (0, import_lodash.isNil)(firstValue) && !scaleOption) {
195
- styleScale.scale = d3.scaleOrdinal([field]);
196
- styleScale.type = import_l7_core.StyleScaleType.CONSTANT;
197
- } else {
198
- let type = scaleOption && scaleOption.type || this.getDefaultType(firstValue);
199
- if (values === "text") {
200
- type = import_l7_core.ScaleTypes.CAT;
270
+ }, {
271
+ key: "getDefaultType",
272
+ value: function getDefaultType(firstValue) {
273
+ var type = _l7Core.ScaleTypes.LINEAR;
274
+
275
+ if (typeof firstValue === 'string') {
276
+ type = dateRegex.test(firstValue) ? _l7Core.ScaleTypes.TIME : _l7Core.ScaleTypes.CAT;
201
277
  }
202
- const cfg = this.createScaleConfig(type, field, scaleOption, data);
203
- styleScale.scale = this.createDefaultScale(cfg);
204
- styleScale.option = cfg;
205
- }
206
- return styleScale;
207
- }
208
- getDefaultType(firstValue) {
209
- let type = import_l7_core.ScaleTypes.LINEAR;
210
- if (typeof firstValue === "string") {
211
- type = dateRegex.test(firstValue) ? import_l7_core.ScaleTypes.TIME : import_l7_core.ScaleTypes.CAT;
212
- }
213
- return type;
214
- }
215
- createScaleConfig(type, field, scaleOption, data) {
216
- const cfg = {
217
- type
218
- };
219
- const values = (data == null ? void 0 : data.map((item) => item[field])) || [];
220
- if (scaleOption == null ? void 0 : scaleOption.domain) {
221
- cfg.domain = scaleOption == null ? void 0 : scaleOption.domain;
222
- } else if (type !== import_l7_core.ScaleTypes.CAT && type !== import_l7_core.ScaleTypes.QUANTILE && type !== import_l7_core.ScaleTypes.DIVERGING) {
223
- cfg.domain = (0, import_d3_array.extent)(values);
224
- } else if (type === import_l7_core.ScaleTypes.CAT) {
225
- cfg.domain = (0, import_lodash.uniq)(values);
226
- } else if (type === import_l7_core.ScaleTypes.QUANTILE) {
227
- cfg.domain = values;
228
- } else if (type === import_l7_core.ScaleTypes.DIVERGING) {
229
- const minMax = (0, import_d3_array.extent)(values);
230
- const neutral = (scaleOption == null ? void 0 : scaleOption.neutral) !== void 0 ? scaleOption == null ? void 0 : scaleOption.neutral : (minMax[0] + minMax[1]) / 2;
231
- cfg.domain = [minMax[0], neutral, minMax[1]];
232
- }
233
- return { ...cfg, ...scaleOption };
234
- }
235
- createDefaultScale({ type, domain, unknown, clamp, nice }) {
236
- const scale = scaleMap[type]();
237
- if (domain && scale.domain) {
238
- scale.domain(domain);
239
- }
240
- if (unknown) {
241
- scale.unknown(unknown);
242
- }
243
- if (clamp !== void 0 && scale.clamp) {
244
- scale.clamp(clamp);
245
- }
246
- if (nice !== void 0 && scale.nice) {
247
- scale.nice(nice);
278
+
279
+ return type;
280
+ } // 生成Scale 默认配置
281
+
282
+ }, {
283
+ key: "createScaleConfig",
284
+ value: function createScaleConfig(type, field, scaleOption, data) {
285
+ var cfg = {
286
+ type: type
287
+ };
288
+ var values = (data === null || data === void 0 ? void 0 : data.map(function (item) {
289
+ return item[field];
290
+ })) || [];
291
+
292
+ if (scaleOption !== null && scaleOption !== void 0 && scaleOption.domain) {
293
+ cfg.domain = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.domain;
294
+ } else if (type !== _l7Core.ScaleTypes.CAT && type !== _l7Core.ScaleTypes.QUANTILE && type !== _l7Core.ScaleTypes.DIVERGING) {
295
+ // linear/
296
+ cfg.domain = (0, _d3Array.extent)(values);
297
+ } else if (type === _l7Core.ScaleTypes.CAT) {
298
+ cfg.domain = (0, _lodash.uniq)(values);
299
+ } else if (type === _l7Core.ScaleTypes.QUANTILE) {
300
+ cfg.domain = values;
301
+ } else if (type === _l7Core.ScaleTypes.DIVERGING) {
302
+ var minMax = (0, _d3Array.extent)(values);
303
+ var neutral = (scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.neutral) !== undefined ? scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.neutral : (minMax[0] + minMax[1]) / 2;
304
+ cfg.domain = [minMax[0], neutral, minMax[1]];
305
+ }
306
+
307
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, cfg), scaleOption);
308
+ } // 创建Scale 实例
309
+
310
+ }, {
311
+ key: "createDefaultScale",
312
+ value: function createDefaultScale(_ref2) {
313
+ var type = _ref2.type,
314
+ domain = _ref2.domain,
315
+ unknown = _ref2.unknown,
316
+ clamp = _ref2.clamp,
317
+ nice = _ref2.nice;
318
+ // @ts-ignore
319
+ var scale = scaleMap[type]();
320
+
321
+ if (domain && scale.domain) {
322
+ scale.domain(domain);
323
+ }
324
+
325
+ if (unknown) {
326
+ scale.unknown(unknown);
327
+ }
328
+
329
+ if (clamp !== undefined && scale.clamp) {
330
+ scale.clamp(clamp);
331
+ }
332
+
333
+ if (nice !== undefined && scale.nice) {
334
+ scale.nice(nice);
335
+ } // TODO 其他属性支持
336
+
337
+
338
+ return scale;
248
339
  }
249
- return scale;
250
- }
251
- };
252
- __decorateClass([
253
- (0, import_inversify.inject)(import_l7_core.TYPES.IGlobalConfigService)
254
- ], FeatureScalePlugin.prototype, "configService", 2);
255
- FeatureScalePlugin = __decorateClass([
256
- (0, import_inversify.injectable)()
257
- ], FeatureScalePlugin);
258
- // Annotate the CommonJS export names for ESM import in node:
259
- 0 && (module.exports = {});
340
+ }]);
341
+ return FeatureScalePlugin;
342
+ }(), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "configService", [_dec2], {
343
+ configurable: true,
344
+ enumerable: true,
345
+ writable: true,
346
+ initializer: null
347
+ })), _class2)) || _class);
348
+ exports.default = FeatureScalePlugin;