@antv/l7-layers 2.20.20 → 2.21.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 (138) hide show
  1. package/es/canvas/index.d.ts +13 -8
  2. package/es/canvas/index.js +63 -36
  3. package/es/canvas/models/canvas.d.ts +19 -14
  4. package/es/canvas/models/canvas.js +125 -139
  5. package/es/canvas/models/constants.d.ts +2 -0
  6. package/es/canvas/models/constants.js +6 -0
  7. package/es/canvas/models/index.d.ts +2 -5
  8. package/es/canvas/models/index.js +2 -5
  9. package/es/core/BaseLayer.d.ts +18 -19
  10. package/es/core/BaseLayer.js +134 -101
  11. package/es/core/BaseModel.js +15 -31
  12. package/es/core/LayerPickService.js +4 -6
  13. package/es/core/TextureService.js +1 -2
  14. package/es/core/interface.d.ts +31 -4
  15. package/es/core/shape/Path.js +1 -2
  16. package/es/core/shape/arrow.js +2 -6
  17. package/es/core/shape/extrude.js +0 -1
  18. package/es/core/triangulation.js +2 -2
  19. package/es/earth/models/base.js +0 -1
  20. package/es/heatmap/index.js +0 -1
  21. package/es/heatmap/models/heatmap.d.ts +0 -1
  22. package/es/heatmap/models/heatmap.js +2 -5
  23. package/es/index.d.ts +2 -1
  24. package/es/index.js +2 -89
  25. package/es/line/models/arc.js +5 -5
  26. package/es/line/models/arc_3d.js +4 -4
  27. package/es/line/models/great_circle.js +4 -4
  28. package/es/line/models/line.js +8 -12
  29. package/es/line/models/simple_line.js +1 -2
  30. package/es/line/models/wall.js +5 -4
  31. package/es/line/shaders/line/line_vert.glsl +0 -2
  32. package/es/line/shaders/wall/wall_vert.glsl +15 -0
  33. package/es/plugins/DataMappingPlugin.d.ts +4 -7
  34. package/es/plugins/DataMappingPlugin.js +8 -25
  35. package/es/plugins/DataSourcePlugin.d.ts +0 -1
  36. package/es/plugins/DataSourcePlugin.js +4 -7
  37. package/es/plugins/FeatureScalePlugin.d.ts +2 -5
  38. package/es/plugins/FeatureScalePlugin.js +5 -7
  39. package/es/plugins/LayerAnimateStylePlugin.d.ts +0 -1
  40. package/es/plugins/LayerAnimateStylePlugin.js +2 -5
  41. package/es/plugins/LayerMaskPlugin.d.ts +0 -1
  42. package/es/plugins/LayerMaskPlugin.js +2 -8
  43. package/es/plugins/LayerModelPlugin.d.ts +0 -1
  44. package/es/plugins/LayerModelPlugin.js +13 -18
  45. package/es/plugins/LayerStylePlugin.d.ts +0 -1
  46. package/es/plugins/LayerStylePlugin.js +2 -5
  47. package/es/plugins/LightingPlugin.d.ts +0 -1
  48. package/es/plugins/LightingPlugin.js +2 -5
  49. package/es/plugins/MultiPassRendererPlugin.d.ts +0 -1
  50. package/es/plugins/MultiPassRendererPlugin.js +2 -5
  51. package/es/plugins/PixelPickingPlugin.d.ts +2 -6
  52. package/es/plugins/PixelPickingPlugin.js +6 -12
  53. package/es/plugins/RegisterStyleAttributePlugin.d.ts +2 -5
  54. package/es/plugins/RegisterStyleAttributePlugin.js +2 -5
  55. package/es/plugins/ShaderUniformPlugin.d.ts +7 -8
  56. package/es/plugins/ShaderUniformPlugin.js +17 -43
  57. package/es/plugins/UpdateModelPlugin.d.ts +0 -1
  58. package/es/plugins/UpdateModelPlugin.js +2 -5
  59. package/es/plugins/UpdateStyleAttributePlugin.d.ts +2 -5
  60. package/es/plugins/UpdateStyleAttributePlugin.js +2 -6
  61. package/es/plugins/index.d.ts +15 -0
  62. package/es/plugins/index.js +18 -0
  63. package/es/point/models/fill.d.ts +1 -1
  64. package/es/point/models/fill.js +7 -10
  65. package/es/point/models/fillImage.js +4 -3
  66. package/es/point/models/image.js +4 -3
  67. package/es/polygon/models/extrude.js +0 -1
  68. package/es/polygon/models/fill.js +2 -3
  69. package/es/polygon/models/index.js +0 -1
  70. package/es/polygon/models/ocean.js +1 -2
  71. package/es/polygon/models/water.js +0 -2
  72. package/es/tile/core/BaseLayer.js +4 -5
  73. package/es/tile/interaction/getRasterData.js +0 -3
  74. package/es/tile/service/TileLayerService.d.ts +0 -1
  75. package/es/tile/service/TileLayerService.js +0 -1
  76. package/es/tile/service/TilePickService.d.ts +1 -1
  77. package/es/tile/service/TilePickService.js +2 -3
  78. package/es/tile/tile/Tile.js +8 -6
  79. package/es/utils/blend.js +7 -8
  80. package/es/utils/polylineNormal.js +0 -1
  81. package/es/utils/rampcolor_legend.js +1 -2
  82. package/es/wind/index.js +0 -1
  83. package/lib/canvas/index.js +63 -37
  84. package/lib/canvas/models/canvas.js +125 -138
  85. package/lib/canvas/models/constants.js +12 -0
  86. package/lib/canvas/models/index.js +22 -7
  87. package/lib/core/BaseLayer.js +134 -101
  88. package/lib/core/BaseModel.js +14 -30
  89. package/lib/core/LayerPickService.js +4 -6
  90. package/lib/core/TextureService.js +1 -2
  91. package/lib/core/shape/Path.js +1 -2
  92. package/lib/core/shape/arrow.js +2 -6
  93. package/lib/core/shape/extrude.js +0 -1
  94. package/lib/core/triangulation.js +2 -2
  95. package/lib/earth/models/base.js +0 -1
  96. package/lib/heatmap/index.js +0 -1
  97. package/lib/heatmap/models/heatmap.js +2 -5
  98. package/lib/index.js +9 -90
  99. package/lib/line/models/arc.js +4 -4
  100. package/lib/line/models/arc_3d.js +4 -4
  101. package/lib/line/models/great_circle.js +4 -4
  102. package/lib/line/models/line.js +10 -12
  103. package/lib/line/models/simple_line.js +0 -1
  104. package/lib/line/models/wall.js +5 -4
  105. package/lib/line/shaders/line/line_vert.glsl +0 -2
  106. package/lib/line/shaders/wall/wall_vert.glsl +15 -0
  107. package/lib/plugins/DataMappingPlugin.js +7 -24
  108. package/lib/plugins/DataSourcePlugin.js +3 -6
  109. package/lib/plugins/FeatureScalePlugin.js +5 -7
  110. package/lib/plugins/LayerAnimateStylePlugin.js +2 -5
  111. package/lib/plugins/LayerMaskPlugin.js +2 -8
  112. package/lib/plugins/LayerModelPlugin.js +13 -18
  113. package/lib/plugins/LayerStylePlugin.js +2 -5
  114. package/lib/plugins/LightingPlugin.js +2 -5
  115. package/lib/plugins/MultiPassRendererPlugin.js +2 -5
  116. package/lib/plugins/PixelPickingPlugin.js +6 -12
  117. package/lib/plugins/RegisterStyleAttributePlugin.js +2 -5
  118. package/lib/plugins/ShaderUniformPlugin.js +16 -42
  119. package/lib/plugins/UpdateModelPlugin.js +2 -5
  120. package/lib/plugins/UpdateStyleAttributePlugin.js +2 -5
  121. package/lib/plugins/index.js +26 -0
  122. package/lib/point/models/fill.js +10 -13
  123. package/lib/point/models/fillImage.js +4 -3
  124. package/lib/point/models/image.js +4 -3
  125. package/lib/polygon/models/extrude.js +0 -1
  126. package/lib/polygon/models/fill.js +1 -2
  127. package/lib/polygon/models/ocean.js +0 -1
  128. package/lib/polygon/models/water.js +0 -2
  129. package/lib/tile/core/BaseLayer.js +4 -5
  130. package/lib/tile/interaction/getRasterData.js +0 -3
  131. package/lib/tile/service/TileLayerService.js +0 -1
  132. package/lib/tile/service/TilePickService.js +2 -3
  133. package/lib/tile/tile/Tile.js +8 -6
  134. package/lib/utils/blend.js +7 -8
  135. package/lib/utils/polylineNormal.js +0 -1
  136. package/lib/utils/rampcolor_legend.js +1 -2
  137. package/lib/wind/index.js +0 -1
  138. package/package.json +18 -20
