Potree eingebunden und Kamera Synchronisiert
This commit is contained in:
93
main.js
93
main.js
@@ -1,9 +1,5 @@
|
||||
import maplibregl from "maplibre-gl";
|
||||
import {Deck} from '@deck.gl/core';
|
||||
import {PointCloudLayer} from '@deck.gl/layers';
|
||||
import {LASLoader} from '@loaders.gl/las';
|
||||
import {MapboxOverlay} from '@deck.gl/mapbox';
|
||||
import {COORDINATE_SYSTEM} from '@deck.gl/core';
|
||||
|
||||
|
||||
|
||||
const center = [9.209116842757239, 52.26520546238239]
|
||||
@@ -23,48 +19,69 @@ map.addControl(
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
const elRenderArea=document.getElementById("potree_render_area");
|
||||
|
||||
const viewer=new Potree.Viewer(elRenderArea, {noDragAndDrop:true});
|
||||
viewer.setEDLEnabled(true);
|
||||
viewer.setFOV(60);
|
||||
viewer.setPointBudget(3*1000*1000);
|
||||
viewer.setMinNodeSize(0);
|
||||
|
||||
//Dateipfade der Punktwolken
|
||||
const pointCloudFiles={
|
||||
first: 'punktwolke_1.laz',
|
||||
second: 'punktwolke_2.laz',
|
||||
third: 'punktwolke_3.laz'
|
||||
//Namen sind gerade nur Platzhalter. Richtige namen müssen rein
|
||||
first: 'punktwolke_1_converted/metadata.json',
|
||||
second: 'punktwolke_2_converted/metadata.json',
|
||||
third: 'punktwolke_3_converted/metadata.json',
|
||||
}
|
||||
//Aktuelle Datei und Sichtbarkeit
|
||||
let currentData=null;
|
||||
let currentPointCloud=null;
|
||||
let isVisible=true;
|
||||
|
||||
const overlay= new MapboxOverlay({layers: []});
|
||||
|
||||
function updateLayer(){
|
||||
if (!currentData || !isVisible){
|
||||
overlay.setProps({layers:[]});
|
||||
return;
|
||||
function loadPointCloud(path){
|
||||
if(currentPointCloud){
|
||||
viewer.scene.removePointCloud(currentPointCloud);
|
||||
currentPointCloud=null;
|
||||
}
|
||||
const layer = new PointCloudLayer({
|
||||
id: 'pointcloud-layer',
|
||||
data: currentData,
|
||||
loaders: [LASLoader],
|
||||
|
||||
// 1. Set the coordinate system to meter offsets
|
||||
coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS,
|
||||
if(!path ||!isVisible) return;
|
||||
|
||||
// 2. Set the anchor point [longitude, latitude, elevation]
|
||||
coordinateOrigin: [9.209116842757239, 52.26520546238239],
|
||||
pointSize: 1,
|
||||
getColor: [255,255,255]
|
||||
Potree.loadPointCloud(path, "punktwolke", function(e) {
|
||||
currentPointCloud=e.pointcloud;
|
||||
viewer.scene.addPointCloud(currentPointCloud);
|
||||
|
||||
let material =currentPointCloud.material;
|
||||
material.size =1;
|
||||
material.pointSizeType=Potree.PointSizeType.ADAPTIVE;
|
||||
});
|
||||
|
||||
overlay.setProps({layers: [layer]});
|
||||
}
|
||||
|
||||
function syncCamera(){
|
||||
const zoom =map.getZoom();
|
||||
const pitch=map.getPitch();
|
||||
const bearing=map.getBearing();
|
||||
|
||||
const distance=Math.pow(2,20-zoom)*0.5;
|
||||
|
||||
|
||||
map.on('style.load', ()=>{
|
||||
if (!map._controls.includes(overlay)) {
|
||||
map.addControl(overlay);
|
||||
const pitchRad=pitch *(Math.PI/180);
|
||||
const bearingRad=bearing*(Math.PI/180);
|
||||
|
||||
const camX=distance*Math.sin(bearingRad) *Math.cos(pitchRad);
|
||||
const camY=-distance*Math.cos(bearingRad) *Math.cos(pitchRad);
|
||||
const camZ=distance*Math.sin(pitchRad) + 50;
|
||||
|
||||
viewer.scene.view.position.set(camX, camY, camZ);
|
||||
viewer.scene.view.lookAt(0,0,0);
|
||||
}
|
||||
updateLayer();
|
||||
})
|
||||
|
||||
map.on('move', syncCamera);
|
||||
map.on('zoom', syncCamera);
|
||||
map.on('pitch', syncCamera);
|
||||
map.on('rotate', syncCamera);
|
||||
|
||||
|
||||
|
||||
|
||||
// Hintergrundkarte ändern
|
||||
@@ -192,16 +209,12 @@ function changeBaseMap(newMap){
|
||||
}
|
||||
|
||||
|
||||
// dargestellte Punktwolke verändern
|
||||
function changePointCloud(value){
|
||||
currentData = pointCloudFiles[value];
|
||||
updateLayer();
|
||||
}
|
||||
|
||||
document.querySelector('input[type="checkbox"]').addEventListener('change', (event)=>
|
||||
{
|
||||
isVisible=!event.target.checked;
|
||||
updateLayer();
|
||||
if (currentPointCloud){
|
||||
currentPointCloud.visible=isVisible;
|
||||
};
|
||||
})
|
||||
|
||||
|
||||
@@ -215,7 +228,7 @@ selectElement.addEventListener('change', (event) => {
|
||||
|
||||
// ausgewähltes Element im Punktwolken DropDown Feld
|
||||
document.querySelector('select[name="pointcloud"]').addEventListener('change', (event) => {
|
||||
changePointCloud(event.target.value);
|
||||
loadPointCloud(pointCloudFiles[event.target.value]);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user