I'm working to plot ways using OSM and leaflet using node as a back end. On the front end I have leaflet2.html which has the following in the script tag:
const mymap = L.map("map");
async function getGeoJSONArr() {
const response = await fetch("http://localhost:3000/data");
const jsonArr = await response.json();
console.log("jsonARR", jsonArr);
const reversedCoords = jsonArr[0].slice().reverse();
console.log(reversedCoords);
return { jsonArr: jsonArr, reversedCoords: reversedCoords };
}
(async function buildMap(params) {
const o = await getGeoJSONArr();
console.log(o);
const polyline1 = o.jsonArr;
const reversedCoords = 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(reversedCoords, 13);
// Add a polyline
L.polyline(polyline1, { color: "blue" }).addTo(mymap);
})();
In the console I see:
{jsonArr: Array(5),
reversedCoords: Array(2)}jsonArr: Array(5)0: (2) [-110.9582708, 31.9323673]
1: (2) [-110.9579731, 31.9323537]2: (2) [-110.9576486, 31.9323673]3: (2) [-110.955342, 31.931959]4: (2) [-110.952628, 31.931936]length: 5[[Prototype]]: Array(0)
reversedCoords: (2) [31.9323673, -110.9582708][[Prototype]]: Object
There are no errors.
I'm expecring to see a polyline on the map, but I don't see it. What am I doing wrong?