No idea what JS library you’re using, but just in case you haven’t seen it, have a look at https://github.com/Leaflet/Leaflet/issues/268 . That contains some links that might be useful (not just for Leaflet).
Thanks for the reply. I am using LeafletJS and according to the documentation there is no rotate function. However, i found Mapbox map control: https://docs.mapbox.com/mapbox-gl-js/example/navigation/. However there is no way (that i can see) to rotate programmatically.