diff --git a/src/PointCloudTree.js b/src/PointCloudTree.js index 7601325f..ff2d7fb4 100644 --- a/src/PointCloudTree.js +++ b/src/PointCloudTree.js @@ -1,6 +1,269 @@ +// +// index is in order xyzxyzxyz +// +Potree.DEMNode = class DEMNode{ + constructor(name, box, tileSize){ + this.name = name; + this.box = box; + this.tileSize = tileSize; + this.level = this.name.length - 1; + this.data = new Float32Array(tileSize * tileSize); + this.children = []; + } + + uv(position){ + let boxSize = this.box.getSize(); + + let u = (position.x - this.box.min.x) / boxSize.x; + let v = (position.y - this.box.min.y) / boxSize.y; + + return [u, v]; + } + + height(position){ + let uv = this.uv(position); + + uv.map(n => Math.min(Math.floor(n), this.tileSize)); + + let i = parseInt(this.tileSize * uv[0] + (this.tileSize ** 2) * uv[1]); + + let height = this.data[i]; + return height; + } +} +Potree.DEM = class DEM{ + constructor(pointcloud){ + + this.pointcloud = pointcloud; + this.matrix = null; + this.boundingBox = null; + this.tileSize = 64; + this.root = null; + this.version = 0; + + } + + // expands the tree to all nodes that intersect at + // returns the intersecting nodes at + expandAndFindByBox(box, level){ + + if(level === 0){ + return [this.root]; + } + + let result = []; + let stack = [this.root]; + + while(stack.length > 0){ + + let node = stack.pop(); + let nodeBoxSize = node.box.getSize(); + + // check which children intersect by transforming min/max to quadrants + let min = { + x: (box.min.x - node.box.min.x) / nodeBoxSize.x, + y: (box.min.y - node.box.min.y) / nodeBoxSize.y}; + let max = { + x: (box.max.x - node.box.max.x) / nodeBoxSize.x, + y: (box.max.y - node.box.max.y) / nodeBoxSize.y}; + + min.x = min.x < 0.5 ? 0 : 1; + min.y = min.y < 0.5 ? 0 : 1; + max.x = max.x < 0.5 ? 0 : 1; + max.y = max.y < 0.5 ? 0 : 1; + + let childIndices; + if(min.x === 0 && min.y === 0 && max.x === 1 && max.y === 1){ + childIndices = [0, 1, 2, 3]; + }else if(min.x === max.x && min.y == max.y){ + childIndices = [(min.x << 1) | min.y]; + }else{ + childIndices = [(min.x << 1) | min.y, (max.x << 1) | max.y]; + } + + for(let index of childIndices){ + if(node.children[index] === undefined){ + let childBox = node.box.clone(); + + if((index & 2) > 0){ + childBox.min.x += nodeBoxSize.x / 2.0; + }else{ + childBox.max.x -= nodeBoxSize.x / 2.0; + } + + if((index & 1) > 0){ + childBox.min.y += nodeBoxSize.y / 2.0; + }else{ + childBox.max.y -= nodeBoxSize.y / 2.0; + } + + let child = new Potree.DEMNode(node.name + index, childBox, this.tileSize); + node.children[index] = child; + } + + let child = node.children[index]; + + if(child.level < level){ + stack.push(child); + }else{ + result.push(child); + } + } + } + + return result; + } + + childIndex(uv){ + let [x, y] = uv.map(n => n < 0.5 ? 0 : 1); + + let index = (x << 1) | y; + + return index; + } + + height(position){ + + if(!this.root){ + return 0; + } + + let list = [this.root]; + while(true){ + let node = list[list.length - 1]; + + let uv = node.uv(position); + let childIndex = this.childIndex(uv); + + if(node.children[childIndex]){ + list.push(node.children[childIndex]); + }else{ + break; + } + } + + let leaf = list[list.length - 1]; + let height = leaf.height(position); + + return height; + } + + update(visibleNodes){ + + if(Potree.getDEMWorkerInstance().working){ + return; + } + + // check if point cloud transformation changed + if(this.matrix === null || !this.matrix.equals(this.pointcloud.matrixWorld)){ + this.matrix = this.pointcloud.matrixWorld.clone(); + this.boundingBox = this.pointcloud.boundingBox.clone().applyMatrix4(this.matrix); + this.root = new Potree.DEMNode("r", this.boundingBox, this.tileSize); + this.version++; + } + + // find node to update + let node = null; + for(let vn of visibleNodes){ + if(vn.demVersion === undefined || vn.demVersion < this.version){ + node = vn; + break; + } + } + if(node === null){ + return; + } + + // update node + let projectedBox = node.getBoundingBox().clone().applyMatrix4(this.matrix); + let projectedBoxSize = projectedBox.getSize(); + + let targetNodes = this.expandAndFindByBox(projectedBox, node.getLevel()); + node.demVersion = this.version; + + Potree.getDEMWorkerInstance().onmessage = (e) => { + + let data = new Float32Array(e.data.dem.data); + + for(let demNode of targetNodes){ + + let boxSize = demNode.box.getSize(); + + for(let i = 0; i < this.tileSize; i++){ + for(let j = 0; j < this.tileSize; j++){ + + let u = (i / (this.tileSize - 1)); + let v = (j / (this.tileSize - 1)); + + let x = demNode.box.min.x + u * boxSize.x; + let y = demNode.box.min.y + v * boxSize.y; + + let ix = this.tileSize * (x - projectedBox.min.x) / projectedBoxSize.x; + let iy = this.tileSize * (y - projectedBox.min.y) / projectedBoxSize.y; + + if(ix < 0 || ix > this.tileSize){ + continue; + } + + if(iy < 0 || iy > this.tileSize){ + continue; + } + + ix = Math.min(Math.floor(ix), this.tileSize - 1); + iy = Math.min(Math.floor(iy), this.tileSize - 1); + + demNode.data[i + this.tileSize * j] = data[ix + this.tileSize * iy]; + + } + } + + Potree.getDEMWorkerInstance().working = false; + + //createDEMMesh(this, demNode); + } + + + + // TODO only works somewhat if there is no rotation to the point cloud + + //let target = targetNodes[0]; + //target.data = new Float32Array(data); + // + // + ////node.dem = e.data.dem; + // + //Potree.getDEMWorkerInstance().working = false; + // + //{ // create scene objects for debugging + // //for(let demNode of targetNodes){ + // var bb = new Potree.Box3Helper(box); + // viewer.scene.scene.add(bb); + // + // createDEMMesh(this, target); + // //} + // + //} + }; + + let position = node.geometryNode.geometry.attributes.position.array; + let message = { + boundingBox: { + min: node.getBoundingBox().min.toArray(), + max: node.getBoundingBox().max.toArray() + }, + position: new Float32Array(position).buffer + }; + let transferables = [message.position]; + Potree.getDEMWorkerInstance().working = true; + Potree.getDEMWorkerInstance().postMessage(message, transferables); + + + } + +}; Potree.PointCloudTreeNode = class{ @@ -43,6 +306,8 @@ Potree.PointCloudTree = class PointCloudTree extends THREE.Object3D{ constructor(){ super(); + + this.dem = new Potree.DEM(this); } initialized(){ diff --git a/src/Potree.js b/src/Potree.js index ddccad98..a7cd3033 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -568,101 +568,113 @@ Potree.DEMRenderer = class{ }; */ -//Potree.getDEMWorkerInstance = function(){ -// if(!Potree.DEMWorkerInstance){ -// let workerPath = Potree.scriptPath + "/workers/DEMWorker.js"; -// Potree.DEMWorkerInstance = Potree.workerPool.getWorker(workerPath); -// } -// -// return Potree.DEMWorkerInstance; -//} +Potree.getDEMWorkerInstance = function(){ + if(!Potree.DEMWorkerInstance){ + let workerPath = Potree.scriptPath + "/workers/DEMWorker.js"; + Potree.DEMWorkerInstance = Potree.workerPool.getWorker(workerPath); + } + + return Potree.DEMWorkerInstance; +} +function createDEMMesh(dem){ + + let box = dem.boundingBox; -//function demHeight(pointcloud, position){ -// -// if(!pointcloud.root.dem){ -// return; -// } -// -// let node = pointcloud.root; -// let dem = pointcloud.root.dem; -// let demHeights = new Float32Array(dem.data); -// let boxSize = pointcloud.boundingBox.getSize(); -// -// let u = (position.x - pointcloud.position.x) / boxSize.x; -// let v = (position.y - pointcloud.position.y) / boxSize.y; -// -// let demX = u * dem.width; -// let demY = v * dem.height; -// -// let clamp = (value, min, max) => Math.min(Math.max(value, min), max); -// let sample = (x, y) => { -// x = parseInt(clamp(x, 0, dem.width - 1)); -// y = parseInt(clamp(y, 0, dem.height - 1)); -// let i = x + dem.width * y; -// -// return demHeights[i]; -// }; -// -// let p00 = sample(Math.floor(demX), Math.floor(demY)); -// let p10 = sample(Math.ceil(demX), Math.floor(demY)); -// let p01 = sample(Math.floor(demX), Math.ceil(demY)); -// let p11 = sample(Math.ceil(demX), Math.ceil(demY)); -// -// let value = -// p00 * (demX % 1) * (demY % 1) + -// p10 * (1 - demX % 1) * (demY % 1) + -// p01 * (demX % 1) * (1 - demY % 1) + -// p11 * (1 - demX % 1) * (1 - demY % 1); -// -// return value; -//} -// -//function createDemMesh(){ -// let pointcloud = viewer.scene.pointclouds[0]; -// let triangles = []; -// let steps = 200; -// for(let i = 0; i <= steps; i++){ -// for(let j = 0; j <= steps; j++){ -// let u0 = i / steps; -// let u1 = (i+1) / steps; -// let v0 = j / steps; -// let v1 = (j+1) / steps; -// -// let x0 = pointcloud.position.x + u0 * pointcloud.boundingBox.getSize().x; -// let x1 = pointcloud.position.x + u1 * pointcloud.boundingBox.getSize().x; -// let y0 = pointcloud.position.y + v0 * pointcloud.boundingBox.getSize().y; -// let y1 = pointcloud.position.y + v1 * pointcloud.boundingBox.getSize().y; -// -// let h00 = demHeight(pointcloud, new THREE.Vector2(x0, y0)); -// let h10 = demHeight(pointcloud, new THREE.Vector2(x1, y0)); -// let h01 = demHeight(pointcloud, new THREE.Vector2(x0, y1)); -// let h11 = demHeight(pointcloud, new THREE.Vector2(x1, y1)); -// -// if(![h00, h10, h01, h11].every(n => isFinite(n))){ -// continue; -// } -// -// triangles.push(x0, y0, h00); -// triangles.push(x0, y1, h01); -// triangles.push(x1, y0, h10); -// -// triangles.push(x0, y1, h01); -// triangles.push(x1, y1, h11); -// triangles.push(x1, y0, h10); -// } -// } -// -// let geometry = new THREE.BufferGeometry(); -// let positions = new Float32Array(triangles); -// geometry.addAttribute( 'position', new THREE.BufferAttribute(positions, 3)); -// geometry.computeBoundingSphere(); -// geometry.computeVertexNormals(); -// let material = new THREE.MeshNormalMaterial({side: THREE.DoubleSide}); -// let mesh = new THREE.Mesh(geometry, material); -// //mesh.position.copy(pointcloud.position); -// viewer.scene.scene.add(mesh); -//} + let steps = 512; + let triangles = []; + for(let i = 0; i < steps; i++){ + for(let j = 0; j < steps; j++){ + let u0 = i / steps; + let u1 = (i+1) / steps; + let v0 = j / steps; + let v1 = (j+1) / steps; + + let x0 = box.min.x + u0 * box.getSize().x; + let x1 = box.min.x + u1 * box.getSize().x; + let y0 = box.min.y + v0 * box.getSize().y; + let y1 = box.min.y + v1 * box.getSize().y; + + let h00 = dem.height(new THREE.Vector3(x0, y0, 0)); + let h10 = dem.height(new THREE.Vector3(x1, y0, 0)); + let h01 = dem.height(new THREE.Vector3(x0, y1, 0)); + let h11 = dem.height(new THREE.Vector3(x1, y1, 0)); + + if(![h00, h10, h01, h11].every(n => isFinite(n))){ + continue; + } + + triangles.push(x0, y0, h00); + triangles.push(x0, y1, h01); + triangles.push(x1, y0, h10); + + triangles.push(x0, y1, h01); + triangles.push(x1, y1, h11); + triangles.push(x1, y0, h10); + } + } + + let geometry = new THREE.BufferGeometry(); + let positions = new Float32Array(triangles); + geometry.addAttribute( 'position', new THREE.BufferAttribute(positions, 3)); + geometry.computeBoundingSphere(); + geometry.computeVertexNormals(); + let material = new THREE.MeshNormalMaterial({side: THREE.DoubleSide}); + let mesh = new THREE.Mesh(geometry, material); + //mesh.position.copy(box.min); + //mesh.position.copy(pointcloud.position); + viewer.scene.scene.add(mesh); +} + +function createDEMMeshNode(dem, demNode){ + + let box = demNode.box; + let tileSize = dem.tileSize; + + let triangles = []; + for(let i = 0; i < tileSize; i++){ + //for(let j = 0; j < 1; j++){ + for(let j = 0; j < tileSize; j++){ + let u0 = i / tileSize; + let u1 = (i+1) / tileSize; + let v0 = j / tileSize; + let v1 = (j+1) / tileSize; + + let x0 = u0 * box.getSize().x; + let x1 = u1 * box.getSize().x; + let y0 = v0 * box.getSize().y; + let y1 = v1 * box.getSize().y; + + let h00 = demNode.data[(i+0) + tileSize * (j+0)]; + let h10 = demNode.data[(i+1) + tileSize * (j+0)]; + let h01 = demNode.data[(i+0) + tileSize * (j+1)]; + let h11 = demNode.data[(i+1) + tileSize * (j+1)]; + + if(![h00, h10, h01, h11].every(n => isFinite(n))){ + continue; + } + + triangles.push(x0, y0, h00); + triangles.push(x0, y1, h01); + triangles.push(x1, y0, h10); + + triangles.push(x0, y1, h01); + triangles.push(x1, y1, h11); + triangles.push(x1, y0, h10); + } + } + + let geometry = new THREE.BufferGeometry(); + let positions = new Float32Array(triangles); + geometry.addAttribute( 'position', new THREE.BufferAttribute(positions, 3)); + geometry.computeBoundingSphere(); + geometry.computeVertexNormals(); + let material = new THREE.MeshNormalMaterial({side: THREE.DoubleSide}); + let mesh = new THREE.Mesh(geometry, material); + mesh.position.copy(box.min); + //mesh.position.copy(pointcloud.position); + viewer.scene.scene.add(mesh); +} Potree.updateVisibility = function(pointclouds, camera, renderer){ let numVisibleNodes = 0; @@ -774,14 +786,11 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){ node.boundingBoxNode.visible = false; } - if(!node.dem){ - - - - - + if(pointcloud.dem){ + pointcloud.dem.update(pointcloud.visibleNodes); } + //if(!node.dem){ // if(!Potree.getDEMWorkerInstance().working){ // Potree.getDEMWorkerInstance().onmessage = (e) => { @@ -868,281 +877,3 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){ lowestSpacing: lowestSpacing }; }; - -//Potree.updateDEMs = function(renderer, visibleNodes){ -// -// return; -// -// let dems = Potree.__dems; -// if(dems === undefined){ -// Potree.__dems = {}; -// dems = Potree.__dems; -// -// dems.target = new THREE.WebGLRenderTarget(128, 128, { -// minFilter: THREE.NearestFilter, -// magFilter: THREE.NearestFilter, -// format: THREE.RGBAFormat, -// type: THREE.FloatType -// }); -// dems.scene = new THREE.Scene(); -// dems.camera = new THREE.OrthographicCamera( 0, 128, 128, 0, 0, 10000 ); -// dems.camera.up.set(0, 0, 1); -// } -// for(let node of visibleNodes){ -// -// if(node.dem !== undefined){ -// continue; -// } -// -// let geometry = node.geometryNode.geometry; -// let material = new THREE.PointsMaterial({color: 0x888888 }); -// -// renderer.clearTarget( dems.target, true, true, true ); -// var pc = new THREE.Points(geometry, material); -// -// let box = geometry.boundingBox; -// -// dems.scene.add(pc); -// dems.camera.position.set(0, 0, box.max.z); -// -// renderer.render(dems.scene, dems.camera, dems.target); -// -// dems.scene.remove(pc); -// -// //{ -// // let pickWindowSize = 128; -// // let pixelCount = pickWindowSize * pickWindowSize; -// // let buffer = new ArrayBuffer(pixelCount*4*4); -// // let pixels = new Uint8Array(buffer); -// // let ibuffer = new Uint32Array(buffer); -// // renderer.context.readPixels( -// // 0, 0, -// // pickWindowSize, pickWindowSize, -// // renderer.context.RGBA, renderer.context.FLOAT, pixels); -// // -// // console.log(pixels[i]); -// //} -// -// } -// -// -//}; - -//Potree.Shader = class Shader{ -// constructor(vertexShader, fragmentShader, program, uniforms){ -// this.vertexShader = vertexShader; -// this.fragmentShader = fragmentShader; -// this.program = program; -// this.uniforms = uniforms; -// } -//}; -// -//Potree.VBO = class VBO{ -// constructor(name, id, attribute){ -// this.name = name; -// this.id = id; -// this.attribute = attribute; -// } -//}; -// -//Potree.VAO = class VAO{ -// constructor(id, geometry, vbos){ -// this.id = id; -// this.geometry = geometry; -// this.vbos = vbos; -// } -//}; -// -//Potree.compileShader = function(gl, vertexShader, fragmentShader){ -// // VERTEX SHADER -// let vs = gl.createShader(gl.VERTEX_SHADER); -// { -// gl.shaderSource(vs, vertexShader); -// gl.compileShader(vs); -// -// let success = gl.getShaderParameter(vs, gl.COMPILE_STATUS); -// if (!success) { -// console.error("could not compile vertex shader:"); -// -// let log = gl.getShaderInfoLog(vs); -// console.error(log, vertexShader); -// -// return; -// } -// } -// -// // FRAGMENT SHADER -// let fs = gl.createShader(gl.FRAGMENT_SHADER); -// { -// gl.shaderSource(fs, fragmentShader); -// gl.compileShader(fs); -// -// let success = gl.getShaderParameter(fs, gl.COMPILE_STATUS); -// if (!success) { -// console.error("could not compile fragment shader:"); -// console.error(fragmentShader); -// -// return; -// } -// } -// -// // PROGRAM -// let program = gl.createProgram(); -// gl.attachShader(program, vs); -// gl.attachShader(program, fs); -// gl.linkProgram(program); -// let success = gl.getProgramParameter(program, gl.LINK_STATUS); -// if (!success) { -// console.error("could not compile shader:"); -// console.error(vertexShader); -// console.error(fragmentShader); -// -// return; -// } -// -// gl.useProgram(program); -// -// let uniforms = {}; -// { // UNIFORMS -// let n = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS); -// -// for(let i = 0; i < n; i++){ -// let uniform = gl.getActiveUniform(program, i); -// let name = uniform.name; -// let loc = gl.getUniformLocation(program, name); -// -// uniforms[name] = loc; -// } -// } -// -// let shader = new Potree.Shader(vertexShader, fragmentShader, program, uniforms); -// -// return shader; -//}; -// -//// http://blog.tojicode.com/2012/10/oesvertexarrayobject-extension.html -//Potree.createVAO = function(gl, geometry){ -// if(Potree.vaos[geometry.uuid] ==! undefined){ -// return Potree.vaos[geometry.uuid]; -// } -// -// let ext = gl.getExtension("OES_vertex_array_object"); -// let id = ext.createVertexArrayOES(); -// -// ext.bindVertexArrayOES(id); -// -// let vbos = {}; -// for(let key in geometry.attributes){ -// let attribute = geometry.attributes[key]; -// -// let type = gl.FLOAT; -// if(attribute.array instanceof Uint8Array){ -// type = gl.UNSIGNED_BYTE; -// }else if(attribute.array instanceof Uint16Array){ -// type = gl.UNSIGNED_SHORT; -// }else if(attribute.array instanceof Uint32Array){ -// type = gl.UNSIGNED_INT; -// }else if(attribute.array instanceof Int8Array){ -// type = gl.BYTE; -// }else if(attribute.array instanceof Int16Array){ -// type = gl.SHORT; -// }else if(attribute.array instanceof Int32Array){ -// type = gl.INT; -// }else if(attribute.array instanceof Float32Array){ -// type = gl.FLOAT; -// } -// -// let vbo = gl.createBuffer(); -// gl.bindBuffer(gl.ARRAY_BUFFER, vbo); -// gl.bufferData(gl.ARRAY_BUFFER, attribute.array, gl.STATIC_DRAW); -// //gl.enableVertexAttribArray(attributePointer); -// //gl.vertexAttribPointer(attributePointer, numElements, type, attribute.normalized, 0, 0); -// -// vbos[key] = new Potree.VBO(key, vbo, attribute); -// } -// -// ext.bindVertexArrayOES(null); -// -// let vao = new Potree.VAO(id, geometry, vbos); -// Potree.vaos[geometry.uuid] = vao; -// -// return vao; -//}; -// -//Potree.renderPointcloud = function(pointcloud, camera, renderer){ -// let gl = renderer.context; -// let webgl = Potree.webgl; -// let material = pointcloud.material; -// -// if(gl.getExtension("OES_vertex_array_object") === null){ -// console.error("OES_vertex_array_object extension not supported"); -// return; -// } -// -// if(material.needsUpdate){ -// Potree.pointcloudShader = Potree.compileShader(gl, -// material.vertexShader, material.fragmentShader); -// -// material.needsUpdate = false; -// } -// -// let shader = Potree.pointcloudShader; -// let uniforms = shader.uniforms; -// -// gl.useProgram(shader.program); -// -// gl.uniformMatrix4fv(uniforms["projectionMatrix"], false, camera.projectionMatrix.elements); -// gl.uniformMatrix4fv(uniforms["viewMatrix"], false, camera.matrixWorldInverse.elements); -// gl.uniform1f(uniforms["fov"], this.material.fov); -// gl.uniform1f(uniforms["screenWidth"], material.screenWidth); -// gl.uniform1f(uniforms["screenHeight"], material.screenHeight); -// gl.uniform1f(uniforms["spacing"], material.spacing); -// gl.uniform1f(uniforms["near"], material.near); -// gl.uniform1f(uniforms["far"], material.far); -// gl.uniform1f(uniforms["size"], material.size); -// gl.uniform1f(uniforms["minSize"], material.minSize); -// gl.uniform1f(uniforms["maxSize"], material.maxSize); -// gl.uniform1f(uniforms["octreeSize"], pointcloud.pcoGeometry.boundingBox.getSize().x); -// -// { -// let apPosition = gl.getAttribLocation(program, "position"); -// let apColor = gl.getAttribLocation(program, "color"); -// let apNormal = gl.getAttribLocation(program, "normal"); -// let apClassification = gl.getAttribLocation(program, "classification"); -// let apIndices = gl.getAttribLocation(program, "indices"); -// -// gl.enableVertexAttribArray(apPosition); -// gl.enableVertexAttribArray(apColor); -// gl.enableVertexAttribArray(apNormal); -// gl.enableVertexAttribArray(apClassification); -// gl.enableVertexAttribArray(apIndices); -// } -// -// let nodes = pointcloud.visibleNodes; -// for(let node of nodes){ -// let object = node.sceneNode; -// let geometry = object.geometry; -// -// -// } -// -//}; - - - - - - - - - - - - - - - - - - - diff --git a/src/viewer/map.js b/src/viewer/map.js index 59c4215b..3804bf66 100644 --- a/src/viewer/map.js +++ b/src/viewer/map.js @@ -17,6 +17,7 @@ Potree.MapView = class{ this.toolLayer = null; this.sourcesLayer = null; this.sourcesLabelLayer = null; + this.enabled = false; this.createAnnotationStyle = (text) => { return [ @@ -640,6 +641,18 @@ Potree.MapView = class{ }); } + toggle(){ + + if(this.elMap.is(":visible")){ + this.elMap.css("display", "none"); + this.enabled = false; + }else{ + this.elMap.css("display", "block"); + this.enabled = true; + } + + } + update(delta){ if(!this.sceneProjection){ return; @@ -647,7 +660,7 @@ Potree.MapView = class{ let pm = $( "#potree_map" ); - if(!pm.is(":visible")){ + if(!this.enabled){ return; } diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index a2e6484b..9451258c 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -1069,8 +1069,12 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ }; toggleMap(){ - let map = $('#potree_map'); - map.toggle(100); + //let map = $('#potree_map'); + //map.toggle(100); + + if(this.mapView){ + this.mapView.toggle(); + } }; @@ -1089,7 +1093,7 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ let imgMapToggle = document.createElement("img"); imgMapToggle.src = new URL(Potree.resourcePath + "/icons/map_icon.png").href; imgMapToggle.style.display = "none"; - imgMapToggle.onclick = this.toggleMap; + imgMapToggle.onclick = e => {this.toggleMap()}; imgMapToggle.id = "potree_map_toggle"; viewer.renderArea.insertBefore(imgMapToggle, viewer.renderArea.children[0]); @@ -1468,6 +1472,7 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ this.mapView.update(delta, this.scene.camera); if(this.mapView.sceneProjection){ $( "#potree_map_toggle" ).css("display", "block"); + } }