cesium_dev_kit 1.0.49 → 1.0.50

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.
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Controller = void 0;
7
+ var _ColorDeal = require("./ColorDeal");
8
+ var _common = require("./common");
9
+ let Cesium = null;
10
+ class Controller {
11
+ // 初始化 controller 类
12
+ constructor(cesiumGlobal) {
13
+ Cesium = cesiumGlobal;
14
+ this.init_data();
15
+ }
16
+ init_data() {
17
+ this.viewer = null;
18
+ }
19
+ init({
20
+ containerId,
21
+ viewerConfig,
22
+ extreaConfig,
23
+ MapImageryList
24
+ }) {
25
+ const mapID = containerId;
26
+ let imageryProviderConfig = new Cesium.SingleTileImageryProvider({
27
+ url: 'https://mapv-data.oss-cn-hangzhou.aliyuncs.com/Cesium-1.82-hawk/background.png'
28
+ });
29
+ if (MapImageryList.length !== 0) {
30
+ imageryProviderConfig = this.setOneimageryProvider(MapImageryList[0]);
31
+ }
32
+ let vConfig = {
33
+ // 加载单张影像 第一层最小最透明的
34
+ imageryProvider: imageryProviderConfig,
35
+ contextOptions: {
36
+ webgl: {
37
+ alpha: false
38
+ }
39
+ },
40
+ // 默认设置
41
+ animation: false,
42
+ //动画控件
43
+ timeline: false,
44
+ //时间线
45
+ fullscreenButton: false,
46
+ // 全屏按钮
47
+ geocoder: false,
48
+ //地名查找(依赖google服务)
49
+ homeButton: false,
50
+ //重置到初始焦点与缩放
51
+ selectionIndicator: false,
52
+ //
53
+ shadow: true,
54
+ sceneMode: Cesium.SceneMode.SCENE3D,
55
+ infoBox: false,
56
+ //消息框
57
+ sceneModePicker: false,
58
+ //场景模式选择
59
+ navigationHelpButton: false,
60
+ //导航帮助按钮
61
+ projectionPicker: false,
62
+ //投影方式选择(3D、2D、Columbus)
63
+ baseLayerPicker: false,
64
+ shouldAnimate: true,
65
+ navigation: false,
66
+ showRenderLoopErrors: true // 是否显示render异常信息
67
+ };
68
+
69
+ vConfig = Object.assign(vConfig, viewerConfig); // 后台接口配置 融合替换 默认配置
70
+ const viewer = new Cesium.Viewer(mapID, vConfig);
71
+ if (!extreaConfig['logo']) {
72
+ const cC = viewer.cesiumWidget.creditContainer;
73
+ cC.style.display = 'none'; // 影藏logo
74
+ }
75
+
76
+ // 是否开启深度参数
77
+ if (extreaConfig['depthTest']) {
78
+ // 设置开启深度检测
79
+ viewer.scene.globe.depthTestAgainstTerrain = true;
80
+ }
81
+
82
+ // 显示 fps
83
+ // viewer.scene.debugShowFramesPerSecond = true
84
+
85
+ // 增加配置图层
86
+ this.setConfigMapList(viewer, MapImageryList);
87
+ // 消除锯齿
88
+ this.removeJagged(viewer);
89
+ this.viewer = viewer;
90
+ return viewer;
91
+ }
92
+ setOneimageryProvider(MapImagery) {
93
+ if (MapImagery.classConfig.customTags) {
94
+ MapImagery.classConfig.customTags = (0, _common.evil)('(' + MapImagery.classConfig.customTags + ')');
95
+ }
96
+ return new Cesium[MapImagery.type](MapImagery.classConfig);
97
+ }
98
+ setConfigMapList(viewer, MapImageryList) {
99
+ const imageryLayers = viewer.imageryLayers;
100
+ MapImageryList.some((elem, index) => {
101
+ if (index === 0) {
102
+ return false;
103
+ }
104
+ imageryLayers.addImageryProvider(this.setOneimageryProvider(elem));
105
+ });
106
+ // 设置具体的 ImageryLayer 参数
107
+ MapImageryList.some((elem, index) => {
108
+ const baseLayer = viewer.imageryLayers.get(index);
109
+ if (elem.interfaceConfig) {
110
+ Object.getOwnPropertyNames(elem.interfaceConfig).forEach(function (key) {
111
+ baseLayer[key] = elem.interfaceConfig[key];
112
+ });
113
+ }
114
+ // 设置 滤镜效果
115
+ baseLayer.invertColor = elem.invertswitch;
116
+ baseLayer.filterRGB = [255.0, 255.0, 255.0];
117
+ if (elem.filterRGB !== '#000000' && elem.filterRGB !== '#ffffff') {
118
+ baseLayer.filterRGB = (0, _ColorDeal.colorRgb)(elem.filterRGB);
119
+ }
120
+
121
+ // 设置 offset 偏移量
122
+ const offset = elem.offset.split(',');
123
+ if (offset.length === 2) {
124
+ try {
125
+ const oxy = [parseFloat(offset[0]), parseFloat(offset[1])];
126
+ baseLayer._imageryProvider._tilingScheme._rectangleNortheastInMeters.x += oxy[0];
127
+ baseLayer._imageryProvider._tilingScheme._rectangleNortheastInMeters.y += oxy[1];
128
+ } catch (error) {
129
+ console.log(error);
130
+ }
131
+ }
132
+
133
+ // 更改cesium的着色器代码 关于滤镜和反色的 [在不更改cesium源文件的情况下]
134
+ this.changeImageryProviderColors(viewer, baseLayer);
135
+ });
136
+ }
137
+ // 消除锯齿
138
+ removeJagged(viewer) {
139
+ viewer.scene.postProcessStages.fxaa.enabled = false;
140
+ viewer.scene.fxaa = false;
141
+ const supportsImageRenderingPixelated = viewer.cesiumWidget._supportsImageRenderingPixelated;
142
+ if (supportsImageRenderingPixelated) {
143
+ let vtxf_dpr = window.devicePixelRatio;
144
+ while (vtxf_dpr >= 2.0) {
145
+ vtxf_dpr /= 2.0;
146
+ }
147
+ viewer.resolutionScale = vtxf_dpr;
148
+ }
149
+ }
150
+ // 更改 cesium 着色的方法
151
+ changeImageryProviderColors(viewer, baseLayer) {
152
+ // 更改底图的着色器 代码
153
+ const baseFragmentShaderSource = viewer.scene.globe._surfaceShaderSet.baseFragmentShaderSource.sources;
154
+ for (let i = 0; i < baseFragmentShaderSource.length; i++) {
155
+ const oneSource = baseFragmentShaderSource[i];
156
+ // 格式必须一致 不能多有空格 且保持版本一致性
157
+ const strS = 'color = czm_saturation(color, textureSaturation);\n#endif\n';
158
+ let strT = 'color = czm_saturation(color, textureSaturation);\n#endif\n';
159
+ if (baseLayer.invertColor) {
160
+ strT += `
161
+ color.r = 1.0 - color.r;
162
+ color.g = 1.0 - color.g;
163
+ color.b = 1.0 - color.b;
164
+ `;
165
+ strT += `
166
+ color.r = color.r * ${baseLayer.filterRGB[0]}.0/255.0;
167
+ color.g = color.g * ${baseLayer.filterRGB[1]}.0/255.0;
168
+ color.b = color.b * ${baseLayer.filterRGB[2]}.0/255.0;
169
+ `;
170
+ }
171
+ if (oneSource.indexOf(strS) !== -1) {
172
+ baseFragmentShaderSource[i] = baseFragmentShaderSource[i].replace(strS, strT);
173
+ }
174
+ }
175
+ }
176
+ // 获取当前视图的中心经纬度
177
+ getCurCenterlonLat(viewer) {
178
+ let result = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(viewer.canvas.clientWidth / 2, viewer.canvas.clientHeight / 2));
179
+ let curPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result);
180
+ let lon = curPosition.longitude * 180 / Math.PI;
181
+ let lat = curPosition.latitude * 180 / Math.PI;
182
+ return {
183
+ lon: lon,
184
+ lat: lat
185
+ };
186
+ }
187
+ }
188
+ exports.Controller = Controller;