update jstree; update shapefile demo

This commit is contained in:
m-schuetz 2019-10-16 12:05:42 +02:00
parent 9ee012310e
commit 908ddda0bc
14 changed files with 632 additions and 504 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ libs/CesiumUnminified
/pointclouds/test
/pointclouds/test1
/pointclouds/mobile
/pointclouds/sjl2

View File

@ -59,167 +59,119 @@
});
// Load and add point cloud to scene
Potree.loadPointCloud("http://5.9.65.151/mschuetz/potree/resources/pointclouds/opentopography/CA13_1.4/cloud.js", "CA13", e => {
Potree.loadPointCloud("http://5.9.65.151/mschuetz/potree/resources/pointclouds/opentopography/CA13_1.4/cloud.js", "CA13", async e => {
let scene = viewer.scene;
let pointcloud = e.pointcloud;
let material = pointcloud.material;
scene.addPointCloud(pointcloud);
material.size = 1;
material.pointSizeType = Potree.PointSizeType.FIXED;
//material.shape = Potree.PointShape.SQUARE;
//material.intensityRange = [0, 1000];
material.size = 1;
//scene.view.position.set(696507.51, 3915713.17, 1891.85);
scene.view.position.set(697757.85, 3913444.33, 2827.33);
scene.view.lookAt(new THREE.Vector3(695231.74, 3916988.94, 87.64));
{
proj4.defs("pointcloud", pointcloud.projection);
// define the transformation from shapefile to point cloud coordinate systems
proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
let toScene = proj4("WGS84", "pointcloud");
let featureToSceneNode = (feature, color) => {
let geometry = feature.geometry;
var color = color ? color : new THREE.Color(1, 1, 1);
if(feature.geometry.type === "Point"){
let sg = new THREE.SphereGeometry(1, 18, 18);
let sm = new THREE.MeshNormalMaterial();
let s = new THREE.Mesh(sg, sm);
let [long, lat] = geometry.coordinates;
let pos = toScene.forward([long, lat]);
s.position.set(...pos, 20);
s.scale.set(10, 10, 10);
return s;
}else if(geometry.type === "LineString"){
let coordinates = [];
let min = new THREE.Vector3(Infinity, Infinity, Infinity);
for(let i = 0; i < geometry.coordinates.length; i++){
let [long, lat] = geometry.coordinates[i];
let pos = toScene.forward([long, lat]);
min.x = Math.min(min.x, pos[0]);
min.y = Math.min(min.y, pos[1]);
min.z = Math.min(min.z, 20);
coordinates.push(...pos, 20);
if(i > 0 && i < geometry.coordinates.length - 1){
coordinates.push(...pos, 20);
}
}
for(let i = 0; i < coordinates.length; i += 3){
coordinates[i+0] -= min.x;
coordinates[i+1] -= min.y;
coordinates[i+2] -= min.z;
}
let positions = new Float32Array(coordinates);
let lineGeometry = new THREE.BufferGeometry();
lineGeometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));
let material = new THREE.LineBasicMaterial( { color: color} );
let line = new THREE.LineSegments(lineGeometry, material);
line.position.copy(min);
return line;
}else if(geometry.type === "Polygon"){
for(let pc of geometry.coordinates){
let coordinates = [];
let min = new THREE.Vector3(Infinity, Infinity, Infinity);
for(let i = 0; i < pc.length; i++){
let [long, lat] = pc[i];
let pos = toScene.forward([long, lat]);
min.x = Math.min(min.x, pos[0]);
min.y = Math.min(min.y, pos[1]);
min.z = Math.min(min.z, 20);
coordinates.push(...pos, 20);
if(i > 0 && i < pc.length - 1){
coordinates.push(...pos, 20);
}
}
for(let i = 0; i < coordinates.length; i += 3){
coordinates[i+0] -= min.x;
coordinates[i+1] -= min.y;
coordinates[i+2] -= min.z;
}
let positions = new Float32Array(coordinates);
let lineGeometry = new THREE.BufferGeometry();
lineGeometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));
let material = new THREE.LineBasicMaterial( { color: color} );
let line = new THREE.LineSegments(lineGeometry, material);
line.position.copy(min);
return line;
}
}else{
console.log("unhandled feature: ", feature);
}
};
proj4.defs("pointcloud", pointcloud.projection);
let transform = proj4("WGS84", "pointcloud");
let shapeNode = new THREE.Object3D();
const loader = new Potree.ShapefileLoader();
loader.transform = transform;
// group all shapefile scene nodes into this node
const shapeNode = new THREE.Object3D();
viewer.scene.scene.add(shapeNode);
// load points.shp
const shpPoints = await loader.load("./morro_bay_shp/shape/points.shp");
shapeNode.add(shpPoints.node);
Potree.Utils.loadShapefileFeatures("./morro_bay_shp/shape/points.shp", features => {
for(let feature of features){
let node = featureToSceneNode(feature, 0x00ff00);
shapeNode.add(node);
// load natural.shp and change colors to green
const shpNatural = await loader.load("./morro_bay_shp/shape/natural.shp");
shapeNode.add(shpNatural.node);
shpNatural.node.traverse(node => {
if(node.material){
node.material.color.setRGB(0, 1, 0)
}
});
Potree.Utils.loadShapefileFeatures("./morro_bay_shp/shape/natural.shp", features => {
for(let feature of features){
let node = featureToSceneNode(feature, 0x00ff00);
shapeNode.add(node);
// load waterways.shp and change colors to blue
const shpWaterways = await loader.load("./morro_bay_shp/shape/waterways.shp");
shapeNode.add(shpWaterways.node);
shpWaterways.node.traverse(node => {
if(node.material){
node.material.color.setRGB(0.3, 0.3, 1)
}
});
Potree.Utils.loadShapefileFeatures("./morro_bay_shp/shape/waterways.shp", features => {
for(let feature of features){
let node = featureToSceneNode(feature, 0x0000ff);
shapeNode.add(node);
}
});
Potree.Utils.loadShapefileFeatures("./morro_bay_shp/shape/roads.shp", features => {
for(let feature of features){
let node = featureToSceneNode(feature, 0xffffff);
shapeNode.add(node);
// add roads.shp and change colors to yellow
const shpRoads = await loader.load("./morro_bay_shp/shape/roads.shp");
shapeNode.add(shpRoads.node);
shpRoads.node.traverse(node => {
if(node.material){
node.material.color.setRGB(1, 1, 0)
}
});
viewer.onGUILoaded(() => {
// Add entry to object list in sidebar
let tree = $(`#jstree_scene`);
let parentNode = "other";
let nodeID = tree.jstree('create_node', parentNode, {
"text": "shapefile",
let shpPointsID = tree.jstree('create_node', parentNode, {
"text": "points",
"icon": `${Potree.resourcePath}/icons/triangle.svg`,
"object": shapeNode
"object": shpPoints.node,
"data": shpPoints.node,
},
"last", false, false);
tree.jstree(shapeNode.visible ? "check_node" : "uncheck_node", nodeID);
tree.jstree(shpPoints.node.visible ? "check_node" : "uncheck_node", shpPointsID);
let shpNaterialID = tree.jstree('create_node', parentNode, {
"text": "natural",
"icon": `${Potree.resourcePath}/icons/triangle.svg`,
"object": shpNatural.node,
"data": shpNatural.node,
},
"last", false, false);
tree.jstree(shpNatural.node.visible ? "check_node" : "uncheck_node", shpNaterialID);
let shpWaterwaysID = tree.jstree('create_node', parentNode, {
"text": "waterways",
"icon": `${Potree.resourcePath}/icons/triangle.svg`,
"object": shpWaterways.node,
"data": shpWaterways.node,
},
"last", false, false);
tree.jstree(shpWaterways.node.visible ? "check_node" : "uncheck_node", shpWaterwaysID);
let shpRoadsID = tree.jstree('create_node', parentNode, {
"text": "roads",
"icon": `${Potree.resourcePath}/icons/triangle.svg`,
"object": shpRoads.node,
"data": shpRoads.node,
},
"last", false, false);
tree.jstree(shpRoads.node.visible ? "check_node" : "uncheck_node", shpRoadsID);
});
}
});

View File

@ -1,22 +1,22 @@
Copyright (c) 2014 Ivan Bozhanov
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2014 Ivan Bozhanov
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

View File

@ -62,8 +62,8 @@ To get started you need 3 things in your page:
```html
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/themes/default/style.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/jstree.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/themes/default/style.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/jstree.min.js"></script>
```
_If you decide to host jstree yourself - the files are located in the `dist` folder. You can safely ignore the `dist/libs` folder._

View File

@ -13,7 +13,7 @@
}(function ($, undefined) {
"use strict";
/*!
* jsTree 3.3.4
* jsTree 3.3.8
* http://jstree.com/
*
* Copyright (c) 2014 Ivan Bozhanov (http://vakata.com)
@ -54,7 +54,7 @@
* specifies the jstree version in use
* @name $.jstree.version
*/
version : '3.3.4',
version : '3.3.8',
/**
* holds all the default options used when creating new instances
* @name $.jstree.defaults
@ -430,10 +430,90 @@
*/
force_text : false,
/**
* Should the node should be toggled if the text is double clicked . Defaults to `true`
* Should the node be toggled if the text is double clicked. Defaults to `true`
* @name $.jstree.defaults.core.dblclick_toggle
*/
dblclick_toggle : true
dblclick_toggle : true,
/**
* Should the loaded nodes be part of the state. Defaults to `false`
* @name $.jstree.defaults.core.loaded_state
*/
loaded_state : false,
/**
* Should the last active node be focused when the tree container is blurred and the focused again. This helps working with screen readers. Defaults to `true`
* @name $.jstree.defaults.core.restore_focus
*/
restore_focus : true,
/**
* Default keyboard shortcuts (an object where each key is the button name or combo - like 'enter', 'ctrl-space', 'p', etc and the value is the function to execute in the instance's scope)
* @name $.jstree.defaults.core.keyboard
*/
keyboard : {
'ctrl-space': function (e) {
// aria defines space only with Ctrl
e.type = "click";
$(e.currentTarget).trigger(e);
},
'enter': function (e) {
// enter
e.type = "click";
$(e.currentTarget).trigger(e);
},
'left': function (e) {
// left
e.preventDefault();
if(this.is_open(e.currentTarget)) {
this.close_node(e.currentTarget);
}
else {
var o = this.get_parent(e.currentTarget);
if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').focus(); }
}
},
'up': function (e) {
// up
e.preventDefault();
var o = this.get_prev_dom(e.currentTarget);
if(o && o.length) { o.children('.jstree-anchor').focus(); }
},
'right': function (e) {
// right
e.preventDefault();
if(this.is_closed(e.currentTarget)) {
this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').focus(); });
}
else if (this.is_open(e.currentTarget)) {
var o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
if(o) { $(this._firstChild(o)).children('.jstree-anchor').focus(); }
}
},
'down': function (e) {
// down
e.preventDefault();
var o = this.get_next_dom(e.currentTarget);
if(o && o.length) { o.children('.jstree-anchor').focus(); }
},
'*': function (e) {
// aria defines * on numpad as open_all - not very common
this.open_all();
},
'home': function (e) {
// home
e.preventDefault();
var o = this._firstChild(this.get_container_ul()[0]);
if(o) { $(o).children('.jstree-anchor').filter(':visible').focus(); }
},
'end': function (e) {
// end
e.preventDefault();
this.element.find('.jstree-anchor').filter(':visible').last().focus();
},
'f2': function (e) {
// f2 - safe to include - if check_callback is false it will fail
e.preventDefault();
this.edit(e.currentTarget);
}
}
};
$.jstree.core.prototype = {
/**
@ -548,7 +628,9 @@
this.teardown();
},
/**
* Create prototype node
* Create a prototype node
* @name _create_prototype_node()
* @return {DOMElement}
*/
_create_prototype_node : function () {
var _node = document.createElement('LI'), _temp1, _temp2;
@ -570,6 +652,48 @@
return _node;
},
_kbevent_to_func : function (e) {
var keys = {
8: "Backspace", 9: "Tab", 13: "Enter", 19: "Pause", 27: "Esc",
32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home",
37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "Print", 45: "Insert",
46: "Delete", 96: "Numpad0", 97: "Numpad1", 98: "Numpad2", 99 : "Numpad3",
100: "Numpad4", 101: "Numpad5", 102: "Numpad6", 103: "Numpad7",
104: "Numpad8", 105: "Numpad9", '-13': "NumpadEnter", 112: "F1",
113: "F2", 114: "F3", 115: "F4", 116: "F5", 117: "F6", 118: "F7",
119: "F8", 120: "F9", 121: "F10", 122: "F11", 123: "F12", 144: "Numlock",
145: "Scrolllock", 16: 'Shift', 17: 'Ctrl', 18: 'Alt',
48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*', 173: '-'
};
var parts = [];
if (e.ctrlKey) { parts.push('ctrl'); }
if (e.altKey) { parts.push('alt'); }
if (e.shiftKey) { parts.push('shift'); }
parts.push(keys[e.which] || e.which);
parts = parts.sort().join('-').toLowerCase();
var kb = this.settings.core.keyboard, i, tmp;
for (i in kb) {
if (kb.hasOwnProperty(i)) {
tmp = i;
if (tmp !== '-' && tmp !== '+') {
tmp = tmp.replace('--', '-MINUS').replace('+-', '-MINUS').replace('++', '-PLUS').replace('-+', '-PLUS');
tmp = tmp.split(/-|\+/).sort().join('-').replace('MINUS', '-').replace('PLUS', '+').toLowerCase();
}
if (tmp === parts) {
return kb[i];
}
}
}
return null;
},
/**
* part of the destroying of an instance. Used internally.
* @private
@ -635,83 +759,16 @@
}, this))
.on('keydown.jstree', '.jstree-anchor', $.proxy(function (e) {
if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
if(e.which !== 32 && e.which !== 13 && (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey)) { return true; }
var o = null;
if(this._data.core.rtl) {
if(e.which === 37) { e.which = 39; }
else if(e.which === 39) { e.which = 37; }
}
switch(e.which) {
case 32: // aria defines space only with Ctrl
if(e.ctrlKey) {
e.type = "click";
$(e.currentTarget).trigger(e);
}
break;
case 13: // enter
e.type = "click";
$(e.currentTarget).trigger(e);
break;
case 37: // left
e.preventDefault();
if(this.is_open(e.currentTarget)) {
this.close_node(e.currentTarget);
}
else {
o = this.get_parent(e.currentTarget);
if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').focus(); }
}
break;
case 38: // up
e.preventDefault();
o = this.get_prev_dom(e.currentTarget);
if(o && o.length) { o.children('.jstree-anchor').focus(); }
break;
case 39: // right
e.preventDefault();
if(this.is_closed(e.currentTarget)) {
this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').focus(); });
}
else if (this.is_open(e.currentTarget)) {
o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
if(o) { $(this._firstChild(o)).children('.jstree-anchor').focus(); }
}
break;
case 40: // down
e.preventDefault();
o = this.get_next_dom(e.currentTarget);
if(o && o.length) { o.children('.jstree-anchor').focus(); }
break;
case 106: // aria defines * on numpad as open_all - not very common
this.open_all();
break;
case 36: // home
e.preventDefault();
o = this._firstChild(this.get_container_ul()[0]);
if(o) { $(o).children('.jstree-anchor').filter(':visible').focus(); }
break;
case 35: // end
e.preventDefault();
this.element.find('.jstree-anchor').filter(':visible').last().focus();
break;
case 113: // f2 - safe to include - if check_callback is false it will fail
e.preventDefault();
this.edit(e.currentTarget);
break;
default:
break;
/*!
// delete
case 46:
e.preventDefault();
o = this.get_node(e.currentTarget);
if(o && o.id && o.id !== $.jstree.root) {
o = this.is_selected(o) ? this.get_selected() : o;
this.delete_node(o);
}
break;
*/
var f = this._kbevent_to_func(e);
if (f) {
var r = f.call(this, e);
if (r === false || r === true) {
return r;
}
}
}, this))
.on("load_node.jstree", $.proxy(function (e, data) {
@ -832,7 +889,7 @@
}, this))
.on('blur.jstree', '.jstree-anchor', $.proxy(function (e) {
this._data.core.focused = null;
$(e.currentTarget).filter('.jstree-hovered').mouseleave();
$(e.currentTarget).filter('.jstree-hovered').trigger('mouseleave');
this.element.attr('tabindex', '0');
}, this))
.on('focus.jstree', '.jstree-anchor', $.proxy(function (e) {
@ -840,12 +897,12 @@
if(tmp && tmp.id) {
this._data.core.focused = tmp.id;
}
this.element.find('.jstree-hovered').not(e.currentTarget).mouseleave();
$(e.currentTarget).mouseenter();
this.element.find('.jstree-hovered').not(e.currentTarget).trigger('mouseleave');
$(e.currentTarget).trigger('mouseenter');
this.element.attr('tabindex', '-1');
}, this))
.on('focus.jstree', $.proxy(function () {
if(+(new Date()) - was_click > 500 && !this._data.core.focused) {
if(+(new Date()) - was_click > 500 && !this._data.core.focused && this.settings.core.restore_focus) {
was_click = 0;
var act = this.get_node(this.element.attr('aria-activedescendant'), true);
if(act) {
@ -966,6 +1023,9 @@
if(obj && obj.id) {
obj = obj.id;
}
if (obj instanceof $ && obj.length && obj[0].id) {
obj = obj[0].id;
}
var dom;
try {
if(this._model.data[obj]) {
@ -977,10 +1037,10 @@
else if(typeof obj === "string" && (dom = $('#' + obj.replace($.jstree.idregex,'\\$&'), this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
obj = this._model.data[dom.closest('.jstree-node').attr('id')];
}
else if((dom = $(obj, this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
else if((dom = this.element.find(obj)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
obj = this._model.data[dom.closest('.jstree-node').attr('id')];
}
else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
else if((dom = this.element.find(obj)).length && dom.hasClass('jstree')) {
obj = this._model.data[$.jstree.root];
}
else {
@ -1274,7 +1334,7 @@
return true;
},
/**
* load an array of nodes (will also load unavailable nodes as soon as the appear in the structure). Used internally.
* load an array of nodes (will also load unavailable nodes as soon as they appear in the structure). Used internally.
* @private
* @name _load_nodes(nodes [, callback])
* @param {array} nodes
@ -1545,6 +1605,7 @@
't_cnt' : this._cnt,
'sel' : this._data.core.selected
},
inst = this,
func = function (data, undefined) {
if(data.data) { data = data.data; }
var dat = data.dat,
@ -1763,8 +1824,10 @@
// 2) populate children (foreach)
for(i = 0, j = dat.length; i < j; i++) {
if (!m[dat[i].parent.toString()]) {
this._data.core.last_error = { 'error' : 'parse', 'plugin' : 'core', 'id' : 'core_07', 'reason' : 'Node with invalid parent', 'data' : JSON.stringify({ 'id' : dat[i].id.toString(), 'parent' : dat[i].parent.toString() }) };
this.settings.core.error.call(this, this._data.core.last_error);
if (typeof inst !== "undefined") {
inst._data.core.last_error = { 'error' : 'parse', 'plugin' : 'core', 'id' : 'core_07', 'reason' : 'Node with invalid parent', 'data' : JSON.stringify({ 'id' : dat[i].id.toString(), 'parent' : dat[i].parent.toString() }) };
inst.settings.core.error.call(inst, inst._data.core.last_error);
}
continue;
}
@ -2231,7 +2294,7 @@
tmp.children_d = tmp.children_d.concat(e.children_d);
}
}
tmp.children_d = tmp.children_d.concat(tmp.children);
tmp.children_d = tmp.children.concat(tmp.children_d);
}
if(d && d.children && d.children === true) {
tmp.state.loaded = false;
@ -2268,7 +2331,7 @@
this.element.empty().append(f);
//this.get_container_ul()[0].appendChild(f);
}
if(fe !== null) {
if(fe !== null && this.settings.core.restore_focus) {
tmp = this.get_node(fe, true);
if(tmp && tmp.length && tmp.children('.jstree-anchor')[0] !== document.activeElement) {
tmp.children('.jstree-anchor').focus();
@ -2551,7 +2614,7 @@
return node;
},
/**
* opens a node, revaling its children. If the node is not loaded it will be loaded and opened once ready.
* opens a node, revealing its children. If the node is not loaded it will be loaded and opened once ready.
* @name open_node(obj [, callback, animation])
* @param {mixed} obj the node to open
* @param {Function} callback a function to execute once the node is opened
@ -2755,7 +2818,7 @@
}
},
/**
* opens all nodes within a node (or the tree), revaling their children. If the node is not loaded it will be loaded and opened once ready.
* opens all nodes within a node (or the tree), revealing their children. If the node is not loaded it will be loaded and opened once ready.
* @name open_all([obj, animation, original_obj])
* @param {mixed} obj the node to open recursively, omit to open all nodes in the tree
* @param {Number} animation the animation duration in milliseconds when opening the nodes, the default is no animation
@ -2796,7 +2859,7 @@
}
},
/**
* closes all nodes within a node (or the tree), revaling their children
* closes all nodes within a node (or the tree), revealing their children
* @name close_all([obj, animation])
* @param {mixed} obj the node to close recursively, omit to close all nodes in the tree
* @param {Number} animation the animation duration in milliseconds when closing the nodes, the default is no animation
@ -3372,6 +3435,7 @@
var state = {
'core' : {
'open' : [],
'loaded' : [],
'scroll' : {
'left' : this.element.scrollLeft(),
'top' : this.element.scrollTop()
@ -3389,6 +3453,9 @@
for(i in this._model.data) {
if(this._model.data.hasOwnProperty(i)) {
if(i !== $.jstree.root) {
if(this._model.data[i].state.loaded && this.settings.core.loaded_state) {
state.core.loaded.push(i);
}
if(this._model.data[i].state.opened) {
state.core.open.push(i);
}
@ -3415,6 +3482,19 @@
}
if(state.core) {
var res, n, t, _this, i;
if(state.core.loaded) {
if(!this.settings.core.loaded_state || !$.isArray(state.core.loaded) || !state.core.loaded.length) {
delete state.core.loaded;
this.set_state(state, callback);
}
else {
this._load_nodes(state.core.loaded, function (nodes) {
delete state.core.loaded;
this.set_state(state, callback);
});
}
return false;
}
if(state.core.open) {
if(!$.isArray(state.core.open) || !state.core.open.length) {
delete state.core.open;
@ -3945,6 +4025,10 @@
var tmp = chk.match(/^move_node|copy_node|create_node$/i) ? par : obj,
chc = this.settings.core.check_callback;
if(chk === "move_node" || chk === "copy_node") {
if((!more || !more.is_multi) && (chk === "move_node" && $.inArray(obj.id, par.children) === pos)) {
this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_08', 'reason' : 'Moving node to its current position', 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
return false;
}
if((!more || !more.is_multi) && (obj.id === par.id || (chk === "move_node" && $.inArray(obj.id, par.children) === pos) || $.inArray(par.id, obj.children_d) !== -1)) {
this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_01', 'reason' : 'Moving parent inside child', 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
return false;
@ -4417,7 +4501,7 @@
w2 = ai.width() * ai.length,
*/
t = default_text;
h1 = $("<"+"div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo("body");
h1 = $("<"+"div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo(document.body);
h2 = $("<"+"input />", {
"value" : t,
"class" : "jstree-rename-input",
@ -4443,6 +4527,7 @@
s.replaceWith(a);
s.remove();
t = f ? t : $('<div></div>').append($.parseHTML(t)).html();
obj = this.get_node(obj);
this.set_text(obj, t);
nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html());
if(!nv) {
@ -5156,7 +5241,7 @@
if(s.indexOf('down') !== -1) {
var selectedIds = this._cascade_new_checked_state(obj.id, false);
cur = cur.filter(function(id) {
cur = $.vakata.array_filter(cur, function(id) {
return allIds.indexOf(id) === -1 || selectedIds.indexOf(id) > -1;
});
}
@ -5176,7 +5261,7 @@
}
}
cur = cur.filter(function(id) {
cur = $.vakata.array_filter(cur, function(id) {
return obj.parents.indexOf(id) === -1;
});
}
@ -5272,16 +5357,18 @@
}, this));
}
};
/**
* set the undetermined state where and if necessary. Used internally.
* @private
* @name _undetermined()
* get an array of all nodes whose state is "undetermined"
* @name get_undetermined([full])
* @param {boolean} full: if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
* @return {Array}
* @plugin checkbox
*/
this._undetermined = function () {
if(this.element === null) { return; }
var i, j, k, l, o = {}, m = this._model.data, t = this.settings.checkbox.tie_selection, s = this._data[ t ? 'core' : 'checkbox' ].selected, p = [], tt = this;
this.get_undetermined = function (full) {
if (this.settings.checkbox.cascade.indexOf('undetermined') === -1) {
return [];
}
var i, j, k, l, o = {}, m = this._model.data, t = this.settings.checkbox.tie_selection, s = this._data[ t ? 'core' : 'checkbox' ].selected, p = [], tt = this, r = [];
for(i = 0, j = s.length; i < j; i++) {
if(m[s[i]] && m[s[i]].parents) {
for(k = 0, l = m[s[i]].parents.length; k < l; k++) {
@ -5334,14 +5421,28 @@
}
}
});
for (i = 0, j = p.length; i < j; i++) {
if(!m[p[i]].state[ t ? 'selected' : 'checked' ]) {
r.push(full ? m[p[i]] : p[i]);
}
}
return r;
};
/**
* set the undetermined state where and if necessary. Used internally.
* @private
* @name _undetermined()
* @plugin checkbox
*/
this._undetermined = function () {
if(this.element === null) { return; }
var p = this.get_undetermined(false), i, j, s;
this.element.find('.jstree-undetermined').removeClass('jstree-undetermined');
for(i = 0, j = p.length; i < j; i++) {
if(!m[p[i]].state[ t ? 'selected' : 'checked' ]) {
s = this.get_node(p[i], true);
if(s && s.length) {
s.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-undetermined');
}
for (i = 0, j = p.length; i < j; i++) {
s = this.get_node(p[i], true);
if(s && s.length) {
s.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-undetermined');
}
}
};
@ -5446,7 +5547,7 @@
};
/**
* enable a node's checkbox
* @name disable_checkbox(obj)
* @name enable_checkbox(obj)
* @param {mixed} obj an array can be used too
* @trigger enable_checkbox.jstree
* @plugin checkbox
@ -5504,13 +5605,14 @@
};
/**
* Unchecks a node and all its descendants. This function does NOT affect hidden and disabled nodes (or their descendants).
* Cascades checked state to a node and all its descendants. This function does NOT affect hidden and disabled nodes (or their descendants).
* However if these unaffected nodes are already selected their ids will be included in the returned array.
* @param id
* @param checkedState
* @private
* @param {string} id the node ID
* @param {bool} checkedState should the nodes be checked or not
* @returns {Array} Array of all node id's (in this tree branch) that are checked.
*/
this._cascade_new_checked_state = function(id, checkedState) {
this._cascade_new_checked_state = function (id, checkedState) {
var self = this;
var t = this.settings.checkbox.tie_selection;
var node = this._model.data[id];
@ -5575,14 +5677,17 @@
/**
* Gets ids of nodes selected in branch (of tree) specified by id (does not include the node specified by id)
* @param id
* @name get_checked_descendants(obj)
* @param {string} id the node ID
* @return {Array} array of IDs
* @plugin checkbox
*/
this.get_checked_descendants = function(id) {
this.get_checked_descendants = function (id) {
var self = this;
var t = self.settings.checkbox.tie_selection;
var node = self._model.data[id];
return node.children_d.filter(function(_id) {
return $.vakata.array_filter(node.children_d, function(_id) {
return self._model.data[_id].state[ t ? 'selected' : 'checked' ];
});
};
@ -5741,7 +5846,7 @@
*/
this.get_checked = function (full) {
if(this.settings.checkbox.tie_selection) { return this.get_selected(full); }
return full ? $.map(this._data.checkbox.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.checkbox.selected;
return full ? $.map(this._data.checkbox.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.checkbox.selected.slice();
};
/**
* get an array of all top level checked nodes (ignoring children of checked nodes) (if tie_selection is on in the settings this function will return the same as get_top_selected)
@ -5828,7 +5933,7 @@
return res;
};
this.refresh = function (skip_loading, forget_state) {
if(!this.settings.checkbox.tie_selection) {
if(this.settings.checkbox.tie_selection) {
this._data.checkbox.selected = [];
}
return parent.refresh.apply(this, arguments);
@ -6330,7 +6435,7 @@
vakata_context.element.html(vakata_context.html);
}
if(vakata_context.items.length) {
vakata_context.element.appendTo("body");
vakata_context.element.appendTo(document.body);
e = vakata_context.element;
x = vakata_context.position_x;
y = vakata_context.position_y;
@ -6386,7 +6491,7 @@
}
};
$(function () {
right_to_left = $("body").css("direction") === "rtl";
right_to_left = $(document.body).css("direction") === "rtl";
var to = false;
vakata_context.element = $("<ul class='vakata-context'></ul>");
@ -6674,11 +6779,23 @@
marker = $('<div id="jstree-marker">&#160;</div>').hide(); //.appendTo('body');
$(document)
.on('dragover.vakata.jstree', function (e) {
if (elm) {
$.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
}
})
.on('drop.vakata.jstree', function (e) {
if (elm) {
$.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
elm = null;
drg = null;
}
})
.on('dnd_start.vakata.jstree', function (e, data) {
lastmv = false;
lastev = false;
if(!data || !data.data || !data.data.jstree) { return; }
marker.appendTo('body'); //.show();
marker.appendTo(document.body); //.show();
})
.on('dnd_move.vakata.jstree', function (e, data) {
var isDifferentNode = data.event.target !== lastev.target;
@ -6812,7 +6929,7 @@
lastmv = false;
data.helper.find('.jstree-icon').removeClass('jstree-ok').addClass('jstree-er');
if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
data.event.originalEvent.dataTransfer.dropEffect = 'none';
//data.event.originalEvent.dataTransfer.dropEffect = 'none';
}
marker.hide();
})
@ -7023,7 +7140,7 @@
Math.abs(e.pageY - vakata_dnd.init_y) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold)
) {
if(vakata_dnd.helper) {
vakata_dnd.helper.appendTo("body");
vakata_dnd.helper.appendTo(document.body);
vakata_dnd.helper_w = vakata_dnd.helper.outerWidth();
}
vakata_dnd.is_drag = true;
@ -7770,7 +7887,13 @@
* @name $.jstree.defaults.state.filter
* @plugin state
*/
filter : false
filter : false,
/**
* Should loaded nodes be restored (setting this to true means that it is possible that the whole tree will be loaded for some users - use with caution). Defaults to `false`
* @name $.jstree.defaults.state.preserve_loaded
* @plugin state
*/
preserve_loaded : false
};
$.jstree.plugins.state = function (options, parent) {
this.bind = function () {
@ -7800,7 +7923,11 @@
* @plugin state
*/
this.save_state = function () {
var st = { 'state' : this.get_state(), 'ttl' : this.settings.state.ttl, 'sec' : +(new Date()) };
var tm = this.get_state();
if (!this.settings.state.preserve_loaded) {
delete tm.core.loaded;
}
var st = { 'state' : tm, 'ttl' : this.settings.state.ttl, 'sec' : +(new Date()) };
$.vakata.storage.set(this.settings.state.key, JSON.stringify(st));
};
/**
@ -7815,6 +7942,9 @@
if(!!k && k.state) { k = k.state; }
if(!!k && $.isFunction(this.settings.state.filter)) { k = this.settings.state.filter.call(this, k); }
if(!!k) {
if (!this.settings.state.preserve_loaded) {
delete k.core.loaded;
}
this.element.one("set_state.jstree", function (e, data) { data.instance.trigger('restore_state', { 'state' : $.extend(true, {}, k) }); });
this.set_state(k);
return true;
@ -8218,6 +8348,12 @@
* @plugin unique
*/
case_sensitive : false,
/**
* Indicates if white space should be trimmed before the comparison. Default is `false`.
* @name $.jstree.defaults.unique.trim_whitespace
* @plugin unique
*/
trim_whitespace : false,
/**
* A callback executed in the instance's scope when a new node is created and the name is already taken, the two arguments are the conflicting name and the counter. The default will produce results like `New node (2)`.
* @name $.jstree.defaults.unique.duplicate
@ -8237,16 +8373,32 @@
var n = chk === "rename_node" ? pos : obj.text,
c = [],
s = this.settings.unique.case_sensitive,
m = this._model.data, i, j;
w = this.settings.unique.trim_whitespace,
m = this._model.data, i, j, t;
for(i = 0, j = par.children.length; i < j; i++) {
c.push(s ? m[par.children[i]].text : m[par.children[i]].text.toLowerCase());
t = m[par.children[i]].text;
if (!s) {
t = t.toLowerCase();
}
if (w) {
t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
}
c.push(t);
}
if(!s) { n = n.toLowerCase(); }
if (w) { n = n.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }
switch(chk) {
case "delete_node":
return true;
case "rename_node":
i = ($.inArray(n, c) === -1 || (obj.text && obj.text[ s ? 'toString' : 'toLowerCase']() === n));
t = obj.text || '';
if (!s) {
t = t.toLowerCase();
}
if (w) {
t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
}
i = ($.inArray(n, c) === -1 || (obj.text && t === n));
if(!i) {
this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_01', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
}
@ -8286,15 +8438,36 @@
return parent.create_node.call(this, par, node, pos, callback, is_loaded);
}
if(!node) { node = {}; }
var tmp, n, dpc, i, j, m = this._model.data, s = this.settings.unique.case_sensitive, cb = this.settings.unique.duplicate;
var tmp, n, dpc, i, j, m = this._model.data, s = this.settings.unique.case_sensitive, w = this.settings.unique.trim_whitespace, cb = this.settings.unique.duplicate, t;
n = tmp = this.get_string('New node');
dpc = [];
for(i = 0, j = par.children.length; i < j; i++) {
dpc.push(s ? m[par.children[i]].text : m[par.children[i]].text.toLowerCase());
t = m[par.children[i]].text;
if (!s) {
t = t.toLowerCase();
}
if (w) {
t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
}
dpc.push(t);
}
i = 1;
while($.inArray(s ? n : n.toLowerCase(), dpc) !== -1) {
t = n;
if (!s) {
t = t.toLowerCase();
}
if (w) {
t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
}
while($.inArray(t, dpc) !== -1) {
n = cb.call(this, tmp, (++i)).toString();
t = n;
if (!s) {
t = t.toLowerCase();
}
if (w) {
t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
}
}
node.text = n;
}
@ -8411,7 +8584,7 @@
};
// include the wholerow plugin by default
// $.jstree.defaults.plugins.push("wholerow");
if(document.registerElement && Object && Object.create) {
if(window.customElements && Object && Object.create) {
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function () {
var c = { core : {}, plugins : [] }, i;
@ -8432,8 +8605,8 @@
};
// proto.attributeChangedCallback = function (name, previous, value) { };
try {
document.registerElement("vakata-jstree", { prototype: proto });
} catch(ignore) { }
window.customElements.define("vakata-jstree", function() {}, { prototype: proto });
} catch (ignore) { }
}
}));

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,7 @@ export * from "./loader/ept/ZstandardLoader.js";
export * from "./loader/GreyhoundBinaryLoader.js";
export * from "./loader/GreyhoundLoader.js";
export * from "./loader/PointAttributes.js";
export * from "./loader/ShapefileLoader.js";
export * from "./utils/Box3Helper.js";
export * from "./utils/ClippingTool.js";

View File

@ -86,16 +86,6 @@ export class BinaryLoader{
geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(buffer), 3));
} else if (property === "RGBA") {
geometry.addAttribute('color', new THREE.BufferAttribute(new Uint8Array(buffer), 4, true));
} else if (property === "INTENSITY") {
geometry.addAttribute('intensity', new THREE.BufferAttribute(new Float32Array(buffer), 1));
} else if (property === "CLASSIFICATION") {
geometry.addAttribute('classification', new THREE.BufferAttribute(new Uint8Array(buffer), 1));
} else if (property === "RETURN_NUMBER") {
geometry.addAttribute('returnNumber', new THREE.BufferAttribute(new Uint8Array(buffer), 1));
} else if (property === "NUMBER_OF_RETURNS") {
geometry.addAttribute('numberOfReturns', new THREE.BufferAttribute(new Uint8Array(buffer), 1));
} else if (property === "SOURCE_ID") {
geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(new Uint16Array(buffer), 1));
} else if (property === "NORMAL_SPHEREMAPPED") {
geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(buffer), 3));
} else if (property === "NORMAL_OCT16") {
@ -109,17 +99,7 @@ export class BinaryLoader{
} else if (property === "SPACING") {
let bufferAttribute = new THREE.BufferAttribute(new Float32Array(buffer), 1);
geometry.addAttribute('spacing', bufferAttribute);
}
// else if (property === "GPS_TIME") {
// let bufferAttribute = new THREE.BufferAttribute(new Float32Array(buffer), 1);
// geometry.addAttribute('gpsTime', bufferAttribute);
// node.gpsTime = {
// offset: buffers[property].offset,
// range: buffers[property].range,
// };
// }
else{
} else {
const bufferAttribute = new THREE.BufferAttribute(new Float32Array(buffer), 1);
bufferAttribute.potree = {
offset: buffers[property].offset,
@ -135,7 +115,6 @@ export class BinaryLoader{
}
}
tightBoundingBox.max.sub(tightBoundingBox.min);
tightBoundingBox.min.set(0, 0, 0);

View File

@ -14,12 +14,14 @@ import {XHRFactory} from "../XHRFactory.js";
export class LasLazLoader {
constructor (version) {
constructor (version, extension) {
if (typeof (version) === 'string') {
this.version = new Version(version);
} else {
this.version = version;
}
this.extension = extension;
}
static progressCB () {
@ -31,12 +33,10 @@ export class LasLazLoader {
return;
}
let pointAttributes = node.pcoGeometry.pointAttributes;
let url = node.getURL();
if (this.version.equalOrHigher('1.4')) {
url += '.' + pointAttributes.toLowerCase();
url += `.${this.extension}`;
}
let xhr = XHRFactory.createXMLHttpRequest();
@ -57,111 +57,59 @@ export class LasLazLoader {
xhr.send(null);
}
parse(node, buffer){
async parse(node, buffer){
let lf = new LASFile(buffer);
let handler = new LasLazBatcher(node);
try{
await lf.open();
lf.isOpen = true;
}catch(e){
console.log("failed to open file. :(");
//
// DEBUG
//
// invoke the laz decompress worker thousands of times to check for memory leaks
// until 2018/03/05, it tended to run out of memory at ~6230 invocations
//
//
//lf.open()
//.then( msg => {
// lf.isOpen = true;
// return lf;
//}).catch( msg => {
// console.log("failed to open file. :(");
//}).then( lf => {
// return lf.getHeader().then(function (h) {
// return [lf, h];
// });
//}).then( v => {
// let lf = v[0];
// let header = v[1];
return;
}
// lf.readData(1000000, 0, 1)
// .then( v => {
// console.log("read");
let header = await lf.getHeader();
// this.parse(node, buffer);
// }).then (v => {
// lf.close();
// });
let skip = 1;
let totalRead = 0;
let totalToRead = (skip <= 1 ? header.pointsCount : header.pointsCount / skip);
//})
let hasMoreData = true;
while(hasMoreData){
let data = await lf.readData(1000 * 1000, 0, skip);
handler.push(new LASDecoder(data.buffer,
header.pointsFormatId,
header.pointsStructSize,
data.count,
header.scale,
header.offset,
header.mins, header.maxs));
lf.open()
.then( msg => {
lf.isOpen = true;
return lf;
}).catch( msg => {
console.log("failed to open file. :(");
}).then( lf => {
return lf.getHeader().then(function (h) {
return [lf, h];
});
}).then( v => {
let lf = v[0];
let header = v[1];
totalRead += data.count;
LasLazLoader.progressCB(totalRead / totalToRead);
let skip = 1;
let totalRead = 0;
let totalToRead = (skip <= 1 ? header.pointsCount : header.pointsCount / skip);
let reader = function () {
let p = lf.readData(1000000, 0, skip);
return p.then(function (data) {
handler.push(new LASDecoder(data.buffer,
header.pointsFormatId,
header.pointsStructSize,
data.count,
header.scale,
header.offset,
header.mins, header.maxs));
hasMoreData = data.hasMoreData;
}
totalRead += data.count;
LasLazLoader.progressCB(totalRead / totalToRead);
header.totalRead = totalRead;
header.versionAsString = lf.versionAsString;
header.isCompressed = lf.isCompressed;
if (data.hasMoreData) {
return reader();
} else {
header.totalRead = totalRead;
header.versionAsString = lf.versionAsString;
header.isCompressed = lf.isCompressed;
return [lf, header, handler];
}
});
};
LasLazLoader.progressCB(1);
return reader();
}).then( v => {
let lf = v[0];
// we're done loading this file
//
LasLazLoader.progressCB(1);
try{
await lf.close();
// Close it
return lf.close().then(function () {
lf.isOpen = false;
return v.slice(1);
}).catch(e => {
// If there was a cancellation, make sure the file is closed, if the file is open
// close and then fail
if (lf.isOpen) {
return lf.close().then(function () {
lf.isOpen = false;
throw e;
});
}
throw e;
});
});
lf.isOpen = false;
}catch(e){
console.error("failed to close las/laz file!!!");
throw e;
}
}
handle (node, url) {
@ -200,7 +148,6 @@ export class LasLazBatcher{
geometry.addAttribute('returnNumber', new THREE.BufferAttribute(returnNumbers, 1));
geometry.addAttribute('numberOfReturns', new THREE.BufferAttribute(numberOfReturns, 1));
geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(pointSourceIDs, 1));
//geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(numPoints * 3), 3));
geometry.addAttribute('indices', new THREE.BufferAttribute(indices, 4));
geometry.attributes.indices.normalized = true;
@ -219,8 +166,6 @@ export class LasLazBatcher{
Potree.numNodesLoading--;
this.node.mean = new THREE.Vector3(...e.data.mean);
//debugger;
Potree.workerPool.returnWorker(workerPath, worker);
};

View File

@ -79,6 +79,24 @@ function parseAttributes(cloudjs){
}
function lasLazAttributes(fMno){
const attributes = new PointAttributes();
attributes.add(PointAttribute.POSITION_CARTESIAN);
attributes.add(new PointAttribute("RGBA", PointAttributeTypes.DATA_TYPE_UINT8, 4));
attributes.add(new PointAttribute("intensity", PointAttributeTypes.DATA_TYPE_UINT16, 1));
attributes.add(new PointAttribute("classification", PointAttributeTypes.DATA_TYPE_UINT8, 1));
attributes.add(new PointAttribute("gps-time", PointAttributeTypes.DATA_TYPE_DOUBLE, 1));
attributes.add(new PointAttribute("returnNumber", PointAttributeTypes.DATA_TYPE_UINT8, 1));
attributes.add(new PointAttribute("number of returns", PointAttributeTypes.DATA_TYPE_UINT8, 1));
attributes.add(new PointAttribute("return number", PointAttributeTypes.DATA_TYPE_UINT8, 1));
attributes.add(new PointAttribute("source id", PointAttributeTypes.DATA_TYPE_UINT16, 1));
//attributes.add(new PointAttribute("pointSourceID", PointAttributeTypes.DATA_TYPE_INT8, 4));
return attributes;
}
export class POCLoader {
static load(url, callback){
@ -131,12 +149,13 @@ export class POCLoader {
pco.tightBoundingSphere = tightBoundingBox.getBoundingSphere(new THREE.Sphere());
pco.offset = offset;
if (fMno.pointAttributes === 'LAS') {
pco.loader = new LasLazLoader(fMno.version);
pco.loader = new LasLazLoader(fMno.version, "las");
pco.pointAttributes = lasLazAttributes(fMno);
} else if (fMno.pointAttributes === 'LAZ') {
pco.loader = new LasLazLoader(fMno.version);
pco.loader = new LasLazLoader(fMno.version, "laz");
pco.pointAttributes = lasLazAttributes(fMno);
} else {
pco.loader = new BinaryLoader(fMno.version, boundingBox, fMno.scale);
//pco.pointAttributes = new PointAttributes(pco.pointAttributes);
pco.pointAttributes = parseAttributes(fMno);
}

View File

@ -0,0 +1,145 @@
export class ShapefileLoader{
constructor(){
this.transform = null;
}
async load(path){
const features = await this.loadShapefileFeatures(path);
const node = new THREE.Object3D();
for(const feature of features){
const fnode = this.featureToSceneNode(feature);
node.add(fnode);
}
const result = {
features: features,
node: node,
};
return result;
}
featureToSceneNode(feature){
let geometry = feature.geometry;
let color = new THREE.Color(1, 1, 1);
let transform = this.transform;
if(transform === null){
transform = {forward: (v) => v};
}
if(feature.geometry.type === "Point"){
let sg = new THREE.SphereGeometry(1, 18, 18);
let sm = new THREE.MeshNormalMaterial();
let s = new THREE.Mesh(sg, sm);
let [long, lat] = geometry.coordinates;
let pos = transform.forward([long, lat]);
s.position.set(...pos, 20);
s.scale.set(10, 10, 10);
return s;
}else if(geometry.type === "LineString"){
let coordinates = [];
let min = new THREE.Vector3(Infinity, Infinity, Infinity);
for(let i = 0; i < geometry.coordinates.length; i++){
let [long, lat] = geometry.coordinates[i];
let pos = transform.forward([long, lat]);
min.x = Math.min(min.x, pos[0]);
min.y = Math.min(min.y, pos[1]);
min.z = Math.min(min.z, 20);
coordinates.push(...pos, 20);
if(i > 0 && i < geometry.coordinates.length - 1){
coordinates.push(...pos, 20);
}
}
for(let i = 0; i < coordinates.length; i += 3){
coordinates[i+0] -= min.x;
coordinates[i+1] -= min.y;
coordinates[i+2] -= min.z;
}
let positions = new Float32Array(coordinates);
let lineGeometry = new THREE.BufferGeometry();
lineGeometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));
let material = new THREE.LineBasicMaterial( { color: color} );
let line = new THREE.LineSegments(lineGeometry, material);
line.position.copy(min);
return line;
}else if(geometry.type === "Polygon"){
for(let pc of geometry.coordinates){
let coordinates = [];
let min = new THREE.Vector3(Infinity, Infinity, Infinity);
for(let i = 0; i < pc.length; i++){
let [long, lat] = pc[i];
let pos = transform.forward([long, lat]);
min.x = Math.min(min.x, pos[0]);
min.y = Math.min(min.y, pos[1]);
min.z = Math.min(min.z, 20);
coordinates.push(...pos, 20);
if(i > 0 && i < pc.length - 1){
coordinates.push(...pos, 20);
}
}
for(let i = 0; i < coordinates.length; i += 3){
coordinates[i+0] -= min.x;
coordinates[i+1] -= min.y;
coordinates[i+2] -= min.z;
}
let positions = new Float32Array(coordinates);
let lineGeometry = new THREE.BufferGeometry();
lineGeometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));
let material = new THREE.LineBasicMaterial( { color: color} );
let line = new THREE.LineSegments(lineGeometry, material);
line.position.copy(min);
return line;
}
}else{
console.log("unhandled feature: ", feature);
}
}
async loadShapefileFeatures(file){
let features = [];
let source = await shapefile.open(file);
while(true){
let result = await source.read();
if (result.done) {
break;
}
if (result.value && result.value.type === 'Feature' && result.value.geometry !== undefined) {
features.push(result.value);
}
}
return features;
}
};

View File

@ -249,7 +249,6 @@ export class PointCloudMaterial extends THREE.RawShaderMaterial {
let attributeName = this.activeAttributeName.replace(/[^a-zA-Z0-9]/g, '_');
defines.push(`#define color_type_${attributeName}`);
console.log(`#define color_type_${attributeName}`);
}
if(this._treeType === TreeType.OCTREE){

View File

@ -16,7 +16,7 @@ export class OrientedImages{
const content = await response.text();
const lines = content.split(/\r?\n/);
const imageParams = [];
const validIDs = [31023, 31024, 31025, 31026, 31027, 31028, 31029, 31030, 31031, 31032, 31033, 31034, 31035, 31036, 31037, 31038, 31039, 31040, 31041, 31042, 31043, 31044, 31045, 31046, 31047, 31048, 31049, 31050, 31296, 31297, 31298, 31299, 31300, 31301, 31302, 31303, 31304, 31305, 31306, 31307, 31308, 31309, 31310, 31311, 31312, 31313, 31314, 31315, 31316, 31317, 31318, 31319, 31320, 31321, 31322, 31323, 31412, 31413, 31414, 31415, 31416, 31417, 31418, 31419, 31420, 31421, 31422, 31423, 31424, 31425, 31426, 31427, 31428, 31429, 31430, 31431, 31432, 31433, 31434, 31679, 31680, 31681, 31682, 31683, 31684, 31685, 31686, 31687, 31688, 31689, 31690, 31691, 31692, 31693, 31694, 31695, 31696, 31697, 31698, 31699, 31700, 31701, 31702, 31703, 31803, 31804, 31805, 31806, 31807, 31808, 31809, 31810, 31811, 31812, 31813, 31814, 31815, 31816, 31817, 31818, 31819, 31820, 31821, 31822, 31823, 31824, 31825, 31826, 31827, 31828, 31829, 32088, 32089, 32090, 32091, 32092, 32093, 32094, 32095, 32096, 32097, 32098, 32099, 32100, 32101, 32102, 32103, 32104, 32105, 32106, 32107, 32108, 32109, 32110, 32111, 32112, 32113, 32277, 32278, 32279, 32280, 32281, 32282, 32283, 32284, 32285, 32286, 32287, 32288, 32289, 32290, 32291, 32292, 32293, 32294, 32295, 32296, 32297, 32298, 32299, 32300, 32594, 32595, 32596, 32597, 32598, 32599, 32600, 32601, 32602, 32603, 32604, 32605, 32606, 32607, 32608, 32609, 32610, 32611, 32612, 32613, 32614, 32615, 32616].map(v => v + "");
//const validIDs = [31023, 31024, 31025, 31026, 31027, 31028, 31029, 31030, 31031, 31032, 31033, 31034, 31035, 31036, 31037, 31038, 31039, 31040, 31041, 31042, 31043, 31044, 31045, 31046, 31047, 31048, 31049, 31050, 31296, 31297, 31298, 31299, 31300, 31301, 31302, 31303, 31304, 31305, 31306, 31307, 31308, 31309, 31310, 31311, 31312, 31313, 31314, 31315, 31316, 31317, 31318, 31319, 31320, 31321, 31322, 31323, 31412, 31413, 31414, 31415, 31416, 31417, 31418, 31419, 31420, 31421, 31422, 31423, 31424, 31425, 31426, 31427, 31428, 31429, 31430, 31431, 31432, 31433, 31434, 31679, 31680, 31681, 31682, 31683, 31684, 31685, 31686, 31687, 31688, 31689, 31690, 31691, 31692, 31693, 31694, 31695, 31696, 31697, 31698, 31699, 31700, 31701, 31702, 31703, 31803, 31804, 31805, 31806, 31807, 31808, 31809, 31810, 31811, 31812, 31813, 31814, 31815, 31816, 31817, 31818, 31819, 31820, 31821, 31822, 31823, 31824, 31825, 31826, 31827, 31828, 31829, 32088, 32089, 32090, 32091, 32092, 32093, 32094, 32095, 32096, 32097, 32098, 32099, 32100, 32101, 32102, 32103, 32104, 32105, 32106, 32107, 32108, 32109, 32110, 32111, 32112, 32113, 32277, 32278, 32279, 32280, 32281, 32282, 32283, 32284, 32285, 32286, 32287, 32288, 32289, 32290, 32291, 32292, 32293, 32294, 32295, 32296, 32297, 32298, 32299, 32300, 32594, 32595, 32596, 32597, 32598, 32599, 32600, 32601, 32602, 32603, 32604, 32605, 32606, 32607, 32608, 32609, 32610, 32611, 32612, 32613, 32614, 32615, 32616].map(v => v + "");
//const validIDs = ["32604"];
for(let i = 1; i < lines.length; i++){
const line = lines[i];
@ -33,9 +33,9 @@ export class OrientedImages{
kappa: Number.parseFloat(tokens[6]),
fov: fov,
};
if(!validIDs.includes(params.id)){
continue;
}
// if(!validIDs.includes(params.id)){
// continue;
// }
imageParams.push(params);
}

View File

@ -2,10 +2,6 @@
import {Version} from "../Version.js";
import {PointAttributes, PointAttribute} from "../loader/PointAttributes.js";
import {InterleavedBuffer} from "../InterleavedBuffer.js";
import {toInterleavedBufferAttribute} from "../utils/toInterleavedBufferAttribute.js";
/* global onmessage:true postMessage:false */
/* exported onmessage */
@ -126,47 +122,6 @@ onmessage = function (event) {
colors[4 * j + 2] = cv.getUint8(inOffset + j * pointAttributes.byteSize + 2);
}
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
}
else if (pointAttribute.name === "CLASSIFICATION") {
let buff = new ArrayBuffer(numPoints);
let classifications = new Uint8Array(buff);
for (let j = 0; j < numPoints; j++) {
let classification = cv.getUint8(inOffset + j * pointAttributes.byteSize);
classifications[j] = classification;
}
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
} else if (pointAttribute.name === "RETURN_NUMBER") {
let buff = new ArrayBuffer(numPoints);
let returnNumbers = new Uint8Array(buff);
for (let j = 0; j < numPoints; j++) {
let returnNumber = cv.getUint8(inOffset + j * pointAttributes.byteSize);
returnNumbers[j] = returnNumber;
}
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
} else if (pointAttribute.name === "NUMBER_OF_RETURNS") {
let buff = new ArrayBuffer(numPoints);
let numberOfReturns = new Uint8Array(buff);
for (let j = 0; j < numPoints; j++) {
let numberOfReturn = cv.getUint8(inOffset + j * pointAttributes.byteSize);
numberOfReturns[j] = numberOfReturn;
}
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
} else if (pointAttribute.name === "SOURCE_ID") {
let buff = new ArrayBuffer(numPoints * 2);
let sourceIDs = new Uint16Array(buff);
for (let j = 0; j < numPoints; j++) {
let sourceID = cv.getUint16(inOffset + j * pointAttributes.byteSize);
sourceIDs[j] = sourceID;
}
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
} else if (pointAttribute.name === "NORMAL_SPHEREMAPPED") {
let buff = new ArrayBuffer(numPoints * 4 * 3);
@ -248,19 +203,7 @@ onmessage = function (event) {
}
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
}
// else if (pointAttribute.name === "GPS_TIME") {
// let buff = new ArrayBuffer(numPoints * 8);
// let gpstimes = new Float64Array(buff);
// for(let j = 0; j < numPoints; j++){
// let gpstime = cv.getFloat64(inOffset + j * pointAttributes.byteSize, true);
// gpstimes[j] = gpstime;
// }
// attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
// }
else{
} else {
let buff = new ArrayBuffer(numPoints * 4);
let f32 = new Float32Array(buff);
@ -320,35 +263,6 @@ onmessage = function (event) {
inOffset += pointAttribute.byteSize;
}
// Convert GPS time from double (unsupported by WebGL) to origin-aligned floats
// if(attributeBuffers["GPS_TIME"]){
// let attribute = attributeBuffers["GPS_TIME"];
// let sourceF64 = new Float64Array(attribute.buffer);
// let target = new ArrayBuffer(numPoints * 4);
// let targetF32 = new Float32Array(target);
// let min = Infinity;
// let max = -Infinity;
// for(let i = 0; i < numPoints; i++){
// let gpstime = sourceF64[i];
// min = Math.min(min, gpstime);
// max = Math.max(max, gpstime);
// }
// for(let i = 0; i < numPoints; i++){
// let gpstime = sourceF64[i];
// targetF32[i] = gpstime - min;
// }
// attributeBuffers["GPS_TIME"] = {
// buffer: target,
// attribute: PointAttribute.GPS_TIME,
// offset: min,
// range: max - min};
// }
{ // add indices
let buff = new ArrayBuffer(numPoints * 4);
let indices = new Uint32Array(buff);