diff --git a/src/Core/TileMesh.js b/src/Core/TileMesh.js index d15b1855e2..a039ac8614 100644 --- a/src/Core/TileMesh.js +++ b/src/Core/TileMesh.js @@ -47,7 +47,7 @@ class TileMesh extends THREE.Mesh { this.geoidHeight = 0; - this.link = []; + this.link = {}; } /** diff --git a/src/Process/FeatureProcessing.js b/src/Process/FeatureProcessing.js index 26c6f35190..7c99c8840e 100644 --- a/src/Process/FeatureProcessing.js +++ b/src/Process/FeatureProcessing.js @@ -21,12 +21,10 @@ export default { node.layerUpdateState[layer.id] = new LayerUpdateState(); } else if (!node.layerUpdateState[layer.id].canTryUpdate()) { // toggle visibility features - node.link.forEach((f) => { - if (f.layer?.id == layer.id) { - f.layer.object3d.add(f); - f.meshes.position.z = geoidLayerIsVisible(layer.parent) ? node.geoidHeight : 0; - f.meshes.updateMatrixWorld(); - } + node.link[layer.id]?.forEach((f) => { + f.layer.object3d.add(f); + f.meshes.position.z = geoidLayerIsVisible(layer.parent) ? node.geoidHeight : 0; + f.meshes.updateMatrixWorld(); }); return; } @@ -60,6 +58,7 @@ export default { featureMeshes.forEach((featureMesh) => { if (featureMesh) { + node.link[layer.id] = node.link[layer.id] || []; featureMesh.as(context.view.referenceCrs); featureMesh.meshes.position.z = geoidLayerIsVisible(layer.parent) ? node.geoidHeight : 0; featureMesh.updateMatrixWorld(); @@ -73,7 +72,7 @@ export default { ObjectRemovalHelper.removeChildrenAndCleanupRecursively(layer, featureMesh); } else { layer.object3d.add(featureMesh); - node.link.push(featureMesh); + node.link[layer.id].push(featureMesh); } featureMesh.layer = layer; } else { diff --git a/src/Process/ObjectRemovalHelper.js b/src/Process/ObjectRemovalHelper.js index 5d846033d2..ea720a91b4 100644 --- a/src/Process/ObjectRemovalHelper.js +++ b/src/Process/ObjectRemovalHelper.js @@ -83,12 +83,10 @@ export default { // Objects are filtered by id because the obj hierarchy may also contain labels that have been added as childs // of the objects which have their own removal logic let toRemove = obj.children.filter(c => c.layer && c.layer.id === layer.id); - if (obj.link) { - const linkedObjects = obj.link.filter(c => c.layer && c.layer.id === layer.id); - if (linkedObjects.length) { - toRemove = toRemove.concat(linkedObjects); - obj.link = obj.link.filter(c => c.layer && c.layer.id !== layer.id); - } + const linked = obj.link && obj.link[layer.id]; + if (linked?.children.length) { + toRemove = toRemove.concat(linked.children); + delete obj.link[layer.id]; } for (const c of toRemove) { this.removeChildrenAndCleanupRecursively(layer, c); diff --git a/utils/debug/TileDebug.js b/utils/debug/TileDebug.js index 88cb825ada..0a96a0e600 100644 --- a/utils/debug/TileDebug.js +++ b/utils/debug/TileDebug.js @@ -122,7 +122,7 @@ export default function createTileDebugUI(datDebugTool, view, layer, debugInstan } // filtering helper attached to node with the current debug layer - let helper = node.link.filter(n => n.layer && (n.layer.id == layer.id))[0]; + let helper = node.link[layer.id]; if (node.visible && node.material && node.material.visible) { if (!helper) { helper = new THREE.Group(); @@ -144,7 +144,7 @@ export default function createTileDebugUI(datDebugTool, view, layer, debugInstan helper.add(sphereHelper); } - node.link.push(helper); + node.link[layer.id] = helper; } layer.object3d.add(helper);