使用 turf.js 插值路径点时出错

问题描述 投票:0回答:0

我正在使用 leaflet、node 和 turf.js 进行 gis 计算。我正在尝试在地图上绘制一条道路,每 200 米有一个点。

在客户端页面(脚本标签内)我有以下内容:

  (async function buildMap(params) {
    const o = await getGeoJSONArr();
    console.log('getGeoJSONArr ',o);
    const polyline1 = o.jsonArr;
    const centerCoords = o.reversedCoords;
    L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
      attribution:
        'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
      maxZoom: 18,
    }).addTo(mymap);

    mymap.setView(centerCoords, 13);

    console.log("polyline1 ", polyline1);

    const reversedPolyLine1 = polyline1.map((coord) => coord.reverse());

    // have to reverse openstreetmap lat/long for leaflet

    L.polyline(reversedPolyLine1, { color: "blue" }).addTo(mymap);

    var road = turf.lineString(reversedPolyLine1);

    const roadLength = turf.length(road, {
      units: "meters",
    });
    console.log("RL ", roadLength);

    let pointList = [];
    for (let distance = 0; distance < roadLength; distance += 200) {
      const point = turf.along(road, distance, { units: "meters" });
      console.log('point ',point);
      pointList.push(point.geometry.coordinates);
    }
    console.log('pointlist ',pointList);
    L.polyline(pointList, { color: 'red' }).addTo(mymap);

  })();

我在亚利桑那州工作,那里的纬度/经度大约为 (31.xx, -112.xx)。您可以看到第一个点看起来是正确的,但“插值”点的其余部分显示为:

31.x,-67.x ,离亚利桑那州很远。我做错了什么?

javascript node.js leaflet gis turfjs
© www.soinside.com 2019 - 2024. All rights reserved.