@antv/l7-layers 2.20.19 → 2.21.0

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 (116) 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 +17 -19
  10. package/es/core/BaseLayer.js +88 -62
  11. package/es/core/BaseModel.js +15 -29
  12. package/es/core/LayerPickService.js +4 -5
  13. package/es/core/TextureService.js +1 -2
  14. package/es/core/interface.d.ts +31 -4
  15. package/es/core/shape/arrow.js +2 -6
  16. package/es/heatmap/models/heatmap.d.ts +0 -1
  17. package/es/heatmap/models/heatmap.js +2 -5
  18. package/es/index.d.ts +2 -1
  19. package/es/index.js +2 -89
  20. package/es/line/models/arc.js +5 -5
  21. package/es/line/models/arc_3d.js +4 -3
  22. package/es/line/models/great_circle.js +4 -4
  23. package/es/line/models/line.js +5 -8
  24. package/es/line/models/simple_line.js +1 -2
  25. package/es/line/models/wall.js +4 -3
  26. package/es/plugins/DataMappingPlugin.d.ts +4 -7
  27. package/es/plugins/DataMappingPlugin.js +8 -23
  28. package/es/plugins/DataSourcePlugin.d.ts +0 -1
  29. package/es/plugins/DataSourcePlugin.js +4 -7
  30. package/es/plugins/FeatureScalePlugin.d.ts +2 -5
  31. package/es/plugins/FeatureScalePlugin.js +4 -6
  32. package/es/plugins/LayerAnimateStylePlugin.d.ts +0 -1
  33. package/es/plugins/LayerAnimateStylePlugin.js +2 -5
  34. package/es/plugins/LayerMaskPlugin.d.ts +0 -1
  35. package/es/plugins/LayerMaskPlugin.js +2 -8
  36. package/es/plugins/LayerModelPlugin.d.ts +0 -1
  37. package/es/plugins/LayerModelPlugin.js +13 -18
  38. package/es/plugins/LayerStylePlugin.d.ts +0 -1
  39. package/es/plugins/LayerStylePlugin.js +2 -5
  40. package/es/plugins/LightingPlugin.d.ts +0 -1
  41. package/es/plugins/LightingPlugin.js +2 -5
  42. package/es/plugins/MultiPassRendererPlugin.d.ts +0 -1
  43. package/es/plugins/MultiPassRendererPlugin.js +2 -5
  44. package/es/plugins/PixelPickingPlugin.d.ts +2 -6
  45. package/es/plugins/PixelPickingPlugin.js +4 -9
  46. package/es/plugins/RegisterStyleAttributePlugin.d.ts +2 -5
  47. package/es/plugins/RegisterStyleAttributePlugin.js +2 -5
  48. package/es/plugins/ShaderUniformPlugin.d.ts +7 -8
  49. package/es/plugins/ShaderUniformPlugin.js +16 -42
  50. package/es/plugins/UpdateModelPlugin.d.ts +0 -1
  51. package/es/plugins/UpdateModelPlugin.js +2 -5
  52. package/es/plugins/UpdateStyleAttributePlugin.d.ts +2 -5
  53. package/es/plugins/UpdateStyleAttributePlugin.js +2 -6
  54. package/es/plugins/index.d.ts +15 -0
  55. package/es/plugins/index.js +18 -0
  56. package/es/point/models/fill.d.ts +1 -1
  57. package/es/point/models/fill.js +6 -9
  58. package/es/point/models/fillImage.js +4 -3
  59. package/es/point/models/image.js +4 -3
  60. package/es/polygon/models/extrude.js +0 -1
  61. package/es/polygon/models/ocean.js +1 -2
  62. package/es/polygon/models/water.js +0 -2
  63. package/es/tile/core/BaseLayer.js +4 -5
  64. package/es/tile/interaction/getRasterData.js +4 -16
  65. package/es/tile/service/TileLayerService.d.ts +0 -1
  66. package/es/tile/service/TileLayerService.js +0 -1
  67. package/es/tile/service/TilePickService.d.ts +1 -1
  68. package/es/tile/service/TilePickService.js +2 -3
  69. package/es/tile/tile/Tile.js +8 -6
  70. package/es/tile/utils/utils.d.ts +0 -4
  71. package/es/tile/utils/utils.js +0 -11
  72. package/lib/canvas/index.js +63 -37
  73. package/lib/canvas/models/canvas.js +125 -138
  74. package/lib/canvas/models/constants.js +12 -0
  75. package/lib/canvas/models/index.js +22 -7
  76. package/lib/core/BaseLayer.js +88 -62
  77. package/lib/core/BaseModel.js +14 -28
  78. package/lib/core/LayerPickService.js +4 -5
  79. package/lib/core/TextureService.js +1 -2
  80. package/lib/core/shape/arrow.js +2 -6
  81. package/lib/heatmap/models/heatmap.js +2 -5
  82. package/lib/index.js +9 -90
  83. package/lib/line/models/arc.js +4 -4
  84. package/lib/line/models/arc_3d.js +4 -3
  85. package/lib/line/models/great_circle.js +4 -4
  86. package/lib/line/models/line.js +5 -8
  87. package/lib/line/models/simple_line.js +0 -1
  88. package/lib/line/models/wall.js +4 -3
  89. package/lib/plugins/DataMappingPlugin.js +7 -22
  90. package/lib/plugins/DataSourcePlugin.js +3 -6
  91. package/lib/plugins/FeatureScalePlugin.js +4 -6
  92. package/lib/plugins/LayerAnimateStylePlugin.js +2 -5
  93. package/lib/plugins/LayerMaskPlugin.js +2 -8
  94. package/lib/plugins/LayerModelPlugin.js +13 -18
  95. package/lib/plugins/LayerStylePlugin.js +2 -5
  96. package/lib/plugins/LightingPlugin.js +2 -5
  97. package/lib/plugins/MultiPassRendererPlugin.js +2 -5
  98. package/lib/plugins/PixelPickingPlugin.js +4 -9
  99. package/lib/plugins/RegisterStyleAttributePlugin.js +2 -5
  100. package/lib/plugins/ShaderUniformPlugin.js +15 -41
  101. package/lib/plugins/UpdateModelPlugin.js +2 -5
  102. package/lib/plugins/UpdateStyleAttributePlugin.js +2 -5
  103. package/lib/plugins/index.js +26 -0
  104. package/lib/point/models/fill.js +6 -9
  105. package/lib/point/models/fillImage.js +4 -3
  106. package/lib/point/models/image.js +4 -3
  107. package/lib/polygon/models/extrude.js +0 -1
  108. package/lib/polygon/models/ocean.js +0 -1
  109. package/lib/polygon/models/water.js +0 -2
  110. package/lib/tile/core/BaseLayer.js +4 -5
  111. package/lib/tile/interaction/getRasterData.js +4 -16
  112. package/lib/tile/service/TileLayerService.js +0 -1
  113. package/lib/tile/service/TilePickService.js +2 -3
  114. package/lib/tile/tile/Tile.js +8 -6
  115. package/lib/tile/utils/utils.js +0 -12
  116. package/package.json +18 -20
