@antv/l7-layers 2.9.25-alpha.0 → 2.9.26-alpha.1

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 (126) hide show
  1. package/es/heatmap/models/heatmap.js +1 -1
  2. package/es/tile/tileFactory/base.d.ts +1 -1
  3. package/es/tile/utils.js +1 -1
  4. package/lib/Geometry/index.js +114 -77
  5. package/lib/Geometry/models/billboard.js +232 -181
  6. package/lib/Geometry/models/index.js +18 -34
  7. package/lib/Geometry/models/plane.js +407 -278
  8. package/lib/Geometry/models/sprite.js +291 -189
  9. package/lib/canvas/index.js +101 -66
  10. package/lib/canvas/models/canvas.js +207 -140
  11. package/lib/canvas/models/index.js +12 -30
  12. package/lib/citybuliding/building.js +98 -63
  13. package/lib/citybuliding/models/build.js +192 -146
  14. package/lib/core/BaseLayer.js +1331 -814
  15. package/lib/core/BaseModel.js +457 -279
  16. package/lib/core/interface.js +40 -53
  17. package/lib/core/schema.js +21 -39
  18. package/lib/core/shape/Path.js +67 -79
  19. package/lib/core/shape/extrude.js +132 -91
  20. package/lib/core/triangulation.js +378 -196
  21. package/lib/earth/index.js +100 -62
  22. package/lib/earth/models/atmosphere.js +146 -112
  23. package/lib/earth/models/base.js +210 -150
  24. package/lib/earth/models/bloomsphere.js +146 -112
  25. package/lib/earth/utils.js +111 -91
  26. package/lib/heatmap/index.js +149 -92
  27. package/lib/heatmap/models/grid.js +118 -91
  28. package/lib/heatmap/models/grid3d.js +155 -123
  29. package/lib/heatmap/models/heatmap.js +475 -338
  30. package/lib/heatmap/models/hexagon.js +121 -92
  31. package/lib/heatmap/models/index.js +22 -37
  32. package/lib/heatmap/triangulation.js +31 -47
  33. package/lib/image/index.js +111 -74
  34. package/lib/image/models/dataImage.js +232 -174
  35. package/lib/image/models/image.js +175 -128
  36. package/lib/image/models/index.js +15 -32
  37. package/lib/index.js +263 -97
  38. package/lib/line/index.js +131 -85
  39. package/lib/line/models/arc.js +352 -237
  40. package/lib/line/models/arc_3d.js +334 -228
  41. package/lib/line/models/earthArc_3d.js +336 -228
  42. package/lib/line/models/great_circle.js +291 -200
  43. package/lib/line/models/half.js +286 -201
  44. package/lib/line/models/index.js +42 -50
  45. package/lib/line/models/line.js +428 -299
  46. package/lib/line/models/linearline.js +277 -203
  47. package/lib/line/models/simpleLine.js +239 -175
  48. package/lib/line/models/tile.js +348 -237
  49. package/lib/line/models/wall.js +327 -235
  50. package/lib/mask/index.js +92 -59
  51. package/lib/mask/models/fill.js +134 -82
  52. package/lib/mask/models/index.js +12 -30
  53. package/lib/plugins/DataMappingPlugin.js +342 -224
  54. package/lib/plugins/DataSourcePlugin.js +102 -87
  55. package/lib/plugins/FeatureScalePlugin.js +330 -240
  56. package/lib/plugins/LayerAnimateStylePlugin.js +61 -55
  57. package/lib/plugins/LayerModelPlugin.js +80 -73
  58. package/lib/plugins/LayerStylePlugin.js +48 -51
  59. package/lib/plugins/LightingPlugin.js +80 -68
  60. package/lib/plugins/MultiPassRendererPlugin.js +91 -65
  61. package/lib/plugins/PixelPickingPlugin.js +150 -109
  62. package/lib/plugins/RegisterStyleAttributePlugin.js +110 -110
  63. package/lib/plugins/ShaderUniformPlugin.js +118 -99
  64. package/lib/plugins/UpdateModelPlugin.js +40 -47
  65. package/lib/plugins/UpdateStyleAttributePlugin.js +93 -75
  66. package/lib/point/index.js +226 -150
  67. package/lib/point/models/earthExtrude.js +279 -201
  68. package/lib/point/models/earthFill.js +287 -202
  69. package/lib/point/models/extrude.js +299 -203
  70. package/lib/point/models/fill.js +406 -275
  71. package/lib/point/models/fillmage.js +365 -256
  72. package/lib/point/models/image.js +241 -168
  73. package/lib/point/models/index.js +46 -52
  74. package/lib/point/models/normal.js +183 -134
  75. package/lib/point/models/radar.js +304 -211
  76. package/lib/point/models/simplePoint.js +194 -142
  77. package/lib/point/models/text.js +608 -385
  78. package/lib/point/models/tile.js +314 -223
  79. package/lib/point/shape/extrude.js +56 -52
  80. package/lib/polygon/index.js +154 -102
  81. package/lib/polygon/models/extrude.js +311 -223
  82. package/lib/polygon/models/fill.js +215 -153
  83. package/lib/polygon/models/index.js +46 -52
  84. package/lib/polygon/models/ocean.js +244 -173
  85. package/lib/polygon/models/tile.js +144 -100
  86. package/lib/polygon/models/water.js +222 -153
  87. package/lib/raster/buffers/triangulation.js +27 -40
  88. package/lib/raster/index.js +115 -75
  89. package/lib/raster/models/index.js +16 -33
  90. package/lib/raster/models/raster.js +178 -135
  91. package/lib/raster/raster.js +187 -132
  92. package/lib/tile/interface.js +4 -16
  93. package/lib/tile/manager/tileConfigManager.js +125 -86
  94. package/lib/tile/manager/tileLayerManager.js +313 -229
  95. package/lib/tile/manager/tilePickerManager.js +192 -123
  96. package/lib/tile/models/tileModel.js +71 -52
  97. package/lib/tile/tileFactory/base.js +432 -309
  98. package/lib/tile/tileFactory/index.js +51 -49
  99. package/lib/tile/tileFactory/line.js +65 -50
  100. package/lib/tile/tileFactory/point.js +65 -50
  101. package/lib/tile/tileFactory/polygon.js +65 -50
  102. package/lib/tile/tileFactory/raster.js +66 -54
  103. package/lib/tile/tileFactory/rasterData.js +88 -76
  104. package/lib/tile/tileFactory/rasterDataLayer.js +97 -62
  105. package/lib/tile/tileFactory/vectorLayer.js +168 -109
  106. package/lib/tile/tileLayer/baseTileLayer.js +420 -221
  107. package/lib/tile/tmsTileLayer.js +110 -67
  108. package/lib/tile/utils.js +110 -92
  109. package/lib/utils/blend.js +59 -79
  110. package/lib/utils/collision-index.js +107 -64
  111. package/lib/utils/dataMappingStyle.js +105 -60
  112. package/lib/utils/extrude_polyline.js +600 -398
  113. package/lib/utils/grid-index.js +163 -111
  114. package/lib/utils/layerData.js +130 -99
  115. package/lib/utils/multiPassRender.js +49 -41
  116. package/lib/utils/polylineNormal.js +148 -96
  117. package/lib/utils/simpleLine.js +100 -85
  118. package/lib/utils/symbol-layout.js +219 -116
  119. package/lib/utils/updateShape.js +15 -41
  120. package/lib/wind/index.js +109 -71
  121. package/lib/wind/models/index.js +12 -30
  122. package/lib/wind/models/utils.js +144 -105
  123. package/lib/wind/models/wind.js +333 -224
  124. package/lib/wind/models/windRender.js +329 -218
  125. package/lib/wind/models/windShader.js +23 -181
  126. package/package.json +6 -6
@@ -1,891 +1,1408 @@
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/core/BaseLayer.ts
32
- var BaseLayer_exports = {};
33
- __export(BaseLayer_exports, {
34
- default: () => BaseLayer
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
35
7
  });
36
- module.exports = __toCommonJS(BaseLayer_exports);
37
- var import_async_hook = require("@antv/async-hook");
38
- var import_l7_core = require("@antv/l7-core");
39
- var import_l7_source = __toESM(require("@antv/l7-source"));
40
- var import_l7_utils = require("@antv/l7-utils");
41
- var import_eventemitter3 = require("eventemitter3");
42
- var import_lodash = require("lodash");
43
- var import_blend = require("../utils/blend");
44
- var import_dataMappingStyle = require("../utils/dataMappingStyle");
45
- var import_layerData = require("../utils/layerData");
46
- var import_multiPassRender = require("../utils/multiPassRender");
47
- var import_updateShape = require("../utils/updateShape");
8
+ exports.default = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
+
16
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
17
+
18
+ var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
19
+
20
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
21
+
22
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
23
+
24
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
25
+
26
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
27
+
28
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
29
+
30
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
31
+
32
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
33
+
34
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
35
+
36
+ var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
37
+
38
+ var _asyncHook = require("@antv/async-hook");
39
+
40
+ var _l7Core = require("@antv/l7-core");
41
+
42
+ var _l7Source = _interopRequireDefault(require("@antv/l7-source"));
43
+
44
+ var _l7Utils = require("@antv/l7-utils");
45
+
46
+ var _eventemitter = require("eventemitter3");
47
+
48
+ var _lodash = require("lodash");
49
+
50
+ var _blend = require("../utils/blend");
51
+
52
+ var _dataMappingStyle = require("../utils/dataMappingStyle");
53
+
54
+ var _layerData = require("../utils/layerData");
55
+
56
+ var _multiPassRender = require("../utils/multiPassRender");
57
+
58
+ var _updateShape = require("../utils/updateShape");
59
+
60
+ var _excluded = ["passes"],
61
+ _excluded2 = ["moduleName", "vertexShader", "fragmentShader", "triangulation", "segmentNumber", "workerEnabled", "workerOptions"];
62
+
63
+ var _dec, _class, _descriptor;
64
+
65
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
66
+
67
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
68
+
69
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
70
+
71
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
72
+
73
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
74
+
75
+ /**
76
+ * 分配 layer id
77
+ */
48
78
  var layerIdCounter = 0;
