-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtazmarGIS.html
412 lines (360 loc) · 14.1 KB
/
tazmarGIS.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Tazmar GIS</title>
<link rel="stylesheet" type="text/css" href="./build/potree/potree.css">
<link rel="stylesheet" type="text/css" href="./libs/jquery-ui/jquery-ui.min.css">
<link rel="stylesheet" type="text/css" href="./libs/openlayers3/ol.css">
<link rel="stylesheet" type="text/css" href="./libs/spectrum/spectrum.css">
<link rel="stylesheet" type="text/css" href="./libs/jstree/themes/mixed/style.css">
<link rel="stylesheet" type="text/css" href="./libs/Cesium/Widgets/CesiumWidget/CesiumWidget.css">
</head>
<>
<script src="./libs/jquery/jquery-3.1.1.min.js"></script>
<script src="./libs/spectrum/spectrum.js"></script>
<script src="./libs/jquery-ui/jquery-ui.min.js"></script>
<script src="./libs/other/BinaryHeap.js"></script>
<script src="./libs/tween/tween.min.js"></script>
<script src="./libs/d3/d3.js"></script>
<script src="./libs/proj4/proj4.js"></script>
<script src="./libs/openlayers3/ol.js"></script>
<script src="./libs/i18next/i18next.js"></script>
<script src="./libs/jstree/jstree.js"></script>
<script src="./build/potree/potree.js"></script>
<script src="./libs/plasio/js/laslaz.js"></script>
<script src="./libs/inflate/inflate.min.js"></script>
<!--<script src="./libs/three.js/loaders/FBXLoader.js"></script>-->
<!--<script src="./libs/Cesium/Cesium.js"></script>-->
<script type="text/javascript" src="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Cesium.js"></script>
<div class="potree_container" style="position: absolute; width: 100%; height: 100%; left: 0px; top: 0px; ">
<div id="potree_render_area" style="background-image: url('./build/potree/resources/images/background.jpg');">
<div id="cesiumContainer" style="position: absolute; width: 100%; height: 100%; background-color:green"></div>
</div>
<div id="potree_sidebar_container"> </div>
</div>
<script type="module">
import * as THREE from "./libs/three.js/build/three.module.js";
import { FBXLoader } from "./libs/three.js/loaders/l2/FBXLoader.js";
import {initModelPositioningGUIController, selectableObjects} from "./libs/custom/modelGuiController.js";
import {objectsConfsOnScene} from "./examples/tazmar_sources/sceneObjectConf.js"
// ========= init default data section ===========
const objectsOnSceneList = {}
window.objectsOnSceneList = objectsOnSceneList
// ===============================================
// ========= run programm ======================
initCesium();
initPotree();
//initModelPositioningGUIController()
requestAnimationFrame(loop);
main();
// =========== end programm ===================
// =========== function declare ===============
function main() {
Object.values(objectsConfsOnScene).forEach(o => {
if (o.objectType === 'pointCloud'){
loadObjectDataOnPotreeScene(o, potreeViewer)
.then(object => {
objectsOnSceneList[o.name] = object
})
} else {
potreeViewer.onGUILoaded(() => {
let tree = $(`#jstree_scene`);
let parentNode = "meshes";
let pierId = tree.jstree(
'create_node',
parentNode,
{
text: o.name,
icon: `${Potree.resourcePath}/icons/target.svg`,
data: o,
class: o.name
},
"last", false, false);
tree.jstree(o.visible ? "check_node" : "uncheck_node", pierId);
tree.jstree(true).get_node(pierId).data.nodeElement = tree.jstree(true).get_node(pierId, true)[0];
tree.on("check_node.jstree", (e, data) => {
let object = data.node.data;
if(object.objectType === 'fbxModel'){
if (!objectsOnSceneList[object.name]){
loadObjectDataOnPotreeScene(object, potreeViewer)
.then(object => {
objectsOnSceneList[o.name] = object
})
} else {
objectsOnSceneList[object.name].visible = true
}
}
});
tree.on("uncheck_node.jstree", (e, data) => {
let object = data.node.data;
// object.visible = false;
objectsOnSceneList[object.name].visible = false
});
});
}
})
// Хак. Выбираем поинтклауд, чтобы убрать черную раскраску, появляющуюся по-умолчанию из-за ошбки при инициализации
setTimeout(() => {
const batimetry7thNode = Object.values(document.querySelectorAll('#jstree_scene #pointclouds .jstree-children .jstree-leaf a')).find(node => node.innerText == '7й причал. Батиметрия')
batimetry7thNode.click()
}, 1500)
}
function initCesium() {
window.cesiumViewer = new Cesium.Viewer('cesiumContainer', {
useDefaultRenderLoop: false,
animation: false,
baseLayerPicker : false,
fullscreenButton: false,
geocoder: false,
homeButton: false,
infoBox: false,
sceneModePicker: true,
selectionIndicator: false,
timeline: false,
navigationHelpButton: false,
// imageryProvider : Cesium.createOpenStreetMapImageryProvider({url : 'https://a.tile.openstreetmap.org/'}),
imageryProvider : new Cesium.OpenStreetMapImageryProvider({url : 'https://a.tile.openstreetmap.org/', crossOrigin: null}),
terrainShadows: Cesium.ShadowMode.DISABLED,
});
Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIwYmFjMzFkNS05M2QwLTQ1OGQtYjVkMi03YjVhYzY2NjI4NjgiLCJpZCI6NjkwMTksImlhdCI6MTYzMzA0NjI4N30.z8PZB6uBWIbRpALYj-mrSCLMQkKbRiQrz2Xle4jq9CA";
let cp = new Cesium.Cartesian3(1323578.895075808, 12702145.969783371, 0);
cesiumViewer.camera.setView({
destination : cp,
orientation: {
heading : 10,
pitch : -Cesium.Math.PI_OVER_TWO * 0.5,
roll : 0.0
}
});
}
function initPotree() {
window.potreeViewer = new Potree.Viewer(document.getElementById("potree_render_area"), {
useDefaultRenderLoop: false
});
potreeViewer.setEDLEnabled(true);
potreeViewer.setFOV(55);
potreeViewer.setPointBudget(1_500_000);
potreeViewer.setMinNodeSize(50);
potreeViewer.loadSettingsFromURL();
potreeViewer.setBackground(null);
potreeViewer.useHQ = true;
// LIGHTS
const directional = new THREE.DirectionalLight( 0xffffff, 1.0);
directional.position.set( 10, 10, 10 );
directional.lookAt(0, 0, 0);
const ambient = new THREE.AmbientLight(0x555555);
potreeViewer.scene.scene.add(directional);
potreeViewer.scene.scene.add(ambient);
potreeViewer.loadGUI(() => {
potreeViewer.setLanguage('en');
document.getElementById('potree_render_area').style.right = '0px'
});
}
async function loadObjectDataOnPotreeScene (options, viewer) {
return new Promise( resolve => {
let scene = viewer.scene;
switch (options.objectType) {
case 'pointCloud': {
Potree.loadPointCloud(options.url, options.name, async function(e){
scene.addPointCloud(e.pointcloud);
e.pointcloud.position.set(options.objectPosition.x, options.objectPosition.y, options.objectPosition.z);
e.pointcloud.rotation.set(options.objectRotation.x, options.objectRotation.y, options.objectRotation.z);
e.pointcloud.scale.set(options.objectScale.x, options.objectScale.y, options.objectScale.z);
let material = e.pointcloud.material;
Object.keys(options.objectMaterial)
.forEach(key => material[key] = options.objectMaterial[key])
scene.view.position.set(options.view.viewPosition.x, options.view.viewPosition.y, options.view.viewPosition.z);
Object.keys(options.view)
.forEach(key => scene.view[key] = options.view[key])
let pointcloudProjection = "+proj=utm +zone=33 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
let mapProjection = proj4.defs("WGS84");
window.toMap = proj4(pointcloudProjection, mapProjection);
window.toScene = proj4(mapProjection, pointcloudProjection);
{
let bb = viewer.getBoundingBox();
let minWGS84 = proj4(pointcloudProjection, mapProjection, bb.min.toArray());
let maxWGS84 = proj4(pointcloudProjection, mapProjection, bb.max.toArray());
}
resolve(e.pointcloud)
});
break;
}
case 'fbxModel': {
let manager = new THREE.LoadingManager();
let scene = viewer.scene;
manager.onProgress = function (item, loaded, total) {
console.log(`${options.name} загружается:`)
console.log(item, loaded, total);
};
let loader = new FBXLoader(manager);
loader.load(options.url, async function(object) {
object.visible = true;
object.position.set(options.objectPosition.x, options.objectPosition.y, options.objectPosition.z);
object.rotation.set(options.objectRotation.x, options.objectRotation.y, options.objectRotation.z);
object.scale.set(options.objectScale.x, options.objectScale.y, options.objectScale.z);
object.rotation.set(Math.PI / 2, Math.PI, 0)
scene.scene.add(object);
object.children[0].rotation.x = options.objectRotation2.x;
object.children[0].rotation.y = options.objectRotation2.y;
object.children[0].rotation.z = options.objectRotation2.z;
object.children[0].position.x = options.objectPosition2.x;
object.children[0].position.y = options.objectPosition2.y;
object.children[0].position.z = options.objectPosition2.z;
selectableObjects(scene.scene);
resolve(object)
},
async function (e) {
options.nodeElement.querySelector('.jstree-anchor').style.background = options.nodeElement.style.background = `linear-gradient(90deg, rgba(50,180,107,1) ${e.loaded / e.total * 100}%, rgba(234,233,237,1) 0%)`;
});
break;
}
}
})
}
function loop(timestamp){
requestAnimationFrame(loop);
potreeViewer.update(potreeViewer.clock.getDelta(), timestamp);
potreeViewer.render();
if(window.toMap !== undefined){
{
let camera = potreeViewer.scene.getActiveCamera();
let pPos = new THREE.Vector3(0, 0, 0).applyMatrix4(camera.matrixWorld);
let pRight = new THREE.Vector3(600, 0, 0).applyMatrix4(camera.matrixWorld);
let pUp = new THREE.Vector3(0, 600, 0).applyMatrix4(camera.matrixWorld);
let pTarget = potreeViewer.scene.view.getPivot();
let toCes = (pos) => {
let xy = [pos.x, pos.y];
let height = pos.z;
let deg = toMap.forward(xy);
let cPos = Cesium.Cartesian3.fromDegrees(...deg, height);
return cPos;
};
window.toCes = toCes
let cPos = toCes(pPos);
let cUpTarget = toCes(pUp);
let cTarget = toCes(pTarget);
let cDir = Cesium.Cartesian3.subtract(cTarget, cPos, new Cesium.Cartesian3());
let cUp = Cesium.Cartesian3.subtract(cUpTarget, cPos, new Cesium.Cartesian3());
cDir = Cesium.Cartesian3.normalize(cDir, new Cesium.Cartesian3());
cUp = Cesium.Cartesian3.normalize(cUp, new Cesium.Cartesian3());
cesiumViewer.camera.setView({
destination : cPos,
orientation : {
direction : cDir,
up : cUp
}
});
}
let aspect = potreeViewer.scene.getActiveCamera().aspect;
if(aspect < 1){
let fovy = Math.PI * (potreeViewer.scene.getActiveCamera().fov / 180);
cesiumViewer.camera.frustum.fov = fovy;
}else{
let fovy = Math.PI * (potreeViewer.scene.getActiveCamera().fov / 180);
let fovx = Math.atan(Math.tan(0.5 * fovy) * aspect) * 2
cesiumViewer.camera.frustum.fov = fovx;
}
}
cesiumViewer.render();
}
</script>
<style rel="stylesheet" type="text/css" href="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Widgets/widgets.css"> </style>
<style>
:root {
font-family: Arial;
}
#sidebar_header {
display: none;
}
#menu_appearance ul.pv-menu-list li:nth-last-child(-n+12) {
display: none !important;
}
.hide {
display: none !important;
}
#potree_sidebar_container {
right: 0;
}
#potree_sidebar_container {
z-index: 10 !important;
background-color: transparent !important;
}
#potree_menu {
background-color: rgba(230,230,230,0.5) !important;
border: 2px groove #fff;
border-radius: 5px;
color: black !important;
}
.accordion > h3 {
background-color: rgb(39 40 40) !important;
background: #ffffff 50% 50% repeat-x;
}
#potree_sidebar_container a {
color: #272828 !important;
}
#tools img.button-icon {
box-shadow: 0 0 2px 2px #fff;
border-radius: 5px;
padding: 4px;
}
#tools img.button-icon:hover {
background-color: #ff000070;
cursor: pointer;
}
.jstree-default .jstree-clicked {
background-color: #ddff9a !important;
}
.jstree-default .jstree-hovered {
background-color: #ddff9a !important;
}
.potree_menu_toggle {
display: none;
}
.cesium-viewer-bottom {
display: none;
}
#potree_menu h3 {
text-align: center;
padding: 4px 10px 4px 10px !important;
}
.cesium-viewer-bottom {
display: none;
}
.navigation-container {
padding: 10px;
border-radius: 10px;
position: absolute;
float: left;
top: 10px;
left: 10px;
width: 300px;
height: 100px;
color: #ffffff;
border: 1px solid black;
z-index: 999;
background-color: rgb(39 40 40);
}
#selectableGeometry {
margin-top: 10px;
}
.btn-directions {
display: flex;
margin-top: 10px;
justify-content: space-between;
align-items: center;
font-size: 20px;
cursor: pointer;
}
#objLeftAdd {}
#objTopAdd {}
#objLeftDef {}
#objTopDef {}
#objRotateLeft {}
#objRotateRight {}
</style>
</body>
</html>