@@ -5,7 +5,6 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
5
  import _createClass from "@babel/runtime/helpers/esm/createClass";
6
6
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
8
- import { TYPES } from '@antv/l7-core';
9
8
  import { decodePickingColor, encodePickingColor } from '@antv/l7-utils';
10
9
  import { TileSourceService } from "./TileSourceService";
11
10
  var SELECT = 'select';
@@ -42,7 +41,7 @@ export var TilePickService = /*#__PURE__*/function () {
42
41
  while (1) switch (_context.prev = _context.next) {
43
42
  case 0:
44
43
  container = this.parent.getContainer();
45
- pickingService = container.get(TYPES.IPickingService);
44
+ pickingService = container.pickingService;
46
45
  if (!(layer.type === 'RasterLayer')) {
47
46
  _context.next = 8;
48
47
  break;
@@ -170,7 +169,7 @@ export var TilePickService = /*#__PURE__*/function () {
170
169
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
171
170
  }, {
172
171
  key: "pickRasterLayer",
173
- value: function pickRasterLayer(layer, target, parent) {
172
+ value: function pickRasterLayer() {
174
173
  return false;
175
174
  }
176
175
  }]);
@@ -118,8 +118,8 @@ var Tile = /*#__PURE__*/function (_EventEmitter) {
118
118
  }).shape('fill').color('#0f0').style({
119
119
  opacity: 0.5
120
120
  });
121
- container = createLayerContainer(this.parent.sceneContainer);
122
- mask.setContainer(container, this.parent.sceneContainer);
121
+ container = createLayerContainer(this.parent.container);
122
+ mask.setContainer(container);
123
123
  _context.next = 5;
124
124
  return mask.init();
125
125
  case 5:
@@ -148,8 +148,8 @@ var Tile = /*#__PURE__*/function (_EventEmitter) {
148
148
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
149
149
  while (1) switch (_context2.prev = _context2.next) {
150
150
  case 0:
151
- container = createLayerContainer(this.parent.sceneContainer);
152
- mask.setContainer(container, this.parent.sceneContainer);
151
+ container = createLayerContainer(this.parent.container);
152
+ mask.setContainer(container);
153
153
  _context2.next = 4;
154
154
  return mask.init();
155
155
  case 4:
@@ -176,8 +176,8 @@ var Tile = /*#__PURE__*/function (_EventEmitter) {
176
176
  case 0:
177
177
  // set flag
178
178
  layer.isTileLayer = true;
179
- container = createLayerContainer(this.parent.sceneContainer);
180
- layer.setContainer(container, this.parent.sceneContainer);
179
+ container = createLayerContainer(this.parent.container);
180
+ layer.setContainer(container);
181
181
  this.layers.push(layer);
182
182
  _context3.next = 6;
183
183
  return layer.init();
@@ -214,6 +214,7 @@ var Tile = /*#__PURE__*/function (_EventEmitter) {
214
214
  value: function getMainLayer() {
215
215
  return this.layers[0];
216
216
  }
217
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
217
218
  }, {
218
219
  key: "getFeatures",
219
220
  value: function getFeatures(sourceLayer) {
@@ -225,6 +226,7 @@ var Tile = /*#__PURE__*/function (_EventEmitter) {
225
226
  * @param id
226
227
  * @returns
227
228
  */
229
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
228
230
  }, {
229
231
  key: "getFeatureById",
230
232
  value: function getFeatureById(id) {
@@ -6,7 +6,3 @@ export declare const tileVectorParser: string[];
6
6
  * @returns
7
7
  */
8
8
  export declare function isTileGroup(layer: ILayer): boolean;
9
- export declare function getContainerSize(container: HTMLCanvasElement | HTMLElement): DOMRect | {
10
- width: number;
11
- height: number;
12
- };
@@ -1,4 +1,3 @@
1
- import { DOM } from '@antv/l7-utils';
2
1
  export var tileVectorParser = ['mvt', 'geojsonvt', 'testTile'];
3
2
 
4
3
  /**
@@ -9,14 +8,4 @@ export var tileVectorParser = ['mvt', 'geojsonvt', 'testTile'];
9
8
  export function isTileGroup(layer) {
10
9
  var source = layer.getSource();
11
10
  return tileVectorParser.includes(source.parser.type);
12
- }
13
- export function getContainerSize(container) {
14
- if (container.getContext) {
15
- return {
16
- width: container.width / DOM.DPR,
17
- height: container.height / DOM.DPR
18
- };
19
- } else {
20
- return container.getBoundingClientRect();
21
- }
22
11
  }
@@ -6,18 +6,20 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
11
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
13
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
14
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
13
15
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
16
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
17
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
16
18
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
19
  var _BaseLayer2 = _interopRequireDefault(require("../core/BaseLayer"));
18
- var _index = _interopRequireDefault(require("./models/index"));
20
+ var _models = require("./models");
19
21
  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); }; }
20
- 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; } }
22
+ 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; } } // import type { ILayerConfig } from '@antv/l7-core';
21
23
  var CanvasLayer = exports.default = /*#__PURE__*/function (_BaseLayer) {
22
24
  (0, _inherits2.default)(CanvasLayer, _BaseLayer);
23
25
  var _super = _createSuper(CanvasLayer);
@@ -29,22 +31,28 @@ var CanvasLayer = exports.default = /*#__PURE__*/function (_BaseLayer) {
29
31
  }
30
32
  _this = _super.call.apply(_super, [this].concat(args));
31
33
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "type", 'CanvasLayer');
32
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "forceRender", true);
33
34
  return _this;
34
35
  }
35
36
  (0, _createClass2.default)(CanvasLayer, [{
37
+ key: "getDefaultConfig",
38
+ value: function getDefaultConfig() {
39
+ return {
40
+ zIndex: 3,
41
+ contextType: 'canvas2d',
42
+ trigger: 'change'
43
+ };
44
+ }
45
+ }, {
36
46
  key: "buildModels",
37
47
  value: function () {
38
48
  var _buildModels = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
39
- var modelType;
40
49
  return _regenerator.default.wrap(function _callee$(_context) {
41
50
  while (1) switch (_context.prev = _context.next) {
42
51
  case 0:
43
- modelType = this.getModelType();
44
- this.layerModel = new _index.default[modelType](this);
45
- _context.next = 4;
52
+ this.layerModel = new _models.CanvasModel(this);
53
+ _context.next = 3;
46
54
  return this.initLayerModels();
47
- case 4:
55
+ case 3:
48
56
  case "end":
49
57
  return _context.stop();
50
58
  }
@@ -56,46 +64,64 @@ var CanvasLayer = exports.default = /*#__PURE__*/function (_BaseLayer) {
56
64
  return buildModels;
57
65
  }()
58
66
  }, {
59
- key: "hide",
60
- value: function hide() {
61
- // 清除画布
62
- if (this.layerModel.clearCanvas) {
63
- this.layerModel.clearCanvas();
64
- }
67
+ key: "getModelType",
68
+ value: function getModelType() {
69
+ return this.getLayerConfig().contextType || 'canvas2d';
70
+ }
71
+ }, {
72
+ key: "draw",
73
+ value: function draw(_draw) {
65
74
  this.updateLayerConfig({
66
- visible: false
75
+ draw: _draw
67
76
  });
68
- this.reRender();
77
+ this.render();
69
78
  return this;
70
79
  }
71
80
  }, {
72
- key: "renderModels",
73
- value: function renderModels() {
74
- var _this$layerModel,
75
- _this2 = this;
76
- if (this !== null && this !== void 0 && (_this$layerModel = this.layerModel) !== null && _this$layerModel !== void 0 && _this$layerModel.renderUpdate) {
77
- this.layerModel.renderUpdate();
81
+ key: "getLayerConfig",
82
+ value: function getLayerConfig() {
83
+ var config = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.getDefaultConfig()), (0, _get2.default)((0, _getPrototypeOf2.default)(CanvasLayer.prototype), "getLayerConfig", this).call(this));
84
+ if (config.zIndex < 3) {
85
+ config.zIndex = 3;
78
86
  }
79
- this.models.forEach(function (model) {
80
- model.draw({
81
- uniforms: _this2.layerModel.getUninforms()
82
- }, false);
83
- });
87
+ return config;
88
+ }
89
+ }, {
90
+ key: "render",
91
+ value: function render() {
92
+ var _this$layerModel;
93
+ (_this$layerModel = this.layerModel) === null || _this$layerModel === void 0 || _this$layerModel.renderCanvas();
84
94
  return this;
85
95
  }
86
96
  }, {
87
- key: "getDefaultConfig",
88
- value: function getDefaultConfig() {
89
- var type = this.getModelType();
90
- var defaultConfig = {
91
- canvas: {}
92
- };
93
- return defaultConfig[type];
97
+ key: "getCanvas",
98
+ value: function getCanvas() {
99
+ var _this$layerModel2;
100
+ return (_this$layerModel2 = this.layerModel) === null || _this$layerModel2 === void 0 ? void 0 : _this$layerModel2.canvas;
94
101
  }
95
102
  }, {
96
- key: "getModelType",
97
- value: function getModelType() {
98
- return 'canvas';
103
+ key: "show",
104
+ value: function show() {
105
+ var canvas = this.getCanvas();
106
+ if (canvas) {
107
+ canvas.style.display = 'unset';
108
+ }
109
+ return this;
110
+ }
111
+ }, {
112
+ key: "hide",
113
+ value: function hide() {
114
+ var canvas = this.getCanvas();
115
+ if (canvas) {
116
+ canvas.style.display = 'none';
117
+ }
118
+ return this;
119
+ }
120
+ }, {
121
+ key: "destroy",
122
+ value: function destroy() {
123
+ this.layerModel.removeCanvas();
124
+ (0, _get2.default)((0, _getPrototypeOf2.default)(CanvasLayer.prototype), "destroy", this).call(this);
99
125
  }
100
126
  }]);
101
127
  return CanvasLayer;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = void 0;
7
+ exports.CanvasModel = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
@@ -17,122 +17,133 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
17
17
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
18
  var _BaseModel2 = _interopRequireDefault(require("../../core/BaseModel"));
19
19
  var _interface = require("../../core/interface");
20
+ var _constants = require("./constants");
20
21
  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); }; }
21
22
  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; } }
22
- var CanvaModel = exports.default = /*#__PURE__*/function (_BaseModel) {
23
- (0, _inherits2.default)(CanvaModel, _BaseModel);
24
- var _super = _createSuper(CanvaModel);
25
- function CanvaModel() {
23
+ var CanvasModel = exports.CanvasModel = /*#__PURE__*/function (_BaseModel) {
24
+ (0, _inherits2.default)(CanvasModel, _BaseModel);
25
+ var _super = _createSuper(CanvasModel);
26
+ function CanvasModel() {
26
27
  var _this;
27
- (0, _classCallCheck2.default)(this, CanvaModel);
28
+ (0, _classCallCheck2.default)(this, CanvasModel);
28
29
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29
30
  args[_key] = arguments[_key];
30
31
  }
31
32
  _this = _super.call.apply(_super, [this].concat(args));
32
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateMode", _interface.CanvasUpdateType.ALWAYS);
33
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderUpdate", function () {
34
- var _ref = _this.layer.getLayerConfig(),
35
- _ref$zIndex = _ref.zIndex,
36
- zIndex = _ref$zIndex === void 0 ? 10 : _ref$zIndex,
37
- _ref$update = _ref.update,
38
- update = _ref$update === void 0 ? _interface.CanvasUpdateType.ALWAYS : _ref$update,
39
- _ref$animateOption = _ref.animateOption,
40
- animateOption = _ref$animateOption === void 0 ? {
41
- enable: false,
42
- duration: 20
43
- } : _ref$animateOption;
44
- if (+_this.canvas.style.zIndex === zIndex) {
45
- _this.canvas.style.zIndex = zIndex + '';
46
- }
47
- if (_this.updateMode !== update) {
48
- _this.updateMode = update;
49
- _this.unBindListener();
50
- _this.bindListener();
51
- }
52
- if (_this.updateMode === _interface.CanvasUpdateType.ALWAYS && animateOption.enable) {
53
- _this.renderCanvas();
33
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "canvas", null);
34
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "initCanvas", function () {
35
+ var _this$mapService$getC, _this$mapService$getC2, _this$mapService, _this$mapService$getM, _this$mapService2;
36
+ var _this$layerConfig = _this.layerConfig,
37
+ zIndex = _this$layerConfig.zIndex,
38
+ getContext = _this$layerConfig.getContext;
39
+ var canvas = document.createElement('canvas');
40
+ var modelType = _this.layer.getModelType();
41
+ _this.canvas = canvas;
42
+ canvas.classList.add('l7-canvas-layer');
43
+ canvas.style.position = 'absolute';
44
+ canvas.style.top = '0';
45
+ canvas.style.left = '0';
46
+ canvas.style.zIndex = String(zIndex);
47
+ _this.resetCanvasSize();
48
+ 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);
49
+ container === null || container === void 0 || container.appendChild(canvas);
50
+ _this.ctx = getContext ? getContext(canvas) : canvas.getContext(_constants.CanvasContextTypeMap[modelType]);
51
+ if (!_this.ctx) {
52
+ console.error('Failed to get rendering context for canvas');
54
53
  }
54
+ _this.bindListeners();
55
55
  });
56
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "unBindListener", function () {
57
- _this.mapService.off('mapchange', _this.renderCanvas);
58
- _this.mapService.off('zoomstart', _this.clearCanvas);
59
- _this.mapService.off('zoomend', _this.renderCanvas);
60
- _this.mapService.off('movestart', _this.clearCanvas);
61
- _this.mapService.off('moveend', _this.renderCanvas);
62
- });
63
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "bindListener", function () {
64
- if (_this.updateMode === _interface.CanvasUpdateType.ALWAYS) {
65
- _this.mapService.on('mapchange', _this.renderCanvas);
66
- } else {
67
- _this.mapService.on('zoomstart', _this.clearCanvas);
68
- _this.mapService.on('zoomend', _this.renderCanvas);
69
- _this.mapService.on('movestart', _this.clearCanvas);
70
- _this.mapService.on('moveend', _this.renderCanvas);
71
- }
56
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "resetViewportSize", function () {
57
+ var _this$rendererService = _this.rendererService.getViewportSize(),
58
+ viewWidth = _this$rendererService.width,
59
+ viewHeight = _this$rendererService.height;
60
+ _this.viewportSize = [viewWidth, viewHeight];
72
61
  });
73
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "clearCanvas", function () {
74
- if (_this.ctx) {
75
- var _this$rendererService = _this.rendererService.getViewportSize(),
76
- w = _this$rendererService.width,
77
- h = _this$rendererService.height;
78
- _this.ctx.clearRect(0, 0, w, h);
62
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "resetCanvasSize", function () {
63
+ var canvas = _this.canvas;
64
+ if (!canvas) {
65
+ return;
79
66
  }
67
+ _this.resetViewportSize();
68
+ var _this$mapService$getS = _this.mapService.getSize(),
69
+ _this$mapService$getS2 = (0, _slicedToArray2.default)(_this$mapService$getS, 2),
70
+ width = _this$mapService$getS2[0],
71
+ height = _this$mapService$getS2[1];
72
+ var _this$viewportSize = (0, _slicedToArray2.default)(_this.viewportSize, 2),
73
+ viewWidth = _this$viewportSize[0],
74
+ viewHeight = _this$viewportSize[1];
75
+ canvas.width = viewWidth;
76
+ canvas.height = viewHeight;
77
+ canvas.style.width = width + 'px';
78
+ canvas.style.height = height + 'px';
80
79
  });
81
80
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderCanvas", function () {
82
- var _this$rendererService2 = _this.rendererService.getViewportSize(),
83
- viewWidth = _this$rendererService2.width,
84
- viewHeight = _this$rendererService2.height;
85
- if (_this.prevSize[0] !== viewWidth || _this.prevSize[1] !== viewHeight) {
86
- _this.prevSize = [viewWidth, viewHeight];
87
- var size = _this.mapService.getSize();
88
- var _size = (0, _slicedToArray2.default)(size, 2),
89
- width = _size[0],
90
- height = _size[1];
91
- _this.canvas.width = viewWidth;
92
- _this.canvas.height = viewHeight;
93
- _this.canvas.style.width = width + 'px';
94
- _this.canvas.style.height = height + 'px';
81
+ var _ref;
82
+ if (!_this.canvas) {
83
+ _this.initCanvas();
95
84
  }
96
- var _ref2 = _this.layer.getLayerConfig(),
97
- drawingOnCanvas = _ref2.drawingOnCanvas;
98
- if (_this.ctx) {
99
- drawingOnCanvas({
100
- canvas: _this.canvas,
101
- ctx: _this.ctx,
102
- mapService: _this.mapService,
103
- size: [viewWidth, viewHeight]
104
- });
85
+ var _this$layerConfig2 = _this.layerConfig,
86
+ draw = _this$layerConfig2.draw,
87
+ drawingOnCanvas = _this$layerConfig2.drawingOnCanvas;
88
+ var _this$viewportSize2 = (0, _slicedToArray2.default)(_this.viewportSize, 2),
89
+ width = _this$viewportSize2[0],
90
+ height = _this$viewportSize2[1];
91
+ var bounds = _this.mapService.getBounds();
92
+ (_ref = draw !== null && draw !== void 0 ? draw : drawingOnCanvas) === null || _ref === void 0 || _ref({
93
+ canvas: _this.canvas,
94
+ ctx: _this.ctx,
95
+ container: {
96
+ width: width,
97
+ height: height,
98
+ bounds: bounds
99
+ },
100
+ size: [width, height],
101
+ utils: {
102
+ lngLatToContainer: _this.lngLatToContainer
103
+ },
104
+ mapService: _this.mapService
105
+ });
106
+ });
107
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "removeCanvas", function () {
108
+ if (_this.canvas) {
109
+ var _this$canvas$parentEl;
110
+ (_this$canvas$parentEl = _this.canvas.parentElement) === null || _this$canvas$parentEl === void 0 || _this$canvas$parentEl.removeChild(_this.canvas);
111
+ _this.canvas = null;
105
112
  }
113
+ _this.unbindListeners();
114
+ });
115
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMapResize", function () {
116
+ requestAnimationFrame(function () {
117
+ _this.resetCanvasSize();
118
+ _this.renderCanvas();
119
+ });
120
+ });
121
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "lngLatToContainer", function (lngLat) {
122
+ var _this$mapService$lngL = _this.mapService.lngLatToContainer(lngLat),
123
+ x = _this$mapService$lngL.x,
124
+ y = _this$mapService$lngL.y;
125
+ return {
126
+ x: x * window.devicePixelRatio,
127
+ y: y * window.devicePixelRatio
128
+ };
106
129
  });
107
130
  return _this;
108
131
  }
109
- (0, _createClass2.default)(CanvaModel, [{
110
- key: "clearModels",
111
- value: function clearModels() {
112
- if (this.canvas) {
113
- var _this$mapService$getC;
114
- (_this$mapService$getC = this.mapService.getContainer()) === null || _this$mapService$getC === void 0 || _this$mapService$getC.removeChild(this.canvas);
115
- // @ts-ignore
116
- this.canvas = null;
117
- }
118
- this.unBindListener();
132
+ (0, _createClass2.default)(CanvasModel, [{
133
+ key: "layerConfig",
134
+ get: function get() {
135
+ return this.layer.getLayerConfig();
119
136
  }
120
137
  }, {
121
138
  key: "initModels",
122
139
  value: function () {
123
140
  var _initModels = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
124
- var _ref3, _ref3$update, update;
125
141
  return _regenerator.default.wrap(function _callee$(_context) {
126
142
  while (1) switch (_context.prev = _context.next) {
127
143
  case 0:
128
- _ref3 = this.layer.getLayerConfig(), _ref3$update = _ref3.update, update = _ref3$update === void 0 ? _interface.CanvasUpdateType.ALWAYS : _ref3$update;
129
- this.updateMode = update;
130
- this.initCanvas();
131
144
  this.renderCanvas();
132
- this.bindListener();
133
- this.mapService.getContainer();
134
145
  return _context.abrupt("return", []);
135
- case 7:
146
+ case 2:
136
147
  case "end":
137
148
  return _context.stop();
138
149
  }
@@ -144,58 +155,34 @@ var CanvaModel = exports.default = /*#__PURE__*/function (_BaseModel) {
144
155
  return initModels;
145
156
  }()
146
157
  }, {
147
- key: "initCanvas",
148
- value: function initCanvas() {
149
- var _this$mapService$getC2;
150
- var _ref4 = this.layer.getLayerConfig(),
151
- zIndex = _ref4.zIndex;
152
- var size = this.mapService.getSize();
153
- var _size2 = (0, _slicedToArray2.default)(size, 2),
154
- width = _size2[0],
155
- height = _size2[1];
156
- var _this$rendererService3 = this.rendererService.getViewportSize(),
157
- viewWidth = _this$rendererService3.width,
158
- viewHeight = _this$rendererService3.height;
159
- this.prevSize = [viewWidth, viewHeight];
160
- var canvas = document.createElement('canvas');
161
- this.canvas = canvas;
162
- canvas.width = viewWidth;
163
- canvas.height = viewHeight;
164
- canvas.style.pointerEvents = 'none';
165
- canvas.style.width = width + 'px';
166
- canvas.style.height = height + 'px';
167
- canvas.style.position = 'absolute';
168
- canvas.style.top = '0';
169
- canvas.style.left = '0';
170
- canvas.style.zIndex = zIndex + '';
171
- (_this$mapService$getC2 = this.mapService.getContainer()) === null || _this$mapService$getC2 === void 0 || _this$mapService$getC2.appendChild(canvas);
172
- var ctx = canvas.getContext('2d');
173
- this.ctx = ctx;
158
+ key: "bindListeners",
159
+ value: function bindListeners() {
160
+ this.mapService.on('resize', this.onMapResize);
161
+ var _this$layerConfig3 = this.layerConfig,
162
+ trigger = _this$layerConfig3.trigger,
163
+ update = _this$layerConfig3.update;
164
+ if (update === _interface.CanvasUpdateType.ALWAYS || trigger === 'change') {
165
+ this.mapService.on('mapchange', this.renderCanvas);
166
+ } else {
167
+ this.mapService.on('zoomstart', this.removeCanvas);
168
+ this.mapService.on('zoomend', this.renderCanvas);
169
+ this.mapService.on('movestart', this.removeCanvas);
170
+ this.mapService.on('moveend', this.renderCanvas);
171
+ }
174
172
  }
175
173
  }, {
176
- key: "buildModels",
177
- value: function () {
178
- var _buildModels = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
179
- return _regenerator.default.wrap(function _callee2$(_context2) {
180
- while (1) switch (_context2.prev = _context2.next) {
181
- case 0:
182
- return _context2.abrupt("return", this.initModels());
183
- case 1:
184
- case "end":
185
- return _context2.stop();
186
- }
187
- }, _callee2, this);
188
- }));
189
- function buildModels() {
190
- return _buildModels.apply(this, arguments);
191
- }
192
- return buildModels;
193
- }()
174
+ key: "unbindListeners",
175
+ value: function unbindListeners() {
176
+ this.mapService.off('resize', this.onMapResize);
177
+ this.mapService.off('mapchange', this.renderCanvas);
178
+ this.mapService.off('zoomstart', this.removeCanvas);
179
+ this.mapService.off('zoomend', this.renderCanvas);
180
+ this.mapService.off('movestart', this.removeCanvas);
181
+ this.mapService.off('moveend', this.renderCanvas);
182
+ }
194
183
  }, {
195
184
  key: "registerBuiltinAttributes",
196
- value: function registerBuiltinAttributes() {
197
- return;
198
- }
185
+ value: function registerBuiltinAttributes() {}
199
186
  }]);
200
- return CanvaModel;
187
+ return CanvasModel;
201
188
  }(_BaseModel2.default);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CanvasContextTypeMap = void 0;
7
+ var CanvasContextTypeMap = exports.CanvasContextTypeMap = {
8
+ canvas2d: '2d',
9
+ webgl: 'webgl',
10
+ webgl2: 'webgl2',
11
+ webgpu: 'webgpu'
12
+ };
@@ -1,12 +1,27 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports.default = void 0;
8
- var _canvas = _interopRequireDefault(require("./canvas"));
9
- var CanvasModels = {
10
- canvas: _canvas.default
11
- };
12
- var _default = exports.default = CanvasModels;
6
+ var _canvas = require("./canvas");
7
+ Object.keys(_canvas).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _canvas[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return _canvas[key];
14
+ }
15
+ });
16
+ });
17
+ var _constants = require("./constants");
18
+ Object.keys(_constants).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _constants[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return _constants[key];
25
+ }
26
+ });
27
+ });