deeptwins-engine-3d 0.1.48 → 0.1.49

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.
@@ -15,6 +15,7 @@ import ModelPrimitiveInstance from "./graphicLayer/ModelPrimitiveInstance";
15
15
  import PointEntity from "./graphicLayer/PointEntity";
16
16
  import PointPrimitive from "./graphicLayer/PointPrimitive";
17
17
  import PolygonEntity from "./graphicLayer/PolygonEntity";
18
+ import PolygonGroundPrimitiveImageMaterialInstance from "./graphicLayer/PolygonGroundPrimitiveImageMaterialInstance";
18
19
  import PolygonPrimitiveImageMaterialInstance from "./graphicLayer/PolygonPrimitiveImageMaterialInstance";
19
20
  import PolygonPrimitiveInstance from "./graphicLayer/PolygonPrimitiveInstance";
20
21
  import PolylineEntity from "./graphicLayer/PolylineEntity";
@@ -639,6 +640,7 @@ export var GRAPHIC_LAYER_TYPE_TO_CLASS = {
639
640
  polygonP: PolygonPrimitiveInstance,
640
641
  polygonImageP: PolygonPrimitiveImageMaterialInstance,
641
642
  polygonGroundP: PolygonPrimitiveInstance,
643
+ polygonGroundImageP: PolygonGroundPrimitiveImageMaterialInstance,
642
644
  boxP: BoxPrimitiveInstance,
643
645
  modelP: ModelPrimitiveInstance,
644
646
  labelP: LabelPrimitive,
@@ -115,6 +115,9 @@ var BaseLayer = /*#__PURE__*/function () {
115
115
  polygonImageP: function polygonImageP() {
116
116
  _this2.primitiveCollection = new PolygonPrimitive(_this2._mapContext);
117
117
  },
118
+ polygonGroundImageP: function polygonGroundImageP() {
119
+ _this2.primitiveCollection = new PolygonPrimitive(_this2._mapContext);
120
+ },
118
121
  polygonGroundP: function polygonGroundP() {
119
122
  _this2.primitiveCollection = new PolygonGroundPrimitive(_this2._mapContext);
120
123
  },
@@ -1,9 +1,11 @@
1
1
  export default class BasePrimitiveInstance {
2
+ private readonly _mapContext;
2
3
  id: any;
3
4
  source: any;
4
5
  style: any;
5
6
  type: string;
6
7
  readonly isPrimitive: boolean;
7
8
  constructor(options: any);
9
+ getMap(): any;
8
10
  updateStyle(): void;
9
11
  }
@@ -6,11 +6,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
6
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
7
  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); }
8
8
  import { v4 as uuidv4 } from 'uuid';
9
-
10
9
  // 基础PrimitiveInstance图层
