
I’m working with leaflet, node and turf.js for gis calculations. I’m trying to plot a road on a map with points every 200 meters.
On the client page (inside the script tag) I have the following:
(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 © <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);
})();
I’m working in arizona which has approximately (31.xx, -112.xx) latitude/longitude. You can see that the first point looks correct, but the remainder of the ‘interpolated’ points show up as:
31.x,-67.x , which is nowhere near Arizona. What am I doing wrong?