Skip to content

Commit 5942253

Browse files
committed
use backward azimuth as base for previous geo angles
1 parent 66915b4 commit 5942253

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

src/components/drawing/index.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,8 @@ function rotate(t, xy) {
15641564
];
15651565
}
15661566

1567+
var previousLon;
1568+
var previousLat;
15671569
var previousX;
15681570
var previousY;
15691571
var previousI;
@@ -1595,7 +1597,7 @@ function getMarkerAngle(d, trace) {
15951597
}
15961598
}
15971599

1598-
if(ref === 'north') {
1600+
if(trace._geo) {
15991601
var lon = d.lonlat[0];
16001602
var lat = d.lonlat[1];
16011603

@@ -1619,11 +1621,32 @@ function getMarkerAngle(d, trace) {
16191621
north[0] - x
16201622
);
16211623

1622-
var t = angle / 180 * Math.PI;
1623-
// To use counter-clockwise angles i.e.
1624-
// East: 90, West: -90
1625-
// to facilitate wind visualisations
1626-
// in future we should use t = -t here.
1624+
var t;
1625+
if(ref === 'north') {
1626+
t = angle / 180 * Math.PI;
1627+
// To use counter-clockwise angles i.e.
1628+
// East: 90, West: -90
1629+
// to facilitate wind visualisations
1630+
// in future we should use t = -t here.
1631+
} else if(ref === 'previous') {
1632+
var lon1 = lon / 180 * Math.PI;
1633+
var lat1 = lat / 180 * Math.PI;
1634+
var lon2 = previousLon / 180 * Math.PI;
1635+
var lat2 = previousLat / 180 * Math.PI;
1636+
1637+
var dLon = lon2 - lon1;
1638+
1639+
var deltaY = cos(lat2) * sin(dLon);
1640+
var deltaX = sin(lat2) * cos(lat1) - cos(lat2) * sin(lat1) * cos(dLon);
1641+
1642+
t = -atan2(
1643+
deltaY,
1644+
deltaX
1645+
) - Math.PI;
1646+
1647+
previousLon = lon;
1648+
previousLat = lat;
1649+
}
16271650

16281651
var A = rotate(u, [cos(t), 0]);
16291652
var B = rotate(v, [sin(t), 0]);
@@ -1632,9 +1655,16 @@ function getMarkerAngle(d, trace) {
16321655
A[1] + B[1],
16331656
A[0] + B[0]
16341657
) / Math.PI * 180;
1658+
1659+
if(ref === 'previous' && !(
1660+
previousTraceUid === trace.uid &&
1661+
d.i === previousI + 1
1662+
)) {
1663+
angle = null;
1664+
}
16351665
}
16361666

1637-
if(ref === 'previous') {
1667+
if(ref === 'previous' && !trace._geo) {
16381668
if(
16391669
previousTraceUid === trace.uid &&
16401670
d.i === previousI + 1 &&
10 Bytes
Loading
825 Bytes
Loading
-23 Bytes
Loading

test/image/mocks/z-marker-standoff.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,44 @@
5151
"mode": "markers+lines",
5252
"line": { "width": 5 },
5353
"marker": {
54-
"standoff": [5, 20, 10],
54+
"standoff": [5, 20, 10, 2.5],
5555
"angleref": "previous",
5656
"symbol": "arrow-wide",
5757
"size": 20
5858
},
5959
"lon": [
6060
-30,
6161
0,
62-
30
62+
30,
63+
15
6364
],
6465
"lat": [
6566
20,
6667
-5,
67-
10
68+
10,
69+
-20
6870
]
6971
},
7072
{
7173
"type": "scattergeo",
7274
"mode": "markers+text",
7375
"marker": {
7476
"opacity": 1,
75-
"size": [10, 40, 20]
77+
"size": [10, 40, 20, 5]
7678
},
77-
"text": [10, 40, 20],
78-
"textposition": ["right", "center", "top"],
79+
"text": [10, 40, 20, 5],
80+
"textposition": ["right", "center", "top", "bottom"],
7981
"lon": [
8082
-30,
8183
0,
82-
30
84+
30,
85+
15
8386
],
8487
"lat": [
8588
20,
8689
-5,
87-
10
90+
10,
91+
-20
8892
]
8993
},
9094
{

0 commit comments

Comments
 (0)