@antv/l7-scene 2.9.32-alpha.2 → 2.9.32-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/index.js ADDED
@@ -0,0 +1,568 @@
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/createClass";
5
+ import { Logo } from '@antv/l7-component';
6
+ import { createLayerContainer, createSceneContainer, SceneEventList, TYPES } from '@antv/l7-core';
7
+ import { MaskLayer } from '@antv/l7-layers';
8
+ import { ReglRendererService } from '@antv/l7-renderer';
9
+ import { DOM, isMini } from '@antv/l7-utils';
10
+ import BoxSelect, { BoxSelectEventList } from "./boxSelect";
11
+
12
+ /**
13
+ * 暴露 Scene API
14
+ *
15
+ * @example
16
+ * import { Scene } from 'l7/scene';
17
+ * import { PointLayer } from 'l7/layers';
18
+ *
19
+ * const scene = new Scene();
20
+ * const pointLayer = new PointLayer();
21
+ * scene.addLayer(pointLayer);
22
+ *
23
+ */
24
+ var Scene = /*#__PURE__*/function () {
25
+ function Scene(config) {
26
+ _classCallCheck(this, Scene);
27
+
28
+ var id = config.id,
29
+ map = config.map,
30
+ canvas = config.canvas,
31
+ hasBaseMap = config.hasBaseMap; // 创建场景容器
32
+
33
+ var sceneContainer = createSceneContainer();
34
+ this.container = sceneContainer; // 绑定地图服务
35
+
36
+ map.setContainer(sceneContainer, id, canvas, hasBaseMap); // 绑定渲染引擎服务
37
+
38
+ sceneContainer.bind(TYPES.IRendererService).to(ReglRendererService).inSingletonScope(); // 依赖注入
39
+
40
+ this.sceneService = sceneContainer.get(TYPES.ISceneService);
41
+ this.mapService = sceneContainer.get(TYPES.IMapService);
42
+ this.iconService = sceneContainer.get(TYPES.IIconService);
43
+ this.fontService = sceneContainer.get(TYPES.IFontService);
44
+ this.controlService = sceneContainer.get(TYPES.IControlService);
45
+ this.layerService = sceneContainer.get(TYPES.ILayerService);
46
+ this.markerService = sceneContainer.get(TYPES.IMarkerService);
47
+ this.interactionService = sceneContainer.get(TYPES.IInteractionService);
48
+ this.popupService = sceneContainer.get(TYPES.IPopupService);
49
+ this.boxSelect = new BoxSelect(this, {
50
+ className: config.selectBoxClassName
51
+ });
52
+
53
+ if (isMini) {
54
+ this.sceneService.initMiniScene(config);
55
+ } else {
56
+ this.initComponent(id); // 初始化 scene
57
+
58
+ this.sceneService.init(config); // TODO: 初始化组件
59
+
60
+ this.initControl();
61
+ }
62
+ }
63
+
64
+ _createClass(Scene, [{
65
+ key: "map",
66
+ get: function get() {
67
+ return this.mapService.map;
68
+ }
69
+ }, {
70
+ key: "loaded",
71
+ get: function get() {
72
+ return this.sceneService.loaded;
73
+ }
74
+ }, {
75
+ key: "getServiceContainer",
76
+ value: function getServiceContainer() {
77
+ return this.container;
78
+ }
79
+ }, {
80
+ key: "getSize",
81
+ value: function getSize() {
82
+ return this.mapService.getSize();
83
+ }
84
+ }, {
85
+ key: "getMinZoom",
86
+ value: function getMinZoom() {
87
+ return this.mapService.getMinZoom();
88
+ }
89
+ }, {
90
+ key: "getMaxZoom",
91
+ value: function getMaxZoom() {
92
+ return this.mapService.getMaxZoom();
93
+ }
94
+ }, {
95
+ key: "getType",
96
+ value: function getType() {
97
+ return this.mapService.getType();
98
+ }
99
+ }, {
100
+ key: "getMapContainer",
101
+ value: function getMapContainer() {
102
+ return this.mapService.getMapContainer();
103
+ }
104
+ }, {
105
+ key: "getMapCanvasContainer",
106
+ value: function getMapCanvasContainer() {
107
+ return this.mapService.getMapCanvasContainer();
108
+ }
109
+ }, {
110
+ key: "getMapService",
111
+ value: function getMapService() {
112
+ return this.mapService;
113
+ }
114
+ }, {
115
+ key: "exportPng",
116
+ value: function exportPng(type) {
117
+ return this.sceneService.exportPng(type);
118
+ }
119
+ }, {
120
+ key: "exportMap",
121
+ value: function exportMap(type) {
122
+ return this.sceneService.exportPng(type);
123
+ }
124
+ }, {
125
+ key: "registerRenderService",
126
+ value: function registerRenderService(render) {
127
+ var _this = this;
128
+
129
+ if (this.sceneService.loaded) {
130
+ var renderSerivce = new render(this);
131
+ renderSerivce.init();
132
+ } else {
133
+ this.on('loaded', function () {
134
+ var renderSerivce = new render(_this);
135
+ renderSerivce.init();
136
+ });
137
+ }
138
+ }
139
+ }, {
140
+ key: "setBgColor",
141
+ value: function setBgColor(color) {
142
+ this.mapService.setBgColor(color);
143
+ } // layer 管理
144
+
145
+ }, {
146
+ key: "addLayer",
147
+ value: function addLayer(layer) {
148
+ // 为当前图层创建一个容器
149
+ // TODO: 初始化的时候设置 容器
150
+ var layerContainer = createLayerContainer(this.container);
151
+ layer.setContainer(layerContainer, this.container);
152
+ this.sceneService.addLayer(layer);
153
+ var layerConfig = layer.getLayerConfig();
154
+
155
+ if (layerConfig) {
156
+ // 若 layer 未初始化成功,则 layerConfig 为 undefined (scene loaded 尚未执行完成)
157
+ var mask = layerConfig.mask,
158
+ maskfence = layerConfig.maskfence,
159
+ _layerConfig$maskColo = layerConfig.maskColor,
160
+ maskColor = _layerConfig$maskColo === void 0 ? '#000' : _layerConfig$maskColo,
161
+ _layerConfig$maskOpac = layerConfig.maskOpacity,
162
+ maskOpacity = _layerConfig$maskOpac === void 0 ? 0 : _layerConfig$maskOpac;
163
+
164
+ if (mask && maskfence) {
165
+ var maskInstance = new MaskLayer().source(maskfence).shape('fill').style({
166
+ color: maskColor,
167
+ opacity: maskOpacity
168
+ });
169
+ this.addMask(maskInstance, layer.id);
170
+ }
171
+ } else {
172
+ console.warn('addLayer should run after scene loaded!');
173
+ }
174
+ }
175
+ }, {
176
+ key: "addMask",
177
+ value: function addMask(mask, layerId) {
178
+ var parent = this.getLayer(layerId);
179
+
180
+ if (parent) {
181
+ var layerContainer = createLayerContainer(this.container);
182
+ mask.setContainer(layerContainer, this.container);
183
+ parent.addMaskLayer(mask);
184
+ this.sceneService.addLayer(mask);
185
+ } else {
186
+ console.warn('parent layer not find!');
187
+ }
188
+ }
189
+ }, {
190
+ key: "getPickedLayer",
191
+ value: function getPickedLayer() {
192
+ return this.layerService.pickedLayerId;
193
+ }
194
+ }, {
195
+ key: "getLayers",
196
+ value: function getLayers() {
197
+ return this.layerService.getLayers();
198
+ }
199
+ }, {
200
+ key: "getLayer",
201
+ value: function getLayer(id) {
202
+ return this.layerService.getLayer(id);
203
+ }
204
+ }, {
205
+ key: "getLayerByName",
206
+ value: function getLayerByName(name) {
207
+ return this.layerService.getLayerByName(name);
208
+ }
209
+ }, {
210
+ key: "removeLayer",
211
+ value: function removeLayer(layer, parentLayer) {
212
+ this.layerService.remove(layer, parentLayer);
213
+ }
214
+ }, {
215
+ key: "removeAllLayer",
216
+ value: function removeAllLayer() {
217
+ this.layerService.removeAllLayers();
218
+ }
219
+ }, {
220
+ key: "render",
221
+ value: function render() {
222
+ this.sceneService.render();
223
+ }
224
+ }, {
225
+ key: "setEnableRender",
226
+ value: function setEnableRender(flag) {
227
+ this.layerService.setEnableRender(flag);
228
+ } // asset method
229
+
230
+ /**
231
+ * 为 layer/point/text 支持 iconfont 模式支持
232
+ * @param fontUnicode
233
+ * @param name
234
+ */
235
+
236
+ }, {
237
+ key: "addIconFont",
238
+ value: function addIconFont(name, fontUnicode) {
239
+ this.fontService.addIconFont(name, fontUnicode);
240
+ }
241
+ }, {
242
+ key: "addIconFonts",
243
+ value: function addIconFonts(options) {
244
+ var _this2 = this;
245
+
246
+ options.forEach(function (_ref) {
247
+ var _ref2 = _slicedToArray(_ref, 2),
248
+ name = _ref2[0],
249
+ fontUnicode = _ref2[1];
250
+
251
+ _this2.fontService.addIconFont(name, fontUnicode);
252
+ });
253
+ }
254
+ /**
255
+ * 用户自定义添加第三方字体
256
+ * @param fontFamily
257
+ * @param fontPath
258
+ */
259
+
260
+ }, {
261
+ key: "addFontFace",
262
+ value: function addFontFace(fontFamily, fontPath) {
263
+ this.sceneService.addFontFace(fontFamily, fontPath);
264
+ }
265
+ }, {
266
+ key: "addImage",
267
+ value: function addImage(id, img) {
268
+ if (!isMini) {
269
+ this.iconService.addImage(id, img);
270
+ } else {
271
+ this.iconService.addImageMini(id, img, this.sceneService);
272
+ } // this.iconService.addImage(id, img);
273
+
274
+ }
275
+ }, {
276
+ key: "hasImage",
277
+ value: function hasImage(id) {
278
+ return this.iconService.hasImage(id);
279
+ }
280
+ }, {
281
+ key: "removeImage",
282
+ value: function removeImage(id) {
283
+ this.iconService.removeImage(id);
284
+ }
285
+ }, {
286
+ key: "addIconFontGlyphs",
287
+ value: function addIconFontGlyphs(fontFamily, glyphs) {
288
+ this.fontService.addIconGlyphs(glyphs);
289
+ } // map control method
290
+
291
+ }, {
292
+ key: "addControl",
293
+ value: function addControl(ctr) {
294
+ this.controlService.addControl(ctr, this.container);
295
+ }
296
+ }, {
297
+ key: "removeControl",
298
+ value: function removeControl(ctr) {
299
+ this.controlService.removeControl(ctr);
300
+ }
301
+ }, {
302
+ key: "getControlByName",
303
+ value: function getControlByName(name) {
304
+ return this.controlService.getControlByName(name);
305
+ } // marker
306
+
307
+ }, {
308
+ key: "addMarker",
309
+ value: function addMarker(marker) {
310
+ this.markerService.addMarker(marker);
311
+ }
312
+ }, {
313
+ key: "addMarkerLayer",
314
+ value: function addMarkerLayer(layer) {
315
+ this.markerService.addMarkerLayer(layer);
316
+ }
317
+ }, {
318
+ key: "removeMarkerLayer",
319
+ value: function removeMarkerLayer(layer) {
320
+ this.markerService.removeMarkerLayer(layer);
321
+ }
322
+ }, {
323
+ key: "removeAllMakers",
324
+ value: function removeAllMakers() {
325
+ this.markerService.removeAllMarkers();
326
+ }
327
+ }, {
328
+ key: "addPopup",
329
+ value: function addPopup(popup) {
330
+ this.popupService.addPopup(popup);
331
+ }
332
+ }, {
333
+ key: "removePopup",
334
+ value: function removePopup(popup) {
335
+ this.popupService.removePopup(popup);
336
+ }
337
+ }, {
338
+ key: "on",
339
+ value: function on(type, handle) {
340
+ if (BoxSelectEventList.includes(type)) {
341
+ var _this$boxSelect;
342
+
343
+ (_this$boxSelect = this.boxSelect) === null || _this$boxSelect === void 0 ? void 0 : _this$boxSelect.on(type, handle);
344
+ } else if (SceneEventList.includes(type)) {
345
+ this.sceneService.on(type, handle);
346
+ } else {
347
+ this.mapService.on(type, handle);
348
+ }
349
+ }
350
+ }, {
351
+ key: "once",
352
+ value: function once(type, handle) {
353
+ if (BoxSelectEventList.includes(type)) {
354
+ var _this$boxSelect2;
355
+
356
+ (_this$boxSelect2 = this.boxSelect) === null || _this$boxSelect2 === void 0 ? void 0 : _this$boxSelect2.once(type, handle);
357
+ } else if (SceneEventList.includes(type)) {
358
+ this.sceneService.once(type, handle);
359
+ } else {
360
+ this.mapService.once(type, handle);
361
+ }
362
+ }
363
+ }, {
364
+ key: "off",
365
+ value: function off(type, handle) {
366
+ if (BoxSelectEventList.includes(type)) {
367
+ var _this$boxSelect3;
368
+
369
+ (_this$boxSelect3 = this.boxSelect) === null || _this$boxSelect3 === void 0 ? void 0 : _this$boxSelect3.off(type, handle);
370
+ } else if (SceneEventList.includes(type)) {
371
+ this.sceneService.off(type, handle);
372
+ } else {
373
+ this.mapService.off(type, handle);
374
+ }
375
+ } // implements IMapController
376
+
377
+ }, {
378
+ key: "getZoom",
379
+ value: function getZoom() {
380
+ return this.mapService.getZoom();
381
+ }
382
+ }, {
383
+ key: "getCenter",
384
+ value: function getCenter(options) {
385
+ return this.mapService.getCenter(options);
386
+ }
387
+ }, {
388
+ key: "setCenter",
389
+ value: function setCenter(center, options) {
390
+ return this.mapService.setCenter(center, options);
391
+ }
392
+ }, {
393
+ key: "getPitch",
394
+ value: function getPitch() {
395
+ return this.mapService.getPitch();
396
+ }
397
+ }, {
398
+ key: "setPitch",
399
+ value: function setPitch(pitch) {
400
+ return this.mapService.setPitch(pitch);
401
+ }
402
+ }, {
403
+ key: "getRotation",
404
+ value: function getRotation() {
405
+ return this.mapService.getRotation();
406
+ }
407
+ }, {
408
+ key: "getBounds",
409
+ value: function getBounds() {
410
+ return this.mapService.getBounds();
411
+ }
412
+ }, {
413
+ key: "setRotation",
414
+ value: function setRotation(rotation) {
415
+ this.mapService.setRotation(rotation);
416
+ }
417
+ }, {
418
+ key: "zoomIn",
419
+ value: function zoomIn() {
420
+ this.mapService.zoomIn();
421
+ }
422
+ }, {
423
+ key: "zoomOut",
424
+ value: function zoomOut() {
425
+ this.mapService.zoomOut();
426
+ }
427
+ }, {
428
+ key: "panTo",
429
+ value: function panTo(p) {
430
+ this.mapService.panTo(p);
431
+ }
432
+ }, {
433
+ key: "panBy",
434
+ value: function panBy(x, y) {
435
+ this.mapService.panBy(x, y);
436
+ }
437
+ }, {
438
+ key: "getContainer",
439
+ value: function getContainer() {
440
+ return this.mapService.getContainer();
441
+ }
442
+ }, {
443
+ key: "setZoom",
444
+ value: function setZoom(zoom) {
445
+ this.mapService.setZoom(zoom);
446
+ }
447
+ }, {
448
+ key: "fitBounds",
449
+ value: function fitBounds(bound, options) {
450
+ var _this$sceneService$ge = this.sceneService.getSceneConfig(),
451
+ fitBoundsOptions = _this$sceneService$ge.fitBoundsOptions,
452
+ animate = _this$sceneService$ge.animate;
453
+
454
+ this.mapService.fitBounds(bound, // 选项优先级:用户传入,覆盖animate直接配置,覆盖Scene配置项传入
455
+ options || _objectSpread(_objectSpread({}, fitBoundsOptions), {}, {
456
+ animate: animate
457
+ }));
458
+ }
459
+ }, {
460
+ key: "setZoomAndCenter",
461
+ value: function setZoomAndCenter(zoom, center) {
462
+ this.mapService.setZoomAndCenter(zoom, center);
463
+ }
464
+ }, {
465
+ key: "setMapStyle",
466
+ value: function setMapStyle(style) {
467
+ this.mapService.setMapStyle(style);
468
+ }
469
+ }, {
470
+ key: "setMapStatus",
471
+ value: function setMapStatus(options) {
472
+ this.mapService.setMapStatus(options);
473
+ } // conversion Method
474
+
475
+ }, {
476
+ key: "pixelToLngLat",
477
+ value: function pixelToLngLat(pixel) {
478
+ return this.mapService.pixelToLngLat(pixel);
479
+ }
480
+ }, {
481
+ key: "lngLatToPixel",
482
+ value: function lngLatToPixel(lnglat) {
483
+ return this.mapService.lngLatToPixel(lnglat);
484
+ }
485
+ }, {
486
+ key: "containerToLngLat",
487
+ value: function containerToLngLat(pixel) {
488
+ return this.mapService.containerToLngLat(pixel);
489
+ }
490
+ }, {
491
+ key: "lngLatToContainer",
492
+ value: function lngLatToContainer(lnglat) {
493
+ return this.mapService.lngLatToContainer(lnglat);
494
+ }
495
+ }, {
496
+ key: "destroy",
497
+ value: function destroy() {
498
+ this.sceneService.destroy(); // TODO: 清理其他 Service 例如 IconService
499
+ }
500
+ }, {
501
+ key: "registerPostProcessingPass",
502
+ value: function registerPostProcessingPass(constructor, name) {
503
+ this.container.bind(TYPES.IPostProcessingPass).to(constructor).whenTargetNamed(name);
504
+ } // 控制 shader pick 计算
505
+
506
+ }, {
507
+ key: "enableShaderPick",
508
+ value: function enableShaderPick() {
509
+ this.layerService.enableShaderPick();
510
+ }
511
+ }, {
512
+ key: "diasbleShaderPick",
513
+ value: function diasbleShaderPick() {
514
+ this.layerService.disableShaderPick();
515
+ }
516
+ }, {
517
+ key: "enableBoxSelect",
518
+ value: function enableBoxSelect() {
519
+ var _this3 = this;
520
+
521
+ var once = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
522
+ this.boxSelect.enable();
523
+
524
+ if (once) {
525
+ this.boxSelect.once('selectend', function () {
526
+ _this3.disableBoxSelect();
527
+ });
528
+ }
529
+ }
530
+ }, {
531
+ key: "disableBoxSelect",
532
+ value: function disableBoxSelect() {
533
+ this.boxSelect.disable();
534
+ } // get current point size info
535
+
536
+ }, {
537
+ key: "getPointSizeRange",
538
+ value: function getPointSizeRange() {
539
+ return this.sceneService.getPointSizeRange();
540
+ }
541
+ }, {
542
+ key: "initComponent",
543
+ value: function initComponent(id) {
544
+ this.controlService.init({
545
+ container: DOM.getContainer(id)
546
+ }, this.container);
547
+ this.markerService.init(this.container);
548
+ this.popupService.init(this.container);
549
+ }
550
+ }, {
551
+ key: "initControl",
552
+ value: function initControl() {
553
+ var _this$sceneService$ge2 = this.sceneService.getSceneConfig(),
554
+ logoVisible = _this$sceneService$ge2.logoVisible,
555
+ logoPosition = _this$sceneService$ge2.logoPosition;
556
+
557
+ if (logoVisible) {
558
+ this.addControl(new Logo({
559
+ position: logoPosition
560
+ }));
561
+ }
562
+ }
563
+ }]);
564
+
565
+ return Scene;
566
+ }();
567
+
568
+ export { Scene };
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/ILayerManager.ts
16
+ var ILayerManager_exports = {};
17
+ module.exports = __toCommonJS(ILayerManager_exports);
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/IMapController.ts
16
+ var IMapController_exports = {};
17
+ module.exports = __toCommonJS(IMapController_exports);
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/IPostProcessingPassPluggable.ts
16
+ var IPostProcessingPassPluggable_exports = {};
17
+ module.exports = __toCommonJS(IPostProcessingPassPluggable_exports);