Finding the center of Leaflet polygon?

后端 未结 4 478
逝去的感伤
逝去的感伤 2020-12-24 13:00

I have a bunch of leaflet polygons on a map I created. Each polygon represents something different. A specific set of information is displayed in a popup depending on the pa

4条回答
  •  醉梦人生
    2020-12-24 13:47

    assuming each polygon has only 4 sides it is simple

    var L20 = [
    [74.0995, -99.92615],
    [74.14008, -99.4043],
    [74.07691, -99.33838],
    [74.03617, -99.86023]
    ];
    

    using this example get max and min lat: 74.03617 and 74.14008 respectively so same for long: -99.92615 and 99.33838 respectively

    Then get the middle value for each: (max - min) / 2 = 0.051955 and -0.293885 then add them to the minimum amount

    gives you a centre of 74.088125, -99.632265

提交回复
热议问题