49
- var BaseLayer = class extends import_eventemitter3.EventEmitter {
50
- constructor(config = {}) {
51
- super();
52
- this.id = `${layerIdCounter++}`;
53
- this.name = `${layerIdCounter}`;
54
- this.visible = true;
55
- this.zIndex = 0;
56
- this.inited = false;
57
- this.layerModelNeedUpdate = false;
58
- this.pickedFeatureID = null;
59
- this.selectedFeatureID = null;
60
- this.styleNeedUpdate = false;
61
- this.clusterZoom = 0;
62
- this.dataState = {
79
+ var BaseLayer = (_dec = (0, _l7Core.lazyInject)(_l7Core.TYPES.IGlobalConfigService), (_class = /*#__PURE__*/function (_ref) {
80
+ (0, _inherits2.default)(BaseLayer, _ref);
81
+
82
+ var _super = _createSuper(BaseLayer);
83
+
84
+ // 生命周期钩子
85
+ // 待渲染 model 列表
86
+ // TODO: 用于保存子图层对象
87
+ // Tip: 用于标识矢量图层
88
+
89
+ /**
90
+ * 待更新样式属性,在初始化阶段完成注册
91
+ */
92
+ // TODO: layer 保底颜色
93
+ // private pickingPassRender: IPass<'pixelPicking'>;
94
+ function BaseLayer() {
95
+ var _this;
96
+
97
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
98
+ (0, _classCallCheck2.default)(this, BaseLayer);
99
+ _this = _super.call(this);
100
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "id", "".concat(layerIdCounter++));
101
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "name", "".concat(layerIdCounter));
102
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "visible", true);
103
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "zIndex", 0);
104
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "inited", false);
105
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "layerModelNeedUpdate", false);
106
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "pickedFeatureID", null);
107
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "selectedFeatureID", null);
108
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "styleNeedUpdate", false);
109
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "clusterZoom", 0);
110
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "dataState", {
63
111
  dataSourceNeedUpdate: false,
64
112
  dataMappingNeedUpdate: false,
65
113
  filterNeedUpdate: false,
66
114
  featureScaleNeedUpdate: false,
67
115
  StyleAttrNeedUpdate: false
68
- };
69
- this.hooks = {
70
- init: new import_async_hook.SyncBailHook(),
71
- afterInit: new import_async_hook.SyncBailHook(),
72
- beforeRender: new import_async_hook.SyncBailHook(),
73
- beforeRenderData: new import_async_hook.SyncWaterfallHook(),
74
- afterRender: new import_async_hook.SyncHook(),
75
- beforePickingEncode: new import_async_hook.SyncHook(),
76
- afterPickingEncode: new import_async_hook.SyncHook(),
77
- beforeHighlight: new import_async_hook.SyncHook(["pickedColor"]),
78
- afterHighlight: new import_async_hook.SyncHook(),
79
- beforeSelect: new import_async_hook.SyncHook(["pickedColor"]),
80
- afterSelect: new import_async_hook.SyncHook(),
81
- beforeDestroy: new import_async_hook.SyncHook(),
82
- afterDestroy: new import_async_hook.SyncHook()
83
- };
84
- this.models = [];
85
- this.layerChildren = [];
86
- this.masks = [];
87
- this.isVector = false;
88
- this.animateOptions = { enable: false };
89
- this.currentPickId = null;
90
- this.pendingStyleAttributes = [];
91
- this.scaleOptions = {};
92
- this.aniamateStatus = false;
93
- this.bottomColor = "rgba(0, 0, 0, 0)";
94
- this.isDestroied = false;
95
- this.sourceEvent = () => {
96
- this.dataState.dataSourceNeedUpdate = true;
97
- const layerConfig = this.getLayerConfig();
116
+ });
117
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hooks", {
118
+ init: new _asyncHook.SyncBailHook(),
119
+ afterInit: new _asyncHook.SyncBailHook(),
120
+ beforeRender: new _asyncHook.SyncBailHook(),
121
+ beforeRenderData: new _asyncHook.SyncWaterfallHook(),
122
+ afterRender: new _asyncHook.SyncHook(),
123
+ beforePickingEncode: new _asyncHook.SyncHook(),
124
+ afterPickingEncode: new _asyncHook.SyncHook(),
125
+ beforeHighlight: new _asyncHook.SyncHook(['pickedColor']),
126
+ afterHighlight: new _asyncHook.SyncHook(),
127
+ beforeSelect: new _asyncHook.SyncHook(['pickedColor']),
128
+ afterSelect: new _asyncHook.SyncHook(),
129
+ beforeDestroy: new _asyncHook.SyncHook(),
130
+ afterDestroy: new _asyncHook.SyncHook()
131
+ });
132
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "models", []);
133
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "layerChildren", []);
134
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "masks", []);
135
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isVector", false);
136
+ (0, _initializerDefineProperty2.default)((0, _assertThisInitialized2.default)(_this), "configService", _descriptor, (0, _assertThisInitialized2.default)(_this));
137
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "animateOptions", {
138
+ enable: false
139
+ });
140
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "currentPickId", null);
141
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "pendingStyleAttributes", []);
142
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "scaleOptions", {});
143
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "aniamateStatus", false);
144
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "bottomColor", 'rgba(0, 0, 0, 0)');
145
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isDestroied", false);
146
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "sourceEvent", function () {
147
+ _this.dataState.dataSourceNeedUpdate = true;
148
+
149
+ var layerConfig = _this.getLayerConfig();
150
+
98
151
  if (layerConfig && layerConfig.autoFit) {
99
- this.fitBounds(layerConfig.fitBoundsOptions);
100
- }
101
- this.reRender();
102
- };
103
- this.name = config.name || this.id;
104
- this.zIndex = config.zIndex || 0;
105
- this.rawConfig = config;
106
- }
107
- addMaskLayer(maskLayer) {
108
- this.masks.push(maskLayer);
152
+ _this.fitBounds(layerConfig.fitBoundsOptions);
153
+ } // 对外暴露事件 迁移到 DataMappingPlugin generateMapping,保证在重新重新映射后触发
154
+ // this.emit('dataUpdate');
155
+
156
+
157
+ _this.reRender();
158
+ });
159
+ _this.name = config.name || _this.id;
160
+ _this.zIndex = config.zIndex || 0;
161
+ _this.rawConfig = config;
162
+ return _this;
109
163
  }