11
10
  var BasePrimitiveInstance = /*#__PURE__*/function () {
12
11
  function BasePrimitiveInstance(options) {
13
12
  _classCallCheck(this, BasePrimitiveInstance);
13
+ _defineProperty(this, "_mapContext", void 0);
14
14
  _defineProperty(this, "id", void 0);
15
15
  _defineProperty(this, "source", void 0);
16
16
  _defineProperty(this, "style", void 0);
@@ -18,14 +18,22 @@ var BasePrimitiveInstance = /*#__PURE__*/function () {
18
18
  _defineProperty(this, "isPrimitive", true);
19
19
  this.id = uuidv4();
20
20
  var style = options.style,
21
- source = options.source;
22
- this.type = options.type;
21
+ source = options.source,
22
+ type = options.type,
23
+ mapContext = options.mapContext;
24
+ this._mapContext = mapContext;
25
+ this.type = type;
23
26
  this.source = source;
24
27
  this.style = style || {};
25
28
  }
26
-
27
- // 更新样式
28
29
  _createClass(BasePrimitiveInstance, [{
30
+ key: "getMap",
31
+ value: function getMap() {
32
+ return this._mapContext && this._mapContext.getMap();
33
+ }
34
+
35
+ // 更新样式
36
+ }, {
29
37
  key: "updateStyle",
30
38
  value: function updateStyle() {
31
39
  console.warn("".concat(this.type, "\u7C7B\u578B\u4E0D\u652F\u6301\u66F4\u65B0\u6837\u5F0F"));
@@ -15,7 +15,7 @@ export default class BaseSource {
15
15
  remove(): void;
16
16
  setData(data: any): this | undefined;
17
17
  _toDestroy(): void;
18
- static analysisSourceType(data: any): "other" | "wkt" | "sourceId" | "sourceInstance" | "geoJson";
18
+ static analysisSourceType(data: any): "clampedPolygonGrid" | "wkt" | "sourceId" | "sourceInstance" | "geoJson" | "other";
19
19
  static wktToGeoJon(wkt: string): any;
20
20
  static geoJsonToGeoCartesian3Array(geoJson: any): any[];
21
21
  static handleFeaturePoint(feature: any): any;
@@ -100,6 +100,9 @@ var BaseSource = /*#__PURE__*/function () {
100
100
  this._handleGeoJson(source);
101
101
  } else if (sourceType === 'wkt') {
102
102
  this._handleGeoJson(BaseSource.wktToGeoJon(source));
103
+ } else if (sourceType === 'clampedPolygonGrid') {
104
+ // 贴地网格
105
+ this.source = source.source;
103
106
  } else {
104
107
  throw new Error('数据格式错误');
105
108
  }
@@ -152,6 +155,9 @@ var BaseSource = /*#__PURE__*/function () {
152
155
  return 'sourceInstance';
153
156
  } else if (data.type === 'Feature' || data.type === 'FeatureCollection') {
154
157
  return 'geoJson';
158
+ } else if (data.type === 'clampedPolygonGrid') {
159
+ // 贴地网格
160
+ return 'clampedPolygonGrid';
155
161
  } else {
156
162
  return 'other';
157
163
  }
@@ -0,0 +1,5 @@
1
+ import PolygonPrimitiveInstance from './PolygonPrimitiveInstance';
2
+ export default class PolygonGroundPrimitiveImageMaterialInstance extends PolygonPrimitiveInstance {
3
+ constructor(options: any);
4
+ _init(options: any): void;
5
+ }
@@ -0,0 +1,84 @@
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
+ var _excluded = ["color", "stRotation"];
3
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ 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); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ 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); }
10
+ 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
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
+ 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); }; }
13
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
14
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
15
+ 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; } }
16
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
17
+ import * as Cesium from 'deeptwins-cesium';
18
+ import * as utils from "../tool/utils";
19
+ import PolygonPrimitiveInstance from "./PolygonPrimitiveInstance";
20
+
21
+ // polygon ground Primitive 图片材质贴图
22
+ var PolygonGroundPrimitiveImageMaterialInstance = /*#__PURE__*/function (_PolygonPrimitiveInst) {
23
+ _inherits(PolygonGroundPrimitiveImageMaterialInstance, _PolygonPrimitiveInst);
24
+ var _super = _createSuper(PolygonGroundPrimitiveImageMaterialInstance);
25
+ function PolygonGroundPrimitiveImageMaterialInstance(options) {
26
+ _classCallCheck(this, PolygonGroundPrimitiveImageMaterialInstance);
27
+ return _super.call(this, options);
28
+ }
29
+
30
+ // 初始化
31
+ _createClass(PolygonGroundPrimitiveImageMaterialInstance, [{
32
+ key: "_init",
33
+ value: function _init(options) {
34
+ var _options$style = options.style,
35
+ color = _options$style.color,
36
+ stRotation = _options$style.stRotation,
37
+ style = _objectWithoutProperties(_options$style, _excluded),
38
+ positions = options.positions,
39
+ indices = options.indices,
40
+ primitiveInstance = options.primitiveInstance;
41
+ if (!indices || indices.length < 3) return;
42
+ if (!positions || positions.length < 3) return;
43
+ var geometry = new Cesium.Geometry({
44
+ // @ts-ignore
45
+ attributes: {
46
+ position: new Cesium.GeometryAttribute({
47
+ componentDatatype: Cesium.ComponentDatatype.DOUBLE,
48
+ componentsPerAttribute: 3,
49
+ values: Cesium.Cartesian3.packArray(positions)
50
+ })
51
+ },
52
+ indices: new Uint32Array(indices),
53
+ primitiveType: Cesium.PrimitiveType.TRIANGLES,
54
+ boundingSphere: Cesium.BoundingSphere.fromPoints(positions)
55
+ });
56
+ if (!style.extrudedHeight) {
57
+ var posAttr = geometry.attributes.position;
58
+ var vertexCount = posAttr.values.length / 3;
59
+ var finalPositions = [];
60
+ for (var i = 0; i < vertexCount; i++) {
61
+ finalPositions.push(new Cesium.Cartesian3(posAttr.values[i * 3], posAttr.values[i * 3 + 1], posAttr.values[i * 3 + 2]));
62
+ }
63
+ geometry.attributes.st = new Cesium.GeometryAttribute({
64
+ componentDatatype: Cesium.ComponentDatatype.FLOAT,
65
+ componentsPerAttribute: 2,
66
+ values: utils.computeSTAlongPlane(finalPositions, stRotation)
67
+ });
68
+ } else {
69
+ utils.error('不支持extrudedHeight');
70
+ return;
71
+ }
72
+ var instance = new Cesium.GeometryInstance({
73
+ id: this.id,
74
+ geometry: geometry,
75
+ attributes: {
76
+ color: color
77
+ }
78
+ });
79
+ primitiveInstance.push(instance);
80
+ }
81
+ }]);
82
+ return PolygonGroundPrimitiveImageMaterialInstance;
83
+ }(PolygonPrimitiveInstance);
84
+ export { PolygonGroundPrimitiveImageMaterialInstance as default };
@@ -51,10 +51,16 @@ var PolygonPrimitiveImageMaterialInstance = /*#__PURE__*/function (_PolygonPrimi
51
51
  }, style));