@@ -1,13 +1,18 @@
1
- import type { ILayer } from '@antv/l7-core';
2
1
  import BaseLayer from '../core/BaseLayer';
3
- import type { ICanvasLayerStyleOptions } from '../core/interface';
4
- import type { CanvasModelType } from './models/index';
5
- export default class CanvasLayer extends BaseLayer<ICanvasLayerStyleOptions> {
2
+ import type { ICanvasLayerOptions } from '../core/interface';
3
+ import type { CanvasModelType } from './models';
4
+ import { CanvasModel } from './models';
5
+ export default class CanvasLayer extends BaseLayer<ICanvasLayerOptions> {
6
6
  type: string;
7
- forceRender: boolean;
7
+ layerModel: CanvasModel;
8
+ protected getDefaultConfig(): Partial<ICanvasLayerOptions>;
8
9
  buildModels(): Promise<void>;
9
- hide(): ILayer;
10
- renderModels(): this;
11
- protected getDefaultConfig(): {};
12
10
  getModelType(): CanvasModelType;
11
+ draw(draw: ICanvasLayerOptions['draw']): this;
12
+ getLayerConfig(): any;
13
+ render(): this;
14
+ getCanvas(): HTMLCanvasElement | null;
15
+ show(): this;
16
+ hide(): this;
17
+ destroy(): void;
13
18
  }
@@ -1,7 +1,9 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
3
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
4
  import _createClass from "@babel/runtime/helpers/esm/createClass";
4
5
  import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
+ import _get from "@babel/runtime/helpers/esm/get";
5
7
  import _inherits from "@babel/runtime/helpers/esm/inherits";
6
8
  import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
7
9
  import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
@@ -9,8 +11,9 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
11
  import _regeneratorRuntime from "@babel/runtime/regenerator";
10
12
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
13
  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; } }
