deeptwins-engine-3d 0.1.1 → 0.1.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.
@@ -14,7 +14,7 @@ export default class BaseSource {
14
14
  remove(): void;
15
15
  setData(data: any): this;
16
16
  _toDestroy(): void;
17
- static analysisSourceType(data: any): "wkt" | "sourceId" | "sourceInstance" | "geoJson" | "other";
17
+ static analysisSourceType(data: any): "other" | "wkt" | "sourceId" | "sourceInstance" | "geoJson";
18
18
  static wktToGeoJon(wkt: string): any;
19
19
  static geoJsonToGeoCartesian3Array(geoJson: any): any[];
20
20
  static handleFeaturePoint(feature: any): any;
package/dist/esm/index.js CHANGED
@@ -48,7 +48,7 @@ loadCss(Cesium.buildModuleUrl('Widgets/widgets.css'));
48
48
  export var DeepTwinsEngine3D = /*#__PURE__*/_createClass(function DeepTwinsEngine3D() {
49
49
  _classCallCheck(this, DeepTwinsEngine3D);
50
50
  });
51
- _defineProperty(DeepTwinsEngine3D, "Version", "0.1.1");
51
+ _defineProperty(DeepTwinsEngine3D, "Version", "0.1.3");
52
52
  _defineProperty(DeepTwinsEngine3D, "Map", Map);
53
53
  _defineProperty(DeepTwinsEngine3D, "GroundSkyBox", GroundSkyBox);
54
54
  _defineProperty(DeepTwinsEngine3D, "RasterLayer", RasterLayer);
@@ -126,7 +126,7 @@ var Event = /*#__PURE__*/function () {
126
126
  return handler;
127
127
  }
128
128
 
129
- // 监听场景头事件
129
+ // 监听场景事件
130
130
  }, {
131
131
  key: "listenToScene",
132
132
  value: function listenToScene(type, event) {
@@ -61,6 +61,7 @@ export default class Map extends Cesium.Viewer {
61
61
  addEffect(effect: any): void;
62
62
  removeEffect(effect: any): void;
63
63
  on(type: any, event: any): any;
64
+ addModuleLayer: (moduleLayer: any) => any;
64
65
  pickMonomer(data: any): any;
65
66
  destroy(): void;
66
67
  }
@@ -76,6 +76,12 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
76
76
  _defineProperty(_assertThisInitialized(_this), "_event", void 0);
77
77
  // 默认的事件监听
78
78
  _defineProperty(_assertThisInitialized(_this), "_eventTrick", []);
79
+ // 添加yunjing module
80
+ _defineProperty(_assertThisInitialized(_this), "addModuleLayer", function (moduleLayer) {
81
+ _this._yunjing = _this._yunjing || moduleLayer.addToMap(_assertThisInitialized(_this));
82
+ common.removeYjIcon();
83
+ return _this._yunjing;
84
+ });
79
85
  _this.configOptions = merge(constant.DEFAULT_VIEW_CONFIG(), options);
80
86
  _this.setConfig(_this.configOptions);
81
87
  if (deepTwins) {
@@ -431,7 +437,7 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
431
437
  }, {
432
438
  key: "removeDefaultLayer",
433
439
  value: function removeDefaultLayer() {
434
- console.log(this.imageryLayers);
440
+ this.imageryLayers.removeDefault();
435
441
  }
436
442
 
437
443
  // 添加矢量数据
@@ -633,11 +639,11 @@ var Map = /*#__PURE__*/function (_Cesium$Viewer) {
633
639
  return this._event.listenToScene(type, event);
634
640
  }
635
641
  }
636
-
637
- // 拾取单体
638
642
  }, {
639
643
  key: "pickMonomer",
640
- value: function pickMonomer(data) {
644
+ value:
645
+ // 拾取单体
646
+ function pickMonomer(data) {
641
647
  if (!this._yunjing) {
642
648
  throw new Error('请先加载模型');
643
649
  }
@@ -1,9 +1,13 @@
1
1
  import BaseMaterialProperty from './BaseMaterialProperty';
2
2
  export default class PolylineTrailLinkMaterialProperty extends BaseMaterialProperty {
3
- private readonly currStyle;
3
+ private _currStyle;
4
+ get currStyle(): any;
5
+ set currStyle(value: any);
4
6
  constructor(style: any);
5
- static handleStyle(style: any): any;
6
7
  private _init;
8
+ static handleStyle(style: any): any;
9
+ getType(): string;
7
10
  getValue(time: any, result: any): any;
8
11
  equals(other: any): boolean;
12
+ dynamicsSize(map: any, layer: any): void;
9
13
  }
@@ -1,5 +1,5 @@
1
1
  var _excluded = ["duration"],
2
- _excluded2 = ["color", "count"];
2
+ _excluded2 = ["color", "repeat"];
3
3
  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); }
4
4
  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; }
5
5
  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; }