52
52
  if (!style.extrudedHeight) {
53
53
  geometry = Cesium.PolygonGeometry.createGeometry(polygonGeometry);
54
+ var posAttr = geometry.attributes.position;
55
+ var vertexCount = posAttr.values.length / 3;
56
+ var finalPositions = [];
57
+ for (var i = 0; i < vertexCount; i++) {
58
+ finalPositions.push(new Cesium.Cartesian3(posAttr.values[i * 3], posAttr.values[i * 3 + 1], posAttr.values[i * 3 + 2]));
59
+ }
54
60
  geometry.attributes.st = new Cesium.GeometryAttribute({
55
61
  componentDatatype: Cesium.ComponentDatatype.FLOAT,
56
62
  componentsPerAttribute: 2,
57
- values: utils.computeSTAlongPlane(positions, stRotation)
63
+ values: utils.computeSTAlongPlane(finalPositions, stRotation)
58
64
  });
59
65
  } else {
60
66
  utils.error('不支持extrudedHeight');
@@ -24,7 +24,7 @@ import { DEFAULT_POLYLINE_PRIMITIVE_OPTIONS } from "../constant";
24
24
  import * as utils from "../tool/utils";
25
25
  import BasePrimitiveInstance from "./BasePrimitiveInstance";
26
26
 
27
- // 线实体图层
27
+ // 线 primitive 实体图层
28
28
  var PolylineGroundPrimitiveInstance = /*#__PURE__*/function (_BasePrimitiveInstanc) {
29
29
  _inherits(PolylineGroundPrimitiveInstance, _BasePrimitiveInstanc);
30
30
  var _super = _createSuper(PolylineGroundPrimitiveInstance);
@@ -70,5 +70,6 @@ export declare class DeepTwinsEngine3D {
70
70
  static PoiLayer: any;
71
71
  static FlightPlanning: any;
72
72
  static FlightRiskEvaluation: any;
73
+ static BuildClampedPolygonGrid: any;
73
74
  }
74
75
  export default DeepTwinsEngine3D;
package/dist/esm/index.js CHANGED
@@ -42,6 +42,7 @@ import ArcGisLayer from "./tileLayer/ArcGisLayer";
42
42
  import RasterLayer from "./tileLayer/RasterLayer";
43
43
  import WmsLayer from "./tileLayer/WmsLayer";
44
44
  import WmtsLayer from "./tileLayer/WmtsLayer";
45
+ import BuildClampedPolygonGrid from "./tool/BuildClampedPolygonGrid";
45
46
  import Compass from "./tool/Compass";
46
47
  import TimerInterval from "./tool/TimerInterval";
47
48
  import { ClampToGround, ShapeSection } from "./tool/common";
@@ -58,11 +59,11 @@ DEEP_TWINS_BASE_URL && (window.CESIUM_BASE_URL = DEEP_TWINS_BASE_URL);
58
59
  // 全局加载css
59
60
  loadCss(Cesium.buildModuleUrl('Widgets/widgets.css'));
60
61
  // 打印版本信息
61
- console.log('DeepTwinsEngine3D Version:', "0.1.48");
62
+ console.log('DeepTwinsEngine3D Version:', "0.1.49");
62
63
  export var DeepTwinsEngine3D = /*#__PURE__*/_createClass(function DeepTwinsEngine3D() {
63
64
  _classCallCheck(this, DeepTwinsEngine3D);
64
65
  });
65
- _defineProperty(DeepTwinsEngine3D, "Version", "0.1.48");
66
+ _defineProperty(DeepTwinsEngine3D, "Version", "0.1.49");
66
67
  _defineProperty(DeepTwinsEngine3D, "Map", Map);
67
68
  _defineProperty(DeepTwinsEngine3D, "GroundSkyBox", GroundSkyBox);
68
69
  _defineProperty(DeepTwinsEngine3D, "RasterLayer", RasterLayer);
@@ -132,4 +133,5 @@ _defineProperty(DeepTwinsEngine3D, "VisitLayer", VisitLayer);
132
133
  _defineProperty(DeepTwinsEngine3D, "PoiLayer", PoiLayer);
133
134
  _defineProperty(DeepTwinsEngine3D, "FlightPlanning", FlightPlanning);
134
135
  _defineProperty(DeepTwinsEngine3D, "FlightRiskEvaluation", FlightRiskEvaluation);
136
+ _defineProperty(DeepTwinsEngine3D, "BuildClampedPolygonGrid", BuildClampedPolygonGrid);
135
137
  export default DeepTwinsEngine3D;
@@ -270,10 +270,10 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
270
270
  if (!deepTwins && !this._yunjing) {
271
271
  !isNil(show) && (this.scene.globe.show = show);
272
272
  !isNil(showGroundAtmosphere) && (this.scene.globe.showGroundAtmosphere = showGroundAtmosphere);
273
- !isNil(depthTestAgainstTerrain) && (this.scene.globe.depthTestAgainstTerrain = depthTestAgainstTerrain);
274
273
  !isNil(baseColor) && (this.scene.globe.baseColor = utils.colorString(baseColor));
275
274
  !isNil(enableLighting) && (this.scene.globe.enableLighting = enableLighting);
276
275
  }
276
+ !isNil(depthTestAgainstTerrain) && (this.scene.globe.depthTestAgainstTerrain = depthTestAgainstTerrain);
277
277
  }
278
278
 
279
279
  // 添加默认近地天空盒
@@ -0,0 +1,11 @@
1
+ import * as Cesium from 'deeptwins-cesium';
2
+ /**
3
+ * 构建贴地的多边形网格
4
+ */
5
+ export default function BuildClampedPolygonGrid(map: any, geoJson: any, gridSize?: number, heightBuffer?: number): Promise<{
6
+ type: string;
7
+ source: {
8
+ positions: Cesium.Cartesian3[];
9
+ indices: number[];
10
+ }[];
11
+ }>;
@@ -0,0 +1,151 @@
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
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ import * as Cesium from 'deeptwins-cesium';
6
+ import BaseSource from "../graphicLayer/BaseSource";
7
+ import { translateSource } from "../tool/common";
8
+ import * as utils from "./utils";
9
+ function pointInPolygon(pt, polygon) {
10
+ var inside = false;
11
+ for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
12
+ var xi = polygon[i].x,
13
+ yi = polygon[i].y;
14
+ var xj = polygon[j].x,
15
+ yj = polygon[j].y;
16
+ var intersect = yi > pt.y !== yj > pt.y && pt.x < (xj - xi) * (pt.y - yi) / (yj - yi) + xi;
17
+ if (intersect) inside = !inside;
18
+ }
19
+ return inside;
20
+ }
21
+
22
+ // 修改 buildGridIndices:不删顶点,只生成 polygon 内部三角形索引
23
+ function buildGridIndices(cols, rows, polygon, gridPoints2D, step) {
24
+ var indices = [];
25
+ for (var y = 0; y < rows - 1; y++) {
26
+ for (var x = 0; x < cols - 1; x++) {
27
+ var i0 = y * cols + x;
28
+ var i1 = i0 + 1;
29
+ var i2 = i0 + cols;
30
+ var i3 = i2 + 1;
31
+
32
+ // 三角形中心点,判断是否在 polygon 内
33
+ var cx = (x + 0.5) * step + gridPoints2D[0].x; // 这里偏移加上最小X
34
+ var cy = (y + 0.5) * step + gridPoints2D[0].y; // 偏移加上最小Y
35
+ if (pointInPolygon(new Cesium.Cartesian2(cx, cy), polygon)) {
36
+ indices.push(i0, i1, i2);
37
+ indices.push(i1, i3, i2);
38
+ }
39
+ }
40
+ }
41
+ return indices;
42
+ }
43
+
44
+ /**
45
+ * 构建贴地的多边形网格
46
+ */
47
+ export default function BuildClampedPolygonGrid(_x, _x2) {
48
+ return _BuildClampedPolygonGrid.apply(this, arguments);
49
+ }
50
+ function _BuildClampedPolygonGrid() {
51
+ _BuildClampedPolygonGrid = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(map, geoJson) {
52
+ var gridSize,
53
+ heightBuffer,
54
+ translatedSource,
55
+ source,
56
+ finalSource,
57
+ _loop,
58
+ i,
59
+ _args2 = arguments;
60
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
61
+ while (1) switch (_context2.prev = _context2.next) {
62
+ case 0:
63
+ gridSize = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : 10;
64
+ heightBuffer = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : 0.5;
65
+ if (!(!map.terrainProvider || map.terrainProvider instanceof Cesium.EllipsoidTerrainProvider)) {
66
+ _context2.next = 4;
67
+ break;
68
+ }
69
+ throw new Error('请设置地形');
70
+ case 4:
71
+ translatedSource = translateSource(geoJson);
72
+ source = BaseSource.geoJsonToGeoCartesian3Array(translatedSource);
73
+ finalSource = [];
74
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
75
+ var positions, ring, center, plane, poly2D, minX, minY, maxX, maxY, cols, rows, gridPoints2D, y, x, indices, positions3D, cartographics, clamped, finalPositions;
76
+ return _regeneratorRuntime().wrap(function _loop$(_context) {
77
+ while (1) switch (_context.prev = _context.next) {
78
+ case 0:
79
+ positions = source[i].positions; // 1️⃣ 去闭合
80
+ ring = utils.buildPolygonHierarchy(positions).positions; // 2️⃣ 局部切平面
81
+ center = Cesium.BoundingSphere.fromPoints(ring).center;
82
+ plane = new Cesium.EllipsoidTangentPlane(center, Cesium.Ellipsoid.WGS84); // 3️⃣ 投影到 2D
83
+ poly2D = ring.map(function (p) {
84
+ return plane.projectPointOntoPlane(p);
85
+ }); // 4️⃣ 包围盒
86
+ minX = Infinity, minY = Infinity;
87
+ maxX = -Infinity, maxY = -Infinity;
88
+ poly2D.forEach(function (p) {
89
+ minX = Math.min(minX, p.x);
90
+ minY = Math.min(minY, p.y);
91
+ maxX = Math.max(maxX, p.x);
92
+ maxY = Math.max(maxY, p.y);
93
+ });
94
+ cols = Math.floor((maxX - minX) / gridSize) + 1;
95
+ rows = Math.floor((maxY - minY) / gridSize) + 1; // 5️⃣ 生成完整规则网格点(不删点)
96
+ gridPoints2D = [];
97
+ for (y = 0; y < rows; y++) {
98
+ for (x = 0; x < cols; x++) {
99
+ gridPoints2D.push(new Cesium.Cartesian2(minX + x * gridSize, minY + y * gridSize));
100
+ }
101
+ }
102
+
103
+ // 6️⃣ 生成三角形索引(只保留 polygon 内部三角形)
104
+ indices = buildGridIndices(cols, rows, poly2D, gridPoints2D, gridSize); // 7️⃣ 回投 3D
105
+ positions3D = gridPoints2D.map(function (p) {
106
+ return plane.projectPointOntoEllipsoid(p);
107
+ }); // 8️⃣ 贴地
108
+ cartographics = positions3D.map(function (p) {
109
+ return Cesium.Cartographic.fromCartesian(p);
110
+ });
111
+ _context.next = 17;
112
+ return Cesium.sampleTerrainMostDetailed(map.terrainProvider, cartographics);
113
+ case 17:
114
+ clamped = _context.sent;
115
+ finalPositions = clamped.map(function (c) {
116
+ return Cesium.Cartesian3.fromRadians(c.longitude, c.latitude, c.height + heightBuffer);
117
+ });
118
+ finalSource.push({
119
+ positions: finalPositions,
120
+ indices: indices
121
+ });
122
+ case 20:
123
+ case "end":
124
+ return _context.stop();
125
+ }
126
+ }, _loop);
127
+ });
128
+ i = 0;
129
+ case 9:
130
+ if (!(i < source.length)) {
131
+ _context2.next = 14;
132
+ break;
133
+ }
134
+ return _context2.delegateYield(_loop(), "t0", 11);
135
+ case 11:
136
+ i++;
137
+ _context2.next = 9;
138
+ break;
139
+ case 14:
140
+ return _context2.abrupt("return", {
141
+ type: 'clampedPolygonGrid',
142
+ source: finalSource
143
+ });
144
+ case 15:
145
+ case "end":
146
+ return _context2.stop();
147
+ }
148
+ }, _callee);
149
+ }));
150
+ return _BuildClampedPolygonGrid.apply(this, arguments);
151
+ }
@@ -11,6 +11,11 @@ export declare const arrCartesian3: (data: any[]) => Cesium.Cartesian3;
11
11
  export declare const toDegrees: (radians: number, precision?: number) => number;
