n9n
n9n

Reputation: 121

create leaflet rectangle from given 2 diagonal points

i have a leaflet feature rectangle and i need to pragmatically draw another squre rectangle . see the image dotted rectangle is the one i need to calculate

possible solutions

  1. get center of rectangle create new 4 point from center draw a rectangle i there any other better solutions for this

enter image description here

Upvotes: 0

Views: 153

Answers (1)

MBo
MBo

Reputation: 80177

Distance from square vertices to rectangle center is

d = rect_width / 2 + rect_height / 2

So their coordinates are

rect_center_x + d; rect_center_y  
rect_center_x; rect_center_y - d  
rect_center_x - d; rect_center_y  
rect_center_x; rect_center_y + d  

Upvotes: 1

Related Questions