Label not showing same values as console output when using proj4js

Hey,

I’m tracking the mouse position on the globe and translating the coordinates from WGS 84 to sweref1630 (E, N) using proj4js.
It works fine when I output the coordinates to the console:

const targetCoord = proj4("EPSG:4326", "EPSG:3010",sourceCoord);
console.log(targetCoord);

image

But when I display them via label they get cramped together:

 entity.label.text = targetCoord;
 document.getElementById("demo").innerHTML = entity.label.text;

image

Is there a way I can somehow modify the label output so it mirrors the console output? Or even better a way where I can split up the targetCoord so i can have the label display for example:

E: 118083.838362, N: 6654085,346521

Thanks

Hi @Albnas,

without a sandcastle or more of your code I can’t tell you much about the “error”.
But here’s a solution for splitting targetCoord:

entity.label.text = `E: ${targetCoord[0]}, N: ${targetCoord[1]}`

Those single quotes are Grave Accent Marks.

Best Lennart

Edit: It’s called Template literals btw.

Hey @lennart.imberg

Thank you very much! Works like a charm, I added toFixed(), to reduce decimals to a more reasonable amount.

I’m still learning JS (not my area of expertise) , I actually used template literals when I used Wgs84 coordinates, but with two variabels and not values returned as an array.

Thanks again, Albin