How to draw rectangle on mouse click in cesium

Hi,

Is there any way to draw a rectangle using mouse click on the cesium map?

I really appreciate any help you can provide.

Hi @Masum_Billah ,

Thanks for you question.

We have a sandcastle example here Cesium Sandcastle which shows how to draw a polygon on the globe (with a terrain layer).

I think this will fit your use case, but please let us know if now and we are happy to try to help find a different example.

Thank you!
Luke

@Luke_McKinstry

Thank you for your reply.
I need to draw a rectangle, but in your shared example, there is no option for drawing a rectangle.
It is hard to draw a rectangle with a polygon.

@Masum_Billah ,
You could make a slight modification to the logic used to draw the polygon in the sandcastle in order to draw a rectangle. Instead of letting the user draw multiple additional points for a n-sided polygon, just allow two. And make those 2 points opposite vertices of the rectangle. I’ve seen this approach used frequently in rectangle draw tools for maps.

Hope that helps and please let us know if you have more questions.
Thanks,
Luke

Thank you for your help.