【问题标题】:Turf.js circle polygon coordinates issueTurf.js 圆形多边形坐标问题
【发布时间】:2018-01-22 12:54:25
【问题描述】:

http://turfjs.org/

平台使用:Node.js v8.9.4

Turf 版本:来自 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 ] ] ]

问题:

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

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

【问题讨论】:

    标签: node.js polygon turfjs


    【解决方案1】:

    尝试将呼叫中心的经度/纬度交换为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>

    【讨论】:

    猜你喜欢
    • 2012-07-05
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多