From f706128e9c31b22caabcf85dc2d7895f1275f0d9 Mon Sep 17 00:00:00 2001 From: Joao Figueiredo Date: Tue, 21 Jul 2026 12:02:48 +0100 Subject: [PATCH] feat: add north reset control --- app.js | 17 +++++++++++++++ assets/icons/north-pointer.svg | 4 ++++ styles.css | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 assets/icons/north-pointer.svg diff --git a/app.js b/app.js index a2dfe87..3459a2f 100644 --- a/app.js +++ b/app.js @@ -69,6 +69,15 @@ const parcelSearchLayer = new ol.layer.Vector({ const map = new ol.Map({ target: "map", + controls: ol.control + .defaults.defaults({ rotate: false }) + .extend([ + new ol.control.Rotate({ + autoHide: true, + label: createNorthPointerIcon(), + tipLabel: "Reset map orientation to north", + }), + ]), layers: [softBasemapLayer, openStreetMapLayer, satelliteLayer, wmsLayer, parcelSearchLayer], view: new ol.View({ center: ol.proj.fromLonLat(DEFAULT_CENTER), @@ -101,6 +110,14 @@ function setSidebarCollapsed(collapsed) { } } +function createNorthPointerIcon() { + const icon = document.createElement("img"); + icon.className = "north-pointer-icon"; + icon.src = "./assets/icons/north-pointer.svg"; + icon.alt = ""; + return icon; +} + async function searchParcela(event) { event.preventDefault(); diff --git a/assets/icons/north-pointer.svg b/assets/icons/north-pointer.svg new file mode 100644 index 0000000..61c7d3e --- /dev/null +++ b/assets/icons/north-pointer.svg @@ -0,0 +1,4 @@ + diff --git a/styles.css b/styles.css index d598e36..b2adfe2 100644 --- a/styles.css +++ b/styles.css @@ -314,6 +314,41 @@ button:disabled { left: auto; } +/* OpenLayers hides this control while the view is north-up. */ +.map-wrap .ol-rotate { + top: auto; + right: 16px; + bottom: 16px; + left: auto; + padding: 0; + background: transparent; +} + +.map-wrap .ol-rotate button { + display: grid; + width: 42px; + height: 42px; + margin: 0; + padding: 0; + place-items: center; + border-radius: 50%; + background: rgba(255, 255, 255, 0.9); + line-height: 1; + box-shadow: 0 10px 24px rgba(52, 43, 28, 0.2); +} + +.north-pointer-icon { + display: block; + width: 26px; + height: 26px; + transform-origin: center; +} + +.map-wrap .ol-rotate button:hover { + background: #fff; + transform: translateY(-1px); +} + @media (max-width: 920px) { .app-shell { padding: 16px; @@ -329,6 +364,11 @@ button:disabled { right: 12px; } + .map-wrap .ol-rotate { + right: 12px; + bottom: 12px; + } + .sidebar { top: 16px; bottom: 16px;