deeptwins-engine-3d 0.1.74 → 0.1.76

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.
@@ -1,4 +1,3 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
1
  var _excluded = ["tilingScheme"];
3
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -7,6 +6,8 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
7
6
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
7
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
8
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
10
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
10
11
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
11
12
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
13
  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); }; }
@@ -17,6 +18,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
17
18
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
19
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
19
20
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
21
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
20
22
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
21
23
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
22
24
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -30,6 +32,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
30
32
  import * as turf from '@turf/turf';
31
33
  import * as Cesium from 'deeptwins-cesium';
32
34
  import proj4 from 'proj4';
35
+ import CustomRasterClipWorkerClient from "./CustomRasterClipWorkerClient";
33
36
  import ImageryLayer from "./ImageryLayer";
34
37
 
35
38
  /**
@@ -81,8 +84,10 @@ import ImageryLayer from "./ImageryLayer";
81
84
  * - `clipFeatureCrs`:可选,clipFeature 的原始坐标系,默认跟随 dataCrs。
82
85
  * - `renderCrs`:可选,bounds、clipFeature 和瓦片范围转换后的目标坐标系,默认 `EPSG:4326`。
83
86
  * - `projectionDefs`:可选,自定义 proj4 坐标系定义。
84
- * - `clipFeature`:可选,GeoJSON Polygon/MultiPolygon/Feature/FeatureCollection
87
+ * - `clipFeature`:可选,GeoJSON Polygon/MultiPolygon/Feature/FeatureCollection,`null` 等同未传。
85
88
  * - `autoFitBounds`:可选,创建后自动将相机定位到最终范围,需同时传入 `map`。
89
+ * - `clipWithWorker`:可选,裁剪几何计算优先使用 Worker,默认 `true`。
90
+ * - `clipWorkerUrl`:可选,自定义裁剪 Worker 地址。
86
91
  * - `debug`:可选,`true` 使用 console.log 输出调试信息,函数则接收结构化调试事件。
87
92
  */
88
93
 
@@ -391,6 +396,14 @@ var transformGeoJson = function transformGeoJson(geoJson, sourceCrs, targetCrs)
391
396
  return clonedGeoJson;
392
397
  };
393
398
 
399
+ /** 将 null、undefined 和非 GeoJSON 对象统一视为未传裁剪面。 */
400
+ var normalizeClipFeature = function normalizeClipFeature(clipFeature) {
401
+ if (!clipFeature || _typeof(clipFeature) !== 'object' || Array.isArray(clipFeature)) {
402
+ return undefined;
403
+ }
404
+ return clipFeature;
405
+ };
406
+
394
407
  /** 将 Geometry 包装为 Turf 可处理的 Feature。 */
395
408
  var createFeature = function createFeature(geometry) {
396
409
  var properties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -450,6 +463,36 @@ var getClipFeatureBounds = function getClipFeatureBounds(clipFeatures) {
450
463
  }
451
464
  return normalizeBounds(bbox);
452
465
  };
