Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intancing pickGeometryAt #2132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/Layer/ColorLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
17 changes: 17 additions & 0 deletions src/Layer/FeatureGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 4 additions & 0 deletions src/Layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down