Rotate amtrak trains correctly

main
Chandler Swift 2024-09-02 14:42:51 -05:00
parent c9ae210d81
commit b357b55c6b
Signed by: chandlerswift
GPG Key ID: A851D929D52FB93F
1 changed files with 17 additions and 2 deletions

View File

@ -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({ image: new Icon({
anchor: [0.5, .9], anchor: [0.5, .9],
src: pinURL, src: pinURL,
rotateWithView: true,
rotation: rotation,
scale: scale,
}), }),
}), });
}
}); });
setInterval(() => vectorLayer.getSource().refresh(), 30000); setInterval(() => vectorLayer.getSource().refresh(), 30000);