deeptwins-engine-3d 0.1.74 → 0.1.75

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,27 @@ 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 createClipFeatureEntries = function createClipFeatureEntries(clipFeatures) {
472
+ return clipFeatures.flatMap(function (feature) {
473
+ var bbox = normalizeBounds(turf.bbox(feature));
474
+ return bbox ? [{
475
+ feature: feature,
476
+ bbox: bbox
477
+ }] : [];
478
+ });
479
+ };
480
+
481
+ /** 高 minimumLevel 必须配合明确范围,避免 Cesium 初始化过多根瓦片。 */
482
+ var validateRasterSchedulingRange = function validateRasterSchedulingRange(options) {
483
+ if ((options.minimumLevel || 0) > 0 && !options.hasRenderBounds && !options.hasSourceRectangle) {
484
+ throw new Error('CustomRasterLayer source.minimumLevel > 0 requires bounds, source.rectangle, or a valid clipFeature bounds.');
485
+ }
486
+ };
453
487
  var getImageSize = function getImageSize(image) {
454
488
  return {
455
489
  width: image.width,
@@ -490,7 +524,7 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
490
524
  var _super = _createSuper(CustomRasterLayer);
491
525
  /** 创建通用栅格图层。 */
492
526
  function CustomRasterLayer(options) {
493
- var _options$map;
527
+ var _options$clipWithWork, _options$clipWorkerUr, _options$map;
494
528
  var _this;
495
529
  _classCallCheck(this, CustomRasterLayer);
496
530
  if (!(options !== null && options !== void 0 && options.source)) {
@@ -500,15 +534,25 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
500
534
  var dataCrs = normalizeCrs(options.dataCrs || DEFAULT_CRS);
501
535
  var clipFeatureCrs = normalizeCrs(options.clipFeatureCrs || dataCrs);
502
536
  var renderCrs = normalizeCrs(options.renderCrs || DEFAULT_CRS);
503
- var transformedClipFeature = transformGeoJson(options.clipFeature, clipFeatureCrs, renderCrs);
537
+ var normalizedClipFeature = normalizeClipFeature(options.clipFeature);
538
+ var transformedClipFeature = normalizedClipFeature ? transformGeoJson(normalizedClipFeature, clipFeatureCrs, renderCrs) : undefined;
504
539
  var clipFeatures = collectPolygonFeatures(transformedClipFeature);
540
+ var clipFeatureEntries = createClipFeatureEntries(clipFeatures);
541
+ var effectiveClipFeatures = clipFeatureEntries.map(function (entry) {
542
+ return entry.feature;
543
+ });
505
544
  var _options$source = options.source,
506
545
  sourceTilingSchemeOption = _options$source.tilingScheme,
507
546
  sourceOptionsRest = _objectWithoutProperties(_options$source, _excluded);
508
547
  var tileBounds = options.bounds ? transformBounds(options.bounds, dataCrs, renderCrs) : undefined;
509
- var clipBounds = getClipFeatureBounds(clipFeatures);
548
+ var clipBounds = getClipFeatureBounds(effectiveClipFeatures);
510
549
  var renderBounds = clipBounds || tileBounds;
511
550
  var sourceRectangleBounds = sourceOptionsRest.rectangle ? rectangleToBounds(sourceOptionsRest.rectangle) : undefined;
551
+ validateRasterSchedulingRange({
552
+ minimumLevel: sourceOptionsRest.minimumLevel,
553
+ hasRenderBounds: !!renderBounds,
554
+ hasSourceRectangle: !!sourceOptionsRest.rectangle
555
+ });
512
556
  var fitBounds = clipBounds || tileBounds || sourceRectangleBounds;
513
557
  var tilingScheme = createRenderTilingScheme(createSourceTilingScheme(sourceTilingSchemeOption), renderCrs);
514
558
  var sourceOptions = _objectSpread(_objectSpread({}, sourceOptionsRest), {}, {
@@ -526,15 +570,25 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
526
570
  _defineProperty(_assertThisInitialized(_this), "source", void 0);
527
571
  _defineProperty(_assertThisInitialized(_this), "_debug", void 0);
528
572
  _defineProperty(_assertThisInitialized(_this), "_clipFeatures", void 0);
573
+ _defineProperty(_assertThisInitialized(_this), "_clipFeatureEntries", void 0);
529
574
  _defineProperty(_assertThisInitialized(_this), "_fitBounds", void 0);
575
+ _defineProperty(_assertThisInitialized(_this), "_clipWorkerUrl", void 0);
576
+ _defineProperty(_assertThisInitialized(_this), "_clipWithWorker", void 0);
577
+ _defineProperty(_assertThisInitialized(_this), "_clipWorkerClient", void 0);
530
578
  _defineProperty(_assertThisInitialized(_this), "_mapContext", void 0);
579
+ _defineProperty(_assertThisInitialized(_this), "_destroyed", void 0);
531
580
  _this.id = options.id;
532
581
  _this.zIndex = options.zIndex;
533
582
  _this.source = imageProvider;
534
583
  _this._debug = options.debug;
535
- _this._clipFeatures = clipFeatures;
584
+ _this._clipFeatures = effectiveClipFeatures;
585
+ _this._clipFeatureEntries = clipFeatureEntries;
536
586
  _this._fitBounds = fitBounds;
587
+ _this._clipWithWorker = (_options$clipWithWork = options.clipWithWorker) !== null && _options$clipWithWork !== void 0 ? _options$clipWithWork : true;
588
+ _this._clipWorkerUrl = (_options$clipWorkerUr = options.clipWorkerUrl) !== null && _options$clipWorkerUr !== void 0 ? _options$clipWorkerUr : '';
589
+ _this._clipWorkerClient = null;
537
590
  _this._mapContext = (_options$map = options.map) === null || _options$map === void 0 ? void 0 : _options$map._mapContext;
591
+ _this._destroyed = false;
538
592
  _this.logDebug({
539
593
  type: 'range',
540
594
  bounds: options.bounds,
@@ -589,6 +643,15 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
589
643
  throw new Error('CustomRasterLayer fitToBounds requires a map camera.');
590
644
  }
591
645
 
646
+ /** 销毁图层并释放裁剪 Worker。 */
647
+ }, {
648
+ key: "destroy",
649
+ value: function destroy() {
650
+ this._destroyed = true;
651
+ this.destroyClipWorkerClient();
652
+ return _get(_getPrototypeOf(CustomRasterLayer.prototype), "destroy", this).call(this);
653
+ }
654
+
592
655
  /**
593
656
  * Cesium 内部纹理创建钩子。
594
657
  *
@@ -600,7 +663,6 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
600
663
  }, {
601
664
  key: "_createTexture",
602
665
  value: function _createTexture(context, imagery) {
603
- var _this2 = this;
604
666
  var tileBbox = rectangleToBounds(imagery.rectangle);
605
667
  this.logDebug({
606
668
  type: 'tile-loaded',
@@ -610,91 +672,263 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
610
672
  bbox: tileBbox,
611
673
  imageSize: getImageSize(imagery.image)
612
674
  });
613
- if (!this._clipFeatures.length) {
675
+ if (!this._clipFeatureEntries.length) {
614
676
  return this.createTexture(context, imagery);
615
677
  }
616
678
  try {
617
- var tileFeature = turf.bboxPolygon(tileBbox);
618
- var isWithin = this._clipFeatures.some(function (feature) {
619
- return turf.booleanWithin(tileFeature, feature);
679
+ return this.createClippedTexture(context, imagery, tileBbox);
680
+ } catch (error) {
681
+ this.logDebug({
682
+ type: 'tile-error',
683
+ x: imagery.x,
684
+ y: imagery.y,
685
+ level: imagery.level,
686
+ bbox: tileBbox,
687
+ error: error
620
688
  });
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);
689
+ return this.createTexture(context, imagery);
690
+ }
691
+ }
692
+
693
+ /** 调用 Cesium 原始纹理创建逻辑。 */
694
+ }, {
695
+ key: "createTexture",
696
+ value: function createTexture(context, imagery) {
697
+ return ImageryLayer.prototype._createTexture.call(this, context, imagery);
698
+ }
699
+
700
+ /** 根据裁剪面 bbox 粗过滤当前瓦片可能相交的面。 */
701
+ }, {
702
+ key: "getCandidateClipFeatureIndexes",
703
+ value: function getCandidateClipFeatureIndexes(tileBbox) {
704
+ var candidateIndexes = [];
705
+ this._clipFeatureEntries.forEach(function (entry, index) {
706
+ if (boundsIntersects(tileBbox, entry.bbox)) {
707
+ candidateIndexes.push(index);
708
+ }
709
+ });
710
+ return candidateIndexes;
711
+ }
712
+ }, {
713
+ key: "getClipFeatures",
714
+ value: function getClipFeatures(candidateIndexes) {
715
+ var _this2 = this;
716
+ var features = [];
717
+ candidateIndexes.forEach(function (index) {
718
+ var _this2$_clipFeatureEn;
719
+ var feature = (_this2$_clipFeatureEn = _this2._clipFeatureEntries[index]) === null || _this2$_clipFeatureEn === void 0 ? void 0 : _this2$_clipFeatureEn.feature;
720
+ if (feature) {
721
+ features.push(feature);
722
+ }
723
+ });
724
+ return features;
725
+ }
726
+
727
+ // 按需创建裁剪 Worker;初始化失败时自动回退主线程裁剪。
728
+ }, {
729
+ key: "getClipWorkerClient",
730
+ value: function getClipWorkerClient() {
731
+ if (!this._clipWithWorker || this._destroyed || !this._clipFeatureEntries.length) {
732
+ return null;
733
+ }
734
+ if (this._clipWorkerClient) {
735
+ return this._clipWorkerClient;
736
+ }
737
+ try {
738
+ this._clipWorkerClient = new CustomRasterClipWorkerClient({
739
+ features: this._clipFeatureEntries,
740
+ workerUrl: this._clipWorkerUrl || undefined
741
+ });
742
+ return this._clipWorkerClient;
743
+ } catch (error) {
744
+ this._clipWithWorker = false;
745
+ console.warn('栅格裁剪 Worker 初始化失败,已回退主线程裁剪', error);
746
+ return null;
747
+ }
748
+ }
749
+
750
+ // 销毁当前裁剪 Worker,避免销毁后仍有挂起任务占用资源。
751
+ }, {
752
+ key: "destroyClipWorkerClient",
753
+ value: function destroyClipWorkerClient() {
754
+ var _this$_clipWorkerClie;
755
+ (_this$_clipWorkerClie = this._clipWorkerClient) === null || _this$_clipWorkerClie === void 0 || _this$_clipWorkerClie.destroy();
756
+ this._clipWorkerClient = null;
757
+ }
758
+ }, {
759
+ key: "createClippedTexture",
760
+ value: function createClippedTexture(context, imagery, tileBbox) {
761
+ var _this3 = this;
762
+ var candidateIndexes = this.getCandidateClipFeatureIndexes(tileBbox);
763
+ if (!candidateIndexes.length) {
764
+ return this.applyClipResult(context, imagery, tileBbox, {
765
+ status: 'discarded',
766
+ reason: 'outside-clip'
767
+ });
768
+ }
769
+ var clipWorkerClient = this.getClipWorkerClient();
770
+ if (!clipWorkerClient) {
771
+ return this.applyClipResult(context, imagery, tileBbox, this.clipTileOnMainThread(tileBbox, candidateIndexes, imagery));
772
+ }
773
+ void clipWorkerClient.clip({
774
+ tileBbox: tileBbox,
775
+ candidateIndexes: candidateIndexes,
776
+ width: imagery.image.width,
777
+ height: imagery.image.height
778
+ }).then(function (result) {
779
+ if (_this3._destroyed) {
780
+ return;
631
781
  }
632
- var intersections = this.getClipIntersections(tileFeature);
633
- if (!intersections.length) {
634
- this.logDebug({
635
- type: 'tile-discarded',
782
+ _this3.applyClipResult(context, imagery, tileBbox, result);
783
+ }).catch(function (error) {
784
+ _this3.destroyClipWorkerClient();
785
+ _this3._clipWithWorker = false;
786
+ if (_this3._destroyed) {
787
+ return;
788
+ }
789
+ _this3.logDebug({
790
+ type: 'tile-error',
791
+ x: imagery.x,
792
+ y: imagery.y,
793
+ level: imagery.level,
794
+ bbox: tileBbox,
795
+ error: error
796
+ });
797
+ try {
798
+ _this3.applyClipResult(context, imagery, tileBbox, _this3.clipTileOnMainThread(tileBbox, candidateIndexes, imagery));
799
+ } catch (fallbackError) {
800
+ _this3.logDebug({
801
+ type: 'tile-error',
636
802
  x: imagery.x,
637
803
  y: imagery.y,
638
804
  level: imagery.level,
639
805
  bbox: tileBbox,
640
- reason: 'outside-clip'
806
+ error: fallbackError
641
807
  });
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);
808
+ _this3.createTexture(context, imagery);
649
809
  }
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({
810
+ });
811
+ return undefined;
812
+ }
813
+
814
+ /** 主线程裁剪回退逻辑,保持与 Worker 返回结构一致。 */
815
+ }, {
816
+ key: "clipTileOnMainThread",
817
+ value: function clipTileOnMainThread(tileBbox, candidateIndexes, imagery) {
818
+ var _this4 = this;
819
+ var clipFeatures = this.getClipFeatures(candidateIndexes);
820
+ if (!clipFeatures.length) {
821
+ return {
822
+ status: 'discarded',
823
+ reason: 'outside-clip'
824
+ };
825
+ }
826
+ var tileFeature = turf.bboxPolygon(tileBbox);
827
+ var isWithin = clipFeatures.some(function (feature) {
828
+ return turf.booleanWithin(tileFeature, feature);
829
+ });
830
+ if (isWithin) {
831
+ return {
832
+ status: 'kept',
833
+ reason: 'within-clip'
834
+ };
835
+ }
836
+ var intersections = this.getClipIntersections(tileFeature, clipFeatures);
837
+ if (!intersections.length) {
838
+ return {
839
+ status: 'discarded',
840
+ reason: 'outside-clip'
841
+ };
842
+ }
843
+ return {
844
+ status: 'clipped',
845
+ reason: 'intersects-clip',
846
+ paths: intersections.flatMap(function (intersection) {
847
+ return _this4.geometryToPathArray({
653
848
  boundPolygon: intersection,
654
849
  bbox: tileBbox,
655
850
  width: imagery.image.width,
656
851
  height: imagery.image.height
657
852
  });
658
- }));
853
+ })
854
+ };
855
+ }
856
+ }, {
857
+ key: "applyClipResult",
858
+ value: function applyClipResult(context, imagery, tileBbox, result) {
859
+ var _this5 = this;
860
+ if (result.status === 'kept') {
659
861
  this.logDebug({
660
- type: 'tile-clipped',
862
+ type: 'tile-kept',
661
863
  x: imagery.x,
662
864
  y: imagery.y,
663
865
  level: imagery.level,
664
866
  bbox: tileBbox,
665
- reason: 'intersects-clip'
867
+ reason: result.reason
666
868
  });
667
- void createImageBitmap(canvas).then(function (image) {
668
- imagery.image = image;
669
- _this2.createTexture(context, imagery);
670
- });
671
- return undefined;
672
- } catch (error) {
869
+ return this.createTexture(context, imagery);
870
+ }
871
+ if (result.status === 'discarded') {
673
872
  this.logDebug({
674
- type: 'tile-error',
873
+ type: 'tile-discarded',
675
874
  x: imagery.x,
676
875
  y: imagery.y,
677
876
  level: imagery.level,
678
877
  bbox: tileBbox,
679
- error: error
878
+ reason: result.reason
680
879
  });
880
+ imagery.image = this.createTileCanvas(imagery);
681
881
  return this.createTexture(context, imagery);
682
882
  }
883
+ var canvas = this.createTileCanvas(imagery);
884
+ var canvasContext = canvas.getContext('2d');
885
+ if (!canvasContext) {
886
+ return this.createTexture(context, imagery);
887
+ }
888
+ canvasContext.drawImage(imagery.image, 0, 0, imagery.image.width, imagery.image.height);
889
+ this.clip(canvasContext, result.paths);
890
+ this.logDebug({
891
+ type: 'tile-clipped',
892
+ x: imagery.x,
893
+ y: imagery.y,
894
+ level: imagery.level,
895
+ bbox: tileBbox,
896
+ reason: result.reason
897
+ });
898
+ if (typeof createImageBitmap !== 'function') {
899
+ imagery.image = canvas;
900
+ return this.createTexture(context, imagery);
901
+ }
902
+ void createImageBitmap(canvas).then(function (image) {
903
+ if (_this5._destroyed) {
904
+ return;
905
+ }
906
+ imagery.image = image;
907
+ _this5.createTexture(context, imagery);
908
+ }).catch(function (error) {
909
+ if (_this5._destroyed) {
910
+ return;
911
+ }
912
+ _this5.logDebug({
913
+ type: 'tile-error',
914
+ x: imagery.x,
915
+ y: imagery.y,
916
+ level: imagery.level,
917
+ bbox: tileBbox,
918
+ error: error
919
+ });
920
+ imagery.image = canvas;
921
+ _this5.createTexture(context, imagery);
922
+ });
923
+ return undefined;
683
924
  }
684
925
 
685
- /** 调用 Cesium 原始纹理创建逻辑。 */
686
- }, {
687
- key: "createTexture",
688
- value: function createTexture(context, imagery) {
689
- return ImageryLayer.prototype._createTexture.call(this, context, imagery);
690
- }
691
-
692
- /** 获取当前瓦片与所有裁剪面的交集,用交集路径裁剪当前瓦片。 */
926
+ /** 获取当前瓦片与候选裁剪面的交集,用交集路径裁剪当前瓦片。 */
693
927
  }, {
694
928
  key: "getClipIntersections",
695
- value: function getClipIntersections(tileFeature) {
929
+ value: function getClipIntersections(tileFeature, clipFeatures) {
696
930
  var intersections = [];
697
- this._clipFeatures.forEach(function (feature) {
931
+ clipFeatures.forEach(function (feature) {
698
932
  if (!turf.booleanIntersects(tileFeature, feature)) {
699
933
  return;
700
934
  }
@@ -734,7 +968,7 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
734
968
  }, {
735
969
  key: "geometryToPathArray",
736
970
  value: function geometryToPathArray(options) {
737
- var _this3 = this;
971
+ var _this6 = this;
738
972
  var featureType = options.boundPolygon.geometry.type;
739
973
  var pointArr = [];
740
974
  if (featureType === 'Polygon') {
@@ -747,7 +981,7 @@ var CustomRasterLayer = /*#__PURE__*/function (_ImageryLayer) {
747
981
  });
748
982
  } else if (featureType === 'MultiPolygon') {
749
983
  options.boundPolygon.geometry.coordinates.forEach(function (polygon) {
750
- _this3.pointToPixel({
984
+ _this6.pointToPixel({
751
985
  pointArr: pointArr,
752
986
  coors: polygon,
753
987
  bbox: options.bbox,