cesium_dev_kit 1.0.50 → 1.0.52
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.
- package/README.md +233 -0
- package/dist/index.js +13582 -68
- package/dist/index.min.js +1 -0
- package/index.js +2 -2
- package/package.json +15 -9
- package/.babelrc +0 -13
- package/dist/ColorDeal.js +0 -59
- package/dist/common.js +0 -40
- package/dist/initConf.js +0 -188
- package/dist/libs/Analysis.js +0 -779
- package/dist/libs/Base.js +0 -950
- package/dist/libs/ChartLayer.js +0 -24
- package/dist/libs/Control.js +0 -947
- package/dist/libs/CustomCesiumPlugin.js +0 -92
- package/dist/libs/DomUtil.js +0 -105
- package/dist/libs/Draw.js +0 -704
- package/dist/libs/Graphics.js +0 -734
- package/dist/libs/MapvLayer.js +0 -26
- package/dist/libs/Material.js +0 -590
- package/dist/libs/Math2d.js +0 -559
- package/dist/libs/Math3d.js +0 -646
- package/dist/libs/PassEffect.js +0 -154
- package/dist/libs/Plugin.js +0 -751
- package/dist/libs/Primitive.js +0 -1559
- package/dist/libs/Shaders.js +0 -298
- package/dist/libs/ThreeJs.js +0 -190
- package/dist/libs/cesium-plugin.js +0 -3387
- package/dist/libs/index.js +0 -117
- package/dist/libs/plot/AttackArrow.js +0 -266
- package/dist/libs/plot/BasePlot.js +0 -41
- package/dist/libs/plot/PincerArrow.js +0 -278
- package/dist/libs/plot/StraightArrow.js +0 -244
- package/dist/libs/plot/algorithm.js +0 -315
- package/dist/libs/plot/index.js +0 -19
- package/dist/libs/plot/plotUtil.js +0 -242
package/dist/libs/Base.js
DELETED
|
@@ -1,950 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Base = Base;
|
|
7
|
-
let Cesium = {};
|
|
8
|
-
function Base(viewer, cesiumGlobal) {
|
|
9
|
-
if (viewer) {
|
|
10
|
-
this._viewer = viewer;
|
|
11
|
-
Cesium = cesiumGlobal;
|
|
12
|
-
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJmYzkwZWEwYy1mMmIwLTQwYjctOWJlOC00OWU4ZWU1YTZhOTkiLCJpZCI6MTIxODIsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1NjA0OTUyNDN9.wagvw7GxUjxvHXO6m2jjX5Jh9lN0UyTJhNGEcSm2pgE';
|
|
13
|
-
this._drawLayer = new Cesium.CustomDataSource('drawLayer');
|
|
14
|
-
viewer && viewer.dataSources.add(this._drawLayer);
|
|
15
|
-
this.myname = 'BASE';
|
|
16
|
-
this._installBaiduImageryProvider();
|
|
17
|
-
this._installGooGleImageryProvider();
|
|
18
|
-
this._installAmapImageryProvider();
|
|
19
|
-
this._installTencentImageryProvider();
|
|
20
|
-
this._installTdtImageryProvider();
|
|
21
|
-
this._installGroundSkyBox();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
Base.prototype = {
|
|
25
|
-
// 创建一个实体图形
|
|
26
|
-
createGraphics: function () {
|
|
27
|
-
return new Cesium.Entity();
|
|
28
|
-
},
|
|
29
|
-
// 天空盒
|
|
30
|
-
setOneSkyBox: function () {
|
|
31
|
-
return new Cesium.SkyBox({
|
|
32
|
-
sources: {
|
|
33
|
-
positiveX: 'static/data/images/SkyBox/00h+00.jpg',
|
|
34
|
-
negativeX: 'static/data/images/SkyBox/12h+00.jpg',
|
|
35
|
-
positiveY: 'static/data/images/SkyBox/06h+00.jpg',
|
|
36
|
-
negativeY: 'static/data/images/SkyBox/18h+00.jpg',
|
|
37
|
-
positiveZ: 'static/data/images/SkyBox/06h+90.jpg',
|
|
38
|
-
negativeZ: 'static/data/images/SkyBox/06h-90.jpg'
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
// 天空盒2
|
|
43
|
-
setTwoSkyBox: function () {
|
|
44
|
-
return new Cesium.SkyBox({
|
|
45
|
-
sources: {
|
|
46
|
-
positiveX: 'static/data/images/SkyBox/Version2_dark_px.jpg',
|
|
47
|
-
negativeX: 'static/data/images/SkyBox/Version2_dark_mx.jpg',
|
|
48
|
-
positiveY: 'static/data/images/SkyBox/Version2_dark_py.jpg',
|
|
49
|
-
negativeY: 'static/data/images/SkyBox/Version2_dark_my.jpg',
|
|
50
|
-
positiveZ: 'static/data/images/SkyBox/Version2_dark_pz.jpg',
|
|
51
|
-
negativeZ: 'static/data/images/SkyBox/Version2_dark_mz.jpg'
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
// 天空盒3
|
|
56
|
-
setThreeSkyBox: function () {
|
|
57
|
-
return new Cesium.SkyBox({
|
|
58
|
-
sources: {
|
|
59
|
-
positiveX: 'static/data/images/SkyBox/tycho2t3_80_pxs.jpg',
|
|
60
|
-
negativeX: 'static/data/images/SkyBox/tycho2t3_80_mxs.jpg',
|
|
61
|
-
positiveY: 'static/data/images/SkyBox/tycho2t3_80_pys.jpg',
|
|
62
|
-
negativeY: 'static/data/images/SkyBox/tycho2t3_80_mys.jpg',
|
|
63
|
-
positiveZ: 'static/data/images/SkyBox/tycho2t3_80_pzs.jpg',
|
|
64
|
-
negativeZ: 'static/data/images/SkyBox/tycho2t3_80_mzs.jpg'
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
//近景天空盒
|
|
69
|
-
setOneGroundSkyBox: function () {
|
|
70
|
-
return new Cesium.Scene.GroundSkyBox({
|
|
71
|
-
sources: {
|
|
72
|
-
positiveX: 'static/data/images/SkyBox/rightav9.jpg',
|
|
73
|
-
negativeX: 'static/data/images/SkyBox/leftav9.jpg',
|
|
74
|
-
positiveY: 'static/data/images/SkyBox/frontav9.jpg',
|
|
75
|
-
negativeY: 'static/data/images/SkyBox/backav9.jpg',
|
|
76
|
-
positiveZ: 'static/data/images/SkyBox/topav9.jpg',
|
|
77
|
-
negativeZ: 'static/data/images/SkyBox/bottomav9.jpg'
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
//近景天空盒 2
|
|
82
|
-
setTwoGroundSkyBox: function () {
|
|
83
|
-
return new Cesium.Scene.GroundSkyBox({
|
|
84
|
-
sources: {
|
|
85
|
-
positiveX: 'static/data/images/SkyBox/SunSetRight.png',
|
|
86
|
-
negativeX: 'static/data/images/SkyBox/SunSetLeft.png',
|
|
87
|
-
positiveY: 'static/data/images/SkyBox/SunSetFront.png',
|
|
88
|
-
negativeY: 'static/data/images/SkyBox/SunSetBack.png',
|
|
89
|
-
positiveZ: 'static/data/images/SkyBox/SunSetUp.png',
|
|
90
|
-
negativeZ: 'static/data/images/SkyBox/SunSetDown.png'
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
//近景天空盒 3
|
|
95
|
-
setThreeGroundSkyBox: function () {
|
|
96
|
-
return new Cesium.Scene.GroundSkyBox({
|
|
97
|
-
sources: {
|
|
98
|
-
positiveX: 'static/data/images/SkyBox/Right.jpg',
|
|
99
|
-
negativeX: 'static/data/images/SkyBox/Left.jpg',
|
|
100
|
-
positiveY: 'static/data/images/SkyBox/Front.jpg',
|
|
101
|
-
negativeY: 'static/data/images/SkyBox/Back.jpg',
|
|
102
|
-
positiveZ: 'static/data/images/SkyBox/Up.jpg',
|
|
103
|
-
negativeZ: 'static/data/images/SkyBox/Down.jpg'
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
//黑夜特效
|
|
108
|
-
setDarkEffect: function (options) {
|
|
109
|
-
options = options || {};
|
|
110
|
-
var fs = 'uniform sampler2D colorTexture;\n' + 'varying vec2 v_textureCoordinates;\n' + 'uniform float scale;\n' + 'uniform vec3 offset;\n' + 'void main() {\n' + ' // vec4 color = texture2D(colorTexture, v_textureCoordinates);\n' + ' vec4 color = texture2D(colorTexture, v_textureCoordinates);\n' + ' // float gray = 0.2989*color.r+0.5870*color.g+0.1140*color.b;\n' + ' // gl_FragColor = vec4(gray,gray,2.0*(gray+1.0), 1.0);\n' + ' gl_FragColor = vec4(color.r*0.2,color.g * 0.4,color.b*0.6, 1.0);\n' + '}\n';
|
|
111
|
-
return this._viewer.scene.postProcessStages.add(new Cesium.PostProcessStage({
|
|
112
|
-
name: 'darkEffect',
|
|
113
|
-
fragmentShader: fs,
|
|
114
|
-
uniforms: {
|
|
115
|
-
scale: 1.0,
|
|
116
|
-
offset: function () {
|
|
117
|
-
return options.offset || new Cesium.Cartesian3(0.1, 0.2, 0.3);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}));
|
|
121
|
-
},
|
|
122
|
-
// 场景蓝光
|
|
123
|
-
setBlurBloom: function (options) {
|
|
124
|
-
if (this._viewer && options) {
|
|
125
|
-
var fs = 'uniform float height;\n' + 'uniform float width;\n' + 'uniform sampler2D colorTexture1;\n' + '\n' + 'varying vec2 v_textureCoordinates;\n' + '\n' + 'const int SAMPLES = 9;\n' + 'void main()\n' + '{\n' + 'vec2 st = v_textureCoordinates;\n' + 'float wr = float(1.0 / width);\n' + 'float hr = float(1.0 / height);\n' + 'vec4 result = vec4(0.0);\n' + 'int count = 0;\n' + 'for(int i = -SAMPLES; i <= SAMPLES; ++i){\n' + 'for(int j = -SAMPLES; j <= SAMPLES; ++j){\n' + 'vec2 offset = vec2(float(i) * wr, float(j) * hr);\n' + 'result += texture2D(colorTexture1, st + offset);\n' + '}\n' + '}\n' + 'result = result / float(count);\n' + 'gl_FragColor = result;\n' + '}\n';
|
|
126
|
-
return this._viewer.scene.postProcessStages.add(new Cesium.PostProcessStage({
|
|
127
|
-
name: 'blur_x_direction',
|
|
128
|
-
fragmentShader: fs,
|
|
129
|
-
uniforms: {
|
|
130
|
-
width: options.width,
|
|
131
|
-
height: options.height,
|
|
132
|
-
colorTexture1: 'Bright'
|
|
133
|
-
}
|
|
134
|
-
}));
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
//雨天特效
|
|
138
|
-
setRainEffect: function () {
|
|
139
|
-
if (this._viewer) {
|
|
140
|
-
var fs = 'uniform sampler2D colorTexture;\n\
|
|
141
|
-
varying vec2 v_textureCoordinates;\n\
|
|
142
|
-
\n\
|
|
143
|
-
float hash(float x){\n\
|
|
144
|
-
return fract(sin(x*23.3)*13.13);\n\
|
|
145
|
-
}\n\
|
|
146
|
-
\n\
|
|
147
|
-
void main(){\n\
|
|
148
|
-
float time = czm_frameNumber / 60.0;\n\
|
|
149
|
-
vec2 resolution = czm_viewport.zw;\n\
|
|
150
|
-
vec2 uv=(gl_FragCoord.xy*2.-resolution.xy)/min(resolution.x,resolution.y);\n\
|
|
151
|
-
vec3 c=vec3(.6,.7,.8);\n\
|
|
152
|
-
float a=-.4;\n\
|
|
153
|
-
float si=sin(a),co=cos(a);\n\
|
|
154
|
-
uv*=mat2(co,-si,si,co);\n\
|
|
155
|
-
uv*=length(uv+vec2(0,4.9))*.3+1.;\n\
|
|
156
|
-
float v=1.-sin(hash(floor(uv.x*100.))*2.);\n\
|
|
157
|
-
float b=clamp(abs(sin(20.*time*v+uv.y*(5./(2.+v))))-.95,0.,1.)*20.;\n\
|
|
158
|
-
c*=v*b;\n\
|
|
159
|
-
gl_FragColor = mix(texture2D(colorTexture, v_textureCoordinates), vec4(c, 1), 0.2);\n\
|
|
160
|
-
}\n\
|
|
161
|
-
';
|
|
162
|
-
return this._viewer.scene.postProcessStages.add(new Cesium.PostProcessStage({
|
|
163
|
-
name: 'rainEffect',
|
|
164
|
-
fragmentShader: fs
|
|
165
|
-
}));
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
//雪天特效
|
|
169
|
-
setSnowEffect: function () {
|
|
170
|
-
if (this._viewer) {
|
|
171
|
-
var fs = 'uniform sampler2D colorTexture;\n\
|
|
172
|
-
varying vec2 v_textureCoordinates;\n\
|
|
173
|
-
\n\
|
|
174
|
-
float snow(vec2 uv,float scale){\n\
|
|
175
|
-
float time = czm_frameNumber / 60.0;\n\
|
|
176
|
-
float w=smoothstep(1.,0.,-uv.y*(scale/10.));\n\
|
|
177
|
-
if(w<.1)return 0.;\n\
|
|
178
|
-
uv+=time/scale;\n\
|
|
179
|
-
uv.y+=time*2./scale;\n\
|
|
180
|
-
uv.x+=sin(uv.y+time*.5)/scale;\n\
|
|
181
|
-
uv*=scale;\n\
|
|
182
|
-
vec2 s=floor(uv),f=fract(uv),p;\n\
|
|
183
|
-
float k=3.,d;\n\
|
|
184
|
-
p=.5+.35*sin(11.*fract(sin((s+p+scale)*mat2(7,3,6,5))*5.))-f;\n\
|
|
185
|
-
d=length(p);\n\
|
|
186
|
-
k=min(d,k);\n\
|
|
187
|
-
k=smoothstep(0.,k,sin(f.x+f.y)*0.01);\n\
|
|
188
|
-
return k*w;\n\
|
|
189
|
-
}\n\
|
|
190
|
-
\n\
|
|
191
|
-
void main(){\n\
|
|
192
|
-
vec2 resolution = czm_viewport.zw;\n\
|
|
193
|
-
vec2 uv=(gl_FragCoord.xy*2.-resolution.xy)/min(resolution.x,resolution.y);\n\
|
|
194
|
-
vec3 finalColor=vec3(0);\n\
|
|
195
|
-
float c = 0.0;\n\
|
|
196
|
-
c+=snow(uv,30.)*.0;\n\
|
|
197
|
-
c+=snow(uv,20.)*.0;\n\
|
|
198
|
-
c+=snow(uv,15.)*.0;\n\
|
|
199
|
-
c+=snow(uv,10.);\n\
|
|
200
|
-
c+=snow(uv,8.);\n\
|
|
201
|
-
c+=snow(uv,6.);\n\
|
|
202
|
-
c+=snow(uv,5.);\n\
|
|
203
|
-
finalColor=(vec3(c));\n\
|
|
204
|
-
gl_FragColor = mix(texture2D(colorTexture, v_textureCoordinates), vec4(finalColor,1), 0.3);\n\
|
|
205
|
-
\n\
|
|
206
|
-
}\n\
|
|
207
|
-
';
|
|
208
|
-
return this._viewer.scene.postProcessStages.add(new Cesium.PostProcessStage({
|
|
209
|
-
name: 'snowEffect',
|
|
210
|
-
fragmentShader: fs
|
|
211
|
-
}));
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
// 雾天
|
|
215
|
-
setFogEffect: function () {
|
|
216
|
-
if (this._viewer) {
|
|
217
|
-
var fs = 'float getDistance(sampler2D depthTexture, vec2 texCoords) \n' + '{ \n' + ' float depth = czm_unpackDepth(texture2D(depthTexture, texCoords)); \n' + ' if (depth == 0.0) { \n' + ' return czm_infinity; \n' + ' } \n' + ' vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, depth); \n' + ' return -eyeCoordinate.z / eyeCoordinate.w; \n' + '} \n' + 'float interpolateByDistance(vec4 nearFarScalar, float distance) \n' + '{ \n' + ' float startDistance = nearFarScalar.x; \n' + ' float startValue = nearFarScalar.y; \n' + ' float endDistance = nearFarScalar.z; \n' + ' float endValue = nearFarScalar.w; \n' + ' float t = clamp((distance - startDistance) / (endDistance - startDistance), 0.0, 1.0); \n' + ' return mix(startValue, endValue, t); \n' + '} \n' + 'vec4 alphaBlend(vec4 sourceColor, vec4 destinationColor) \n' + '{ \n' + ' return sourceColor * vec4(sourceColor.aaa, 1.0) + destinationColor * (1.0 - sourceColor.a); \n' + '} \n' + 'uniform sampler2D colorTexture; \n' + 'uniform sampler2D depthTexture; \n' + 'uniform vec4 fogByDistance; \n' + 'uniform vec4 fogColor; \n' + 'varying vec2 v_textureCoordinates; \n' + 'void main(void) \n' + '{ \n' + ' float distance = getDistance(depthTexture, v_textureCoordinates); \n' + ' vec4 sceneColor = texture2D(colorTexture, v_textureCoordinates); \n' + ' float blendAmount = interpolateByDistance(fogByDistance, distance); \n' + ' vec4 finalFogColor = vec4(fogColor.rgb, fogColor.a * blendAmount); \n' + ' gl_FragColor = alphaBlend(finalFogColor, sceneColor); \n' + '} \n';
|
|
218
|
-
return this._viewer.scene.postProcessStages.add(new Cesium.PostProcessStage({
|
|
219
|
-
fragmentShader: fs,
|
|
220
|
-
uniforms: {
|
|
221
|
-
fogByDistance: new Cesium.Cartesian4(10, 0.0, 200, 0.3),
|
|
222
|
-
fogColor: Cesium.Color.AZURE
|
|
223
|
-
}
|
|
224
|
-
}));
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
/**
|
|
228
|
-
* 默认场景配置
|
|
229
|
-
*/
|
|
230
|
-
setDefSceneConfig: function () {
|
|
231
|
-
if (this._viewer) {
|
|
232
|
-
this._viewer.scene.sun.show = false;
|
|
233
|
-
this._viewer.scene.moon.show = false;
|
|
234
|
-
this._viewer.scene.fxaa = true;
|
|
235
|
-
this._viewer.scene.globe.depthTestAgainstTerrain = true;
|
|
236
|
-
this._viewer.scene.undergroundMode = false;
|
|
237
|
-
this._viewer.scene.terrainProvider.isCreateSkirt = false;
|
|
238
|
-
this._viewer.scene.skyAtmosphere.show = false;
|
|
239
|
-
this._viewer.scene.globe.showGroundAtmosphere = false;
|
|
240
|
-
this._viewer.scene.globe.enableLighting = true;
|
|
241
|
-
this._viewer.scene.fog.enabled = false;
|
|
242
|
-
this._viewer.cesiumWidget.creditContainer.style.display = 'none';
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
/**
|
|
246
|
-
* 场景泛光
|
|
247
|
-
*/
|
|
248
|
-
setBloomLightScene: function () {
|
|
249
|
-
if (this._viewer) {
|
|
250
|
-
this._viewer.scene.postProcessStages.bloom.enabled = true;
|
|
251
|
-
this._viewer.scene.postProcessStages.bloom.uniforms.contrast = 119;
|
|
252
|
-
this._viewer.scene.postProcessStages.bloom.uniforms.brightness = -0.4;
|
|
253
|
-
this._viewer.scene.postProcessStages.bloom.uniforms.glowOnly = false;
|
|
254
|
-
this._viewer.scene.postProcessStages.bloom.uniforms.delta = 0.9;
|
|
255
|
-
this._viewer.scene.postProcessStages.bloom.uniforms.sigma = 3.78;
|
|
256
|
-
this._viewer.scene.postProcessStages.bloom.uniforms.stepSize = 5;
|
|
257
|
-
this._viewer.scene.postProcessStages.bloom.uniforms.isSelected = false;
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
/**
|
|
261
|
-
* 删除后置效果
|
|
262
|
-
* @param {*} stage
|
|
263
|
-
*/
|
|
264
|
-
removePostProcessStage: function (stage) {
|
|
265
|
-
if (stage) {
|
|
266
|
-
if (Array.isArray(stage)) {
|
|
267
|
-
stage.forEach(e => {
|
|
268
|
-
if (this._viewer.scene.postProcessStages.contains(e)) {
|
|
269
|
-
this._viewer.scene.postProcessStages.remove(e);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
} else {
|
|
273
|
-
if (this._viewer.scene.postProcessStages.contains(stage)) {
|
|
274
|
-
this._viewer.scene.postProcessStages.remove(stage);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
//相机定位
|
|
280
|
-
setView: function (options) {
|
|
281
|
-
if (this._viewer && options && options.position) {
|
|
282
|
-
if (options.distance) {
|
|
283
|
-
//距离
|
|
284
|
-
|
|
285
|
-
var pos1 = new Cesium.Cartesian3(0, options.distance, window.opt.distance);
|
|
286
|
-
options.position = Cesium.Cartesian3.add(options.position, pos1, new Cesium.Cartesian3());
|
|
287
|
-
}
|
|
288
|
-
this._viewer.scene.camera.setView({
|
|
289
|
-
destination: options.position,
|
|
290
|
-
orientation: options.orientation || {
|
|
291
|
-
heading: Cesium.Math.toRadians(90.0),
|
|
292
|
-
pitch: Cesium.Math.toRadians(90.0),
|
|
293
|
-
roll: Cesium.Math.toRadians(0.0)
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
//相机飞行
|
|
299
|
-
flyTo: function (options) {
|
|
300
|
-
if (this._viewer && options && options.position) {
|
|
301
|
-
if (options.distance) {
|
|
302
|
-
//距离
|
|
303
|
-
var pos1 = new Cesium.Cartesian3(0, options.distance, options.distance);
|
|
304
|
-
options.position = Cesium.Cartesian3.add(options.position, pos1, new Cesium.Cartesian3());
|
|
305
|
-
}
|
|
306
|
-
this._viewer.scene.camera.flyTo({
|
|
307
|
-
destination: options.position,
|
|
308
|
-
orientation: options.orientation || {
|
|
309
|
-
heading: Cesium.Math.toRadians(90.0),
|
|
310
|
-
pitch: Cesium.Math.toRadians(90.0),
|
|
311
|
-
roll: Cesium.Math.toRadians(0.0)
|
|
312
|
-
},
|
|
313
|
-
// pitchAdjustHeight: 500,
|
|
314
|
-
easingFunction: options.easingFunction || Cesium.EasingFunction.LINEAR_NONE,
|
|
315
|
-
duration: options.duration || 3,
|
|
316
|
-
complete: options.callback
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
},
|
|
320
|
-
//坐标转换 笛卡尔转84
|
|
321
|
-
transformCartesianToWGS84: function (cartesian) {
|
|
322
|
-
if (this._viewer && cartesian) {
|
|
323
|
-
var ellipsoid = Cesium.Ellipsoid.WGS84;
|
|
324
|
-
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
|
|
325
|
-
return {
|
|
326
|
-
lng: Cesium.Math.toDegrees(cartographic.longitude),
|
|
327
|
-
lat: Cesium.Math.toDegrees(cartographic.latitude),
|
|
328
|
-
alt: cartographic.height
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
},
|
|
332
|
-
//坐标数组转换 笛卡尔转84
|
|
333
|
-
transformWGS84ArrayToCartesianArray: function (WSG84Arr, alt) {
|
|
334
|
-
if (this._viewer && WSG84Arr) {
|
|
335
|
-
var $this = this;
|
|
336
|
-
return WSG84Arr ? WSG84Arr.map(function (item) {
|
|
337
|
-
return $this.transformWGS84ToCartesian(item, alt);
|
|
338
|
-
}) : [];
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
//坐标转换 84转笛卡尔
|
|
342
|
-
transformWGS84ToCartesian: function (position, alt) {
|
|
343
|
-
if (this._viewer) {
|
|
344
|
-
return position ? Cesium.Cartesian3.fromDegrees(position.lng || position.lon, position.lat, position.alt = alt || position.alt, Cesium.Ellipsoid.WGS84) : Cesium.Cartesian3.ZERO;
|
|
345
|
-
}
|
|
346
|
-
},
|
|
347
|
-
//坐标数组转换 84转笛卡尔
|
|
348
|
-
transformCartesianArrayToWGS84Array: function (cartesianArr) {
|
|
349
|
-
if (this._viewer) {
|
|
350
|
-
var $this = this;
|
|
351
|
-
return cartesianArr ? cartesianArr.map(function (item) {
|
|
352
|
-
return $this.transformCartesianToWGS84(item);
|
|
353
|
-
}) : [];
|
|
354
|
-
}
|
|
355
|
-
},
|
|
356
|
-
/**
|
|
357
|
-
* 相机绕点旋转
|
|
358
|
-
* @param viewer
|
|
359
|
-
* let options = {
|
|
360
|
-
lng: 117.1423291616,
|
|
361
|
-
lat: 39.0645831633,
|
|
362
|
-
height: 15.8,
|
|
363
|
-
heading: 0.0,
|
|
364
|
-
pitch: 0.0,
|
|
365
|
-
roll: 0.0
|
|
366
|
-
};
|
|
367
|
-
viewer.clock.stopTime = viewer.clock.startTime
|
|
368
|
-
*/
|
|
369
|
-
setCameraEotateHeading(options) {
|
|
370
|
-
if (options) {
|
|
371
|
-
let viewer = this._viewer;
|
|
372
|
-
let position = Cesium.Cartesian3.fromDegrees(options.lng, options.lat, options.height);
|
|
373
|
-
// 相机看点的角度,如果大于0那么则是从地底往上看,所以要为负值,这里取-30度
|
|
374
|
-
let pitch = Cesium.Math.toRadians(-30);
|
|
375
|
-
// 给定飞行一周所需时间,比如10s, 那么每秒转动度数
|
|
376
|
-
let angle = 360 / 30;
|
|
377
|
-
// 给定相机距离点多少距离飞行,这里取值为5000m
|
|
378
|
-
let distance = 5000;
|
|
379
|
-
let startTime = Cesium.JulianDate.fromDate(new Date());
|
|
380
|
-
viewer.clock.startTime = startTime.clone(); // 开始时间
|
|
381
|
-
viewer.clock.currentTime = startTime.clone(); // 当前时间
|
|
382
|
-
viewer.clock.clockRange = Cesium.ClockRange.CLAMPED; // 行为方式
|
|
383
|
-
viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK; // 时钟设置为当前系统时间; 忽略所有其他设置。
|
|
384
|
-
//相机的当前heading
|
|
385
|
-
let initialHeading = viewer.camera.heading;
|
|
386
|
-
let Exection = function TimeExecution() {
|
|
387
|
-
// 当前已经过去的时间,单位s
|
|
388
|
-
let delTime = Cesium.JulianDate.secondsDifference(viewer.clock.currentTime, viewer.clock.startTime);
|
|
389
|
-
let heading = Cesium.Math.toRadians(delTime * angle) + initialHeading;
|
|
390
|
-
viewer.scene.camera.setView({
|
|
391
|
-
destination: position,
|
|
392
|
-
// 点的坐标
|
|
393
|
-
orientation: {
|
|
394
|
-
heading: heading,
|
|
395
|
-
pitch: pitch
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
viewer.scene.camera.moveBackward(distance);
|
|
399
|
-
if (Cesium.JulianDate.compare(viewer.clock.currentTime, viewer.clock.stopTime) >= 0) {
|
|
400
|
-
viewer.clock.onTick.removeEventListener(Exection);
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
viewer.clock.onTick.addEventListener(Exection);
|
|
404
|
-
}
|
|
405
|
-
},
|
|
406
|
-
/**
|
|
407
|
-
*
|
|
408
|
-
* @param {*} position
|
|
409
|
-
* 84坐标转制图坐标
|
|
410
|
-
*/
|
|
411
|
-
transformWGS84ToCartographic: function (position) {
|
|
412
|
-
return position ? Cesium.Cartographic.fromDegrees(position.lng || position.lon, position.lat, position.alt) : Cesium.Cartographic.ZERO;
|
|
413
|
-
},
|
|
414
|
-
// 拾取位置点
|
|
415
|
-
getCatesian3FromPX: function (px) {
|
|
416
|
-
if (this._viewer && px) {
|
|
417
|
-
// var picks = this._viewer.scene.drillPick(px); // 3dtilset
|
|
418
|
-
// for (var i = 0; i < picks.length; i++) {
|
|
419
|
-
// if (picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
|
|
420
|
-
// isOn3dtiles = true;
|
|
421
|
-
// }
|
|
422
|
-
// }
|
|
423
|
-
var picks = this._viewer.scene.pick(px);
|
|
424
|
-
var cartesian = null;
|
|
425
|
-
var isOn3dtiles = false,
|
|
426
|
-
isOnTerrain = false;
|
|
427
|
-
if (picks instanceof Cesium.Cesium3DTileFeature) {
|
|
428
|
-
//模型上拾取
|
|
429
|
-
isOn3dtiles = true;
|
|
430
|
-
}
|
|
431
|
-
// 3dtilset
|
|
432
|
-
if (isOn3dtiles) {
|
|
433
|
-
cartesian = this._viewer.scene.pickPosition(px);
|
|
434
|
-
if (cartesian) {
|
|
435
|
-
let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
|
436
|
-
if (cartographic.height < 0) cartographic.height = 0;
|
|
437
|
-
let lon = Cesium.Math.toDegrees(cartographic.longitude),
|
|
438
|
-
lat = Cesium.Math.toDegrees(cartographic.latitude),
|
|
439
|
-
height = cartographic.height; //模型高度
|
|
440
|
-
cartesian = this.transformWGS84ToCartesian({
|
|
441
|
-
lng: lon,
|
|
442
|
-
lat: lat,
|
|
443
|
-
alt: height
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
// 地形
|
|
448
|
-
if (!picks) {
|
|
449
|
-
var ray = this._viewer.scene.camera.getPickRay(px);
|
|
450
|
-
if (!ray) return null;
|
|
451
|
-
cartesian = this._viewer.scene.globe.pick(ray, this._viewer.scene);
|
|
452
|
-
isOnTerrain = true;
|
|
453
|
-
}
|
|
454
|
-
// 地球
|
|
455
|
-
if (!isOn3dtiles && !isOnTerrain) {
|
|
456
|
-
cartesian = this._viewer.scene.camera.pickEllipsoid(px, this._viewer.scene.globe.ellipsoid);
|
|
457
|
-
}
|
|
458
|
-
if (cartesian) {
|
|
459
|
-
let position = this.transformCartesianToWGS84(cartesian);
|
|
460
|
-
if (position.alt < 0) {
|
|
461
|
-
cartesian = this.transformWGS84ToCartesian(position, 0.1);
|
|
462
|
-
}
|
|
463
|
-
return cartesian;
|
|
464
|
-
}
|
|
465
|
-
return false;
|
|
466
|
-
}
|
|
467
|
-
},
|
|
468
|
-
//获取相机位置
|
|
469
|
-
getCameraPosition: function () {
|
|
470
|
-
if (this._viewer) {
|
|
471
|
-
var result = this._viewer.scene.camera.pickEllipsoid(new Cesium.Cartesian2(this._viewer.canvas.clientWidth / 2, this._viewer.canvas.clientHeight / 2));
|
|
472
|
-
if (result) {
|
|
473
|
-
var curPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result),
|
|
474
|
-
lon = curPosition.longitude * 180 / Math.PI,
|
|
475
|
-
lat = curPosition.latitude * 180 / Math.PI;
|
|
476
|
-
var direction = this._viewer.camera._direction,
|
|
477
|
-
x = Cesium.Math.toDegrees(direction.x),
|
|
478
|
-
y = Cesium.Math.toDegrees(direction.y),
|
|
479
|
-
z = Cesium.Math.toDegrees(direction.z),
|
|
480
|
-
height = this._viewer.camera.positionCartographic.height,
|
|
481
|
-
heading = Cesium.Math.toDegrees(this._viewer.camera.heading),
|
|
482
|
-
pitch = Cesium.Math.toDegrees(this._viewer.camera.pitch),
|
|
483
|
-
roll = Cesium.Math.toDegrees(this._viewer.camera.roll);
|
|
484
|
-
var rectangle = this._viewer.camera.computeViewRectangle(),
|
|
485
|
-
west = rectangle.west / Math.PI * 180,
|
|
486
|
-
north = rectangle.north / Math.PI * 180,
|
|
487
|
-
east = rectangle.east / Math.PI * 180,
|
|
488
|
-
south = rectangle.south / Math.PI * 180,
|
|
489
|
-
centerx = (west + east) / 2,
|
|
490
|
-
cnetery = (north + south) / 2;
|
|
491
|
-
return {
|
|
492
|
-
lon: lon,
|
|
493
|
-
lat: lat,
|
|
494
|
-
height: height,
|
|
495
|
-
heading: heading,
|
|
496
|
-
pitch: pitch,
|
|
497
|
-
roll: roll,
|
|
498
|
-
position: this._viewer.camera.position,
|
|
499
|
-
cameraHeading: this._viewer.camera.heading,
|
|
500
|
-
cameraPitch: this._viewer.camera.pitch,
|
|
501
|
-
cameraRoll: this._viewer.camera.roll,
|
|
502
|
-
center: {
|
|
503
|
-
x: centerx,
|
|
504
|
-
y: cnetery
|
|
505
|
-
},
|
|
506
|
-
direction: new Cesium.Cartesian3(x, y, z)
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
},
|
|
511
|
-
//修改相机状态
|
|
512
|
-
updateCameraState: function (flag) {
|
|
513
|
-
this._viewer.scene._screenSpaceCameraController.enableRotate = flag;
|
|
514
|
-
this._viewer.scene._screenSpaceCameraController.enableTranslate = flag;
|
|
515
|
-
this._viewer.scene._screenSpaceCameraController.enableZoom = flag;
|
|
516
|
-
this._viewer.scene._screenSpaceCameraController.enableTilt = flag;
|
|
517
|
-
this._viewer.scene._screenSpaceCameraController.enableLook = flag;
|
|
518
|
-
},
|
|
519
|
-
/**
|
|
520
|
-
* 鼠标事件注册
|
|
521
|
-
* @param {*} param0
|
|
522
|
-
* { leftClick,mouseMove,dubleClick,leftDown,
|
|
523
|
-
* mouseWheel,leftUp}
|
|
524
|
-
*/
|
|
525
|
-
bindHandelEvent: function ({
|
|
526
|
-
leftClick: _mouseLeftClickHandler,
|
|
527
|
-
mouseMove: _mouseMoveHandler,
|
|
528
|
-
doubleClick: _mouseDbClickHandler,
|
|
529
|
-
leftDown: _mouseLeftDownHandler,
|
|
530
|
-
mouseWheel: _mouseWheelHandler,
|
|
531
|
-
leftUp: _mouseLeftUpHandler
|
|
532
|
-
}) {
|
|
533
|
-
if (this._viewer) {
|
|
534
|
-
var _handlers = new Cesium.ScreenSpaceEventHandler(this._viewer.canvas);
|
|
535
|
-
_mouseLeftClickHandler && _handlers.setInputAction(function (movement) {
|
|
536
|
-
_mouseLeftClickHandler(movement, _handlers);
|
|
537
|
-
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
538
|
-
_mouseMoveHandler && _handlers.setInputAction(function (movement) {
|
|
539
|
-
_mouseMoveHandler(movement, _handlers);
|
|
540
|
-
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
541
|
-
_mouseDbClickHandler && _handlers.setInputAction(function (movement) {
|
|
542
|
-
_mouseDbClickHandler(movement, _handlers);
|
|
543
|
-
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
|
544
|
-
_mouseLeftDownHandler && _handlers.setInputAction(function (movement) {
|
|
545
|
-
_mouseLeftDownHandler(movement, _handlers);
|
|
546
|
-
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
|
547
|
-
_mouseWheelHandler && _handlers.setInputAction(function (movement) {
|
|
548
|
-
_mouseWheelHandler(movement, _handlers);
|
|
549
|
-
}, Cesium.ScreenSpaceEventType.WHEEL);
|
|
550
|
-
_mouseLeftUpHandler && _handlers.setInputAction(function (movement) {
|
|
551
|
-
_mouseLeftUpHandler(movement, _handlers);
|
|
552
|
-
}, Cesium.ScreenSpaceEventType.LEFT_UP);
|
|
553
|
-
}
|
|
554
|
-
},
|
|
555
|
-
//获取鼠标信息
|
|
556
|
-
getHandelPosition: function (callback) {
|
|
557
|
-
if (this._viewer) {
|
|
558
|
-
var _handler = new Cesium.ScreenSpaceEventHandler(this._viewer.scene.canvas),
|
|
559
|
-
$this = this;
|
|
560
|
-
_handler.setInputAction(function (movement) {
|
|
561
|
-
var cartesian = $this._viewer.scene.camera.pickEllipsoid(movement.endPosition, $this._viewer.scene.globe.ellipsoid);
|
|
562
|
-
if (typeof callback === 'function') {
|
|
563
|
-
callback($this.transformCartesianToWGS84(cartesian), _handler);
|
|
564
|
-
}
|
|
565
|
-
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
566
|
-
}
|
|
567
|
-
},
|
|
568
|
-
//保存当前场景png
|
|
569
|
-
saveSceneImages: function () {
|
|
570
|
-
if (this._viewer) {
|
|
571
|
-
const dataURLtoBlob = function (dataurl) {
|
|
572
|
-
var arr = dataurl.split(','),
|
|
573
|
-
mime = arr[0].match(/:(.*?);/)[1],
|
|
574
|
-
bstr = atob(arr[1]),
|
|
575
|
-
n = bstr.length,
|
|
576
|
-
u8arr = new Uint8Array(n);
|
|
577
|
-
while (n--) {
|
|
578
|
-
u8arr[n] = bstr.charCodeAt(n);
|
|
579
|
-
}
|
|
580
|
-
return new Blob([u8arr], {
|
|
581
|
-
type: mime
|
|
582
|
-
});
|
|
583
|
-
};
|
|
584
|
-
var canvas = this._viewer.scene.canvas;
|
|
585
|
-
var image = canvas.toDataURL('image/png').replace('image/png', 'image/octet-stream');
|
|
586
|
-
var link = document.createElement('a');
|
|
587
|
-
// var strDataURI = image.substr(22, image.length)
|
|
588
|
-
var blob = dataURLtoBlob(image);
|
|
589
|
-
var objurl = URL.createObjectURL(blob);
|
|
590
|
-
link.download = 'scene.png';
|
|
591
|
-
link.href = objurl;
|
|
592
|
-
link.click();
|
|
593
|
-
}
|
|
594
|
-
},
|
|
595
|
-
/**
|
|
596
|
-
* amap
|
|
597
|
-
*/
|
|
598
|
-
_installAmapImageryProvider: function () {
|
|
599
|
-
const IMG_URL = 'https://webst{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}';
|
|
600
|
-
const ELEC_URL = 'http://webrd{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}';
|
|
601
|
-
function AmapImageryProvider(options) {
|
|
602
|
-
options['url'] = options.style === 'img' ? IMG_URL : ELEC_URL;
|
|
603
|
-
if (!options.subdomains) {
|
|
604
|
-
options['subdomains'] = ['01', '02', '03', '04'];
|
|
605
|
-
}
|
|
606
|
-
return new Cesium.UrlTemplateImageryProvider(options);
|
|
607
|
-
}
|
|
608
|
-
Cesium.Scene.AmapImageryProvider = AmapImageryProvider;
|
|
609
|
-
},
|
|
610
|
-
/**
|
|
611
|
-
* 天地图
|
|
612
|
-
*/
|
|
613
|
-
_installTdtImageryProvider: function () {
|
|
614
|
-
const MAP_URL = 'http://t{s}.tianditu.gov.cn/{layer}_c/wmts?service=WMTS&version=1.0.0&request=GetTile&tilematrix={TileMatrix}&layer={layer}&style={style}&tilerow={TileRow}&tilecol={TileCol}&tilematrixset={TileMatrixSet}&format=tiles&tk={key}';
|
|
615
|
-
function TdtImageryProvider(options) {
|
|
616
|
-
return new Cesium.UrlTemplateImageryProvider({
|
|
617
|
-
url: MAP_URL.replace(/\{layer\}/g, options.style || 'vec').replace(/\{key\}/g, options.key || ''),
|
|
618
|
-
style: 'default',
|
|
619
|
-
format: 'tiles',
|
|
620
|
-
tileMatrixSetID: 'c',
|
|
621
|
-
matrixSet: 'c',
|
|
622
|
-
wrapX: true,
|
|
623
|
-
crossOrigin: 'anonymous',
|
|
624
|
-
// 跨域
|
|
625
|
-
subdomains: [...Array(6).keys()].map(item => (item + 1).toString()),
|
|
626
|
-
tileMatrixLabels: [...Array(18).keys()].map(item => (item + 1).toString()),
|
|
627
|
-
tilingScheme: new Cesium.GeographicTilingScheme(),
|
|
628
|
-
maximumLevel: 18
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
Cesium.Scene.TdtImageryProvider = TdtImageryProvider;
|
|
632
|
-
},
|
|
633
|
-
/**
|
|
634
|
-
* 腾讯
|
|
635
|
-
*/
|
|
636
|
-
_installTencentImageryProvider: function () {
|
|
637
|
-
const IMG_URL = 'https://p2.map.gtimg.com/sateTiles/{z}/{sx}/{sy}/{x}_{reverseY}.jpg?version=229';
|
|
638
|
-
const ELEC_URL = 'https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}';
|
|
639
|
-
function TencentImageryProvider(options) {
|
|
640
|
-
if (options.layer = 'img') {
|
|
641
|
-
options['url'] = IMG_URL;
|
|
642
|
-
if (!options.subdomains) {
|
|
643
|
-
options['subdomains'] = ['0', '1', '2'];
|
|
644
|
-
}
|
|
645
|
-
options['customTags'] = {
|
|
646
|
-
sx: function (imageryProvider, x, y, level) {
|
|
647
|
-
return x >> 4;
|
|
648
|
-
},
|
|
649
|
-
sy: function (imageryProvider, x, y, level) {
|
|
650
|
-
return (1 << level) - y >> 4;
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
|
-
} else {
|
|
654
|
-
options['url'] = ELEC_URL;
|
|
655
|
-
}
|
|
656
|
-
return new Cesium.UrlTemplateImageryProvider(options);
|
|
657
|
-
}
|
|
658
|
-
Cesium.Scene.TencentImageryProvider = TencentImageryProvider;
|
|
659
|
-
},
|
|
660
|
-
/**
|
|
661
|
-
* google
|
|
662
|
-
*/
|
|
663
|
-
_installGooGleImageryProvider: function () {
|
|
664
|
-
//标注 影像 地形三种
|
|
665
|
-
const ELEC_URL = 'http://mt{s}.google.cn/vt/lyrs=m@207000000&hl=zh-CN&gl=CN&src=app&x={x}&y={y}&z={z}&s=Galile';
|
|
666
|
-
const IMG_URL = 'http://mt{s}.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali';
|
|
667
|
-
const TER_URL = 'http://mt{s}.google.cn/vt/lyrs=t@131,r@227000000&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}&s=Galile';
|
|
668
|
-
function GoogleImageryProvider(options) {
|
|
669
|
-
options['url'] = options.style === 'img' ? IMG_URL : options.style === 'ter' ? TER_URL : ELEC_URL;
|
|
670
|
-
if (!options.subdomains) {
|
|
671
|
-
options['subdomains'] = ['1', '2', '3', '4', '5'];
|
|
672
|
-
}
|
|
673
|
-
return new Cesium.UrlTemplateImageryProvider(options);
|
|
674
|
-
}
|
|
675
|
-
Cesium.Scene.GoogleImageryProvider = GoogleImageryProvider;
|
|
676
|
-
},
|
|
677
|
-
/**
|
|
678
|
-
* 百度影像拓展
|
|
679
|
-
*/
|
|
680
|
-
_installBaiduImageryProvider: function () {
|
|
681
|
-
var TEMP_MAP_URL = 'http://api{s}.map.bdimg.com/customimage/tile?&x={x}&y={y}&z={z}&scale=1&customid={style}';
|
|
682
|
-
function BaiduImageryProvider(options) {
|
|
683
|
-
TEMP_MAP_URL = options.temp_url || TEMP_MAP_URL;
|
|
684
|
-
this._url = TEMP_MAP_URL;
|
|
685
|
-
this._tileWidth = 256;
|
|
686
|
-
this._tileHeight = 256;
|
|
687
|
-
this._maximumLevel = 18;
|
|
688
|
-
this._minimumLevel = 1;
|
|
689
|
-
this._tilingScheme = new Cesium.WebMercatorTilingScheme({
|
|
690
|
-
rectangleSouthwestInMeters: new Cesium.Cartesian2(-33554054, -33746824),
|
|
691
|
-
rectangleNortheastInMeters: new Cesium.Cartesian2(33554054, 33746824)
|
|
692
|
-
});
|
|
693
|
-
this._rectangle = this._tilingScheme.rectangle;
|
|
694
|
-
this._credit = undefined;
|
|
695
|
-
this._style = options.style || 'normal';
|
|
696
|
-
}
|
|
697
|
-
Object.defineProperties(BaiduImageryProvider.prototype, {
|
|
698
|
-
url: {
|
|
699
|
-
get: function () {
|
|
700
|
-
return this._url;
|
|
701
|
-
}
|
|
702
|
-
},
|
|
703
|
-
token: {
|
|
704
|
-
get: function () {
|
|
705
|
-
return this._token;
|
|
706
|
-
}
|
|
707
|
-
},
|
|
708
|
-
tileWidth: {
|
|
709
|
-
get: function () {
|
|
710
|
-
if (!this.ready) {
|
|
711
|
-
throw new Cesium.DeveloperError('tileWidth must not be called before the imagery provider is ready.');
|
|
712
|
-
}
|
|
713
|
-
return this._tileWidth;
|
|
714
|
-
}
|
|
715
|
-
},
|
|
716
|
-
tileHeight: {
|
|
717
|
-
get: function () {
|
|
718
|
-
if (!this.ready) {
|
|
719
|
-
throw new Cesium.DeveloperError('tileHeight must not be called before the imagery provider is ready.');
|
|
720
|
-
}
|
|
721
|
-
return this._tileHeight;
|
|
722
|
-
}
|
|
723
|
-
},
|
|
724
|
-
maximumLevel: {
|
|
725
|
-
get: function () {
|
|
726
|
-
if (!this.ready) {
|
|
727
|
-
throw new Cesium.DeveloperError('tileHeight must not be called before the imagery provider is ready.');
|
|
728
|
-
}
|
|
729
|
-
return this._tileHeight;
|
|
730
|
-
}
|
|
731
|
-
},
|
|
732
|
-
minimumLevel: {
|
|
733
|
-
get: function () {
|
|
734
|
-
if (!this.ready) {
|
|
735
|
-
throw new Cesium.DeveloperError('minimumLevel must not be called before the imagery provider is ready.');
|
|
736
|
-
}
|
|
737
|
-
return 0;
|
|
738
|
-
}
|
|
739
|
-
},
|
|
740
|
-
tilingScheme: {
|
|
741
|
-
get: function () {
|
|
742
|
-
if (!this.ready) {
|
|
743
|
-
throw new Cesium.DeveloperError('tilingScheme must not be called before the imagery provider is ready.');
|
|
744
|
-
}
|
|
745
|
-
return this._tilingScheme;
|
|
746
|
-
}
|
|
747
|
-
},
|
|
748
|
-
rectangle: {
|
|
749
|
-
get: function () {
|
|
750
|
-
if (!this.ready) {
|
|
751
|
-
throw new Cesium.DeveloperError('rectangle must not be called before the imagery provider is ready.');
|
|
752
|
-
}
|
|
753
|
-
return this._rectangle;
|
|
754
|
-
}
|
|
755
|
-
},
|
|
756
|
-
ready: {
|
|
757
|
-
get: function () {
|
|
758
|
-
return !!this._url;
|
|
759
|
-
}
|
|
760
|
-
},
|
|
761
|
-
credit: {
|
|
762
|
-
get: function () {
|
|
763
|
-
return this._credit;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
// BaiduImageryProvider.prototype.getTileCredits = function (x, y, level) {}
|
|
769
|
-
|
|
770
|
-
BaiduImageryProvider.prototype.requestImage = function (x, y, level) {
|
|
771
|
-
if (!this.ready) {
|
|
772
|
-
throw new Cesium.DeveloperError('requestImage must not be called before the imagery provider is ready.');
|
|
773
|
-
}
|
|
774
|
-
var xTiles = this._tilingScheme.getNumberOfXTilesAtLevel(level);
|
|
775
|
-
var yTiles = this._tilingScheme.getNumberOfYTilesAtLevel(level);
|
|
776
|
-
var url = this._url.replace('{x}', x - xTiles / 2).replace('{y}', yTiles / 2 - y - 1).replace('{z}', level).replace('{s}', 1).replace('{style}', this._style);
|
|
777
|
-
return Cesium.ImageryProvider.loadImage(this, url);
|
|
778
|
-
};
|
|
779
|
-
Cesium.Scene.BaiduImageryProvider = BaiduImageryProvider;
|
|
780
|
-
},
|
|
781
|
-
// 拓展近景天空盒
|
|
782
|
-
_installGroundSkyBox: function () {
|
|
783
|
-
var BoxGeometry = Cesium.BoxGeometry,
|
|
784
|
-
Cartesian3 = Cesium.Cartesian3,
|
|
785
|
-
defaultValue = Cesium.defaultValue,
|
|
786
|
-
defined = Cesium.defined,
|
|
787
|
-
destroyObject = Cesium.destroyObject,
|
|
788
|
-
DeveloperError = Cesium.DeveloperError,
|
|
789
|
-
GeometryPipeline = Cesium.GeometryPipeline,
|
|
790
|
-
Matrix3 = Cesium.Matrix3,
|
|
791
|
-
Matrix4 = Cesium.Matrix4,
|
|
792
|
-
Transforms = Cesium.Transforms,
|
|
793
|
-
VertexFormat = Cesium.VertexFormat,
|
|
794
|
-
BufferUsage = Cesium.BufferUsage,
|
|
795
|
-
CubeMap = Cesium.CubeMap,
|
|
796
|
-
DrawCommand = Cesium.DrawCommand,
|
|
797
|
-
loadCubeMap = Cesium.loadCubeMap,
|
|
798
|
-
RenderState = Cesium.RenderState,
|
|
799
|
-
VertexArray = Cesium.VertexArray,
|
|
800
|
-
BlendingState = Cesium.BlendingState,
|
|
801
|
-
SceneMode = Cesium.SceneMode,
|
|
802
|
-
ShaderProgram = Cesium.ShaderProgram,
|
|
803
|
-
ShaderSource = Cesium.ShaderSource;
|
|
804
|
-
//片元着色器,直接从源码复制
|
|
805
|
-
var SkyBoxFS = 'uniform samplerCube u_cubeMap;\n\
|
|
806
|
-
varying vec3 v_texCoord;\n\
|
|
807
|
-
void main()\n\
|
|
808
|
-
{\n\
|
|
809
|
-
vec4 color = textureCube(u_cubeMap, normalize(v_texCoord));\n\
|
|
810
|
-
gl_FragColor = vec4(czm_gammaCorrect(color).rgb, czm_morphTime);\n\
|
|
811
|
-
}\n\
|
|
812
|
-
';
|
|
813
|
-
|
|
814
|
-
//顶点着色器有修改,主要是乘了一个旋转矩阵
|
|
815
|
-
var SkyBoxVS = 'attribute vec3 position;\n\
|
|
816
|
-
varying vec3 v_texCoord;\n\
|
|
817
|
-
uniform mat3 u_rotateMatrix;\n\
|
|
818
|
-
void main()\n\
|
|
819
|
-
{\n\
|
|
820
|
-
vec3 p = czm_viewRotation * u_rotateMatrix * (czm_temeToPseudoFixed * (czm_entireFrustum.y * position));\n\
|
|
821
|
-
gl_Position = czm_projection * vec4(p, 1.0);\n\
|
|
822
|
-
v_texCoord = position.xyz;\n\
|
|
823
|
-
}\n\
|
|
824
|
-
';
|
|
825
|
-
/**
|
|
826
|
-
* 为了兼容高版本的Cesium,因为新版cesium中getRotation被移除
|
|
827
|
-
*/
|
|
828
|
-
if (!defined(Matrix4.getRotation)) {
|
|
829
|
-
Matrix4.getRotation = Matrix4.getMatrix3;
|
|
830
|
-
}
|
|
831
|
-
function SkyBoxOnGround(options) {
|
|
832
|
-
this.sources = options.sources;
|
|
833
|
-
this._sources = undefined;
|
|
834
|
-
/**
|
|
835
|
-
* Determines if the sky box will be shown.
|
|
836
|
-
*
|
|
837
|
-
* @type {Boolean}
|
|
838
|
-
* @default true
|
|
839
|
-
*/
|
|
840
|
-
this.show = defaultValue(options.show, true);
|
|
841
|
-
this._command = new DrawCommand({
|
|
842
|
-
modelMatrix: Matrix4.clone(Matrix4.IDENTITY),
|
|
843
|
-
owner: this
|
|
844
|
-
});
|
|
845
|
-
this._cubeMap = undefined;
|
|
846
|
-
this._attributeLocations = undefined;
|
|
847
|
-
this._useHdr = undefined;
|
|
848
|
-
}
|
|
849
|
-
var skyboxMatrix3 = new Matrix3();
|
|
850
|
-
SkyBoxOnGround.prototype.update = function (frameState, useHdr) {
|
|
851
|
-
var that = this;
|
|
852
|
-
if (!this.show) {
|
|
853
|
-
return undefined;
|
|
854
|
-
}
|
|
855
|
-
if (frameState.mode !== SceneMode.SCENE3D && frameState.mode !== SceneMode.MORPHING) {
|
|
856
|
-
return undefined;
|
|
857
|
-
}
|
|
858
|
-
if (!frameState.passes.render) {
|
|
859
|
-
return undefined;
|
|
860
|
-
}
|
|
861
|
-
var context = frameState.context;
|
|
862
|
-
if (this._sources !== this.sources) {
|
|
863
|
-
this._sources = this.sources;
|
|
864
|
-
var sources = this.sources;
|
|
865
|
-
if (!defined(sources.positiveX) || !defined(sources.negativeX) || !defined(sources.positiveY) || !defined(sources.negativeY) || !defined(sources.positiveZ) || !defined(sources.negativeZ)) {
|
|
866
|
-
throw new DeveloperError('this.sources is required and must have positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ properties.');
|
|
867
|
-
}
|
|
868
|
-
if (typeof sources.positiveX !== typeof sources.negativeX || typeof sources.positiveX !== typeof sources.positiveY || typeof sources.positiveX !== typeof sources.negativeY || typeof sources.positiveX !== typeof sources.positiveZ || typeof sources.positiveX !== typeof sources.negativeZ) {
|
|
869
|
-
throw new DeveloperError('this.sources properties must all be the same type.');
|
|
870
|
-
}
|
|
871
|
-
if (typeof sources.positiveX === 'string') {
|
|
872
|
-
// Given urls for cube-map images. Load them.
|
|
873
|
-
loadCubeMap(context, this._sources).then(function (cubeMap) {
|
|
874
|
-
that._cubeMap = that._cubeMap && that._cubeMap.destroy();
|
|
875
|
-
that._cubeMap = cubeMap;
|
|
876
|
-
});
|
|
877
|
-
} else {
|
|
878
|
-
this._cubeMap = this._cubeMap && this._cubeMap.destroy();
|
|
879
|
-
this._cubeMap = new CubeMap({
|
|
880
|
-
context: context,
|
|
881
|
-
source: sources
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
var command = this._command;
|
|
886
|
-
command.modelMatrix = Transforms.eastNorthUpToFixedFrame(frameState.camera._positionWC);
|
|
887
|
-
if (!defined(command.vertexArray)) {
|
|
888
|
-
command.uniformMap = {
|
|
889
|
-
u_cubeMap: function () {
|
|
890
|
-
return that._cubeMap;
|
|
891
|
-
},
|
|
892
|
-
u_rotateMatrix: function () {
|
|
893
|
-
return Matrix4.getRotation(command.modelMatrix, skyboxMatrix3);
|
|
894
|
-
}
|
|
895
|
-
};
|
|
896
|
-
var geometry = BoxGeometry.createGeometry(BoxGeometry.fromDimensions({
|
|
897
|
-
dimensions: new Cartesian3(2.0, 2.0, 2.0),
|
|
898
|
-
vertexFormat: VertexFormat.POSITION_ONLY
|
|
899
|
-
}));
|
|
900
|
-
var attributeLocations = this._attributeLocations = GeometryPipeline.createAttributeLocations(geometry);
|
|
901
|
-
command.vertexArray = VertexArray.fromGeometry({
|
|
902
|
-
context: context,
|
|
903
|
-
geometry: geometry,
|
|
904
|
-
attributeLocations: attributeLocations,
|
|
905
|
-
bufferUsage: BufferUsage._DRAW
|
|
906
|
-
});
|
|
907
|
-
command.renderState = RenderState.fromCache({
|
|
908
|
-
blending: BlendingState.ALPHA_BLEND
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
if (!defined(command.shaderProgram) || this._useHdr !== useHdr) {
|
|
912
|
-
var fs = new ShaderSource({
|
|
913
|
-
defines: [useHdr ? 'HDR' : ''],
|
|
914
|
-
sources: [SkyBoxFS]
|
|
915
|
-
});
|
|
916
|
-
command.shaderProgram = ShaderProgram.fromCache({
|
|
917
|
-
context: context,
|
|
918
|
-
vertexShaderSource: SkyBoxVS,
|
|
919
|
-
fragmentShaderSource: fs,
|
|
920
|
-
attributeLocations: this._attributeLocations
|
|
921
|
-
});
|
|
922
|
-
this._useHdr = useHdr;
|
|
923
|
-
}
|
|
924
|
-
if (!defined(this._cubeMap)) {
|
|
925
|
-
return undefined;
|
|
926
|
-
}
|
|
927
|
-
return command;
|
|
928
|
-
};
|
|
929
|
-
SkyBoxOnGround.prototype.isDestroyed = function () {
|
|
930
|
-
return false;
|
|
931
|
-
};
|
|
932
|
-
SkyBoxOnGround.prototype.destroy = function () {
|
|
933
|
-
var command = this._command;
|
|
934
|
-
command.vertexArray = command.vertexArray && command.vertexArray.destroy();
|
|
935
|
-
command.shaderProgram = command.shaderProgram && command.shaderProgram.destroy();
|
|
936
|
-
this._cubeMap = this._cubeMap && this._cubeMap.destroy();
|
|
937
|
-
return destroyObject(this);
|
|
938
|
-
};
|
|
939
|
-
Cesium.Scene.GroundSkyBox = SkyBoxOnGround;
|
|
940
|
-
},
|
|
941
|
-
/**
|
|
942
|
-
*
|
|
943
|
-
* @param {*} eventNameArr handler名称数组,如['LEFT_CLICK','MOUSE_MOVE']
|
|
944
|
-
*/
|
|
945
|
-
removeHandlerByName(eventNameArr = []) {
|
|
946
|
-
eventNameArr.forEach(eHandler => {
|
|
947
|
-
this._viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType[eHandler]);
|
|
948
|
-
});
|
|
949
|
-
}
|
|
950
|
-
};
|