Rotate amtrak trains correctly
This commit is contained in:
parent
c9ae210d81
commit
b357b55c6b
|
@ -26,12 +26,27 @@ const vectorLayer = new VectorLayer({
|
|||
}
|
||||
},
|
||||
}),
|
||||
style: new Style({
|
||||
style: function(feature){
|
||||
let scale = [1, 1];
|
||||
let rotation = ['E', 'SE', 'S', 'SW', 'W', 'NW', 'N', 'NE'].indexOf(feature.get('heading'));
|
||||
if (rotation < 0) { // heading not found in array
|
||||
console.warn(`Could not find ${feature.get('heading')} in rotation array`);
|
||||
}
|
||||
if (2 < rotation && rotation <= 6 ) {
|
||||
rotation -= 4; // half turn
|
||||
scale = [-1, 1];
|
||||
}
|
||||
rotation = Math.PI / 4 * rotation;
|
||||
return new Style({
|
||||
image: new Icon({
|
||||
anchor: [0.5, .9],
|
||||
src: pinURL,
|
||||
rotateWithView: true,
|
||||
rotation: rotation,
|
||||
scale: scale,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
setInterval(() => vectorLayer.getSource().refresh(), 30000);
|
||||
|
|
Loading…
Reference in a new issue