From 549d6b31b7eeb0cf7ecd19b565713a47c695f080 Mon Sep 17 00:00:00 2001 From: a-dutremble <106082983+a-dutremble@users.noreply.github.com> Date: Thu, 6 Jul 2023 17:57:16 +0200 Subject: [PATCH] feature(View): instancing pickGeometryAt --- src/Core/View.js | 5 +++++ src/Layer/ColorLayer.js | 7 +++++++ src/Layer/FeatureGeometryLayer.js | 17 +++++++++++++++++ src/Layer/Layer.js | 4 ++++ 4 files changed, 33 insertions(+) diff --git a/src/Core/View.js b/src/Core/View.js index 11d0ad8835..94973ec902 100644 --- a/src/Core/View.js +++ b/src/Core/View.js @@ -774,6 +774,11 @@ class View extends THREE.EventDispatcher { return results; } + pickGeometryAt(mouseOrEvt, radius = 0, where) { + const layer = this.getLayerById(where); + return layer.selectGeometry(mouseOrEvt, radius, this); + } + /** * Return the current zoom scale at the central point of the view. This * function compute the scale of a map. diff --git a/src/Layer/ColorLayer.js b/src/Layer/ColorLayer.js index a0b437a48a..770fceb620 100644 --- a/src/Layer/ColorLayer.js +++ b/src/Layer/ColorLayer.js @@ -116,6 +116,13 @@ class ColorLayer extends RasterLayer { update(context, layer, node, parent) { return updateLayeredMaterialNodeImagery(context, this, node, parent); } + + selectGeometry(mouseOrEvt, radius, view) { + const results = view.pickFeaturesAt(mouseOrEvt, radius, this.id); + if (results[this.id].length) { + return results[this.id][0].geometry; + } + } } export default ColorLayer; diff --git a/src/Layer/FeatureGeometryLayer.js b/src/Layer/FeatureGeometryLayer.js index 21713db058..afa112963f 100644 --- a/src/Layer/FeatureGeometryLayer.js +++ b/src/Layer/FeatureGeometryLayer.js @@ -61,6 +61,23 @@ class FeatureGeometryLayer extends GeometryLayer { this.object3d.clear(); } } + + selectGeometry(mouseOrEvt, radius, view) { + const results = view.pickObjectsAt(mouseOrEvt, radius, this.id); + if (results.length) { + if (results[0].object.isLine) { + const batchId = results[0].object.geometry.attributes.batchId.array[results[0].object.geometry.index.array[results[0].index]]; + return { geometry: results[0].object.feature.geometries[batchId], mesh: results[0].object }; + } else if (results[0].object.isPoints) { + const batchId = results[0].object.geometry.attributes.batchId.array[results[0].index]; + return { geometry: results[0].object.feature.geometries[batchId], mesh: results[0].object }; + } else if (results[0].object.isMesh) { + const batchId = results[0].object.geometry.attributes.batchId.array[results[0].face.a]; + return { geometry: results[0].object.feature.geometries[batchId], mesh: results[0].object }; + } + } + return undefined; + } } export default FeatureGeometryLayer; diff --git a/src/Layer/Layer.js b/src/Layer/Layer.js index 55651d1f96..7da0adaf95 100644 --- a/src/Layer/Layer.js +++ b/src/Layer/Layer.js @@ -258,6 +258,10 @@ class Layer extends THREE.EventDispatcher { delete(clearCache) { console.warn('Function delete doesn\'t exist for this layer'); } + + selectGeometry() { + throw new Error('selectGeometry is not supported yet in this type of layer'); + } } export default Layer;