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

User draw a polygon on the map #207

Closed
jduncanRadBlue opened this issue Jan 21, 2020 · 3 comments
Closed

User draw a polygon on the map #207

jduncanRadBlue opened this issue Jan 21, 2020 · 3 comments
Labels

Comments

@jduncanRadBlue
Copy link

jduncanRadBlue commented Jan 21, 2020

Does anyone have an idea of how you could allow the user to draw a polygon on the map? I have an app that has entities placed on the map and I'd like to allow the user to select an area on the map by drawing a polygon using their mouse and be able to filter out entities not in the polygon the user created. Thanks in advance for any sample code you can offer me!

@rot1024
Copy link
Member

rot1024 commented Jan 27, 2020

  1. You can get mouse position with onClick prop of Viewer component
  2. You can get location from the mouse position with get position from map #219
  3. Save clicked locations to state as list
  4. Draw entities with PointGraphics on the location to display points of the creating polygon
  5. If any one of the point entities are clicked (Entity.onClick), the creating polyline is closed and you can draw polygon with PolygonGraphics.

@jduncanRadBlue
Copy link
Author

@rot1024 I was able to get this working! Thank you. Now I ask, do you know how to find out if any point entities are inside the drawn polygon? I need to remove any entities that are not within the drawn polygon....or at least change their color to note the filter.

@rot1024
Copy link
Member

rot1024 commented Jan 30, 2020

I don't know how to detect polygon and point intersection with Cesium, but you can use https://github.com/substack/point-in-polygon. Or implement ray casting algorithm yourself.

@rot1024 rot1024 closed this as completed Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants