Course rounding may be improved

Joeri Spitaels2 years ago

If you feed Traccar a course of 192° it will show it as S (South) in the web app, whereas SE (South-East) would be more accurate.
Therefor, in
web/app/AttributeFormatter.js
I suggest to replace

courseFormatter: function (value) {
    var courseValues = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
    return courseValues[Math.floor(value / 45)];
},

with

courseFormatter: function (value) {
    var courseValues = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
    return courseValues[Math.floor((value + 11.25) / 45)];
},
Anton Tananaev2 years ago
Joeri Spitaels2 years ago

I believe it should be

  let normalizedValue = (value + 45 / 4) % 360;

instead of

  let normalizedValue = (value + 45 / 2) % 360;
Anton Tananaev2 years ago

What makes you think that? We have a step of 45 degrees. We need to increase by half a step, if I understand it correctly.

Do you have an example that doesn't work?

Joeri Spitaels2 years ago

Ok my bad, I confused 90° and 45° angles.
But still, when I feed the modern web app a course of 192°, it shows as S, instead of SW.
I will double check now.

Anton Tananaev2 years ago

It sounds like you're using an outdated version of the app.

Joeri Spitaels2 years ago

It's fine. Apologies for the false alarm.

Joeri Spitaels2 years ago

I'm still getting incorrect course rounding on the demo3 server with the modern web app.

Anton Tananaev2 years ago

Can you please provide a screenshot and course value?

Joeri Spitaels2 years ago
Anton Tananaev2 years ago

Looks like you haven't clear your browser cache. That's an old version of the app.

Joeri Spitaels2 years ago

Indeed it was!
I tested courses 22.4°, 22.6°, 337.4°, 337,6° and got arrows in the right direction (N, NE, NW, N).
Thx a lot.