110
- removeMaskLayer(maskLayer) {
111
- const layerIndex = this.masks.indexOf(maskLayer);
112
- if (layerIndex > -1) {
113
- this.masks.splice(layerIndex, 1);
164
+
165
+ (0, _createClass2.default)(BaseLayer, [{
166
+ key: "addMaskLayer",
167
+ value: function addMaskLayer(maskLayer) {
168
+ this.masks.push(maskLayer);
114
169
  }
115
- maskLayer.destroy();
116
- }
117
- getAttribute(name) {
118
- return this.styleAttributeService.getLayerStyleAttribute(name);
119
- }
120
- getLayerConfig() {
121
- return this.configService.getLayerConfig(this.id);
122
- }
123
- updateLayerConfig(configToUpdate) {
124
- Object.keys(configToUpdate).map((key) => {
125
- if (key in this.rawConfig) {
126
- this.rawConfig[key] = configToUpdate[key];
170
+ }, {
171
+ key: "removeMaskLayer",
172
+ value: function removeMaskLayer(maskLayer) {
173
+ var layerIndex = this.masks.indexOf(maskLayer);
174
+
175
+ if (layerIndex > -1) {
176
+ this.masks.splice(layerIndex, 1);
127
177
  }
128
- });
129
- if (!this.inited) {
130
- this.needUpdateConfig = {
131
- ...this.needUpdateConfig,
132
- ...configToUpdate
133
- };
134
- } else {
135
- const sceneId = this.container.get(import_l7_core.TYPES.SceneID);
136
- (0, import_dataMappingStyle.handleStyleDataMapping)(configToUpdate, this);
137
- this.configService.setLayerConfig(sceneId, this.id, {
138
- ...this.configService.getLayerConfig(this.id),
139
- ...this.needUpdateConfig,
140
- ...configToUpdate
141
- });
142
- this.needUpdateConfig = {};
178
+
179
+ maskLayer.destroy();
143
180
  }
144
- }
145
- setContainer(container, sceneContainer) {
146
- this.container = container;
147
- this.sceneContainer = sceneContainer;
148
- }
149
- getContainer() {
150
- return this.container;
151
- }
152
- setBottomColor(color) {
153
- this.bottomColor = color;
154
- }
155
- getBottomColor() {
156
- return this.bottomColor;
157
- }
158
- addPlugin(plugin) {
159
- this.plugins.push(plugin);
160
- return this;
161
- }
162
- init() {
163
- const sceneId = this.container.get(import_l7_core.TYPES.SceneID);
164
- this.configService.setLayerConfig(sceneId, this.id, this.rawConfig);
165
- this.layerType = this.rawConfig.layerType;
166
- this.iconService = this.container.get(import_l7_core.TYPES.IIconService);
167
- this.fontService = this.container.get(import_l7_core.TYPES.IFontService);
168
- this.rendererService = this.container.get(import_l7_core.TYPES.IRendererService);
169
- this.layerService = this.container.get(import_l7_core.TYPES.ILayerService);
170
- this.interactionService = this.container.get(import_l7_core.TYPES.IInteractionService);
171
- this.pickingService = this.container.get(import_l7_core.TYPES.IPickingService);
172
- this.mapService = this.container.get(import_l7_core.TYPES.IMapService);
173
- const { enableMultiPassRenderer, passes } = this.getLayerConfig();
174
- if (enableMultiPassRenderer && (passes == null ? void 0 : passes.length) && passes.length > 0) {
175
- this.mapService.on("mapAfterFrameChange", () => {
176
- this.renderLayers();
177
- });
181
+ }, {
182
+ key: "getAttribute",
183
+ value: function getAttribute(name) {
184
+ return this.styleAttributeService.getLayerStyleAttribute(name);
185
+ }
186
+ }, {
187
+ key: "getLayerConfig",
188
+ value: function getLayerConfig() {
189
+ return this.configService.getLayerConfig(this.id);
178
190
  }
179
- this.cameraService = this.container.get(import_l7_core.TYPES.ICameraService);
180
- this.coordinateService = this.container.get(import_l7_core.TYPES.ICoordinateSystemService);
181
- this.shaderModuleService = this.container.get(import_l7_core.TYPES.IShaderModuleService);
182
- this.postProcessingPassFactory = this.container.get(import_l7_core.TYPES.IFactoryPostProcessingPass);
183
- this.normalPassFactory = this.container.get(import_l7_core.TYPES.IFactoryNormalPass);
184
- this.styleAttributeService = this.container.get(import_l7_core.TYPES.IStyleAttributeService);
185
- this.multiPassRenderer = this.container.get(import_l7_core.TYPES.IMultiPassRenderer);
186
- this.multiPassRenderer.setLayer(this);
187
- this.pendingStyleAttributes.forEach(({ attributeName, attributeField, attributeValues, updateOptions }) => {
188
- this.styleAttributeService.updateStyleAttribute(attributeName, {
189
- scale: {
190
- field: attributeField,
191
- ...this.splitValuesAndCallbackInAttribute(attributeValues, this.getLayerConfig()[attributeName])
191
+ }, {
192
+ key: "updateLayerConfig",
193
+ value: function updateLayerConfig(configToUpdate) {
194
+ var _this2 = this;
195
+
196
+ // 同步 rawConfig
197
+ Object.keys(configToUpdate).map(function (key) {
198
+ if (key in _this2.rawConfig) {
199
+ // @ts-ignore
200
+ _this2.rawConfig[key] = configToUpdate[key];
192
201
  }
193
- }, updateOptions);
194
- });
195
- this.pendingStyleAttributes = [];
196
- this.plugins = this.container.getAll(import_l7_core.TYPES.ILayerPlugin);
197
- for (const plugin of this.plugins) {
198
- plugin.apply(this, {
199
- rendererService: this.rendererService,
200
- mapService: this.mapService,
201
- styleAttributeService: this.styleAttributeService,
202
- normalPassFactory: this.normalPassFactory,
203
- postProcessingPassFactory: this.postProcessingPassFactory
204
202
  });
203
+
204
+ if (!this.inited) {
205
+ this.needUpdateConfig = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.needUpdateConfig), configToUpdate);
206
+ } else {
207
+ var sceneId = this.container.get(_l7Core.TYPES.SceneID); // @ts-ignore
208
+
209
+ (0, _dataMappingStyle.handleStyleDataMapping)(configToUpdate, this); // 处理 style 中进行数据映射的属性字段
210
+
211
+ this.configService.setLayerConfig(sceneId, this.id, (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.configService.getLayerConfig(this.id)), this.needUpdateConfig), configToUpdate));
212
+ this.needUpdateConfig = {};
213
+ }
205
214
  }
206
- this.hooks.init.call();
207
- this.hooks.afterInit.call();
208
- this.emit("inited", {
209
- target: this,
210
- type: "inited"
211
- });
212
- this.emit("add", {
213
- target: this,
214
- type: "add"
215
- });
216
- return this;
217
- }
218
- updateModelData(data) {
219
- if (data.attributes && data.elements) {
220
- this.models.map((m) => {
221
- m.updateAttributesAndElements(data.attributes, data.elements);
215
+ /**
216
+ * 注入图层容器,父容器为场景容器
217
+ * RootContainer 1
218
+ * -> SceneContainer 1.*
219
+ * -> LayerContainer 1.*
220
+ */
221
+
222
+ }, {
223
+ key: "setContainer",
224
+ value: function setContainer(container, sceneContainer) {
225
+ this.container = container;
226
+ this.sceneContainer = sceneContainer;
227
+ }
228
+ }, {
229
+ key: "getContainer",
230
+ value: function getContainer() {
231
+ return this.container;
232
+ }
233
+ }, {
234
+ key: "setBottomColor",
235
+ value: function setBottomColor(color) {
236
+ this.bottomColor = color;
237
+ }
238
+ }, {
239
+ key: "getBottomColor",
240
+ value: function getBottomColor() {
241
+ return this.bottomColor;
242
+ }
243
+ }, {
244
+ key: "addPlugin",
245
+ value: function addPlugin(plugin) {
246
+ // TODO: 控制插件注册顺序
247
+ // @example:
248
+ // pointLayer.addPlugin(new MyCustomPlugin(), {
249
+ // before: 'L7BuiltinPlugin'
250
+ // });
251
+ this.plugins.push(plugin);
252
+ return this;
253
+ }
254
+ }, {
255
+ key: "init",
256
+ value: function init() {
257
+ var _this3 = this;
258
+
259
+ // 设置配置项
260
+ var sceneId = this.container.get(_l7Core.TYPES.SceneID); // 初始化图层配置项
261
+ // const { enableMultiPassRenderer = false } = this.rawConfig;
262
+ // this.configService.setLayerConfig(sceneId, this.id, {
263
+ // enableMultiPassRenderer,
264
+ // });
265
+
266
+ this.configService.setLayerConfig(sceneId, this.id, this.rawConfig);
267
+ this.layerType = this.rawConfig.layerType; // 全局容器服务
268
+ // 场景容器服务
269
+
270
+ this.iconService = this.container.get(_l7Core.TYPES.IIconService);
271
+ this.fontService = this.container.get(_l7Core.TYPES.IFontService);
272
+ this.rendererService = this.container.get(_l7Core.TYPES.IRendererService);
273
+ this.layerService = this.container.get(_l7Core.TYPES.ILayerService);
274
+ this.interactionService = this.container.get(_l7Core.TYPES.IInteractionService);
275
+ this.pickingService = this.container.get(_l7Core.TYPES.IPickingService);
276
+ this.mapService = this.container.get(_l7Core.TYPES.IMapService);
277
+
278
+ var _this$getLayerConfig = this.getLayerConfig(),
279
+ enableMultiPassRenderer = _this$getLayerConfig.enableMultiPassRenderer,
280
+ passes = _this$getLayerConfig.passes;
281
+
282
+ if (enableMultiPassRenderer && passes !== null && passes !== void 0 && passes.length && passes.length > 0) {
283
+ // Tip: 兼容 multiPassRender 在 amap1 时存在的图层不同步问题 zoom
284
+ this.mapService.on('mapAfterFrameChange', function () {
285
+ _this3.renderLayers();
286
+ });
287
+ }
288
+
289
+ this.cameraService = this.container.get(_l7Core.TYPES.ICameraService);
290
+ this.coordinateService = this.container.get(_l7Core.TYPES.ICoordinateSystemService);
291
+ this.shaderModuleService = this.container.get(_l7Core.TYPES.IShaderModuleService);
292
+ this.postProcessingPassFactory = this.container.get(_l7Core.TYPES.IFactoryPostProcessingPass);
293
+ this.normalPassFactory = this.container.get(_l7Core.TYPES.IFactoryNormalPass); // 图层容器服务
294
+
295
+ this.styleAttributeService = this.container.get(_l7Core.TYPES.IStyleAttributeService);
296
+ this.multiPassRenderer = this.container.get(_l7Core.TYPES.IMultiPassRenderer);
297
+ this.multiPassRenderer.setLayer(this); // 完成样式服务注册完成前添加的属性
298
+
299
+ this.pendingStyleAttributes.forEach(function (_ref2) {
300
+ var attributeName = _ref2.attributeName,
301
+ attributeField = _ref2.attributeField,
302
+ attributeValues = _ref2.attributeValues,
303
+ updateOptions = _ref2.updateOptions;
304
+
305
+ _this3.styleAttributeService.updateStyleAttribute(attributeName, {
306
+ // @ts-ignore
307
+ scale: (0, _objectSpread2.default)({
308
+ field: attributeField
309
+ }, _this3.splitValuesAndCallbackInAttribute( // @ts-ignore
310
+ attributeValues, // @ts-ignore
311
+ _this3.getLayerConfig()[attributeName]))
312
+ }, // @ts-ignore
313
+ updateOptions);
314
+ });
315
+ this.pendingStyleAttributes = []; // 获取插件集
316
+
317
+ this.plugins = this.container.getAll(_l7Core.TYPES.ILayerPlugin); // 完成插件注册,传入场景和图层容器内的服务
318
+
319
+ var _iterator = _createForOfIteratorHelper(this.plugins),
320
+ _step;
321
+
322
+ try {
323
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
324
+ var plugin = _step.value;
325
+ plugin.apply(this, {
326
+ rendererService: this.rendererService,
327
+ mapService: this.mapService,
328
+ styleAttributeService: this.styleAttributeService,
329
+ normalPassFactory: this.normalPassFactory,
330
+ postProcessingPassFactory: this.postProcessingPassFactory
331
+ });
332
+ } // 触发 init 生命周期插件
333
+
334
+ } catch (err) {
335
+ _iterator.e(err);
336
+ } finally {
337
+ _iterator.f();
338
+ }
339
+
340
+ this.hooks.init.call(); // this.pickingPassRender = this.normalPassFactory('pixelPicking');
341
+ // this.pickingPassRender.init(this);
342
+
343
+ this.hooks.afterInit.call(); // 触发初始化完成事件;
344
+
345
+ this.emit('inited', {
346
+ target: this,
347
+ type: 'inited'
348
+ });
349
+ this.emit('add', {
350
+ target: this,
351
+ type: 'add'
222
352
  });
223
- } else {
224
- console.warn("data error");
353
+ return this;
225
354
  }
226
- }
227
- createModelData(data, option) {
228
- var _a;
229
- if ((_a = this.layerModel) == null ? void 0 : _a.createModelData) {
230
- return this.layerModel.createModelData(option);
231
- }
232
- const calEncodeData = this.calculateEncodeData(data, option);
233
- const triangulation = this.triangulation;
234
- if (calEncodeData && triangulation) {
235
- return this.styleAttributeService.createAttributesAndIndices(calEncodeData, triangulation);
236
- } else {
237
- return {
238
- attributes: void 0,
239
- elements: void 0
240
- };
355
+ }, {
356
+ key: "updateModelData",
357
+ value: function updateModelData(data) {
358
+ if (data.attributes && data.elements) {
359
+ this.models.map(function (m) {
360
+ m.updateAttributesAndElements(data.attributes, data.elements);
361
+ });
362
+ } else {
363
+ console.warn('data error');
364
+ }
241
365
  }
242
- }
243
- calculateEncodeData(data, option) {
244
- if (this.inited) {
245
- return (0, import_layerData.calculateData)(this, this.fontService, this.mapService, this.styleAttributeService, data, option);
246
- } else {
247
- console.warn("layer not inited!");
248
- return null;
366
+ }, {
367
+ key: "createModelData",
368
+ value: function createModelData(data, option) {
369
+ var _this$layerModel;
370
+
371
+ if ((_this$layerModel = this.layerModel) !== null && _this$layerModel !== void 0 && _this$layerModel.createModelData) {
372
+ // 在某些特殊图层中单独构建 attribute & elements
373
+ return this.layerModel.createModelData(option);
374
+ }
375
+
376
+ var calEncodeData = this.calculateEncodeData(data, option);
377
+ var triangulation = this.triangulation;
378
+
379
+ if (calEncodeData && triangulation) {
380
+ return this.styleAttributeService.createAttributesAndIndices(calEncodeData, triangulation);
381
+ } else {
382
+ return {
383
+ attributes: undefined,
384
+ elements: undefined
385
+ };
386
+ }
249
387
  }
250
- }
251
- prepareBuildModel() {
252
- this.inited = true;
253
- this.updateLayerConfig({
254
- ...this.getDefaultConfig(),
255
- ...this.rawConfig
256
- });
257
- const { animateOption } = this.getLayerConfig();
258
- if (animateOption == null ? void 0 : animateOption.enable) {
259
- this.layerService.startAnimate();
260
- this.aniamateStatus = true;
388
+ }, {
389
+ key: "calculateEncodeData",
390
+ value: function calculateEncodeData(data, option) {
391
+ if (this.inited) {
392
+ return (0, _layerData.calculateData)(this, this.fontService, this.mapService, this.styleAttributeService, data, option);
393
+ } else {
394
+ console.warn('layer not inited!');
395
+ return null;
396
+ }
261
397
  }
262
- }
263
- color(field, values, updateOptions) {
264
- this.updateStyleAttribute("color", field, values, updateOptions);
265
- return this;
266
- }
267
- texture(field, values, updateOptions) {
268
- this.updateStyleAttribute("texture", field, values, updateOptions);
269
- return this;
270
- }
271
- rotate(field, values, updateOptions) {
272
- this.updateStyleAttribute("rotate", field, values, updateOptions);
273
- return this;
274
- }
275
- size(field, values, updateOptions) {
276
- this.updateStyleAttribute("size", field, values, updateOptions);
277
- return this;
278
- }
279
- filter(field, values, updateOptions) {
280
- this.updateStyleAttribute("filter", field, values, updateOptions);
281
- return this;
282
- }
283
- shape(field, values, updateOptions) {
284
- var _a, _b, _c;
285
- const lastShape = (_c = (_b = (_a = this.styleAttributeService) == null ? void 0 : _a.getLayerStyleAttribute("shape")) == null ? void 0 : _b.scale) == null ? void 0 : _c.field;
286
- const currentShape = field;
287
- this.shapeOption = {
288
- field,
289
- values
290
- };
291
- this.updateStyleAttribute("shape", field, values, updateOptions);
292
- if (!this.tileLayer) {
293
- (0, import_updateShape.updateShape)(this, lastShape, currentShape);
294
- }
295
- return this;
296
- }
297
- label(field, values, updateOptions) {
298
- this.pendingStyleAttributes.push({
299
- attributeName: "label",
300
- attributeField: field,
301
- attributeValues: values,
302
- updateOptions
303
- });
304
- return this;
305
- }
306
- animate(options) {
307
- let rawAnimate = {};
308
- if ((0, import_lodash.isObject)(options)) {
309
- rawAnimate.enable = true;
310
- rawAnimate = {
311
- ...rawAnimate,
312
- ...options
313
- };
314
- } else {
315
- rawAnimate.enable = options;
398
+ /**
399
+ * Model初始化前需要更新Model样式
400
+ */
401
+
402
+ }, {
403
+ key: "prepareBuildModel",
404
+ value: function prepareBuildModel() {
405
+ this.inited = true;
406
+ this.updateLayerConfig((0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.getDefaultConfig()), this.rawConfig)); // 启动动画
407
+
408
+ var _this$getLayerConfig2 = this.getLayerConfig(),
409
+ animateOption = _this$getLayerConfig2.animateOption;
410
+
411
+ if (animateOption !== null && animateOption !== void 0 && animateOption.enable) {
412
+ this.layerService.startAnimate();
413
+ this.aniamateStatus = true;
414
+ }
316
415
  }
317
- this.updateLayerConfig({
318
- animateOption: rawAnimate
319
- });
320
- return this;
321
- }
322
- source(data, options) {
323
- if (data == null ? void 0 : data.data) {
324
- this.setSource(data);
416
+ }, {
417
+ key: "color",
418
+ value: function color(field, values, updateOptions) {
419
+ // 设置 color、size、shape、style 时由于场景服务尚未完成(并没有调用 scene.addLayer),因此暂时加入待更新属性列表
420
+ this.updateStyleAttribute('color', field, values, updateOptions); // this.pendingStyleAttributes.push({
421
+ // attributeName: 'color',
422
+ // attributeField: field,
423
+ // attributeValues: values,
424
+ // defaultName: 'colors',
425
+ // updateOptions,
426
+ // });
427
+
428
+ return this;
429
+ } // 为对应的图层传入纹理的编号名称(point/image 在 shape 方法中传入纹理名称的方法并不通用)
430
+
431
+ }, {
432
+ key: "texture",
433
+ value: function texture(field, values, updateOptions) {
434
+ this.updateStyleAttribute('texture', field, values, updateOptions);
325
435
  return this;
326
436
  }
327
- this.sourceOption = {
328
- data,
329
- options
330
- };
331
- this.clusterZoom = 0;
332
- return this;
333
- }
334
- setData(data, options) {
335
- if (this.inited) {
336
- this.layerSource.setData(data, options);
337
- } else {
338
- this.on("inited", () => {
339
- const currentSource = this.getSource();
340
- if (!currentSource) {
341
- this.source(new import_l7_source.default(data, options));
342
- this.sourceEvent();
343
- } else {
344
- this.layerSource.setData(data, options);
345
- }
346
- });
437
+ }, {
438
+ key: "rotate",
439
+ value: function rotate(field, values, updateOptions) {
440
+ this.updateStyleAttribute('rotate', field, values, updateOptions);
441
+ return this;
347
442
  }
348
- return this;
349
- }
350
- style(options) {
351
- const lastConfig = this.getLayerConfig();
352
- const { passes, ...rest } = options;
353
- if (passes) {
354
- (0, import_multiPassRender.normalizePasses)(passes).forEach((pass) => {
355
- const postProcessingPass = this.multiPassRenderer.getPostProcessor().getPostProcessingPassByName(pass[0]);
356
- if (postProcessingPass) {
357
- postProcessingPass.updateOptions(pass[1]);
358
- }
359
- });
443
+ }, {
444
+ key: "size",
445
+ value: function size(field, values, updateOptions) {
446
+ this.updateStyleAttribute('size', field, values, updateOptions);
447
+ return this;
448
+ } // 对mapping后的数据过滤,scale保持不变
449
+
450
+ }, {
451
+ key: "filter",
452
+ value: function filter(field, values, updateOptions) {
453
+ this.updateStyleAttribute('filter', field, values, updateOptions);
454
+ return this;
455
+ }
456
+ }, {
457
+ key: "shape",
458
+ value: function shape(field, values, updateOptions) {
459
+ var _this$styleAttributeS, _this$styleAttributeS2, _this$styleAttributeS3;
460
+
461
+ var lastShape = (_this$styleAttributeS = this.styleAttributeService) === null || _this$styleAttributeS === void 0 ? void 0 : (_this$styleAttributeS2 = _this$styleAttributeS.getLayerStyleAttribute('shape')) === null || _this$styleAttributeS2 === void 0 ? void 0 : (_this$styleAttributeS3 = _this$styleAttributeS2.scale) === null || _this$styleAttributeS3 === void 0 ? void 0 : _this$styleAttributeS3.field;
462
+ var currentShape = field;
463
+ this.shapeOption = {
464
+ field: field,
465
+ values: values
466
+ };
467
+ this.updateStyleAttribute('shape', field, values, updateOptions); // TODO: 根据 shape 判断是否需要更新 model
468
+
469
+ if (!this.tileLayer) {
470
+ (0, _updateShape.updateShape)(this, lastShape, currentShape);
471
+ }
472
+
473
+ return this;
360
474
  }
361
- this.rawConfig = {
362
- ...this.rawConfig,
363
- ...rest
364
- };
365
- if (this.container) {
366
- this.updateLayerConfig(this.rawConfig);
367
- this.styleNeedUpdate = true;
368
- }
369
- if (lastConfig && lastConfig.mask === true && options.mask === false) {
370
- this.clearModels();
371
- this.layerModel.buildModels((models) => {
372
- this.models = models;
475
+ }, {
476
+ key: "label",
477
+ value: function label(field, values, updateOptions) {
478
+ this.pendingStyleAttributes.push({
479
+ attributeName: 'label',
480
+ attributeField: field,
481
+ attributeValues: values,
482
+ updateOptions: updateOptions
373
483
  });
484
+ return this;
374
485
  }
375
- return this;
376
- }
377
- scale(field, cfg) {
378
- if ((0, import_lodash.isObject)(field)) {
379
- this.scaleOptions = {
380
- ...this.scaleOptions,
381
- ...field
486
+ }, {
487
+ key: "animate",
488
+ value: function animate(options) {
489
+ var rawAnimate = {};
490
+
491
+ if ((0, _lodash.isObject)(options)) {
492
+ rawAnimate.enable = true;
493
+ rawAnimate = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, rawAnimate), options);
494
+ } else {
495
+ rawAnimate.enable = options;
496
+ }
497
+
498
+ this.updateLayerConfig({
499
+ animateOption: rawAnimate
500
+ }); // this.animateOptions = options;
501
+
502
+ return this;
503
+ }
504
+ }, {
505
+ key: "source",
506
+ value: function source(data, options) {
507
+ if (data !== null && data !== void 0 && data.data) {
508
+ // 判断是否为source
509
+ this.setSource(data);
510
+ return this;
511
+ }
512
+
513
+ this.sourceOption = {
514
+ data: data,
515
+ options: options
382
516
  };
383
- } else {
384
- this.scaleOptions[field] = cfg;
517
+ this.clusterZoom = 0;
518
+ return this;
385
519
  }
386
- return this;
387
- }
388
- renderLayers() {
389
- this.rendering = true;
390
- this.layerService.renderLayers();
391
- this.rendering = false;
392
- }
393
- render() {
394
- if (this.tileLayer !== void 0) {
395
- this.tileLayer.render();
520
+ }, {
521
+ key: "setData",
522
+ value: function setData(data, options) {
523
+ var _this4 = this;
524
+
525
+ if (this.inited) {
526
+ this.layerSource.setData(data, options);
527
+ } else {
528
+ this.on('inited', function () {
529
+ var currentSource = _this4.getSource();
530
+
531
+ if (!currentSource) {
532
+ // 执行 setData 的时候 source 还不存在(还未执行 addLayer)
533
+ _this4.source(new _l7Source.default(data, options));
534
+
535
+ _this4.sourceEvent();
536
+ } else {
537
+ _this4.layerSource.setData(data, options);
538
+ } // this.layerSource.setData(data, options);
539
+
540
+ });
541
+ }
542
+
396
543
  return this;
397
544
  }
398
- if (this.getEncodedData() && this.getEncodedData().length !== 0) {
399
- this.renderModels();
545
+ }, {
546
+ key: "style",
547
+ value: function style(options) {
548
+ var _this5 = this;
549
+
550
+ var lastConfig = this.getLayerConfig();
551
+ var passes = options.passes,
552
+ rest = (0, _objectWithoutProperties2.default)(options, _excluded); // passes 特殊处理
553
+
554
+ if (passes) {
555
+ (0, _multiPassRender.normalizePasses)(passes).forEach(function (pass) {
556
+ var postProcessingPass = _this5.multiPassRenderer.getPostProcessor().getPostProcessingPassByName(pass[0]);
557
+
558
+ if (postProcessingPass) {
559
+ postProcessingPass.updateOptions(pass[1]);
560
+ }
561
+ });
562
+ }
563
+
564
+ this.rawConfig = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.rawConfig), rest);
565
+
566
+ if (this.container) {
567
+ this.updateLayerConfig(this.rawConfig);
568
+ this.styleNeedUpdate = true;
569
+ } // @ts-ignore
570
+
571
+
572
+ if (lastConfig && lastConfig.mask === true && options.mask === false) {
573
+ this.clearModels();
574
+ this.layerModel.buildModels(function (models) {
575
+ _this5.models = models;
576
+ });
577
+ }
578
+
579
+ return this;
400
580
  }
401
- return this;
402
- }
403
- async renderMultiPass() {
404
- if (this.getEncodedData() && this.getEncodedData().length !== 0) {
405
- if (this.multiPassRenderer && this.multiPassRenderer.getRenderFlag()) {
406
- await this.multiPassRenderer.render();
407
- } else if (this.multiPassRenderer) {
408
- this.renderModels();
581
+ }, {
582
+ key: "scale",
583
+ value: function scale(field, cfg) {
584
+ if ((0, _lodash.isObject)(field)) {
585
+ this.scaleOptions = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.scaleOptions), field);
409
586
  } else {
587
+ this.scaleOptions[field] = cfg;
588
+ }
589
+
590
+ return this;
591
+ }
592
+ /**
593
+ * 渲染所有的图层
594
+ */
595
+
596
+ }, {
597
+ key: "renderLayers",
598
+ value: function renderLayers() {
599
+ this.rendering = true;
600
+ this.layerService.renderLayers();
601
+ this.rendering = false;
602
+ }
603
+ }, {
604
+ key: "render",
605
+ value: function render() {
606
+ if (this.tileLayer !== undefined) {
607
+ // 瓦片图层执行单独的 render 渲染队列
608
+ this.tileLayer.render();
609
+ return this;
610
+ } // TODO: this.getEncodedData().length !== 0 这个判断是为了解决在 2.5.x 引入数据纹理后产生的 空数据渲染导致 texture 超出上限问题
611
+
612
+
613
+ if (this.getEncodedData() && this.getEncodedData().length !== 0) {
410
614
  this.renderModels();
411
615
  }
616
+
617
+ return this;
412
618
  }
413
- }
414
- active(options) {
415
- const activeOption = {};
416
- activeOption.enableHighlight = (0, import_lodash.isObject)(options) ? true : options;
417
- if ((0, import_lodash.isObject)(options)) {
418
- activeOption.enableHighlight = true;
419
- if (options.color) {
420
- activeOption.highlightColor = options.color;
421
- }
422
- if (options.mix) {
423
- activeOption.activeMix = options.mix;
424
- }
425
- } else {
426
- activeOption.enableHighlight = !!options;
427
- }
428
- this.updateLayerConfig(activeOption);
429
- return this;
430
- }
431
- setActive(id, options) {
432
- if ((0, import_lodash.isObject)(id)) {
433
- const { x = 0, y = 0 } = id;
619
+ /**
620
+ * renderMultiPass 专门用于渲染支持 multipass 的 layer
621
+ */
622
+
623
+ }, {
624
+ key: "renderMultiPass",
625
+ value: function () {
626
+ var _renderMultiPass = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
627
+ return _regenerator.default.wrap(function _callee$(_context) {
628
+ while (1) {
629
+ switch (_context.prev = _context.next) {
630
+ case 0:
631
+ if (!(this.getEncodedData() && this.getEncodedData().length !== 0)) {
632
+ _context.next = 7;
633
+ break;
634
+ }
635
+
636
+ if (!(this.multiPassRenderer && this.multiPassRenderer.getRenderFlag())) {
637
+ _context.next = 6;
638
+ break;
639
+ }
640
+
641
+ _context.next = 4;
642
+ return this.multiPassRenderer.render();
643
+
644
+ case 4:
645
+ _context.next = 7;
646
+ break;
647
+
648
+ case 6:
649
+ if (this.multiPassRenderer) {
650
+ // renderPass 触发的渲染
651
+ this.renderModels();
652
+ } else {
653
+ this.renderModels();
654
+ }
655
+
656
+ case 7:
657
+ case "end":
658
+ return _context.stop();
659
+ }
660
+ }
661
+ }, _callee, this);
662
+ }));
663
+
664
+ function renderMultiPass() {
665
+ return _renderMultiPass.apply(this, arguments);
666
+ }
667
+
668
+ return renderMultiPass;
669
+ }()
670
+ }, {
671
+ key: "active",
672
+ value: function active(options) {
673
+ var activeOption = {};
674
+ activeOption.enableHighlight = (0, _lodash.isObject)(options) ? true : options;
675
+
676
+ if ((0, _lodash.isObject)(options)) {
677
+ activeOption.enableHighlight = true;
678
+
679
+ if (options.color) {
680
+ activeOption.highlightColor = options.color;
681
+ }
682
+
683
+ if (options.mix) {
684
+ activeOption.activeMix = options.mix;
685
+ }
686
+ } else {
687
+ activeOption.enableHighlight = !!options;
688
+ }
689
+
690
+ this.updateLayerConfig(activeOption);
691
+ return this;
692
+ }
693
+ }, {
694
+ key: "setActive",
695
+ value: function setActive(id, options) {
696
+ var _this6 = this;
697
+
698
+ if ((0, _lodash.isObject)(id)) {
699
+ var _id$x = id.x,
700
+ x = _id$x === void 0 ? 0 : _id$x,
701
+ _id$y = id.y,
702
+ y = _id$y === void 0 ? 0 : _id$y;
703
+ this.updateLayerConfig({
704
+ highlightColor: (0, _lodash.isObject)(options) ? options.color : this.getLayerConfig().highlightColor,
705
+ activeMix: (0, _lodash.isObject)(options) ? options.mix : this.getLayerConfig().activeMix
706
+ });
707
+ this.pick({
708
+ x: x,
709
+ y: y
710
+ });
711
+ } else {
712
+ this.updateLayerConfig({
713
+ pickedFeatureID: id,
714
+ highlightColor: (0, _lodash.isObject)(options) ? options.color : this.getLayerConfig().highlightColor,
715
+ activeMix: (0, _lodash.isObject)(options) ? options.mix : this.getLayerConfig().activeMix
716
+ });
717
+ this.hooks.beforeSelect.call((0, _l7Utils.encodePickingColor)(id)) // @ts-ignore
718
+ .then(function () {
719
+ setTimeout(function () {
720
+ _this6.reRender();
721
+ }, 1);
722
+ });
723
+ }
724
+ }
725
+ }, {
726
+ key: "select",
727
+ value: function select(option) {
728
+ var activeOption = {};
729
+ activeOption.enableSelect = (0, _lodash.isObject)(option) ? true : option;
730
+
731
+ if ((0, _lodash.isObject)(option)) {
732
+ activeOption.enableSelect = true;
733
+
734
+ if (option.color) {
735
+ activeOption.selectColor = option.color;
736
+ }
737
+
738
+ if (option.mix) {
739
+ activeOption.selectMix = option.mix;
740
+ }
741
+ } else {
742
+ activeOption.enableSelect = !!option;
743
+ }
744
+
745
+ this.updateLayerConfig(activeOption);
746
+ return this;
747
+ }
748
+ }, {
749
+ key: "setSelect",
750
+ value: function setSelect(id, options) {
751
+ var _this7 = this;
752
+
753
+ if ((0, _lodash.isObject)(id)) {
754
+ var _id$x2 = id.x,
755
+ x = _id$x2 === void 0 ? 0 : _id$x2,
756
+ _id$y2 = id.y,
757
+ y = _id$y2 === void 0 ? 0 : _id$y2;
758
+ this.updateLayerConfig({
759
+ selectColor: (0, _lodash.isObject)(options) ? options.color : this.getLayerConfig().selectColor,
760
+ selectMix: (0, _lodash.isObject)(options) ? options.mix : this.getLayerConfig().selectMix
761
+ });
762
+ this.pick({
763
+ x: x,
764
+ y: y
765
+ });
766
+ } else {
767
+ this.updateLayerConfig({
768
+ pickedFeatureID: id,
769
+ selectColor: (0, _lodash.isObject)(options) ? options.color : this.getLayerConfig().selectColor,
770
+ selectMix: (0, _lodash.isObject)(options) ? options.mix : this.getLayerConfig().selectMix
771
+ });
772
+ this.hooks.beforeSelect.call((0, _l7Utils.encodePickingColor)(id)) // @ts-ignore
773
+ .then(function () {
774
+ setTimeout(function () {
775
+ _this7.reRender();
776
+ }, 1);
777
+ });
778
+ }
779
+ }
780
+ }, {
781
+ key: "setBlend",
782
+ value: function setBlend(type) {
434
783
  this.updateLayerConfig({
435
- highlightColor: (0, import_lodash.isObject)(options) ? options.color : this.getLayerConfig().highlightColor,
436
- activeMix: (0, import_lodash.isObject)(options) ? options.mix : this.getLayerConfig().activeMix
784
+ blend: type
437
785
  });
438
- this.pick({ x, y });
439
- } else {
786
+ this.layerModelNeedUpdate = true;
787
+ this.reRender();
788
+ return this;
789
+ }
790
+ }, {
791
+ key: "show",
792
+ value: function show() {
440
793
  this.updateLayerConfig({
441
- pickedFeatureID: id,
442
- highlightColor: (0, import_lodash.isObject)(options) ? options.color : this.getLayerConfig().highlightColor,
443
- activeMix: (0, import_lodash.isObject)(options) ? options.mix : this.getLayerConfig().activeMix
444
- });
445
- this.hooks.beforeSelect.call((0, import_l7_utils.encodePickingColor)(id)).then(() => {
446
- setTimeout(() => {
447
- this.reRender();
448
- }, 1);
794
+ visible: true
449
795
  });
796
+ this.reRender();
797
+ return this;
450
798
  }
451
- }
452
- select(option) {
453
- const activeOption = {};
454
- activeOption.enableSelect = (0, import_lodash.isObject)(option) ? true : option;
455
- if ((0, import_lodash.isObject)(option)) {
456
- activeOption.enableSelect = true;
457
- if (option.color) {
458
- activeOption.selectColor = option.color;
459
- }
460
- if (option.mix) {
461
- activeOption.selectMix = option.mix;
462
- }
463
- } else {
464
- activeOption.enableSelect = !!option;
465
- }
466
- this.updateLayerConfig(activeOption);
467
- return this;
468
- }
469
- setSelect(id, options) {
470
- if ((0, import_lodash.isObject)(id)) {
471
- const { x = 0, y = 0 } = id;
799
+ }, {
800
+ key: "hide",
801
+ value: function hide() {
802
+ if (this.type === 'CanvasLayer' && this.layerModel.clearCanvas) {
803
+ // canvasLayer 的 hide 操作做特殊处理
804
+ this.layerModel.clearCanvas();
805
+ }
806
+
472
807
  this.updateLayerConfig({
473
- selectColor: (0, import_lodash.isObject)(options) ? options.color : this.getLayerConfig().selectColor,
474
- selectMix: (0, import_lodash.isObject)(options) ? options.mix : this.getLayerConfig().selectMix
808
+ visible: false
475
809
  });
476
- this.pick({ x, y });
477
- } else {
810
+ this.reRender();
811
+ return this;
812
+ }
813
+ }, {
814
+ key: "setIndex",
815
+ value: function setIndex(index) {
816
+ this.zIndex = index;
817
+ this.layerService.updateLayerRenderList();
818
+ this.layerService.renderLayers();
819
+ return this;
820
+ }
821
+ }, {
822
+ key: "setCurrentPickId",
823
+ value: function setCurrentPickId(id) {
824
+ this.currentPickId = id;
825
+ }
826
+ }, {
827
+ key: "getCurrentPickId",
828
+ value: function getCurrentPickId() {
829
+ return this.currentPickId;
830
+ }
831
+ }, {
832
+ key: "setCurrentSelectedId",
833
+ value: function setCurrentSelectedId(id) {
834
+ this.selectedFeatureID = id;
835
+ }
836
+ }, {
837
+ key: "getCurrentSelectedId",
838
+ value: function getCurrentSelectedId() {
839
+ return this.selectedFeatureID;
840
+ }
841
+ }, {
842
+ key: "isVisible",
843
+ value: function isVisible() {
844
+ var zoom = this.mapService.getZoom();
845
+
846
+ var _this$getLayerConfig3 = this.getLayerConfig(),
847
+ visible = _this$getLayerConfig3.visible,
848
+ _this$getLayerConfig4 = _this$getLayerConfig3.minZoom,
849
+ minZoom = _this$getLayerConfig4 === void 0 ? -Infinity : _this$getLayerConfig4,
850
+ _this$getLayerConfig5 = _this$getLayerConfig3.maxZoom,
851
+ maxZoom = _this$getLayerConfig5 === void 0 ? Infinity : _this$getLayerConfig5;
852
+
853
+ return !!visible && zoom >= minZoom && zoom <= maxZoom;
854
+ }
855
+ }, {
856
+ key: "setMultiPass",
857
+ value: function setMultiPass(enableMultiPass, currentPasses) {
478
858
  this.updateLayerConfig({
479
- pickedFeatureID: id,
480
- selectColor: (0, import_lodash.isObject)(options) ? options.color : this.getLayerConfig().selectColor,
481
- selectMix: (0, import_lodash.isObject)(options) ? options.mix : this.getLayerConfig().selectMix
859
+ enableMultiPassRenderer: enableMultiPass
482
860
  });
483
- this.hooks.beforeSelect.call((0, import_l7_utils.encodePickingColor)(id)).then(() => {
484
- setTimeout(() => {
485
- this.reRender();
486
- }, 1);
861
+
862
+ if (currentPasses) {
863
+ this.updateLayerConfig({
864
+ passes: currentPasses
865
+ });
866
+ }
867
+
868
+ if (enableMultiPass) {
869
+ var _this$getLayerConfig6 = this.getLayerConfig(),
870
+ _this$getLayerConfig7 = _this$getLayerConfig6.passes,
871
+ passes = _this$getLayerConfig7 === void 0 ? [] : _this$getLayerConfig7;
872
+
873
+ this.multiPassRenderer = (0, _multiPassRender.createMultiPassRenderer)(this, passes, this.postProcessingPassFactory, this.normalPassFactory);
874
+ this.multiPassRenderer.setRenderFlag(true);
875
+
876
+ var _this$rendererService = this.rendererService.getViewportSize(),
877
+ width = _this$rendererService.width,
878
+ height = _this$rendererService.height;
879
+
880
+ this.multiPassRenderer.resize(width, height);
881
+ }
882
+
883
+ return this;
884
+ }
885
+ }, {
886
+ key: "setMinZoom",
887
+ value: function setMinZoom(minZoom) {
888
+ this.updateLayerConfig({
889
+ minZoom: minZoom
487
890
  });
891
+ return this;
488
892
  }
489
- }
490
- setBlend(type) {
491
- this.updateLayerConfig({
492
- blend: type
493
- });
494
- this.layerModelNeedUpdate = true;
495
- this.reRender();
496
- return this;
497
- }
498
- show() {
499
- this.updateLayerConfig({
500
- visible: true
501
- });
502
- this.reRender();
503
- return this;
504
- }
505
- hide() {
506
- if (this.type === "CanvasLayer" && this.layerModel.clearCanvas) {
507
- this.layerModel.clearCanvas();
893
+ }, {
894
+ key: "getMinZoom",
895
+ value: function getMinZoom() {
896
+ var _this$getLayerConfig8 = this.getLayerConfig(),
897
+ minZoom = _this$getLayerConfig8.minZoom;
898
+
899
+ return minZoom;
508
900
  }
509
- this.updateLayerConfig({
510
- visible: false
511
- });
512
- this.reRender();
513
- return this;
514
- }
515
- setIndex(index) {
516
- this.zIndex = index;
517
- this.layerService.updateLayerRenderList();
518
- this.layerService.renderLayers();
519
- return this;
520
- }
521
- setCurrentPickId(id) {
522
- this.currentPickId = id;
523
- }
524
- getCurrentPickId() {
525
- return this.currentPickId;
526
- }
527
- setCurrentSelectedId(id) {
528
- this.selectedFeatureID = id;
529
- }
530
- getCurrentSelectedId() {
531
- return this.selectedFeatureID;
532
- }
533
- isVisible() {
534
- const zoom = this.mapService.getZoom();
535
- const {
536
- visible,
537
- minZoom = -Infinity,
538
- maxZoom = Infinity
539
- } = this.getLayerConfig();
540
- return !!visible && zoom >= minZoom && zoom <= maxZoom;
541
- }
542
- setMultiPass(enableMultiPass, currentPasses) {
543
- this.updateLayerConfig({
544
- enableMultiPassRenderer: enableMultiPass
545
- });
546
- if (currentPasses) {
901
+ }, {
902
+ key: "getMaxZoom",
903
+ value: function getMaxZoom() {
904
+ var _this$getLayerConfig9 = this.getLayerConfig(),
905
+ maxZoom = _this$getLayerConfig9.maxZoom;
906
+
907
+ return maxZoom;
908
+ }
909
+ }, {
910
+ key: "get",
911
+ value: function get(name) {
912
+ var cfg = this.getLayerConfig(); // @ts-ignore
913
+
914
+ return cfg[name];
915
+ }
916
+ }, {
917
+ key: "setMaxZoom",
918
+ value: function setMaxZoom(maxZoom) {
547
919
  this.updateLayerConfig({
548
- passes: currentPasses
920
+ maxZoom: maxZoom
549
921
  });
922
+ return this;
550
923
  }
551
- if (enableMultiPass) {
552
- const { passes = [] } = this.getLayerConfig();
553
- this.multiPassRenderer = (0, import_multiPassRender.createMultiPassRenderer)(this, passes, this.postProcessingPassFactory, this.normalPassFactory);
554
- this.multiPassRenderer.setRenderFlag(true);
555
- const { width, height } = this.rendererService.getViewportSize();
556
- this.multiPassRenderer.resize(width, height);
557
- }
558
- return this;
559
- }
560
- setMinZoom(minZoom) {
561
- this.updateLayerConfig({
562
- minZoom
563
- });
564
- return this;
565
- }
566
- getMinZoom() {
567
- const { minZoom } = this.getLayerConfig();
568
- return minZoom;
569
- }
570
- getMaxZoom() {
571
- const { maxZoom } = this.getLayerConfig();
572
- return maxZoom;
573
- }
574
- get(name) {
575
- const cfg = this.getLayerConfig();
576
- return cfg[name];
577
- }
578
- setMaxZoom(maxZoom) {
579
- this.updateLayerConfig({
580
- maxZoom
581
- });
582
- return this;
583
- }
584
- setAutoFit(autoFit) {
585
- this.updateLayerConfig({
586
- autoFit
587
- });
588
- return this;
589
- }
590
- fitBounds(fitBoundsOptions) {
591
- if (!this.inited) {
924
+ }, {
925
+ key: "setAutoFit",
926
+ value: function setAutoFit(autoFit) {
592
927
  this.updateLayerConfig({
593
- autoFit: true
928
+ autoFit: autoFit
594
929
  });
595
930
  return this;
596
931
  }
597
- const source = this.getSource();
598
- const extent = source.extent;
599
- const isValid = extent.some((v) => Math.abs(v) === Infinity);
600
- if (isValid) {
932
+ /**
933
+ * zoom to layer Bounds
934
+ */
935
+
936
+ }, {
937
+ key: "fitBounds",
938
+ value: function fitBounds(fitBoundsOptions) {
939
+ if (!this.inited) {
940
+ this.updateLayerConfig({
941
+ autoFit: true
942
+ });
943
+ return this;
944
+ }
945
+
946
+ var source = this.getSource();
947
+ var extent = source.extent;
948
+ var isValid = extent.some(function (v) {
949
+ return Math.abs(v) === Infinity;
950
+ });
951
+
952
+ if (isValid) {
953
+ return this;
954
+ }
955
+
956
+ this.mapService.fitBounds([[extent[0], extent[1]], [extent[2], extent[3]]], fitBoundsOptions);
601
957
  return this;
602
958
  }
603
- this.mapService.fitBounds([
604
- [extent[0], extent[1]],
605
- [extent[2], extent[3]]
606
- ], fitBoundsOptions);
607
- return this;
608
- }
609
- destroy(refresh = true) {
610
- var _a;
611
- if (this.isDestroied) {
612
- return;
613
- }
614
- this.layerChildren.map((child) => child.destroy());
615
- this.layerChildren = [];
616
- this.masks.map((mask) => mask.destroy());
617
- this.masks = [];
618
- this.hooks.beforeDestroy.call();
619
- this.layerSource.off("sourceUpdate", this.sourceEvent);
620
- this.multiPassRenderer.destroy();
621
- this.styleAttributeService.clearAllAttributes();
622
- this.hooks.afterDestroy.call();
623
- (_a = this.layerModel) == null ? void 0 : _a.clearModels();
624
- this.models = [];
625
- this.layerService.cleanRemove(this, refresh);
626
- this.emit("remove", {
627
- target: this,
628
- type: "remove"
629
- });
630
- this.emit("destroy", {
631
- target: this,
632
- type: "destroy"
633
- });
634
- this.removeAllListeners();
635
- this.isDestroied = true;
636
- }
637
- clear() {
638
- this.styleAttributeService.clearAllAttributes();
639
- }
640
- clearModels() {
641
- var _a;
642
- this.models.forEach((model) => model.destroy());
643
- (_a = this.layerModel) == null ? void 0 : _a.clearModels();
644
- this.models = [];
645
- }
646
- isDirty() {
647
- return !!(this.styleAttributeService.getLayerStyleAttributes() || []).filter((attribute) => attribute.needRescale || attribute.needRemapping || attribute.needRegenerateVertices).length;
648
- }
649
- setSource(source) {
650
- if (this.layerSource) {
651
- this.layerSource.off("sourceUpdate", this.sourceEvent);
959
+ }, {
960
+ key: "destroy",
961
+ value: function destroy() {
962
+ var _this$layerModel2;
963
+
964
+ var refresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
965
+
966
+ if (this.isDestroied) {
967
+ return;
968
+ } // remove child layer
969
+
970
+
971
+ this.layerChildren.map(function (child) {
972
+ return child.destroy();
973
+ });
974
+ this.layerChildren = []; // remove mask list
975
+
976
+ this.masks.map(function (mask) {
977
+ return mask.destroy();
978
+ });
979
+ this.masks = [];
980
+ this.hooks.beforeDestroy.call(); // 清除sources事件
981
+
982
+ this.layerSource.off('sourceUpdate', this.sourceEvent);
983
+ this.multiPassRenderer.destroy(); // console.log(this.styleAttributeService.getAttributes())
984
+ // 清除所有属性以及关联的 vao == 销毁所有 => model this.models.forEach((model) => model.destroy());
985
+
986
+ this.styleAttributeService.clearAllAttributes(); // 执行每个图层单独的 clearModels 方法 (清除一些额外的 texture、program、buffer 等)
987
+
988
+ this.hooks.afterDestroy.call(); // TODO: 清除各个图层自定义的 models 资源
989
+
990
+ (_this$layerModel2 = this.layerModel) === null || _this$layerModel2 === void 0 ? void 0 : _this$layerModel2.clearModels();
991
+ this.models = [];
992
+ this.layerService.cleanRemove(this, refresh);
993
+ this.emit('remove', {
994
+ target: this,
995
+ type: 'remove'
996
+ });
997
+ this.emit('destroy', {
998
+ target: this,
999
+ type: 'destroy'
1000
+ });
1001
+ this.removeAllListeners(); // 解绑图层容器中的服务
1002
+ // this.container.unbind(TYPES.IStyleAttributeService);
1003
+
1004
+ this.isDestroied = true;
652
1005
  }
653
- this.layerSource = source;
654
- this.clusterZoom = 0;
655
- if (this.inited && this.layerSource.cluster) {
656
- const zoom = this.mapService.getZoom();
657
- this.layerSource.updateClusterData(zoom);
1006
+ }, {
1007
+ key: "clear",
1008
+ value: function clear() {
1009
+ this.styleAttributeService.clearAllAttributes(); // 销毁所有 model
658
1010
  }
659
- if (this.layerSource.inited) {
660
- this.sourceEvent();
1011
+ }, {
1012
+ key: "clearModels",
1013
+ value: function clearModels() {
1014
+ var _this$layerModel3;
1015
+
1016
+ this.models.forEach(function (model) {
1017
+ return model.destroy();
1018
+ });
1019
+ (_this$layerModel3 = this.layerModel) === null || _this$layerModel3 === void 0 ? void 0 : _this$layerModel3.clearModels();
1020
+ this.models = [];
661
1021
  }
662
- this.layerSource.on("sourceUpdate", () => {
663
- this.sourceEvent();
664
- });
665
- }
666
- getSource() {
667
- return this.layerSource;
668
- }
669
- getScaleOptions() {
670
- return this.scaleOptions;
671
- }
672
- setEncodedData(encodedData) {
673
- this.encodedData = encodedData;
674
- }
675
- getEncodedData() {
676
- return this.encodedData;
677
- }
678
- getScale(name) {
679
- return this.styleAttributeService.getLayerAttributeScale(name);
680
- }
681
- getLegendItems(name) {
682
- const scale = this.styleAttributeService.getLayerAttributeScale(name);
683
- if (!scale) {
684
- return [];
1022
+ }, {
1023
+ key: "isDirty",
1024
+ value: function isDirty() {
1025
+ return !!(this.styleAttributeService.getLayerStyleAttributes() || []).filter(function (attribute) {
1026
+ return attribute.needRescale || attribute.needRemapping || attribute.needRegenerateVertices;
1027
+ }).length;
685
1028
  }
686
- if (scale.invertExtent) {
687
- const items = scale.range().map((item) => {
688
- return {
689
- value: scale.invertExtent(item),
690
- [name]: item
691
- };
692
- });
693
- return items;
694
- } else if (scale.ticks) {
695
- const items = scale.ticks().map((item) => {
696
- return {
697
- value: item,
698
- [name]: scale(item)
699
- };
1029
+ }, {
1030
+ key: "setSource",
1031
+ value: function setSource(source) {
1032
+ var _this8 = this;
1033
+
1034
+ // 清除旧 sources 事件
1035
+ if (this.layerSource) {
1036
+ this.layerSource.off('sourceUpdate', this.sourceEvent);
1037
+ }
1038
+
1039
+ this.layerSource = source;
1040
+ this.clusterZoom = 0; // 已 inited 且启用聚合进行更新聚合数据
1041
+
1042
+ if (this.inited && this.layerSource.cluster) {
1043
+ var zoom = this.mapService.getZoom();
1044
+ this.layerSource.updateClusterData(zoom);
1045
+ } // source 可能会复用,会在其它layer被修改
1046
+
1047
+
1048
+ if (this.layerSource.inited) {
1049
+ this.sourceEvent();
1050
+ } // this.layerSource.inited 为 true 后,sourceUpdate 事件不会再触发
1051
+
1052
+
1053
+ this.layerSource.on('sourceUpdate', function () {
1054
+ _this8.sourceEvent();
700
1055
  });
701
- return items;
702
- } else if (scale == null ? void 0 : scale.domain) {
703
- const items = scale.domain().filter((item) => !(0, import_lodash.isUndefined)(item)).map((item) => {
704
- return {
705
- value: item,
706
- [name]: scale(item)
707
- };
1056
+ }
1057
+ }, {
1058
+ key: "getSource",
1059
+ value: function getSource() {
1060
+ return this.layerSource;
1061
+ }
1062
+ }, {
1063
+ key: "getScaleOptions",
1064
+ value: function getScaleOptions() {
1065
+ return this.scaleOptions;
1066
+ }
1067
+ }, {
1068
+ key: "setEncodedData",
1069
+ value: function setEncodedData(encodedData) {
1070
+ this.encodedData = encodedData;
1071
+ }
1072
+ }, {
1073
+ key: "getEncodedData",
1074
+ value: function getEncodedData() {
1075
+ return this.encodedData;
1076
+ }
1077
+ }, {
1078
+ key: "getScale",
1079
+ value: function getScale(name) {
1080
+ return this.styleAttributeService.getLayerAttributeScale(name);
1081
+ }
1082
+ }, {
1083
+ key: "getLegendItems",
1084
+ value: function getLegendItems(name) {
1085
+ var scale = this.styleAttributeService.getLayerAttributeScale(name); // 函数自定义映射,没有 scale 返回为空数组
1086
+
1087
+ if (!scale) {
1088
+ return [];
1089
+ }
1090
+
1091
+ if (scale.invertExtent) {
1092
+ // 分段类型 Quantize、Quantile、Threshold
1093
+ var items = scale.range().map(function (item) {
1094
+ return (0, _defineProperty2.default)({
1095
+ value: scale.invertExtent(item)
1096
+ }, name, item);
1097
+ });
1098
+ return items;
1099
+ } else if (scale.ticks) {
1100
+ // 连续类型 Continuous (Linear, Power, Log, Identity, Time)
1101
+ var _items = scale.ticks().map(function (item) {
1102
+ return (0, _defineProperty2.default)({
1103
+ value: item
1104
+ }, name, scale(item));
1105
+ });
1106
+
1107
+ return _items;
1108
+ } else if (scale !== null && scale !== void 0 && scale.domain) {
1109
+ // 枚举类型 Cat
1110
+ var _items2 = scale.domain().filter(function (item) {
1111
+ return !(0, _lodash.isUndefined)(item);
1112
+ }).map(function (item) {
1113
+ return (0, _defineProperty2.default)({
1114
+ value: item
1115
+ }, name, scale(item));
1116
+ });
1117
+
1118
+ return _items2;
1119
+ }
1120
+
1121
+ return [];
1122
+ }
1123
+ }, {
1124
+ key: "pick",
1125
+ value: function pick(_ref6) {
1126
+ var x = _ref6.x,
1127
+ y = _ref6.y;
1128
+ this.interactionService.triggerHover({
1129
+ x: x,
1130
+ y: y
708
1131
  });
709
- return items;
710
1132
  }
711
- return [];
712
- }
713
- pick({ x, y }) {
714
- this.interactionService.triggerHover({ x, y });
715
- }
716
- boxSelect(box, cb) {
717
- this.pickingService.boxPickLayer(this, box, cb);
718
- }
719
- buildLayerModel(options) {
720
- const {
721
- moduleName,
722
- vertexShader,
723
- fragmentShader,
724
- triangulation,
725
- segmentNumber,
726
- workerEnabled = false,
727
- workerOptions,
728
- ...rest
729
- } = options;
730
- this.shaderModuleService.registerModule(moduleName, {
731
- vs: vertexShader,
732
- fs: fragmentShader
733
- });
734
- const { vs, fs, uniforms } = this.shaderModuleService.getModule(moduleName);
735
- const { createModel } = this.rendererService;
736
- return new Promise((resolve, reject) => {
737
- if (workerOptions && workerOptions.modelType in import_l7_utils.WorkerSourceMap && workerEnabled) {
738
- this.styleAttributeService.createAttributesAndIndicesAscy(this.encodedData, segmentNumber, workerOptions).then(({ attributes, elements }) => {
739
- const m = createModel({
740
- attributes,
741
- uniforms,
742
- fs,
743
- vs,
744
- elements,
745
- blend: import_blend.BlendTypes[import_l7_core.BlendType.normal],
746
- ...rest
1133
+ }, {
1134
+ key: "boxSelect",
1135
+ value: function boxSelect(box, cb) {
1136
+ this.pickingService.boxPickLayer(this, box, cb);
1137
+ }
1138
+ }, {
1139
+ key: "buildLayerModel",
1140
+ value: function buildLayerModel(options) {
1141
+ var _this9 = this;
1142
+
1143
+ var moduleName = options.moduleName,
1144
+ vertexShader = options.vertexShader,
1145
+ fragmentShader = options.fragmentShader,
1146
+ triangulation = options.triangulation,
1147
+ segmentNumber = options.segmentNumber,
1148
+ _options$workerEnable = options.workerEnabled,
1149
+ workerEnabled = _options$workerEnable === void 0 ? false : _options$workerEnable,
1150
+ workerOptions = options.workerOptions,
1151
+ rest = (0, _objectWithoutProperties2.default)(options, _excluded2);
1152
+ this.shaderModuleService.registerModule(moduleName, {
1153
+ vs: vertexShader,
1154
+ fs: fragmentShader
1155
+ });
1156
+
1157
+ var _this$shaderModuleSer = this.shaderModuleService.getModule(moduleName),
1158
+ vs = _this$shaderModuleSer.vs,
1159
+ fs = _this$shaderModuleSer.fs,
1160
+ uniforms = _this$shaderModuleSer.uniforms;
1161
+
1162
+ var createModel = this.rendererService.createModel;
1163
+ return new Promise(function (resolve, reject) {
1164
+ // filter supported worker & worker enabled layer
1165
+ if (workerOptions && workerOptions.modelType in _l7Utils.WorkerSourceMap && workerEnabled) {
1166
+ _this9.styleAttributeService.createAttributesAndIndicesAscy(_this9.encodedData, segmentNumber, workerOptions).then(function (_ref7) {
1167
+ var attributes = _ref7.attributes,
1168
+ elements = _ref7.elements;
1169
+ var m = createModel((0, _objectSpread2.default)({
1170
+ attributes: attributes,
1171
+ uniforms: uniforms,
1172
+ fs: fs,
1173
+ vs: vs,
1174
+ elements: elements,
1175
+ blend: _blend.BlendTypes[_l7Core.BlendType.normal]
1176
+ }, rest));
1177
+ resolve(m);
1178
+ }).catch(function (err) {
1179
+ return reject(err);
747
1180
  });
1181
+ } else {
1182
+ var _this9$styleAttribute = _this9.styleAttributeService.createAttributesAndIndices(_this9.encodedData, triangulation, segmentNumber),
1183
+ attributes = _this9$styleAttribute.attributes,
1184
+ elements = _this9$styleAttribute.elements,
1185
+ count = _this9$styleAttribute.count;
1186
+
1187
+ var modeloptions = (0, _objectSpread2.default)({
1188
+ attributes: attributes,
1189
+ uniforms: uniforms,
1190
+ fs: fs,
1191
+ vs: vs,
1192
+ elements: elements,
1193
+ blend: _blend.BlendTypes[_l7Core.BlendType.normal]
1194
+ }, rest);
1195
+
1196
+ if (count) {
1197
+ modeloptions.count = count;
1198
+ }
1199
+
1200
+ var m = createModel(modeloptions);
748
1201
  resolve(m);
749
- }).catch((err) => reject(err));
750
- } else {
751
- const {
752
- attributes,
753
- elements,
754
- count
755
- } = this.styleAttributeService.createAttributesAndIndices(this.encodedData, triangulation, segmentNumber);
756
- const modeloptions = {
757
- attributes,
758
- uniforms,
759
- fs,
760
- vs,
761
- elements,
762
- blend: import_blend.BlendTypes[import_l7_core.BlendType.normal],
763
- ...rest
764
- };
765
- if (count) {
766
- modeloptions.count = count;
767
- }
768
- const m = createModel(modeloptions);
769
- resolve(m);
770
- }
771
- });
772
- }
773
- createAttrubutes(options) {
774
- const { triangulation } = options;
775
- const { attributes } = this.styleAttributeService.createAttributes(this.encodedData, triangulation);
776
- return attributes;
777
- }
778
- getTime() {
779
- return this.layerService.clock.getDelta();
780
- }
781
- setAnimateStartTime() {
782
- this.animateStartTime = this.layerService.clock.getElapsedTime();
783
- }
784
- stopAnimate() {
785
- if (this.aniamateStatus) {
786
- this.layerService.stopAnimate();
787
- this.aniamateStatus = false;
788
- this.updateLayerConfig({
789
- animateOption: {
790
- enable: false
791
1202
  }
792
1203
  });
793
1204
  }
794
- }
795
- getLayerAnimateTime() {
796
- return this.layerService.clock.getElapsedTime() - this.animateStartTime;
797
- }
798
- needPick(type) {
799
- const {
800
- enableHighlight = true,
801
- enableSelect = true
802
- } = this.getLayerConfig();
803
- let isPick = this.eventNames().indexOf(type) !== -1 || this.eventNames().indexOf("un" + type) !== -1;
804
- if ((type === "click" || type === "dblclick") && enableSelect) {
805
- isPick = true;
806
- }
807
- if (type === "mousemove" && (enableHighlight || this.eventNames().indexOf("mouseenter") !== -1 || this.eventNames().indexOf("unmousemove") !== -1 || this.eventNames().indexOf("mouseout") !== -1)) {
808
- isPick = true;
809
- }
810
- return this.isVisible() && isPick;
811
- }
812
- buildModels() {
813
- throw new Error("Method not implemented.");
814
- }
815
- rebuildModels() {
816
- throw new Error("Method not implemented.");
817
- }
818
- async renderMulPass(multiPassRenderer) {
819
- await multiPassRenderer.render();
820
- }
821
- renderModels(isPicking) {
822
- var _a;
823
- if (this.getEncodedData() && this.getEncodedData().length > 0) {
824
- if (this.layerModelNeedUpdate && this.layerModel) {
825
- this.layerModel.buildModels((models) => {
826
- this.models = models;
827
- this.hooks.beforeRender.call();
828
- this.layerModelNeedUpdate = false;
1205
+ }, {
1206
+ key: "createAttrubutes",
1207
+ value: function createAttrubutes(options) {
1208
+ var triangulation = options.triangulation; // @ts-ignore
1209
+
1210
+ var _this$styleAttributeS4 = this.styleAttributeService.createAttributes(this.encodedData, triangulation),
1211
+ attributes = _this$styleAttributeS4.attributes;
1212
+
1213
+ return attributes;
1214
+ }
1215
+ }, {
1216
+ key: "getTime",
1217
+ value: function getTime() {
1218
+ return this.layerService.clock.getDelta();
1219
+ }
1220
+ }, {
1221
+ key: "setAnimateStartTime",
1222
+ value: function setAnimateStartTime() {
1223
+ this.animateStartTime = this.layerService.clock.getElapsedTime();
1224
+ }
1225
+ }, {
1226
+ key: "stopAnimate",
1227
+ value: function stopAnimate() {
1228
+ if (this.aniamateStatus) {
1229
+ this.layerService.stopAnimate();
1230
+ this.aniamateStatus = false;
1231
+ this.updateLayerConfig({
1232
+ animateOption: {
1233
+ enable: false
1234
+ }
829
1235
  });
830
1236
  }
831
- if ((_a = this == null ? void 0 : this.layerModel) == null ? void 0 : _a.renderUpdate) {
832
- this.layerModel.renderUpdate();
1237
+ }
1238
+ }, {
1239
+ key: "getLayerAnimateTime",
1240
+ value: function getLayerAnimateTime() {
1241
+ return this.layerService.clock.getElapsedTime() - this.animateStartTime;
1242
+ }
1243
+ }, {
1244
+ key: "needPick",
1245
+ value: function needPick(type) {
1246
+ var _this$getLayerConfig10 = this.getLayerConfig(),
1247
+ _this$getLayerConfig11 = _this$getLayerConfig10.enableHighlight,
1248
+ enableHighlight = _this$getLayerConfig11 === void 0 ? true : _this$getLayerConfig11,
1249
+ _this$getLayerConfig12 = _this$getLayerConfig10.enableSelect,
1250
+ enableSelect = _this$getLayerConfig12 === void 0 ? true : _this$getLayerConfig12; // 判断layer是否监听事件;
1251
+
1252
+
1253
+ var isPick = this.eventNames().indexOf(type) !== -1 || this.eventNames().indexOf('un' + type) !== -1;
1254
+
1255
+ if ((type === 'click' || type === 'dblclick') && enableSelect) {
1256
+ isPick = true;
1257
+ }
1258
+
1259
+ if (type === 'mousemove' && (enableHighlight || this.eventNames().indexOf('mouseenter') !== -1 || this.eventNames().indexOf('unmousemove') !== -1 || this.eventNames().indexOf('mouseout') !== -1)) {
1260
+ isPick = true;
833
1261
  }
834
- this.models.forEach((model) => {
835
- model.draw({
836
- uniforms: this.layerModel.getUninforms()
837
- }, isPicking);
838
- });
1262
+
1263
+ return this.isVisible() && isPick;
839
1264
  }
840
- return this;
841
- }
842
- updateStyleAttribute(type, field, values, updateOptions) {
843
- if (!this.inited) {
844
- this.pendingStyleAttributes.push({
845
- attributeName: type,
846
- attributeField: field,
847
- attributeValues: values,
848
- updateOptions
849
- });
850
- } else {
851
- this.styleAttributeService.updateStyleAttribute(type, {
852
- scale: {
853
- field,
854
- ...this.splitValuesAndCallbackInAttribute(values, this.getLayerConfig()[field])
1265
+ }, {
1266
+ key: "buildModels",
1267
+ value: function buildModels() {
1268
+ throw new Error('Method not implemented.');
1269
+ }
1270
+ }, {
1271
+ key: "rebuildModels",
1272
+ value: function rebuildModels() {
1273
+ throw new Error('Method not implemented.');
1274
+ }
1275
+ }, {
1276
+ key: "renderMulPass",
1277
+ value: function () {
1278
+ var _renderMulPass = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(multiPassRenderer) {
1279
+ return _regenerator.default.wrap(function _callee2$(_context2) {
1280
+ while (1) {
1281
+ switch (_context2.prev = _context2.next) {
1282
+ case 0:
1283
+ _context2.next = 2;
1284
+ return multiPassRenderer.render();
1285
+
1286
+ case 2:
1287
+ case "end":
1288
+ return _context2.stop();
1289
+ }
1290
+ }
1291
+ }, _callee2);
1292
+ }));
1293
+
1294
+ function renderMulPass(_x) {
1295
+ return _renderMulPass.apply(this, arguments);
1296
+ }
1297
+
1298
+ return renderMulPass;
1299
+ }()
1300
+ }, {
1301
+ key: "renderModels",
1302
+ value: function renderModels(isPicking) {
1303
+ var _this10 = this;
1304
+
1305
+ // TODO: this.getEncodedData().length > 0 这个判断是为了解决在 2.5.x 引入数据纹理后产生的 空数据渲染导致 texture 超出上限问题
1306
+ if (this.getEncodedData() && this.getEncodedData().length > 0) {
1307
+ var _this$layerModel4;
1308
+
1309
+ if (this.layerModelNeedUpdate && this.layerModel) {
1310
+ this.layerModel.buildModels(function (models) {
1311
+ _this10.models = models;
1312
+
1313
+ _this10.hooks.beforeRender.call();
1314
+
1315
+ _this10.layerModelNeedUpdate = false;
1316
+ });
855
1317
  }
856
- }, updateOptions);
1318
+
1319
+ if (this !== null && this !== void 0 && (_this$layerModel4 = this.layerModel) !== null && _this$layerModel4 !== void 0 && _this$layerModel4.renderUpdate) {
1320
+ this.layerModel.renderUpdate();
1321
+ }
1322
+
1323
+ this.models.forEach(function (model) {
1324
+ model.draw({
1325
+ uniforms: _this10.layerModel.getUninforms()
1326
+ }, isPicking);
1327
+ });
1328
+ }
1329
+
1330
+ return this;
857
1331
  }
858
- }
859
- getShaderPickStat() {
860
- return this.layerService.getShaderPickStat();
861
- }
862
- setEarthTime(time) {
863
- console.warn("empty fn");
864
- }
865
- getConfigSchema() {
866
- throw new Error("Method not implemented.");
867
- }
868
- getModelType() {
869
- throw new Error("Method not implemented.");
870
- }
871
- getDefaultConfig() {
872
- return {};
873
- }
874
- reRender() {
875
- if (this.inited) {
876
- this.layerService.updateLayerRenderList();
877
- this.layerService.renderLayers();
1332
+ }, {
1333
+ key: "updateStyleAttribute",
1334
+ value: function updateStyleAttribute(type, field, values, updateOptions) {
1335
+ if (!this.inited) {
1336
+ this.pendingStyleAttributes.push({
1337
+ attributeName: type,
1338
+ attributeField: field,
1339
+ attributeValues: values,
1340
+ updateOptions: updateOptions
1341
+ });
1342
+ } else {
1343
+ this.styleAttributeService.updateStyleAttribute(type, {
1344
+ // @ts-ignore
1345
+ scale: (0, _objectSpread2.default)({
1346
+ field: field
1347
+ }, this.splitValuesAndCallbackInAttribute( // @ts-ignore
1348
+ values, // @ts-ignore
1349
+ this.getLayerConfig()[field]))
1350
+ }, // @ts-ignore
1351
+ updateOptions);
1352
+ }
878
1353
  }
879
- }
880
- splitValuesAndCallbackInAttribute(valuesOrCallback, defaultValues) {
881
- return {
882
- values: (0, import_lodash.isFunction)(valuesOrCallback) ? void 0 : valuesOrCallback || defaultValues,
883
- callback: (0, import_lodash.isFunction)(valuesOrCallback) ? valuesOrCallback : void 0
884
- };
885
- }
886
- };
887
- __decorateClass([
888
- (0, import_l7_core.lazyInject)(import_l7_core.TYPES.IGlobalConfigService)
889
- ], BaseLayer.prototype, "configService", 2);
890
- // Annotate the CommonJS export names for ESM import in node:
891
- 0 && (module.exports = {});
1354
+ }, {
1355
+ key: "getShaderPickStat",
1356
+ value: function getShaderPickStat() {
1357
+ return this.layerService.getShaderPickStat();
1358
+ }
1359
+ /**
1360
+ * 继承空方法
1361
+ * @param time
1362
+ */
1363
+
1364
+ }, {
1365
+ key: "setEarthTime",
1366
+ value: function setEarthTime(time) {
1367
+ console.warn('empty fn');
1368
+ }
1369
+ }, {
1370
+ key: "getConfigSchema",
1371
+ value: function getConfigSchema() {
1372
+ throw new Error('Method not implemented.');
1373
+ }
1374
+ }, {
1375
+ key: "getModelType",
1376
+ value: function getModelType() {
1377
+ throw new Error('Method not implemented.');
1378
+ }
1379
+ }, {
1380
+ key: "getDefaultConfig",
1381
+ value: function getDefaultConfig() {
1382
+ return {};
1383
+ }
1384
+ }, {
1385
+ key: "reRender",
1386
+ value: function reRender() {
1387
+ if (this.inited) {
1388
+ this.layerService.updateLayerRenderList();
1389
+ this.layerService.renderLayers();
1390
+ }
1391
+ }
1392
+ }, {
1393
+ key: "splitValuesAndCallbackInAttribute",
1394
+ value: function splitValuesAndCallbackInAttribute(valuesOrCallback, defaultValues) {
1395
+ return {
1396
+ values: (0, _lodash.isFunction)(valuesOrCallback) ? undefined : valuesOrCallback || defaultValues,
1397
+ callback: (0, _lodash.isFunction)(valuesOrCallback) ? valuesOrCallback : undefined
1398
+ };
1399
+ }
1400
+ }]);
1401
+ return BaseLayer;
1402
+ }(_eventemitter.EventEmitter), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class.prototype, "configService", [_dec], {
1403
+ configurable: true,
1404
+ enumerable: true,
1405
+ writable: true,
1406
+ initializer: null
1407
+ })), _class));
1408
+ exports.default = BaseLayer;