@antv/l7-scene 2.9.37-alpha.2 → 2.9.37-alpha.3

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,586 @@
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
+
51
+ if (isMini) {
52
+ this.sceneService.initMiniScene(config);
53
+ } else {
54
+ this.initComponent(id); // 初始化 scene
55
+
56
+ this.sceneService.init(config); // TODO: 初始化组件
57
+
58
+ this.initControl();
59
+ }
60
+ }
61
+
62
+ _createClass(Scene, [{
63
+ key: "map",
64
+ get: function get() {
65
+ return this.mapService.map;
66
+ }
67
+ }, {
68
+ key: "loaded",
69
+ get: function get() {
70
+ return this.sceneService.loaded;
71
+ }
72
+ }, {
73
+ key: "getServiceContainer",
74
+ value: function getServiceContainer() {
75
+ return this.container;
76
+ }
77
+ }, {
78
+ key: "getSize",
79
+ value: function getSize() {
80
+ return this.mapService.getSize();
81
+ }
82
+ }, {
83
+ key: "getMinZoom",
84
+ value: function getMinZoom() {
85
+ return this.mapService.getMinZoom();
86
+ }
87
+ }, {
88
+ key: "getMaxZoom",
89
+ value: function getMaxZoom() {
90
+ return this.mapService.getMaxZoom();
91
+ }
92
+ }, {
93
+ key: "getType",
94
+ value: function getType() {
95
+ return this.mapService.getType();
96
+ }
97
+ }, {
98
+ key: "getMapContainer",
99
+ value: function getMapContainer() {
100
+ return this.mapService.getMapContainer();
101
+ }
102
+ }, {
103
+ key: "getMapCanvasContainer",
104
+ value: function getMapCanvasContainer() {
105
+ return this.mapService.getMapCanvasContainer();
106
+ }
107
+ }, {
108
+ key: "getMapService",
109
+ value: function getMapService() {
110
+ return this.mapService;
111
+ }
112
+ }, {
113
+ key: "exportPng",
114
+ value: function exportPng(type) {
115
+ return this.sceneService.exportPng(type);
116
+ }
117
+ }, {
118
+ key: "exportMap",
119
+ value: function exportMap(type) {
120
+ return this.sceneService.exportPng(type);
121
+ }
122
+ }, {
123
+ key: "registerRenderService",
124
+ value: function registerRenderService(render) {
125
+ var _this = this;
126
+
127
+ if (this.sceneService.loaded) {
128
+ var renderSerivce = new render(this);
129
+ renderSerivce.init();
130
+ } else {
131
+ this.on('loaded', function () {
132
+ var renderSerivce = new render(_this);
133
+ renderSerivce.init();
134
+ });
135
+ }
136
+ }
137
+ }, {
138
+ key: "setBgColor",
139
+ value: function setBgColor(color) {
140
+ this.mapService.setBgColor(color);
141
+ } // layer 管理
142
+
143
+ }, {
144
+ key: "addLayer",
145
+ value: function addLayer(layer) {
146
+ var _this2 = this;
147
+
148
+ // 为当前图层创建一个容器
149
+ // TODO: 初始化的时候设置 容器
150
+ var layerContainer = createLayerContainer(this.container);
151
+ layer.setContainer(layerContainer, this.container);
152
+ this.sceneService.addLayer(layer); // mask 在 scene loaded 之后执行
153
+
154
+ if (layer.inited) {
155
+ var maskInstance = this.initMask(layer);
156
+ this.addMask(maskInstance, layer.id);
157
+ } else {
158
+ layer.on('inited', function () {
159
+ var maskInstance = _this2.initMask(layer);
160
+
161
+ _this2.addMask(maskInstance, layer.id);
162
+ });
163
+ }
164
+ }
165
+ }, {
166
+ key: "initMask",
167
+ value: function initMask(layer) {
168
+ var _layer$getLayerConfig = layer.getLayerConfig(),
169
+ mask = _layer$getLayerConfig.mask,
170
+ maskfence = _layer$getLayerConfig.maskfence,
171
+ _layer$getLayerConfig2 = _layer$getLayerConfig.maskColor,
172
+ maskColor = _layer$getLayerConfig2 === void 0 ? '#000' : _layer$getLayerConfig2,
173
+ _layer$getLayerConfig3 = _layer$getLayerConfig.maskOpacity,
174
+ maskOpacity = _layer$getLayerConfig3 === void 0 ? 0 : _layer$getLayerConfig3;
175
+
176
+ if (!mask) return undefined;
177
+ var maskInstance = new MaskLayer().source(maskfence).shape('fill').style({
178
+ color: maskColor,
179
+ opacity: maskOpacity
180
+ });
181
+ return maskInstance;
182
+ }
183
+ }, {
184
+ key: "addMask",
185
+ value: function addMask(mask, layerId) {
186
+ if (!mask) return;
187
+ var parent = this.getLayer(layerId);
188
+
189
+ if (parent) {
190
+ var layerContainer = createLayerContainer(this.container);
191
+ mask.setContainer(layerContainer, this.container);
192
+ parent.addMaskLayer(mask);
193
+ this.sceneService.addLayer(mask);
194
+ } else {
195
+ console.warn('parent layer not find!');
196
+ }
197
+ }
198
+ }, {
199
+ key: "getPickedLayer",
200
+ value: function getPickedLayer() {
201
+ return this.layerService.pickedLayerId;
202
+ }
203
+ }, {
204
+ key: "getLayers",
205
+ value: function getLayers() {
206
+ return this.layerService.getLayers();
207
+ }
208
+ }, {
209
+ key: "getLayer",
210
+ value: function getLayer(id) {
211
+ return this.layerService.getLayer(id);
212
+ }
213
+ }, {
214
+ key: "getLayerByName",
215
+ value: function getLayerByName(name) {
216
+ return this.layerService.getLayerByName(name);
217
+ }
218
+ }, {
219
+ key: "removeLayer",
220
+ value: function removeLayer(layer, parentLayer) {
221
+ this.layerService.remove(layer, parentLayer);
222
+ }
223
+ }, {
224
+ key: "removeAllLayer",
225
+ value: function removeAllLayer() {
226
+ this.layerService.removeAllLayers();
227
+ }
228
+ }, {
229
+ key: "render",
230
+ value: function render() {
231
+ this.sceneService.render();
232
+ }
233
+ }, {
234
+ key: "setEnableRender",
235
+ value: function setEnableRender(flag) {
236
+ this.layerService.setEnableRender(flag);
237
+ } // asset method
238
+
239
+ /**
240
+ * 为 layer/point/text 支持 iconfont 模式支持
241
+ * @param fontUnicode
242
+ * @param name
243
+ */
244
+
245
+ }, {
246
+ key: "addIconFont",
247
+ value: function addIconFont(name, fontUnicode) {
248
+ this.fontService.addIconFont(name, fontUnicode);
249
+ }
250
+ }, {
251
+ key: "addIconFonts",
252
+ value: function addIconFonts(options) {
253
+ var _this3 = this;
254
+
255
+ options.forEach(function (_ref) {
256
+ var _ref2 = _slicedToArray(_ref, 2),
257
+ name = _ref2[0],
258
+ fontUnicode = _ref2[1];
259
+
260
+ _this3.fontService.addIconFont(name, fontUnicode);
261
+ });
262
+ }
263
+ /**
264
+ * 用户自定义添加第三方字体
265
+ * @param fontFamily
266
+ * @param fontPath
267
+ */
268
+
269
+ }, {
270
+ key: "addFontFace",
271
+ value: function addFontFace(fontFamily, fontPath) {
272
+ var _this4 = this;
273
+
274
+ this.fontService.once('fontloaded', function (e) {
275
+ _this4.emit('fontloaded', e);
276
+ });
277
+ this.fontService.addFontFace(fontFamily, fontPath);
278
+ }
279
+ }, {
280
+ key: "addImage",
281
+ value: function addImage(id, img) {
282
+ if (!isMini) {
283
+ this.iconService.addImage(id, img);
284
+ } else {
285
+ this.iconService.addImageMini(id, img, this.sceneService);
286
+ }
287
+ }
288
+ }, {
289
+ key: "hasImage",
290
+ value: function hasImage(id) {
291
+ return this.iconService.hasImage(id);
292
+ }
293
+ }, {
294
+ key: "removeImage",
295
+ value: function removeImage(id) {
296
+ this.iconService.removeImage(id);
297
+ }
298
+ }, {
299
+ key: "addIconFontGlyphs",
300
+ value: function addIconFontGlyphs(fontFamily, glyphs) {
301
+ this.fontService.addIconGlyphs(glyphs);
302
+ } // map control method
303
+
304
+ }, {
305
+ key: "addControl",
306
+ value: function addControl(ctr) {
307
+ this.controlService.addControl(ctr, this.container);
308
+ }
309
+ }, {
310
+ key: "removeControl",
311
+ value: function removeControl(ctr) {
312
+ this.controlService.removeControl(ctr);
313
+ }
314
+ }, {
315
+ key: "getControlByName",
316
+ value: function getControlByName(name) {
317
+ return this.controlService.getControlByName(name);
318
+ } // marker
319
+
320
+ }, {
321
+ key: "addMarker",
322
+ value: function addMarker(marker) {
323
+ this.markerService.addMarker(marker);
324
+ }
325
+ }, {
326
+ key: "addMarkerLayer",
327
+ value: function addMarkerLayer(layer) {
328
+ this.markerService.addMarkerLayer(layer);
329
+ }
330
+ }, {
331
+ key: "removeMarkerLayer",
332
+ value: function removeMarkerLayer(layer) {
333
+ this.markerService.removeMarkerLayer(layer);
334
+ }
335
+ }, {
336
+ key: "removeAllMakers",
337
+ value: function removeAllMakers() {
338
+ this.markerService.removeAllMarkers();
339
+ }
340
+ }, {
341
+ key: "addPopup",
342
+ value: function addPopup(popup) {
343
+ this.popupService.addPopup(popup);
344
+ }
345
+ }, {
346
+ key: "removePopup",
347
+ value: function removePopup(popup) {
348
+ this.popupService.removePopup(popup);
349
+ }
350
+ }, {
351
+ key: "on",
352
+ value: function on(type, handle) {
353
+ if (BoxSelectEventList.includes(type)) {
354
+ var _this$boxSelect;
355
+
356
+ (_this$boxSelect = this.boxSelect) === null || _this$boxSelect === void 0 ? void 0 : _this$boxSelect.on(type, handle);
357
+ } else if (SceneEventList.includes(type)) {
358
+ this.sceneService.on(type, handle);
359
+ } else {
360
+ this.mapService.on(type, handle);
361
+ }
362
+ }
363
+ }, {
364
+ key: "once",
365
+ value: function once(type, handle) {
366
+ if (BoxSelectEventList.includes(type)) {
367
+ var _this$boxSelect2;
368
+
369
+ (_this$boxSelect2 = this.boxSelect) === null || _this$boxSelect2 === void 0 ? void 0 : _this$boxSelect2.once(type, handle);
370
+ } else if (SceneEventList.includes(type)) {
371
+ this.sceneService.once(type, handle);
372
+ } else {
373
+ this.mapService.once(type, handle);
374
+ }
375
+ }
376
+ }, {
377
+ key: "emit",
378
+ value: function emit(type, handle) {
379
+ SceneEventList.indexOf(type) === -1 ? this.mapService.on(type, handle) : this.sceneService.emit(type, handle);
380
+ }
381
+ }, {
382
+ key: "off",
383
+ value: function off(type, handle) {
384
+ if (BoxSelectEventList.includes(type)) {
385
+ var _this$boxSelect3;
386
+
387
+ (_this$boxSelect3 = this.boxSelect) === null || _this$boxSelect3 === void 0 ? void 0 : _this$boxSelect3.off(type, handle);
388
+ } else if (SceneEventList.includes(type)) {
389
+ this.sceneService.off(type, handle);
390
+ } else {
391
+ this.mapService.off(type, handle);
392
+ }
393
+ } // implements IMapController
394
+
395
+ }, {
396
+ key: "getZoom",
397
+ value: function getZoom() {
398
+ return this.mapService.getZoom();
399
+ }
400
+ }, {
401
+ key: "getCenter",
402
+ value: function getCenter(options) {
403
+ return this.mapService.getCenter(options);
404
+ }
405
+ }, {
406
+ key: "setCenter",
407
+ value: function setCenter(center, options) {
408
+ return this.mapService.setCenter(center, options);
409
+ }
410
+ }, {
411
+ key: "getPitch",
412
+ value: function getPitch() {
413
+ return this.mapService.getPitch();
414
+ }
415
+ }, {
416
+ key: "setPitch",
417
+ value: function setPitch(pitch) {
418
+ return this.mapService.setPitch(pitch);
419
+ }
420
+ }, {
421
+ key: "getRotation",
422
+ value: function getRotation() {
423
+ return this.mapService.getRotation();
424
+ }
425
+ }, {
426
+ key: "getBounds",
427
+ value: function getBounds() {
428
+ return this.mapService.getBounds();
429
+ }
430
+ }, {
431
+ key: "setRotation",
432
+ value: function setRotation(rotation) {
433
+ this.mapService.setRotation(rotation);
434
+ }
435
+ }, {
436
+ key: "zoomIn",
437
+ value: function zoomIn() {
438
+ this.mapService.zoomIn();
439
+ }
440
+ }, {
441
+ key: "zoomOut",
442
+ value: function zoomOut() {
443
+ this.mapService.zoomOut();
444
+ }
445
+ }, {
446
+ key: "panTo",
447
+ value: function panTo(p) {
448
+ this.mapService.panTo(p);
449
+ }
450
+ }, {
451
+ key: "panBy",
452
+ value: function panBy(x, y) {
453
+ this.mapService.panBy(x, y);
454
+ }
455
+ }, {
456
+ key: "getContainer",
457
+ value: function getContainer() {
458
+ return this.mapService.getContainer();
459
+ }
460
+ }, {
461
+ key: "setZoom",
462
+ value: function setZoom(zoom) {
463
+ this.mapService.setZoom(zoom);
464
+ }
465
+ }, {
466
+ key: "fitBounds",
467
+ value: function fitBounds(bound, options) {
468
+ var _this$sceneService$ge = this.sceneService.getSceneConfig(),
469
+ fitBoundsOptions = _this$sceneService$ge.fitBoundsOptions,
470
+ animate = _this$sceneService$ge.animate;
471
+
472
+ this.mapService.fitBounds(bound, // 选项优先级:用户传入,覆盖animate直接配置,覆盖Scene配置项传入
473
+ options || _objectSpread(_objectSpread({}, fitBoundsOptions), {}, {
474
+ animate: animate
475
+ }));
476
+ }
477
+ }, {
478
+ key: "setZoomAndCenter",
479
+ value: function setZoomAndCenter(zoom, center) {
480
+ this.mapService.setZoomAndCenter(zoom, center);
481
+ }
482
+ }, {
483
+ key: "setMapStyle",
484
+ value: function setMapStyle(style) {
485
+ this.mapService.setMapStyle(style);
486
+ }
487
+ }, {
488
+ key: "setMapStatus",
489
+ value: function setMapStatus(options) {
490
+ this.mapService.setMapStatus(options);
491
+ } // conversion Method
492
+
493
+ }, {
494
+ key: "pixelToLngLat",
495
+ value: function pixelToLngLat(pixel) {
496
+ return this.mapService.pixelToLngLat(pixel);
497
+ }
498
+ }, {
499
+ key: "lngLatToPixel",
500
+ value: function lngLatToPixel(lnglat) {
501
+ return this.mapService.lngLatToPixel(lnglat);
502
+ }
503
+ }, {
504
+ key: "containerToLngLat",
505
+ value: function containerToLngLat(pixel) {
506
+ return this.mapService.containerToLngLat(pixel);
507
+ }
508
+ }, {
509
+ key: "lngLatToContainer",
510
+ value: function lngLatToContainer(lnglat) {
511
+ return this.mapService.lngLatToContainer(lnglat);
512
+ }
513
+ }, {
514
+ key: "destroy",
515
+ value: function destroy() {
516
+ this.sceneService.destroy(); // TODO: 清理其他 Service 例如 IconService
517
+ }
518
+ }, {
519
+ key: "registerPostProcessingPass",
520
+ value: function registerPostProcessingPass(constructor, name) {
521
+ this.container.bind(TYPES.IPostProcessingPass).to(constructor).whenTargetNamed(name);
522
+ } // 控制 shader pick 计算
523
+
524
+ }, {
525
+ key: "enableShaderPick",
526
+ value: function enableShaderPick() {
527
+ this.layerService.enableShaderPick();
528
+ }
529
+ }, {
530
+ key: "diasbleShaderPick",
531
+ value: function diasbleShaderPick() {
532
+ this.layerService.disableShaderPick();
533
+ }
534
+ }, {
535
+ key: "enableBoxSelect",
536
+ value: function enableBoxSelect() {
537
+ var _this5 = this;
538
+
539
+ var once = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
540
+ this.boxSelect.enable();
541
+
542
+ if (once) {
543
+ this.boxSelect.once('selectend', function () {
544
+ _this5.disableBoxSelect();
545
+ });
546
+ }
547
+ }
548
+ }, {
549
+ key: "disableBoxSelect",
550
+ value: function disableBoxSelect() {
551
+ this.boxSelect.disable();
552
+ } // get current point size info
553
+
554
+ }, {
555
+ key: "getPointSizeRange",
556
+ value: function getPointSizeRange() {
557
+ return this.sceneService.getPointSizeRange();
558
+ }
559
+ }, {
560
+ key: "initComponent",
561
+ value: function initComponent(id) {
562
+ this.controlService.init({
563
+ container: DOM.getContainer(id)
564
+ }, this.container);
565
+ this.markerService.init(this.container);
566
+ this.popupService.init(this.container);
567
+ }
568
+ }, {
569
+ key: "initControl",
570
+ value: function initControl() {
571
+ var _this$sceneService$ge2 = this.sceneService.getSceneConfig(),
572
+ logoVisible = _this$sceneService$ge2.logoVisible,
573
+ logoPosition = _this$sceneService$ge2.logoPosition;
574
+
575
+ if (logoVisible) {
576
+ this.addControl(new Logo({
577
+ position: logoPosition
578
+ }));
579
+ }
580
+ }
581
+ }]);
582
+
583
+ return Scene;
584
+ }();
585
+
586
+ 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);