466
+ var boundsIntersects = function boundsIntersects(left, right) {
467
+ return left[0] <= right[2] && left[2] >= right[0] && left[1] <= right[3] && left[3] >= right[1];
468
+ };
469
+
470
+ /** 计算两个 bbox 的有效交集范围;仅边界相切时不视为可飞行区域。 */
471
+ var intersectBounds = function intersectBounds(left, right) {
472
+ var bounds = normalizeBounds([Math.max(left[0], right[0]), Math.max(left[1], right[1]), Math.min(left[2], right[2]), Math.min(left[3], right[3])]);
473
+ if (!bounds || bounds[0] >= bounds[2] || bounds[1] >= bounds[3]) {
474
+ return undefined;
475
+ }
476
+ return bounds;
477
+ };
478
+
479
+ /** 为裁剪面预计算 bbox,供瓦片级粗过滤使用。 */
480
+ var createClipFeatureEntries = function createClipFeatureEntries(clipFeatures) {
481
+ return clipFeatures.flatMap(function (feature) {
482
+ var bbox = normalizeBounds(turf.bbox(feature));
483
+ return bbox ? [{
484
+ feature: feature,
485
+ bbox: bbox
486
+ }] : [];
487
+ });
488
+ };
489
+
490
+ /** 高 minimumLevel 必须配合明确范围,避免 Cesium 初始化过多根瓦片。 */
491
+ var validateRasterSchedulingRange = function validateRasterSchedulingRange(options) {
492
+ if ((options.minimumLevel || 0) > 0 && !options.hasRenderBounds && !options.hasSourceRectangle) {
493
+ throw new Error('CustomRasterLayer source.minimumLevel > 0 requires bounds, source.rectangle, or a valid clipFeature bounds.');
494
+ }
495
+ };
453
496
  var getImageSize = function getImageSize(image) {
454
497
  return {
455
498
  width: image.width,
@@ -490,7 +533,7 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
490
533
  var _super = _createSuper(CustomRasterLayer);
491
534
  /** 创建通用栅格图层。 */
492
535
  function CustomRasterLayer(options) {
493
- var _options$map;
536
+ var _options$clipWithWork, _options$clipWorkerUr, _options$map;
494
537
  var _this;
495
538
  _classCallCheck(this, CustomRasterLayer);
496
539
  if (!(options !== null && options !== void 0 && options.source)) {
@@ -500,16 +543,27 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
500
543
  var dataCrs = normalizeCrs(options.dataCrs || DEFAULT_CRS);
501
544
  var clipFeatureCrs = normalizeCrs(options.clipFeatureCrs || dataCrs);
502
545
  var renderCrs = normalizeCrs(options.renderCrs || DEFAULT_CRS);
503
- var transformedClipFeature = transformGeoJson(options.clipFeature, clipFeatureCrs, renderCrs);
546
+ var normalizedClipFeature = normalizeClipFeature(options.clipFeature);
547
+ var transformedClipFeature = normalizedClipFeature ? transformGeoJson(normalizedClipFeature, clipFeatureCrs, renderCrs) : undefined;
504
548
  var clipFeatures = collectPolygonFeatures(transformedClipFeature);
549
+ var clipFeatureEntries = createClipFeatureEntries(clipFeatures);
550
+ var effectiveClipFeatures = clipFeatureEntries.map(function (entry) {
551
+ return entry.feature;
552
+ });
505
553
  var _options$source = options.source,
506
554
  sourceTilingSchemeOption = _options$source.tilingScheme,
507
555
  sourceOptionsRest = _objectWithoutProperties(_options$source, _excluded);
508
556
  var tileBounds = options.bounds ? transformBounds(options.bounds, dataCrs, renderCrs) : undefined;
509
- var clipBounds = getClipFeatureBounds(clipFeatures);
510
- var renderBounds = clipBounds || tileBounds;
557
+ var clipBounds = getClipFeatureBounds(effectiveClipFeatures);
558
+ var boundsIntersection = tileBounds && clipBounds ? intersectBounds(tileBounds, clipBounds) : undefined;
559
+ var renderBounds = boundsIntersection || clipBounds || tileBounds;
511
560
  var sourceRectangleBounds = sourceOptionsRest.rectangle ? rectangleToBounds(sourceOptionsRest.rectangle) : undefined;
512
- var fitBounds = clipBounds || tileBounds || sourceRectangleBounds;
561
+ validateRasterSchedulingRange({
562
+ minimumLevel: sourceOptionsRest.minimumLevel,
563
+ hasRenderBounds: !!renderBounds,
564
+ hasSourceRectangle: !!sourceOptionsRest.rectangle
565
+ });
566
+ var fitBounds = renderBounds || sourceRectangleBounds;
513
567
  var tilingScheme = createRenderTilingScheme(createSourceTilingScheme(sourceTilingSchemeOption), renderCrs);
514
568
  var sourceOptions = _objectSpread(_objectSpread({}, sourceOptionsRest), {}, {
515
569
  tilingScheme: tilingScheme
@@ -526,15 +580,25 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
526
580
  _defineProperty(_assertThisInitialized(_this), "source", void 0);
527
581
  _defineProperty(_assertThisInitialized(_this), "_debug", void 0);
528
582
  _defineProperty(_assertThisInitialized(_this), "_clipFeatures", void 0);
583
+ _defineProperty(_assertThisInitialized(_this), "_clipFeatureEntries", void 0);
529
584
  _defineProperty(_assertThisInitialized(_this), "_fitBounds", void 0);
585
+ _defineProperty(_assertThisInitialized(_this), "_clipWorkerUrl", void 0);
586
+ _defineProperty(_assertThisInitialized(_this), "_clipWithWorker", void 0);
587
+ _defineProperty(_assertThisInitialized(_this), "_clipWorkerClient", void 0);
530
588
  _defineProperty(_assertThisInitialized(_this), "_mapContext", void 0);
589
+ _defineProperty(_assertThisInitialized(_this), "_destroyed", void 0);
531
590
  _this.id = options.id;
532
591
  _this.zIndex = options.zIndex;
533
592
  _this.source = imageProvider;
534
593
  _this._debug = options.debug;
535
- _this._clipFeatures = clipFeatures;
594
+ _this._clipFeatures = effectiveClipFeatures;
595
+ _this._clipFeatureEntries = clipFeatureEntries;
536
596
  _this._fitBounds = fitBounds;
597
+ _this._clipWithWorker = (_options$clipWithWork = options.clipWithWorker) !== null && _options$clipWithWork !== void 0 ? _options$clipWithWork : true;
598
+ _this._clipWorkerUrl = (_options$clipWorkerUr = options.clipWorkerUrl) !== null && _options$clipWorkerUr !== void 0 ? _options$clipWorkerUr : '';
599
+ _this._clipWorkerClient = null;
537
600
  _this._mapContext = (_options$map = options.map) === null || _options$map === void 0 ? void 0 : _options$map._mapContext;
601
+ _this._destroyed = false;
538
602
  _this.logDebug({
539
603
  type: 'range',
540
604
  bounds: options.bounds,
@@ -589,6 +653,15 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
589
653
  throw new Error('CustomRasterLayer fitToBounds requires a map camera.');
590
654
  }
591
655
 
656
+ /** 销毁图层并释放裁剪 Worker。 */
657
+ }, {
658
+ key: "destroy",
659
+ value: function destroy() {
660
+ this._destroyed = true;
661
+ this.destroyClipWorkerClient();
662
+ return _get(_getPrototypeOf(CustomRasterLayer.prototype), "destroy", this).call(this);
663
+ }
664
+
592
665
  /**
593
666
  * Cesium 内部纹理创建钩子。
594
667
  *
@@ -600,7 +673,6 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
600
673
  }, {
601
674
  key: "_createTexture",
602
675
  value: function _createTexture(context, imagery) {
603
- var _this2 = this;
604
676
  var tileBbox = rectangleToBounds(imagery.rectangle);
605
677
  this.logDebug({
606
678
  type: 'tile-loaded',
@@ -610,91 +682,263 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
610
682
  bbox: tileBbox,
611
683
  imageSize: getImageSize(imagery.image)
612
684
  });
613
- if (!this._clipFeatures.length) {
685
+ if (!this._clipFeatureEntries.length) {
614
686
  return this.createTexture(context, imagery);
615
687
  }
616
688
  try {
617
- var tileFeature = turf.bboxPolygon(tileBbox);
618
- var isWithin = this._clipFeatures.some(function (feature) {
619
- return turf.booleanWithin(tileFeature, feature);
689
+ return this.createClippedTexture(context, imagery, tileBbox);
690
+ } catch (error) {
691
+ this.logDebug({
692
+ type: 'tile-error',
693
+ x: imagery.x,
694
+ y: imagery.y,
695
+ level: imagery.level,
696
+ bbox: tileBbox,
697
+ error: error
620
698
  });
621
- if (isWithin) {
622
- this.logDebug({
623
- type: 'tile-kept',
624
- x: imagery.x,
625
- y: imagery.y,
626
- level: imagery.level,
627
- bbox: tileBbox,
628
- reason: 'within-clip'
629
- });
630
- return this.createTexture(context, imagery);
699
+ return this.createTexture(context, imagery);
700
+ }
701
+ }
702
+
703
+ /** 调用 Cesium 原始纹理创建逻辑。 */
704
+ }, {
705
+ key: "createTexture",
706
+ value: function createTexture(context, imagery) {
707
+ return ImageryLayer.prototype._createTexture.call(this, context, imagery);
708
+ }
709
+
710
+ /** 根据裁剪面 bbox 粗过滤当前瓦片可能相交的面。 */
711
+ }, {
712
+ key: "getCandidateClipFeatureIndexes",
713
+ value: function getCandidateClipFeatureIndexes(tileBbox) {
714
+ var candidateIndexes = [];
715
+ this._clipFeatureEntries.forEach(function (entry, index) {
716
+ if (boundsIntersects(tileBbox, entry.bbox)) {
717
+ candidateIndexes.push(index);
718
+ }
719
+ });
720
+ return candidateIndexes;
721
+ }
722
+ }, {
723
+ key: "getClipFeatures",
724
+ value: function getClipFeatures(candidateIndexes) {
725
+ var _this2 = this;
726
+ var features = [];
727
+ candidateIndexes.forEach(function (index) {
728
+ var _this2$_clipFeatureEn;
729
+ var feature = (_this2$_clipFeatureEn = _this2._clipFeatureEntries[index]) === null || _this2$_clipFeatureEn === void 0 ? void 0 : _this2$_clipFeatureEn.feature;
730
+ if (feature) {
731
+ features.push(feature);
732
+ }
733
+ });
734
+ return features;
735
+ }
736
+
737
+ // 按需创建裁剪 Worker;初始化失败时自动回退主线程裁剪。
738
+ }, {
739
+ key: "getClipWorkerClient",
740
+ value: function getClipWorkerClient() {
741
+ if (!this._clipWithWorker || this._destroyed || !this._clipFeatureEntries.length) {
742
+ return null;
743
+ }
744
+ if (this._clipWorkerClient) {
745
+ return this._clipWorkerClient;
746
+ }
747
+ try {
748
+ this._clipWorkerClient = new CustomRasterClipWorkerClient({
749
+ features: this._clipFeatureEntries,
750
+ workerUrl: this._clipWorkerUrl || undefined
751
+ });
752
+ return this._clipWorkerClient;
753
+ } catch (error) {
754
+ this._clipWithWorker = false;
755
+ console.warn('栅格裁剪 Worker 初始化失败,已回退主线程裁剪', error);
756
+ return null;
757
+ }
758
+ }
759
+
760
+ // 销毁当前裁剪 Worker,避免销毁后仍有挂起任务占用资源。
761
+ }, {
762
+ key: "destroyClipWorkerClient",
763
+ value: function destroyClipWorkerClient() {
764
+ var _this$_clipWorkerClie;
765
+ (_this$_clipWorkerClie = this._clipWorkerClient) === null || _this$_clipWorkerClie === void 0 || _this$_clipWorkerClie.destroy();
766
+ this._clipWorkerClient = null;
767
+ }
768
+ }, {
769
+ key: "createClippedTexture",
770
+ value: function createClippedTexture(context, imagery, tileBbox) {
771
+ var _this3 = this;
772
+ var candidateIndexes = this.getCandidateClipFeatureIndexes(tileBbox);
773
+ if (!candidateIndexes.length) {
774
+ return this.applyClipResult(context, imagery, tileBbox, {
775
+ status: 'discarded',
776
+ reason: 'outside-clip'
777
+ });
778
+ }
779
+ var clipWorkerClient = this.getClipWorkerClient();
780
+ if (!clipWorkerClient) {
781
+ return this.applyClipResult(context, imagery, tileBbox, this.clipTileOnMainThread(tileBbox, candidateIndexes, imagery));
782
+ }
783
+ void clipWorkerClient.clip({
784
+ tileBbox: tileBbox,
785
+ candidateIndexes: candidateIndexes,
786
+ width: imagery.image.width,
787
+ height: imagery.image.height
788
+ }).then(function (result) {
789
+ if (_this3._destroyed) {
790
+ return;
791
+ }
792
+ _this3.applyClipResult(context, imagery, tileBbox, result);
793
+ }).catch(function (error) {
794
+ _this3.destroyClipWorkerClient();
795
+ _this3._clipWithWorker = false;
796
+ if (_this3._destroyed) {
797
+ return;
631
798
  }
632
- var intersections = this.getClipIntersections(tileFeature);
633
- if (!intersections.length) {
634
- this.logDebug({
635
- type: 'tile-discarded',
799
+ _this3.logDebug({
800
+ type: 'tile-error',
801
+ x: imagery.x,
802
+ y: imagery.y,
803
+ level: imagery.level,
804
+ bbox: tileBbox,
805
+ error: error
806
+ });
807
+ try {
808
+ _this3.applyClipResult(context, imagery, tileBbox, _this3.clipTileOnMainThread(tileBbox, candidateIndexes, imagery));
809
+ } catch (fallbackError) {
810
+ _this3.logDebug({
811
+ type: 'tile-error',
636
812
  x: imagery.x,
637
813
  y: imagery.y,
638
814
  level: imagery.level,
639
815
  bbox: tileBbox,
640
- reason: 'outside-clip'
816
+ error: fallbackError
641
817
  });
642
- imagery.image = this.createTileCanvas(imagery);
643
- return this.createTexture(context, imagery);
644
- }
645
- var canvas = this.createTileCanvas(imagery);
646
- var canvasContext = canvas.getContext('2d');
647
- if (!canvasContext) {
648
- return this.createTexture(context, imagery);
818
+ _this3.createTexture(context, imagery);
649
819
  }
650
- canvasContext.drawImage(imagery.image, 0, 0, imagery.image.width, imagery.image.height);
651
- this.clip(canvasContext, intersections.flatMap(function (intersection) {
652
- return _this2.geometryToPathArray({
820
+ });
821
+ return undefined;
822
+ }
823
+
824
+ /** 主线程裁剪回退逻辑,保持与 Worker 返回结构一致。 */
825
+ }, {
826
+ key: "clipTileOnMainThread",
827
+ value: function clipTileOnMainThread(tileBbox, candidateIndexes, imagery) {
828
+ var _this4 = this;
829
+ var clipFeatures = this.getClipFeatures(candidateIndexes);
830
+ if (!clipFeatures.length) {
831
+ return {
832
+ status: 'discarded',
833
+ reason: 'outside-clip'
834
+ };
835
+ }
836
+ var tileFeature = turf.bboxPolygon(tileBbox);
837
+ var isWithin = clipFeatures.some(function (feature) {
838
+ return turf.booleanWithin(tileFeature, feature);
839
+ });
840
+ if (isWithin) {
841
+ return {
842
+ status: 'kept',
843
+ reason: 'within-clip'
844
+ };
845
+ }
846
+ var intersections = this.getClipIntersections(tileFeature, clipFeatures);
847
+ if (!intersections.length) {
848
+ return {
849
+ status: 'discarded',
850
+ reason: 'outside-clip'
851
+ };
852
+ }
853
+ return {
854
+ status: 'clipped',
855
+ reason: 'intersects-clip',
856
+ paths: intersections.flatMap(function (intersection) {
857
+ return _this4.geometryToPathArray({
653
858
  boundPolygon: intersection,
654
859
  bbox: tileBbox,
655
860
  width: imagery.image.width,
656
861
  height: imagery.image.height
657
862
  });
658
- }));
863
+ })
864
+ };
865
+ }
866
+ }, {
867
+ key: "applyClipResult",
868
+ value: function applyClipResult(context, imagery, tileBbox, result) {
869
+ var _this5 = this;
870
+ if (result.status === 'kept') {
659
871
  this.logDebug({
660
- type: 'tile-clipped',
872
+ type: 'tile-kept',
661
873
  x: imagery.x,
662
874
  y: imagery.y,
663
875
  level: imagery.level,
664
876
  bbox: tileBbox,
665
- reason: 'intersects-clip'
666
- });
667
- void createImageBitmap(canvas).then(function (image) {
668
- imagery.image = image;
669
- _this2.createTexture(context, imagery);
877
+ reason: result.reason
670
878
  });
671
- return undefined;
672
- } catch (error) {
879
+ return this.createTexture(context, imagery);
880
+ }
881
+ if (result.status === 'discarded') {
673
882
  this.logDebug({
674
- type: 'tile-error',
883
+ type: 'tile-discarded',
675
884
  x: imagery.x,
676
885
  y: imagery.y,
677
886
  level: imagery.level,
678
887
  bbox: tileBbox,
679
- error: error
888
+ reason: result.reason
680
889
  });
890
+ imagery.image = this.createTileCanvas(imagery);
681
891
  return this.createTexture(context, imagery);
682
892
  }
893
+ var canvas = this.createTileCanvas(imagery);
894
+ var canvasContext = canvas.getContext('2d');
895
+ if (!canvasContext) {
896
+ return this.createTexture(context, imagery);
897
+ }
898
+ canvasContext.drawImage(imagery.image, 0, 0, imagery.image.width, imagery.image.height);
899
+ this.clip(canvasContext, result.paths);
900
+ this.logDebug({
901
+ type: 'tile-clipped',
902
+ x: imagery.x,
903
+ y: imagery.y,
904
+ level: imagery.level,
905
+ bbox: tileBbox,
906
+ reason: result.reason
907
+ });
908
+ if (typeof createImageBitmap !== 'function') {
909
+ imagery.image = canvas;
910
+ return this.createTexture(context, imagery);
911
+ }
912
+ void createImageBitmap(canvas).then(function (image) {
913
+ if (_this5._destroyed) {
914
+ return;
915
+ }
916
+ imagery.image = image;
917
+ _this5.createTexture(context, imagery);
918
+ }).catch(function (error) {
919
+ if (_this5._destroyed) {
920
+ return;
921
+ }
922
+ _this5.logDebug({
923
+ type: 'tile-error',
924
+ x: imagery.x,
925
+ y: imagery.y,
926
+ level: imagery.level,
927
+ bbox: tileBbox,
928
+ error: error
929
+ });
930
+ imagery.image = canvas;
931
+ _this5.createTexture(context, imagery);
932
+ });
933
+ return undefined;
683
934
  }
684
935
 
685
- /** 调用 Cesium 原始纹理创建逻辑。 */
686
- }, {
687
- key: "createTexture",
688
- value: function createTexture(context, imagery) {
689
- return ImageryLayer.prototype._createTexture.call(this, context, imagery);
690
- }
691
-
692
- /** 获取当前瓦片与所有裁剪面的交集,用交集路径裁剪当前瓦片。 */
936
+ /** 获取当前瓦片与候选裁剪面的交集,用交集路径裁剪当前瓦片。 */
693
937
  }, {
694
938
  key: "getClipIntersections",
695
- value: function getClipIntersections(tileFeature) {
939
+ value: function getClipIntersections(tileFeature, clipFeatures) {
696
940
  var intersections = [];
697
- this._clipFeatures.forEach(function (feature) {
941
+ clipFeatures.forEach(function (feature) {
698
942
  if (!turf.booleanIntersects(tileFeature, feature)) {
699
943
  return;
700
944
  }
@@ -734,7 +978,7 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
734
978
  }, {
735
979
  key: "geometryToPathArray",
736
980
  value: function geometryToPathArray(options) {
737
- var _this3 = this;
981
+ var _this6 = this;
738
982
  var featureType = options.boundPolygon.geometry.type;
739
983
  var pointArr = [];
740
984
  if (featureType === 'Polygon') {
@@ -747,7 +991,7 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
747
991
  });
748
992
  } else if (featureType === 'MultiPolygon') {
749
993
  options.boundPolygon.geometry.coordinates.forEach(function (polygon) {
750
- _this3.pointToPixel({
994
+ _this6.pointToPixel({
751
995
  pointArr: pointArr,
752
996
  coors: polygon,
753
997
  bbox: options.bbox,