How to filter in points that exist in a given area?

My map has a list of coordinates represented by points in the map.
I’ve got a circular element that is placed on top of cesium, that is always centred.

I’d like to find which points are inside the circular area, so that after I can find which one
is in the closest distance to the centre point of the camera.

I found that someone asked a similar question in the past ( Check if a Point(Cartesia3) exists in a circle ) the answer was “You just need to check if the distance between centre and your point is equal to radius”.

What is centre? The camera viewer position?

  function getMapCenter() {            
    var windowPosition = new window.Cesium.Cartesian2(viewer.container.clientWidth / 2, viewer.container.clientHeight / 2);
    var pickRay = viewer.scene.camera.getPickRay(windowPosition);
    var pickPosition = viewer.scene.globe.pick(pickRay, viewer.scene);
    var pickPositionCartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(pickPosition);
    console.log(pickPositionCartographic.longitude * (180/Math.PI));
    console.log(pickPositionCartographic.latitude * (180/Math.PI));
  }

As referenced in https://stackoverflow.com/questions/33348761/get-center-in-cesium-map

So, let’s say that my circle is always 100px, radius would be 50px but how would I translate these values against what getCenterMap function provides?

I found the Occluder might help, so will take some time to see if I can use it for my use case ( /docs/cesiumjs-ref-doc/Occluder.html ).

Thank you :slight_smile:

I didn’t find a solution for filtering, so I’m computing all existing points (which doesn’t scale); I’m literally computing the distance for each point to identify which one is the closest, but I have a small range of points, if I scale to hundreds it won’t perform. Anyway, just letting any future reader know.

1 Like

So the right way to do this that would scale up would be to insert your points into some spatial data structure when you first create the, like a quad tree. That would allow you to very efficiently find all points within a given area.

The other way is if your data is 3D Tiles, you can color/show hide etc using the 3D Tiles styling language: https://sandcastle.cesium.com/index.html?src=3D%20Tiles%20Feature%20Styling.html. Here this example shows coloring all 1 million buildings in Manhatten. It does this efficiently by passing a uniform to the GPU, instead of having to iteratively go through each one (so you can do things like, color all buildings within a specific range very quickly).