@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
|
@@ -1,258 +1,348 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
layer
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
attributeScale.names.forEach((field) => {
|
|
112
|
-
var _a;
|
|
113
|
-
scales.push(this.createScale(field, attribute.name, (_a = attribute.scale) == null ? void 0 : _a.values, dataArray));
|
|
114
|
-
});
|
|
115
|
-
if (scales.some((scale) => scale.type === import_l7_core.StyleScaleType.VARIABLE)) {
|
|
116
|
-
attributeScale.type = import_l7_core.StyleScaleType.VARIABLE;
|
|
117
|
-
scales.forEach((scale) => {
|
|
118
|
-
var _a, _b;
|
|
119
|
-
if (!attributeScale.callback && attributeScale.values !== "text") {
|
|
120
|
-
switch ((_a = scale.option) == null ? void 0 : _a.type) {
|
|
121
|
-
case import_l7_core.ScaleTypes.LOG:
|
|
122
|
-
case import_l7_core.ScaleTypes.LINEAR:
|
|
123
|
-
case import_l7_core.ScaleTypes.POWER:
|
|
124
|
-
if (attributeScale.values && attributeScale.values.length > 2) {
|
|
125
|
-
const tick = scale.scale.ticks(attributeScale.values.length);
|
|
126
|
-
scale.scale.domain(tick);
|
|
127
|
-
}
|
|
128
|
-
attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
|
|
129
|
-
break;
|
|
130
|
-
case import_l7_core.ScaleTypes.QUANTILE:
|
|
131
|
-
case import_l7_core.ScaleTypes.QUANTIZE:
|
|
132
|
-
case import_l7_core.ScaleTypes.THRESHOLD:
|
|
133
|
-
scale.scale.range(attributeScale.values);
|
|
134
|
-
break;
|
|
135
|
-
case import_l7_core.ScaleTypes.CAT:
|
|
136
|
-
attributeScale.values ? scale.scale.range(attributeScale.values) : scale.scale.range(scale.option.domain);
|
|
137
|
-
break;
|
|
138
|
-
case import_l7_core.ScaleTypes.DIVERGING:
|
|
139
|
-
case import_l7_core.ScaleTypes.SEQUENTIAL:
|
|
140
|
-
scale.scale.interpolator(d3interpolate.interpolateRgbBasis(attributeScale.values));
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (attributeScale.values === "text") {
|
|
145
|
-
scale.scale.range((_b = scale.option) == null ? void 0 : _b.domain);
|
|
146
|
-
}
|
|
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;
|
|
147
105
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
+
};
|
|
152
197
|
});
|
|
198
|
+
attribute.needRescale = false;
|
|
153
199
|
}
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
field: scale.field,
|
|
157
|
-
func: scale.scale,
|
|
158
|
-
option: scale.option
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
attribute.needRescale = false;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
parseFields(field) {
|
|
166
|
-
if (Array.isArray(field)) {
|
|
167
|
-
return field;
|
|
200
|
+
});
|
|
168
201
|
}
|
|
169
|
-
|
|
170
|
-
|
|
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];
|
|
171
220
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
field
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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) {
|
|
187
252
|
styleScale.scale = d3.scaleOrdinal([field]);
|
|
188
|
-
styleScale.type =
|
|
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;
|
|
189
266
|
}
|
|
267
|
+
|
|
190
268
|
return styleScale;
|
|
191
269
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
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;
|
|
200
277
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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;
|
|
247
339
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
258
|
-
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;
|