Welcome to the community! Thank you for bringing us your question! It seems like you have created a polyline. How do you intend to add points to the scene?
var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
handler.setInputAction(function(movement){
var feature = scene.pick(movement.endPosition);
let cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(movement.position), viewer.scene);
let point = viewer.entities.add({
position: cartesian,
point: {
color: Cesium.Color.WHITE,
pixelSize: 5,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 1
},
});
if( feature == myPolylineEntity ){ // Do points and lines overlap
// overlap
} else {
// No overlap
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
If lots of entities end up in the near vicinity of each other, you move to scene.drillPick() and sift through the resulting array for your polyline entity instead.
I think in your example I modified, movement.endPosition should be movement.position. You’re using the screen position there to create the ray that returns the Cartesian3, so in a sense you’ve got both.
Hello @mcck,
I have a similar problem (only to determine if a point is in a given area) and I thought about it a lot - I think that using a corridor instead of a polyline can help you - it has a height - https://cesium.com/learn/cesiumjs/ref-doc/CorridorGeometry.html?classFilter=cor
this is how intersection tests can be used https://cesium.com/learn/cesiumjs/ref-doc/IntersectionTests.html
here you can fantasize:
1 you can direct a ray from a point and determine its intersection with a primitive
2, you can define the intersection of the corridor primitive and the dimension sphere of the entity with the geometry of the point
there are a lot of pitfalls - I will not say exactly from memory now - however, there are definitely opportunities - when I have time, I will also return to the implementation of my tool and perhaps write more accurately with code examples. So far, I am only suggesting the direction of a possible solution.
Hope this helps you.