-
Notifications
You must be signed in to change notification settings - Fork 5
/
Cesium2c3.html
262 lines (234 loc) · 6.8 KB
/
Cesium2c3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<title>二三维联动</title>
<link href="https://cdn.bootcdn.net/ajax/libs/openlayers/4.6.5/ol.css" rel="stylesheet">
<script src="Cesium/Cesium.js"></script>
<link href="Cesium/Widgets/widgets.css" rel="stylesheet" />
<script src="https://cdn.bootcdn.net/ajax/libs/openlayers/4.6.5/ol.js"></script>
<script src="plugin/Cesium2c3Plugin.js"></script>
<style>
html,
body,
.main-view,
#cesiumContainer {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#infobox {
position: absolute;
top: 20px;
left: 30px;
font-size: 14px;
z-index: 99;
padding: 10px 20px;
background-color: white;
border: 1px solid #cccccc;
}
.toolbox {
position: absolute;
top: 49%;
left: 30px;
z-index: 99;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.tool-item {
background-color: #303336;
cursor: pointer;
}
/* pop框css*/
.cesium-popup-panel {
opacity: 0.8;
width: 312px;
position: absolute;
z-index: 999;
color: #00fcf9;
background: rgba(23, 50, 108, 0.6);
border: 1px solid #4674d6;
}
.cesium-popup-tip-panel {
width: 40px;
height: 20px;
position: absolute;
left: 50%;
bottom: -20px;
margin-left: -20px;
overflow: hidden;
pointer-events: none;
opacity: 0.8;
}
.cesium-popup-tip-bottom {
width: 17px;
background: rgba(23, 50, 108, 0.8);
border-bottom: 1px solid #4674d6;
height: 17px;
padding: 1px;
margin: -10px auto 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.cesium-popup-header-panel {
/* display: flex; */
/* justify-content: space-between; */
align-items: center;
font-size: 14px;
padding: 5px 15px;
background: rgba(23, 50, 108, 0.8);
border-bottom: 1px solid #4674d6;
}
.cesium-poput-header-title {
font-size: 16px;
font-family: Microsoft YaHei;
font-weight: 400;
color: #ffffff;
}
.cesium-popup-content-panel {
padding: 18px;
}
.cesium-popup-close-btn {
float: right;
position: relative;
right: 10px;
}
.cesium-popup-close-btn,
.cesium-popup-close-btn:focus {
cursor: pointer;
}
cesium-popup-close-btn>svg:hover {
color: #00fcf9 !important;
}
.cesium-popup-close-btn>svg {
user-select: auto;
color: #4674d6;
cursor: pointer;
width: 15px;
/* height: 15px; */
}
</style>
</head>
<body>
<div class="main-view" style="position: relative;display: flex">
<div id="infobox"></div>
<div class="toolbox">
<button id="zoomIn" class="tool-item">++
</button>
<button id="zoomOut" class="tool-item">--
</button>
<button id='point' style="color: white;" class="tool-item">联动</button>
<button id='clear' style="color: white;" class="tool-item">关闭</button>
</div>
<div id="cesiumContainer"></div>
</div>
</body>
<script type="module">
var viewer = new Cesium.Viewer('cesiumContainer', {
imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
}),
shouldAnimate: true,
timeline: false,
animation: false,
shadow: false,
mapProjection: new Cesium.WebMercatorProjection(),
});
viewer._cesiumWidget._creditContainer.style.display = 'none'; // 隐藏版权
viewer.scene.globe.show = true;
viewer.scene.debugShowFramesPerSecond = true;
var tilesets = new Cesium.Cesium3DTileset({
url: 'data/Tileset/tileset.json',
skipLevelOfDetail: true,
maximumMemoryUsage: 1500,
maximumScreenSpaceError: 16,
// cullRequestsWhileMovingMultiplier: 100,
dynamicScreenSpaceError: false,
preferLeaves: true,
debugShowContentBoundingVolume: false,
debugShowViewerRequestVolume: false,
debugShowBoundingVolume: false,
});
tilesets.readyPromise
.then(function (tileset) {
viewer.scene.primitives.add(tileset);
viewer.flyTo(tileset);
})
.catch(function (error) {
console.log(error);
});
var linkUtil = new Cesium2c3()
document.getElementById('point').onclick = function () {
if (linkUtil.isActive) return
linkUtil.active(viewer)
}
document.getElementById('clear').onclick = function () {
linkUtil.deactive()
}
// 放大缩小
document.getElementById('zoomIn').onclick = function () {
// 获取当前镜头位置的笛卡尔坐标
let cameraPos = viewer.camera.position;
// 获取当前坐标系标准
let ellipsoid = viewer.scene.globe.ellipsoid;
// 根据坐标系标准,将笛卡尔坐标转换为地理坐标
let cartographic = ellipsoid.cartesianToCartographic(cameraPos);
// 获取镜头的高度
let height = cartographic.height;
// if (height < 40) {
// return
// }
// 镜头拉近
viewer.camera.zoomIn(height / 3);
};
document.getElementById('zoomOut').onclick = function () {
// 获取当前镜头位置的笛卡尔坐标
let cameraPos = viewer.camera.position;
// 获取当前坐标系标准
let ellipsoid = viewer.scene.globe.ellipsoid;
// 根据坐标系标准,将笛卡尔坐标转换为地理坐标
let cartographic = ellipsoid.cartesianToCartographic(cameraPos);
// 获取镜头的高度
let height = cartographic.height;
// if (height < 40) {
// return
// }
// 镜头拉近
viewer.camera.zoomOut(height * 1.2);
};
//经纬度显示
viewer.screenSpaceEventHandler.setInputAction(function (event) {
var earthPosition = viewer.camera.pickEllipsoid(
event.position,
viewer.scene.globe.ellipsoid
);
var cartographic = Cesium.Cartographic.fromCartesian(
earthPosition,
viewer.scene.globe.ellipsoid,
new Cesium.Cartographic()
);
var lat = Cesium.Math.toDegrees(cartographic.latitude);
var lng = Cesium.Math.toDegrees(cartographic.longitude);
var height = viewer.camera.positionCartographic.height;
document.getElementById('infobox').innerHTML =
'<span>经度:' +
lng.toFixed(3) +
'</span>' +
'<span> 纬度:' +
lat.toFixed(3) +
'</span>' +
'<span> 相机高度:' +
height +
'</span>';
// console.log(lat, lng, height);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
</script>
</html>