@@ -20,11 +20,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
20
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
21
  import * as Cesium from 'deeptwins-cesium';
22
22
  import { cloneDeep, isEqual, merge } from 'lodash';
23
- import { DEFAULT_POLYLINE_TRAIL_LINK_MATERIAL_STYLE } from "../constant";
23
+ import { CAMERA_EVENT_TYPE, DEFAULT_POLYLINE_TRAIL_LINK_MATERIAL_STYLE } from "../constant";
24
+ import BaseLayer from "../graphicLayer/BaseLayer";
24
25
  import * as utils from "../tool/utils";
25
26
  import BaseMaterialProperty from "./BaseMaterialProperty";
26
27
  /* babel-plugin-inline-import './shader/PolylineTrailLinkShader.glsl' */
27
- var PolylineTrailLinkShader = "czm_material czm_getMaterial(czm_materialInput materialInput)\n{\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = vec2(fract(materialInput.st.s * count - time), materialInput.st.t * 1.0);\n vec4 colorImage = texture(image, vec2(fract(st.s - time), st.t));\n material.alpha = colorImage.a * color.a;\n material.diffuse = mix(colorImage.rgb, color.rgb, mixRatio);\n return material;\n}\n"; // 流动线材质
28
+ var PolylineTrailLinkShader = "czm_material czm_getMaterial(czm_materialInput materialInput)\n{\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = vec2(fract(materialInput.st.s * repeat.x - time), fract(materialInput.st.t * repeat.y));\n vec4 colorImage = texture(image, vec2(fract(st.s - time), st.t));\n material.alpha = colorImage.a * color.a;\n material.diffuse = mix(colorImage.rgb, color.rgb, mixRatio);\n return material;\n}\n";
28
29
  var PolylineTrailLinkMaterialProperty = /*#__PURE__*/function (_BaseMaterialProperty) {
29
30
  _inherits(PolylineTrailLinkMaterialProperty, _BaseMaterialProperty);
30
31
  var _super = _createSuper(PolylineTrailLinkMaterialProperty);
@@ -33,14 +34,20 @@ var PolylineTrailLinkMaterialProperty = /*#__PURE__*/function (_BaseMaterialProp
33
34
  _classCallCheck(this, PolylineTrailLinkMaterialProperty);
34
35
  var mergeStyle = merge(DEFAULT_POLYLINE_TRAIL_LINK_MATERIAL_STYLE(), cloneDeep(style || {}));
35
36
  _this = _super.call(this, 'PolylineTrailLink', mergeStyle);
36
- _defineProperty(_assertThisInitialized(_this), "currStyle", void 0);
37
+ _defineProperty(_assertThisInitialized(_this), "_currStyle", void 0);
37
38
  _this.currStyle = PolylineTrailLinkMaterialProperty.handleStyle(mergeStyle);
38
39
  _this._init();
39
40
  return _this;
40
41
  }
41
-
42
- // 处理参数
43
42
  _createClass(PolylineTrailLinkMaterialProperty, [{
43
+ key: "currStyle",
44
+ get: function get() {
45
+ return this._currStyle;
46
+ },
47
+ set: function set(value) {
48
+ this._currStyle = value;
49
+ }
50
+ }, {
44
51
  key: "_init",
45
52
  value: function _init() {
46
53
  // @ts-ignore
@@ -57,6 +64,13 @@ var PolylineTrailLinkMaterialProperty = /*#__PURE__*/function (_BaseMaterialProp
57
64
  }
58
65
  });
59
66
  }
67
+
68
+ // 处理参数
69
+ }, {
70
+ key: "getType",
71
+ value: function getType() {
72
+ return this.type;
73
+ }
60
74
  }, {
61
75
  key: "getValue",
62
76
  value: function getValue(time, result) {
@@ -76,17 +90,40 @@ var PolylineTrailLinkMaterialProperty = /*#__PURE__*/function (_BaseMaterialProp
76
90
  }, {
77
91
  key: "equals",
78
92
  value: function equals(other) {
79
- return other instanceof PolylineTrailLinkMaterialProperty && isEqual(this.style, other.style);
93
+ return this === other || other instanceof PolylineTrailLinkMaterialProperty && isEqual(this.style, other.style);
94
+ }
95
+
96
+ // 动态尺寸
97
+ }, {
98
+ key: "dynamicsSize",
99
+ value: function dynamicsSize(map, layer) {
100
+ var _this2 = this;
101
+ var event = map.on(CAMERA_EVENT_TYPE.CHANGED, function () {
102
+ if (layer instanceof BaseLayer) {
103
+ if (layer.isDestroyed) {
104
+ event.off();
105
+ return;
106
+ }
107
+ layer.layers.forEach(function (t) {
108
+ var _utils$cartesian3ToLn = utils.cartesian3ToLngLatAlt(t.source.positions[0]),
109
+ alt = _utils$cartesian3ToLn.alt;
110
+ var scale = utils.getHeightCompensatedScale(map, alt || 0);
111
+ scale = scale < 0.1 ? 0.1 : scale;
112
+ var r = utils.calculateLength(t.source.positions) / scale / _this2.currStyle.repeatPixel;
113
+ t.entity.polyline.material.currStyle.repeat.x = Math.round(_this2.currStyle.repeat.x * r) || 1;
114
+ });
115
+ }
116
+ });
80
117
  }
81
118
  }], [{
82
119
  key: "handleStyle",
83
120
  value: function handleStyle(style) {
84
121
  var color = style.color,
85
- count = style.count,
122
+ repeat = style.repeat,
86
123
  options = _objectWithoutProperties(style, _excluded2);
87
124
  var backStyle = _objectSpread({}, options);
88
125
  backStyle.color = utils.colorString(color);
89
- backStyle.count = count <= 0 ? 1 : count;
126
+ backStyle.repeat = utils.arrCartesian2(repeat);
90
127
  return backStyle;
91
128
  }
92
129
  }]);
@@ -1,7 +1,7 @@
1
1
  czm_material czm_getMaterial(czm_materialInput materialInput)
2
2
  {
3
3
  czm_material material = czm_getDefaultMaterial(materialInput);
4
- vec2 st = vec2(fract(materialInput.st.s * count - time), materialInput.st.t * 1.0);
4
+ vec2 st = vec2(fract(materialInput.st.s * repeat.x - time), fract(materialInput.st.t * repeat.y));
5
5
  vec4 colorImage = texture(image, vec2(fract(st.s - time), st.t));
6
6
  material.alpha = colorImage.a * color.a;
7
7
  material.diffuse = mix(colorImage.rgb, color.rgb, mixRatio);
@@ -29,3 +29,18 @@ export declare const julianDateToDate: (julianDate: any) => Date;
29
29
  export declare const getElCss: (el: any, css: string) => string;
30
30
  export declare const cameraFlyToPositions: (camera: any, positions: any, options: any) => void;
31
31
  export declare function loadCss(url: string): Promise<void>;
32
+ /**
33
+ * 计算比例尺 1像素比多少米
34
+ * @param map Cesium.Viewer实例
35
+ * @param entityHeight 物体的椭球高度(单位:米)
36
+ * @param options 可调参数: {
37
+ * baseIntensity?: number, // 基础补偿强度(默认0.4)
38
+ * transitionHeight?: number // 高度差过渡阈值(默认5km)
39
+ * }
40
+ */
41
+ export declare const getHeightCompensatedScale: (map: Cesium.Viewer, entityHeight: number, options?: {
42
+ mode?: 'auto' | 'linear' | 'log' | 'hyperbolic';
43
+ baseIntensity?: number;
44
+ transitionHeight?: number;
45
+ }) => number;
46
+ export declare function calculateLength(positions: any[]): number;
@@ -244,6 +244,16 @@ export var cameraFlyToPositions = function cameraFlyToPositions(camera, position
244
244
  export function loadCss(_x3) {
245
245
  return _loadCss.apply(this, arguments);
246
246
  }
247
+
248
+ /**
249
+ * 计算比例尺 1像素比多少米
250
+ * @param map Cesium.Viewer实例
251
+ * @param entityHeight 物体的椭球高度(单位:米)
252
+ * @param options 可调参数: {
253
+ * baseIntensity?: number, // 基础补偿强度(默认0.4)
254
+ * transitionHeight?: number // 高度差过渡阈值(默认5km)
255
+ * }
256
+ */
247
257
  function _loadCss() {
248
258
  _loadCss = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(url) {
249
259
  var response, cssText, style;
@@ -275,4 +285,40 @@ function _loadCss() {
275
285
  }, _callee2, null, [[0, 12]]);
276
286
  }));
277
287
  return _loadCss.apply(this, arguments);
288
+ }
289
+ export var getHeightCompensatedScale = function getHeightCompensatedScale(map, entityHeight, options) {
290
+ var _options$baseIntensit, _options$transitionHe;
291
+ // 参数默认值
292
+ var config = {
293
+ baseIntensity: (_options$baseIntensit = options === null || options === void 0 ? void 0 : options.baseIntensity) !== null && _options$baseIntensit !== void 0 ? _options$baseIntensit : 0.4,
294
+ transitionHeight: (_options$transitionHe = options === null || options === void 0 ? void 0 : options.transitionHeight) !== null && _options$transitionHe !== void 0 ? _options$transitionHe : 5000 // 5km过渡阈值
295
+ };
296
+ var camera = map.camera;
297
+ var cameraHeight = camera.positionCartographic.height;
298
+ var fovy = camera.frustum.fovy;
299
+ var viewport = map.scene.canvas.clientHeight;
300
+
301
+ // 校验无效输入
302
+ if (viewport <= 0 || !fovy || cameraHeight <= 0) return 1;
303
+
304
+ // 计算物体与相机的高度差(绝对值)
305
+ var deltaHeight = Math.abs(entityHeight - cameraHeight);
306
+ var compensationFactor;
307
+ if (deltaHeight < config.transitionHeight) {
308
+ compensationFactor = 1 + config.baseIntensity * (deltaHeight / 1000);
309
+ } else {
310
+ compensationFactor = 1 + config.baseIntensity * Math.log1p(deltaHeight / 1000);
311
+ }
312
+ var groundPerPixel = 2 * cameraHeight * Math.tan(fovy / 2) / viewport;
313
+ return groundPerPixel * compensationFactor;
314
+ };
315
+
316
+ // 计算长度(米)
317
+ export function calculateLength(positions) {
318
+ if (!positions || positions.length < 2) return 0;
319
+ var length = 0;
320
+ for (var i = 1; i < positions.length; i++) {
321
+ length += Cesium.Cartesian3.distance(positions[i - 1], positions[i]);
322
+ }
323
+ return length;
278
324
  }