Improve the custom-controls example with a rotating north arrow
Author: Egge-JanCreated Sep 24, 2026Updated Sep 24, 2026
Here I am with a proposal to amend/improve one of the long-standing examples, custom-controls, which has been around since at least 2015... This custom-controls example defines a "rotate to north" button that actually replicates the default Rotate control (which is still shown in the upper right corner of the same map, when the map is rotated).
I propose to:
- replace the static letter N on the button with a dynamic inline SVG north arrow,
- rotate this arrow on the button together with the map in the control's render method, so it always points north,
- hide the control with the ol-hidden class when the map is not rotated,
- and - last but not least - leave the default Rotate control out of the map. This will free up the upper right corner of the map div and leave room for other controls at that position. (Personally, I prefer this upper right corner as the location of an address search bar...)
The change is ready on my fork https://github.com/Egge-Jan/openlayers/tree/custom-controls-north-arrow. I can open a PR once accepted. TIA, Egge-Jan
Source: openlayers/openlayers