2

图书馆http ://turfjs.org/

平台使用:Node.js v8.9.4

草皮版本:来自 npm 的最新版本 - @turf/turf

代码:

var center = [20.659698486328125, -103.349609375];
var options = { steps: 5, units: 'kilometers', options: {} };
var radius = 1;
var polygon = turf.circle(center, radius, options);

我收到的多边形:

[ [ [ 20.659698486328125, -76.65938382863723 ],
[ 20.663518747226156, -76.65934049531025 ],
[ 20.66730214442299, -76.65921091347738 ],
[ 20.655878225430094, -76.65934049531025 ],
[ 20.659698486328125, -76.65938382863723 ] ] ]

问题:

多边形坐标错误,纬度正确。但是,经度完全不同。

用这个库尝试了所有的东西,仍然坐标是错误的,在完全不同的区域创建多边形。

4

1 回答 1

0

尝试在调用中交换中心的经度/纬度turf.circle

var center_orig = [20.659698486328125, -103.349609375];
var center = [-103.349609375, 20.659698486328125];
var options = {
  steps: 5,
  units: 'kilometers',
  options: {}
};
var radius = 1;
var polygon = turf.circle(center, radius, options);

var map = L.map('mapid').setView(center_orig, 13);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);

L.geoJSON(polygon, {
  style: function(feature) {
    return {
      color: "red"
    };
  }
}).addTo(map);
#mapid {
  height: 264px;
}
<link href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" rel="stylesheet" />
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>

<div id="mapid"></div>

于 2018-01-22T13:13:00.743 回答