Draw personalized polygons on leaflet map withim shiny



Hi all.

Is it possible to draw polygons on leaflet markers?
Not predefined ones.

I want to be able to plot a triangle on every marker (which in this case are wind turbines).
The opening angle of the triangle is given as result of some equation and can change depending on the parameters considered. This is related to wake effect on wind turbines.

I put a picture of what I am thinking. Sorry for the bad drawing quality. I did in a hurry. I can provided one better if its not clear.

Is it possible to do such a thing?

Thanks folks!


You would need to do the following:

  • Figure out the three pairs of lat/long coordinates that form the vertices of each triangle
  • Arrange them in a two-column matrix; the first column is longitude and the second is latitude. (So each triangle is represented by a matrix with 3 rows and 2 columns.)
  • Join all of the matrices together, with rows of c(NA, NA) in between.
  • Call addPolylines(data = matrix) on your map, where matrix is the result of the previous step.

Or, if you are familiar with the sp or sf packages, you can create SpatialLines or LINESTRING objects, respectively, and use those instead of the matrix.


Thanks Joe.

As far as I can tell the most challenging part is the first one in which the vertices coordinates will be given as result of wake calculation.

As future development I am thinking about to also plot the intensity of the wake, as a gradual shaded area inside the triangle. And add a button to export as kmz.

Anyway, thanks.