12
12
  export declare const toRadians: (degrees: number) => number;
13
13
  export declare const lngLatAltToCartographic: (lng: number, lat: number, alt?: number) => Cesium.Cartographic;
14
+ export declare const cartographicToLngLatAlt: (cartographic: any) => {
15
+ lng: number;
16
+ lat: number;
17
+ alt: any;
18
+ };
14
19
  export declare const cartesian3ToLngLatAlt: (cartesian3: any) => {
15
20
  lng: number;
16
21
  lat: number;
@@ -18,6 +23,8 @@ export declare const cartesian3ToLngLatAlt: (cartesian3: any) => {
18
23
  };
19
24
  export declare const lngLatAltToCartesian3: (lng: number, lat: number, alt?: number) => Cesium.Cartesian3;
20
25
  export declare const lngLatAltArrayToCartesian3Array: (lngLatAltArray: any[]) => Cesium.Cartesian3[];
26
+ export declare const cartesian3ToCartographic: (cartesian3: any) => Cesium.Cartographic;
27
+ export declare const cartographicToCartesian3: (cartographic: any) => Cesium.Cartesian3;
21
28
  export declare const isWKT: (str: string) => boolean;
22
29
  export declare const styleFun: (style: any, properties: any) => any;
23
30
  export declare const dateToJulianDate: (date: Date) => Cesium.JulianDate;
@@ -63,3 +70,4 @@ export declare function getMidpoint(position1: Cartesian3, position2: Cartesian3
63
70
  lat: number;
64
71
  alt: number;
65
72
  };
73
+ export declare function densifyLine(p1: Cartesian3, p2: Cartesian3, count?: number): Cesium.Cartesian3[];
@@ -149,6 +149,15 @@ export var lngLatAltToCartographic = function lngLatAltToCartographic(lng, lat)
149
149
  return Cesium.Cartographic.fromDegrees(lng, lat, alt);
150
150
  };