14
+ // import type { ILayerConfig } from '@antv/l7-core';
12
15
  import BaseLayer from "../core/BaseLayer";
13
- import CanvasModels from "./models/index";
16
+ import { CanvasModel } from "./models";
14
17
  var CanvasLayer = /*#__PURE__*/function (_BaseLayer) {
15
18
  _inherits(CanvasLayer, _BaseLayer);
16
19
  var _super = _createSuper(CanvasLayer);
@@ -22,22 +25,28 @@ var CanvasLayer = /*#__PURE__*/function (_BaseLayer) {
22
25
  }
23
26
  _this = _super.call.apply(_super, [this].concat(args));
24
27
  _defineProperty(_assertThisInitialized(_this), "type", 'CanvasLayer');
25
- _defineProperty(_assertThisInitialized(_this), "forceRender", true);
26
28
  return _this;
27
29
  }
28
30
  _createClass(CanvasLayer, [{
31
+ key: "getDefaultConfig",
32
+ value: function getDefaultConfig() {
33
+ return {
34
+ zIndex: 3,
35
+ contextType: 'canvas2d',
36
+ trigger: 'change'
37
+ };
38
+ }
39
+ }, {
29
40
  key: "buildModels",
30
41
  value: function () {
31
42
  var _buildModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
32
- var modelType;
33
43
  return _regeneratorRuntime.wrap(function _callee$(_context) {
34
44
  while (1) switch (_context.prev = _context.next) {
35
45
  case 0:
36
- modelType = this.getModelType();
37
- this.layerModel = new CanvasModels[modelType](this);
38
- _context.next = 4;
46
+ this.layerModel = new CanvasModel(this);
47
+ _context.next = 3;
39
48
  return this.initLayerModels();
40
- case 4:
49
+ case 3:
41
50
  case "end":
42
51
  return _context.stop();
43
52
  }
@@ -49,46 +58,64 @@ var CanvasLayer = /*#__PURE__*/function (_BaseLayer) {
49
58
  return buildModels;
50
59
  }()
51
60
  }, {
52
- key: "hide",
53
- value: function hide() {
54
- // 清除画布
55
- if (this.layerModel.clearCanvas) {
56
- this.layerModel.clearCanvas();
57
- }
61
+ key: "getModelType",
62
+ value: function getModelType() {
63
+ return this.getLayerConfig().contextType || 'canvas2d';
64
+ }
65
+ }, {
66
+ key: "draw",
67
+ value: function draw(_draw) {
58
68
  this.updateLayerConfig({
59
- visible: false
69
+ draw: _draw
60
70
  });
61
- this.reRender();
71
+ this.render();
62
72
  return this;
63
73
  }
64
74
  }, {
65
- key: "renderModels",
66
- value: function renderModels() {
67
- var _this$layerModel,
68
- _this2 = this;
69
- if (this !== null && this !== void 0 && (_this$layerModel = this.layerModel) !== null && _this$layerModel !== void 0 && _this$layerModel.renderUpdate) {
70
- this.layerModel.renderUpdate();
75
+ key: "getLayerConfig",
76
+ value: function getLayerConfig() {
77
+ var config = _objectSpread(_objectSpread({}, this.getDefaultConfig()), _get(_getPrototypeOf(CanvasLayer.prototype), "getLayerConfig", this).call(this));
78
+ if (config.zIndex < 3) {
79
+ config.zIndex = 3;
71
80
  }
72
- this.models.forEach(function (model) {
73
- model.draw({
74
- uniforms: _this2.layerModel.getUninforms()
75
- }, false);
76
- });
81
+ return config;
82
+ }
83
+ }, {
84
+ key: "render",
85
+ value: function render() {
86
+ var _this$layerModel;
87
+ (_this$layerModel = this.layerModel) === null || _this$layerModel === void 0 || _this$layerModel.renderCanvas();
77
88
  return this;
78
89
  }
79
90
  }, {
80
- key: "getDefaultConfig",
81
- value: function getDefaultConfig() {
82
- var type = this.getModelType();
83
- var defaultConfig = {
84
- canvas: {}
85
- };
86
- return defaultConfig[type];
91
+ key: "getCanvas",
92
+ value: function getCanvas() {
93
+ var _this$layerModel2;
94
+ return (_this$layerModel2 = this.layerModel) === null || _this$layerModel2 === void 0 ? void 0 : _this$layerModel2.canvas;
87
95
  }
88
96
  }, {
89
- key: "getModelType",
90
- value: function getModelType() {
91
- return 'canvas';
97
+ key: "show",
98
+ value: function show() {
99
+ var canvas = this.getCanvas();
100
+ if (canvas) {
101
+ canvas.style.display = 'unset';
102
+ }
103
+ return this;
104
+ }
105
+ }, {
106
+ key: "hide",
107
+ value: function hide() {
108
+ var canvas = this.getCanvas();
109
+ if (canvas) {
110
+ canvas.style.display = 'none';
111
+ }
112
+ return this;
113
+ }
114
+ }, {
115
+ key: "destroy",
116
+ value: function destroy() {
117
+ this.layerModel.removeCanvas();
118
+ _get(_getPrototypeOf(CanvasLayer.prototype), "destroy", this).call(this);
92
119
  }
93
120
  }]);
94
121
  return CanvasLayer;
@@ -1,18 +1,23 @@
1
1
  import BaseModel from '../../core/BaseModel';
2
- import { CanvasUpdateType } from '../../core/interface';
3
- export default class CanvaModel extends BaseModel {
4
- protected updateMode: CanvasUpdateType;
5
- protected canvas: HTMLCanvasElement;
6
- protected ctx: CanvasRenderingContext2D;
7
- protected prevSize: [number, number];
8
- renderUpdate: () => void;
9
- unBindListener: () => void;
10
- bindListener: () => void;
11
- clearModels(): void;
2
+ import { type ICanvasLayerOptions } from '../../core/interface';
3
+ export declare class CanvasModel extends BaseModel {
4
+ canvas: HTMLCanvasElement | null;
5
+ ctx: any;
6
+ ctxType: string;
7
+ viewportSize: [number, number];
8
+ get layerConfig(): ICanvasLayerOptions;
12
9
  initModels(): Promise<never[]>;
13
- initCanvas(): void;
14
- clearCanvas: () => void;
10
+ initCanvas: () => void;
11
+ resetViewportSize: () => void;
12
+ resetCanvasSize: () => void;
15
13
  renderCanvas: () => void;
16
- buildModels(): Promise<never[]>;
17
- protected registerBuiltinAttributes(): void;
14
+ removeCanvas: () => void;
15
+ onMapResize: () => void;
16
+ bindListeners(): void;
17
+ unbindListeners(): void;
18
+ lngLatToContainer: (lngLat: [number, number]) => {
19
+ x: number;
20
+ y: number;
21
+ };
22
+ registerBuiltinAttributes(): void;
18
23
  }
@@ -12,120 +12,131 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
12
12
  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; } }
13
13
  import BaseModel from "../../core/BaseModel";
14
14
  import { CanvasUpdateType } from "../../core/interface";
15
- var CanvaModel = /*#__PURE__*/function (_BaseModel) {
16
- _inherits(CanvaModel, _BaseModel);
17
- var _super = _createSuper(CanvaModel);
18
- function CanvaModel() {
15
+ import { CanvasContextTypeMap } from "./constants";
16
+ export var CanvasModel = /*#__PURE__*/function (_BaseModel) {
17
+ _inherits(CanvasModel, _BaseModel);
18
+ var _super = _createSuper(CanvasModel);
19
+ function CanvasModel() {
19
20
  var _this;
20
- _classCallCheck(this, CanvaModel);
21
+ _classCallCheck(this, CanvasModel);
21
22
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
22
23
  args[_key] = arguments[_key];
23
24
  }
24
25
  _this = _super.call.apply(_super, [this].concat(args));
25
- _defineProperty(_assertThisInitialized(_this), "updateMode", CanvasUpdateType.ALWAYS);
26
- _defineProperty(_assertThisInitialized(_this), "renderUpdate", function () {
27
- var _ref = _this.layer.getLayerConfig(),
28
- _ref$zIndex = _ref.zIndex,
29
- zIndex = _ref$zIndex === void 0 ? 10 : _ref$zIndex,
30
- _ref$update = _ref.update,
31
- update = _ref$update === void 0 ? CanvasUpdateType.ALWAYS : _ref$update,
32
- _ref$animateOption = _ref.animateOption,
33
- animateOption = _ref$animateOption === void 0 ? {
34
- enable: false,
35
- duration: 20
36
- } : _ref$animateOption;
37
- if (+_this.canvas.style.zIndex === zIndex) {
38
- _this.canvas.style.zIndex = zIndex + '';
39
- }
40
- if (_this.updateMode !== update) {
41
- _this.updateMode = update;
42
- _this.unBindListener();
43
- _this.bindListener();
44
- }
45
- if (_this.updateMode === CanvasUpdateType.ALWAYS && animateOption.enable) {
46
- _this.renderCanvas();
26
+ _defineProperty(_assertThisInitialized(_this), "canvas", null);
27
+ _defineProperty(_assertThisInitialized(_this), "initCanvas", function () {
28
+ var _this$mapService$getC, _this$mapService$getC2, _this$mapService, _this$mapService$getM, _this$mapService2;
29
+ var _this$layerConfig = _this.layerConfig,
30
+ zIndex = _this$layerConfig.zIndex,
31
+ getContext = _this$layerConfig.getContext;
32
+ var canvas = document.createElement('canvas');
33
+ var modelType = _this.layer.getModelType();
34
+ _this.canvas = canvas;
35
+ canvas.classList.add('l7-canvas-layer');
36
+ canvas.style.position = 'absolute';
37
+ canvas.style.top = '0';
38
+ canvas.style.left = '0';
39
+ canvas.style.zIndex = String(zIndex);
40
+ _this.resetCanvasSize();
41
+ var container = (_this$mapService$getC = (_this$mapService$getC2 = (_this$mapService = _this.mapService).getCanvasOverlays) === null || _this$mapService$getC2 === void 0 ? void 0 : _this$mapService$getC2.call(_this$mapService)) !== null && _this$mapService$getC !== void 0 ? _this$mapService$getC : (_this$mapService$getM = (_this$mapService2 = _this.mapService).getMapCanvasContainer) === null || _this$mapService$getM === void 0 ? void 0 : _this$mapService$getM.call(_this$mapService2);
42
+ container === null || container === void 0 || container.appendChild(canvas);
43
+ _this.ctx = getContext ? getContext(canvas) : canvas.getContext(CanvasContextTypeMap[modelType]);
44
+ if (!_this.ctx) {
45
+ console.error('Failed to get rendering context for canvas');
47
46
  }
47
+ _this.bindListeners();
48
48
  });
49
- _defineProperty(_assertThisInitialized(_this), "unBindListener", function () {
50
- _this.mapService.off('mapchange', _this.renderCanvas);
51
- _this.mapService.off('zoomstart', _this.clearCanvas);
52
- _this.mapService.off('zoomend', _this.renderCanvas);
53
- _this.mapService.off('movestart', _this.clearCanvas);
54
- _this.mapService.off('moveend', _this.renderCanvas);
55
- });
56
- _defineProperty(_assertThisInitialized(_this), "bindListener", function () {
57
- if (_this.updateMode === CanvasUpdateType.ALWAYS) {
58
- _this.mapService.on('mapchange', _this.renderCanvas);
59
- } else {
60
- _this.mapService.on('zoomstart', _this.clearCanvas);
61
- _this.mapService.on('zoomend', _this.renderCanvas);
62
- _this.mapService.on('movestart', _this.clearCanvas);
63
- _this.mapService.on('moveend', _this.renderCanvas);
64
- }
49
+ _defineProperty(_assertThisInitialized(_this), "resetViewportSize", function () {
50
+ var _this$rendererService = _this.rendererService.getViewportSize(),
51
+ viewWidth = _this$rendererService.width,
52
+ viewHeight = _this$rendererService.height;
53
+ _this.viewportSize = [viewWidth, viewHeight];
65
54
  });
66
- _defineProperty(_assertThisInitialized(_this), "clearCanvas", function () {
67
- if (_this.ctx) {
68
- var _this$rendererService = _this.rendererService.getViewportSize(),
69
- w = _this$rendererService.width,
70
- h = _this$rendererService.height;
71
- _this.ctx.clearRect(0, 0, w, h);
55
+ _defineProperty(_assertThisInitialized(_this), "resetCanvasSize", function () {
56
+ var canvas = _this.canvas;
57
+ if (!canvas) {
58
+ return;
72
59
  }
60
+ _this.resetViewportSize();
61
+ var _this$mapService$getS = _this.mapService.getSize(),
62
+ _this$mapService$getS2 = _slicedToArray(_this$mapService$getS, 2),
63
+ width = _this$mapService$getS2[0],
64
+ height = _this$mapService$getS2[1];
65
+ var _this$viewportSize = _slicedToArray(_this.viewportSize, 2),
66
+ viewWidth = _this$viewportSize[0],
67
+ viewHeight = _this$viewportSize[1];
68
+ canvas.width = viewWidth;
69
+ canvas.height = viewHeight;
70
+ canvas.style.width = width + 'px';
71
+ canvas.style.height = height + 'px';
73
72
  });
74
73
  _defineProperty(_assertThisInitialized(_this), "renderCanvas", function () {
75
- var _this$rendererService2 = _this.rendererService.getViewportSize(),
76
- viewWidth = _this$rendererService2.width,
77
- viewHeight = _this$rendererService2.height;
78
- if (_this.prevSize[0] !== viewWidth || _this.prevSize[1] !== viewHeight) {
79
- _this.prevSize = [viewWidth, viewHeight];
80
- var size = _this.mapService.getSize();
81
- var _size = _slicedToArray(size, 2),
82
- width = _size[0],
83
- height = _size[1];
84
- _this.canvas.width = viewWidth;
85
- _this.canvas.height = viewHeight;
86
- _this.canvas.style.width = width + 'px';
87
- _this.canvas.style.height = height + 'px';
74
+ var _ref;
75
+ if (!_this.canvas) {
76
+ _this.initCanvas();
88
77
  }
89
- var _ref2 = _this.layer.getLayerConfig(),
90
- drawingOnCanvas = _ref2.drawingOnCanvas;
91
- if (_this.ctx) {
92
- drawingOnCanvas({
93
- canvas: _this.canvas,
94
- ctx: _this.ctx,
95
- mapService: _this.mapService,
96
- size: [viewWidth, viewHeight]
97
- });
78
+ var _this$layerConfig2 = _this.layerConfig,
79
+ draw = _this$layerConfig2.draw,
80
+ drawingOnCanvas = _this$layerConfig2.drawingOnCanvas;
81
+ var _this$viewportSize2 = _slicedToArray(_this.viewportSize, 2),
82
+ width = _this$viewportSize2[0],
83
+ height = _this$viewportSize2[1];
84
+ var bounds = _this.mapService.getBounds();
85
+ (_ref = draw !== null && draw !== void 0 ? draw : drawingOnCanvas) === null || _ref === void 0 || _ref({
86
+ canvas: _this.canvas,
87
+ ctx: _this.ctx,
88
+ container: {
89
+ width: width,
90
+ height: height,
91
+ bounds: bounds
92
+ },
93
+ size: [width, height],
94
+ utils: {
95
+ lngLatToContainer: _this.lngLatToContainer
96
+ },
97
+ mapService: _this.mapService
98
+ });
99
+ });
100
+ _defineProperty(_assertThisInitialized(_this), "removeCanvas", function () {
101
+ if (_this.canvas) {
102
+ var _this$canvas$parentEl;
103
+ (_this$canvas$parentEl = _this.canvas.parentElement) === null || _this$canvas$parentEl === void 0 || _this$canvas$parentEl.removeChild(_this.canvas);
104
+ _this.canvas = null;
98
105
  }
106
+ _this.unbindListeners();
107
+ });
108
+ _defineProperty(_assertThisInitialized(_this), "onMapResize", function () {
109
+ requestAnimationFrame(function () {
110
+ _this.resetCanvasSize();
111
+ _this.renderCanvas();
112
+ });
113
+ });
114
+ _defineProperty(_assertThisInitialized(_this), "lngLatToContainer", function (lngLat) {
115
+ var _this$mapService$lngL = _this.mapService.lngLatToContainer(lngLat),
116
+ x = _this$mapService$lngL.x,
117
+ y = _this$mapService$lngL.y;
118
+ return {
119
+ x: x * window.devicePixelRatio,
120
+ y: y * window.devicePixelRatio
121
+ };
99
122
  });
100
123
  return _this;
101
124
  }
102
- _createClass(CanvaModel, [{
103
- key: "clearModels",
104
- value: function clearModels() {
105
- if (this.canvas) {
106
- var _this$mapService$getC;
107
- (_this$mapService$getC = this.mapService.getContainer()) === null || _this$mapService$getC === void 0 || _this$mapService$getC.removeChild(this.canvas);
108
- // @ts-ignore
109
- this.canvas = null;
110
- }
111
- this.unBindListener();
125
+ _createClass(CanvasModel, [{
126
+ key: "layerConfig",
127
+ get: function get() {
128
+ return this.layer.getLayerConfig();
112
129
  }
113
130
  }, {
114
131
  key: "initModels",
115
132
  value: function () {
116
133
  var _initModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
117
- var _ref3, _ref3$update, update;
118
134
  return _regeneratorRuntime.wrap(function _callee$(_context) {
119
135
  while (1) switch (_context.prev = _context.next) {
120
136
  case 0:
121
- _ref3 = this.layer.getLayerConfig(), _ref3$update = _ref3.update, update = _ref3$update === void 0 ? CanvasUpdateType.ALWAYS : _ref3$update;
122
- this.updateMode = update;
123
- this.initCanvas();
124
137
  this.renderCanvas();
125
- this.bindListener();
126
- this.mapService.getContainer();
127
138
  return _context.abrupt("return", []);
128
- case 7:
139
+ case 2:
129
140
  case "end":
130
141
  return _context.stop();
131
142
  }
@@ -137,59 +148,34 @@ var CanvaModel = /*#__PURE__*/function (_BaseModel) {
137
148
  return initModels;
138
149
  }()
139
150
  }, {
140
- key: "initCanvas",
141
- value: function initCanvas() {
142
- var _this$mapService$getC2;
143
- var _ref4 = this.layer.getLayerConfig(),
144
- zIndex = _ref4.zIndex;
145
- var size = this.mapService.getSize();
146
- var _size2 = _slicedToArray(size, 2),
147
- width = _size2[0],
148
- height = _size2[1];
149
- var _this$rendererService3 = this.rendererService.getViewportSize(),
150
- viewWidth = _this$rendererService3.width,
151
- viewHeight = _this$rendererService3.height;
152
- this.prevSize = [viewWidth, viewHeight];
153
- var canvas = document.createElement('canvas');
154
- this.canvas = canvas;
155
- canvas.width = viewWidth;
156
- canvas.height = viewHeight;
157
- canvas.style.pointerEvents = 'none';
158
- canvas.style.width = width + 'px';
159
- canvas.style.height = height + 'px';
160
- canvas.style.position = 'absolute';
161
- canvas.style.top = '0';
162
- canvas.style.left = '0';
163
- canvas.style.zIndex = zIndex + '';
164
- (_this$mapService$getC2 = this.mapService.getContainer()) === null || _this$mapService$getC2 === void 0 || _this$mapService$getC2.appendChild(canvas);
165
- var ctx = canvas.getContext('2d');
166
- this.ctx = ctx;
151
+ key: "bindListeners",
152
+ value: function bindListeners() {
153
+ this.mapService.on('resize', this.onMapResize);
154
+ var _this$layerConfig3 = this.layerConfig,
155
+ trigger = _this$layerConfig3.trigger,
156
+ update = _this$layerConfig3.update;
157
+ if (update === CanvasUpdateType.ALWAYS || trigger === 'change') {
158
+ this.mapService.on('mapchange', this.renderCanvas);
159
+ } else {
160
+ this.mapService.on('zoomstart', this.removeCanvas);
161
+ this.mapService.on('zoomend', this.renderCanvas);
162
+ this.mapService.on('movestart', this.removeCanvas);
163
+ this.mapService.on('moveend', this.renderCanvas);
164
+ }
167
165
  }
168
166
  }, {
169
- key: "buildModels",
170
- value: function () {
171
- var _buildModels = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
172
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
173
- while (1) switch (_context2.prev = _context2.next) {
174
- case 0:
175
- return _context2.abrupt("return", this.initModels());
176
- case 1:
177
- case "end":
178
- return _context2.stop();
179
- }
180
- }, _callee2, this);
181
- }));
182
- function buildModels() {
183
- return _buildModels.apply(this, arguments);
184
- }
185
- return buildModels;
186
- }()
167
+ key: "unbindListeners",
168
+ value: function unbindListeners() {
169
+ this.mapService.off('resize', this.onMapResize);
170
+ this.mapService.off('mapchange', this.renderCanvas);
171
+ this.mapService.off('zoomstart', this.removeCanvas);
172
+ this.mapService.off('zoomend', this.renderCanvas);
173
+ this.mapService.off('movestart', this.removeCanvas);
174
+ this.mapService.off('moveend', this.renderCanvas);
175
+ }
187
176
  }, {
188
177
  key: "registerBuiltinAttributes",
189
- value: function registerBuiltinAttributes() {
190
- return;
191
- }
178
+ value: function registerBuiltinAttributes() {}
192
179
  }]);
193
- return CanvaModel;
194
- }(BaseModel);
195
- export { CanvaModel as default };
180
+ return CanvasModel;
181
+ }(BaseModel);
@@ -0,0 +1,2 @@
1
+ export type CanvasModelType = 'canvas2d' | 'webgl' | 'webgl2' | 'webgpu';
2
+ export declare const CanvasContextTypeMap: Record<CanvasModelType, string>;
@@ -0,0 +1,6 @@
1
+ export var CanvasContextTypeMap = {
2
+ canvas2d: '2d',
3
+ webgl: 'webgl',
4
+ webgl2: 'webgl2',
5
+ webgpu: 'webgpu'
6
+ };
@@ -1,5 +1,2 @@
1
- export type CanvasModelType = 'canvas';
2
- declare const CanvasModels: {
3
- [key in CanvasModelType]: any;
4
- };
5
- export default CanvasModels;
1
+ export * from './canvas';
2
+ export * from './constants';
@@ -1,5 +1,2 @@
1
- import CanvasModel from "./canvas";
2
- var CanvasModels = {
3
- canvas: CanvasModel
4
- };
5
- export default CanvasModels;
1
+ export * from "./canvas";
2
+ export * from "./constants";
@@ -1,9 +1,8 @@
1
1
  import { AsyncSeriesBailHook, AsyncWaterfallHook, SyncBailHook, SyncHook } from '@antv/async-hook';
2
- import type { IActiveOption, IAnimateOption, IAttributeAndElements, IBuffer, ICameraService, ICoordinateSystemService, IDataState, IDebugService, IEncodeFeature, IFontService, IGlobalConfigService, IIconService, IInteractionService, ILayer, ILayerAttributesOption, ILayerConfig, ILayerModel, ILayerModelInitializationOptions, ILayerPickService, ILayerPlugin, ILayerService, ILegend, IMapService, IModel, IModelInitializationOptions, IMultiPassRenderer, IParseDataItem, IPass, IPickingService, IPostProcessingPass, IRenderOptions, IRendererService, IScale, IScaleOptions, IShaderModuleService, ISourceCFG, IStyleAttributeService, IStyleAttributeUpdateOptions, ITextureService, LayerEventType, LegendItems, StyleAttributeField, StyleAttributeOption, Triangulation } from '@antv/l7-core';
2
+ import type { IActiveOption, IAnimateOption, IAttributeAndElements, IBuffer, IDataState, IEncodeFeature, IGlobalConfigService, ILayer, ILayerAttributesOption, ILayerConfig, ILayerModel, ILayerModelInitializationOptions, ILayerPickService, ILayerPlugin, ILegend, IModel, IModelInitializationOptions, IMultiPassRenderer, IParseDataItem, IPostProcessingPass, IRenderOptions, IScale, IScaleOptions, ISourceCFG, IStyleAttributeService, IStyleAttributeUpdateOptions, ITextureService, L7Container, LayerEventType, LegendItems, StyleAttributeField, StyleAttributeOption, Triangulation } from '@antv/l7-core';
3
3
  import { BlendType } from '@antv/l7-core';
4
- import Source from '@antv/l7-source';
4
+ import type Source from '@antv/l7-source';
5
5
  import { EventEmitter } from 'eventemitter3';
6
- import type { Container } from 'inversify';
7
6
  export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter<LayerEventType> implements ILayer {
8
7
  id: string;
9
8
  name: string;
@@ -59,31 +58,30 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
59
58
  field: any;
60
59
  values: any;
61
60
  };
62
- sceneContainer: Container | undefined;
63
61
  tileLayer: any | undefined;
64
62
  layerChildren: ILayer[];
65
63
  masks: ILayer[];
66
64
  protected readonly configService: IGlobalConfigService;
67
- protected shaderModuleService: IShaderModuleService;
68
- protected cameraService: ICameraService;
69
- protected coordinateService: ICoordinateSystemService;
70
- protected iconService: IIconService;
71
- protected fontService: IFontService;
72
- protected pickingService: IPickingService;
73
- protected rendererService: IRendererService;
74
- protected layerService: ILayerService;
75
- protected debugService: IDebugService;
76
- protected interactionService: IInteractionService;
77
- protected mapService: IMapService;
65
+ protected get shaderModuleService(): import("@antv/l7-core").IShaderModuleService;
66
+ protected get cameraService(): import("@antv/l7-core").ICameraService;
67
+ protected get coordinateService(): import("@antv/l7-core").ICoordinateSystemService;
68
+ protected get iconService(): import("@antv/l7-core").IIconService;
69
+ protected get fontService(): import("@antv/l7-core").IFontService;
70
+ protected get pickingService(): import("@antv/l7-core").IPickingService;
71
+ protected get rendererService(): import("@antv/l7-core").IRendererService;
72
+ protected get layerService(): import("@antv/l7-core").ILayerService;
73
+ protected get debugService(): import("@antv/l7-core").IDebugService;
74
+ protected get interactionService(): import("@antv/l7-core/es/services/interaction/InteractionService").default;
75
+ protected get mapService(): import("@antv/l7-core").IMapService<{}>;
78
76
  styleAttributeService: IStyleAttributeService;
79
77
  protected layerSource: Source;
80
78
  postProcessingPassFactory: (name: string) => IPostProcessingPass<unknown>;
81
- normalPassFactory: (name: string) => IPass<unknown>;
79
+ get normalPassFactory(): (name: string) => import("@antv/l7-core").IPass<unknown>;
82
80
  protected animateOptions: IAnimateOption;
83
81
  /**
84
82
  * 图层容器
85
83
  */
86
- protected container: Container;
84
+ container: L7Container;
87
85
  private encodedData;
88
86
  private currentPickId;
89
87
  protected rawConfig: Partial<ILayerConfig & ChildLayerStyleOptions>;
@@ -130,8 +128,8 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
130
128
  * -> SceneContainer 1.*
131
129
  * -> LayerContainer 1.*
132
130
  */
133
- setContainer(container: Container, sceneContainer: Container): void;
134
- getContainer(): Container;
131
+ setContainer(container: L7Container): void;
132
+ getContainer(): L7Container;
135
133
  addPlugin(plugin: ILayerPlugin): ILayer;
136
134
  init(): Promise<void>;
137
135
  log(logType: string, step?: string): void;
@@ -151,6 +149,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
151
149
  animate(options: IAnimateOption | boolean): this;
152
150
  source(data: any, options?: ISourceCFG): ILayer;
153
151
  setData(data: any, options?: ISourceCFG): this;
152
+ private dataUpdatelog;
154
153
  style(options: Partial<ChildLayerStyleOptions> & Partial<ILayerConfig>): ILayer;
155
154
  private encodeStyle;
156
155
  scale(field: string | number | IScaleOptions, cfg?: IScale): this;