diff --git a/layers/amtrak-live/layer.js b/layers/amtrak-live/layer.js index 266d8e7..b645362 100644 --- a/layers/amtrak-live/layer.js +++ b/layers/amtrak-live/layer.js @@ -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);