151
151
 
152
+ // Cartographic转经纬度
153
+ export var cartographicToLngLatAlt = function cartographicToLngLatAlt(cartographic) {
154
+ return {
155
+ lng: toDegrees(cartographic.longitude),
156
+ lat: toDegrees(cartographic.latitude),
157
+ alt: cartographic.height || 0
158
+ };
159
+ };
160
+
152
161
  // Cartesian3转经纬度
153
162
  export var cartesian3ToLngLatAlt = function cartesian3ToLngLatAlt(cartesian3) {
154
163
  var cartographic = Cesium.Cartographic.fromCartesian(cartesian3);
@@ -178,6 +187,16 @@ export var lngLatAltArrayToCartesian3Array = function lngLatAltArrayToCartesian3
178
187
  return Cesium.Cartesian3.fromDegreesArrayHeights(lngLatAltArrayString);
179
188
  };
180
189
 
190
+ // Cartesian3转Cartographic
191
+ export var cartesian3ToCartographic = function cartesian3ToCartographic(cartesian3) {
192
+ return Cesium.Cartographic.fromCartesian(cartesian3);
193
+ };
194
+
195
+ // Cartographic转Cartesian3
196
+ export var cartographicToCartesian3 = function cartographicToCartesian3(cartographic) {
197
+ return Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height);
198
+ };
199
+
181
200
  // 是否是wkt类型的字符串
182
201
  export var isWKT = function isWKT(str) {
183
202
  return str.startsWith('POINT') || str.startsWith('LINESTRING') || str.startsWith('POLYGON') || str.startsWith('MULTIPOINT') || str.startsWith('MULTILINESTRING') || str.startsWith('GEOMETRYCOLLECTION');
@@ -448,4 +467,14 @@ export function getMidpoint(position1, position2) {
448
467
  lat: lat,
449
468
  alt: alt
450
469
  };
470
+ }
471
+
472
+ // 对两点间进行插值
473
+ export function densifyLine(p1, p2) {
474
+ var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
475
+ var result = [];
476
+ for (var i = 0; i <= count; i++) {
477
+ result.push(Cesium.Cartesian3.lerp(p1, p2, i / count, new Cesium.Cartesian3()));
478
+ }
479
+ return result;
451
480
  }