From e89b6097ec2ba9a24168c8abf01d528eccd44857 Mon Sep 17 00:00:00 2001 From: stanislawpuda-tomtom <85107223+stanislawpuda-tomtom@users.noreply.github.com> Date: Wed, 5 Feb 2025 10:53:51 +0100 Subject: [PATCH] Fix URL hash bearing validation range (#5462) * fix hash bearing validation range * update changelog --- CHANGELOG.md | 1 + src/ui/hash.test.ts | 14 ++++++++++++++ src/ui/hash.ts | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f76344a3a..4befde2743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### 🐞 Bug fixes - _...Add new stuff here..._ - Fix how padding is applied when using flyTo() with Globe ([#5406](https://github.com/maplibre/maplibre-gl-js/pull/5406)) +- Fix URL hash validation to support bearing range -180 to 180 ([#5461](https://github.com/maplibre/maplibre-gl-js/issues/5461)) ## 5.1.0 diff --git a/src/ui/hash.test.ts b/src/ui/hash.test.ts index 6c79c4cf1c..34f21b9453 100644 --- a/src/ui/hash.test.ts +++ b/src/ui/hash.test.ts @@ -341,6 +341,10 @@ describe('hash', () => { window.location.hash = '#5/1.00/0.50/30/60'; expect(hash._isValidHash(hash._getCurrentHash())).toBeTruthy(); + + window.location.hash = '#5/1.00/0.50/-30/60'; + + expect(hash._isValidHash(hash._getCurrentHash())).toBeTruthy(); }); test('invalidate hash with string values', () => { @@ -367,6 +371,16 @@ describe('hash', () => { expect(hash._isValidHash(hash._getCurrentHash())).toBeFalsy(); }); + test('invalidate hash, bearing out of range', () => { + window.location.hash = '#10/3.00/-1.00/450'; + + expect(hash._isValidHash(hash._getCurrentHash())).toBeFalsy(); + + window.location.hash = '#10/3.00/-1.00/-450'; + + expect(hash._isValidHash(hash._getCurrentHash())).toBeFalsy(); + }); + test('invalidate hash, pitch greater than maxPitch', () => { window.location.hash = '#10/3.00/-1.00/30/90'; diff --git a/src/ui/hash.ts b/src/ui/hash.ts index fc817eb4e3..8c584223e6 100644 --- a/src/ui/hash.ts +++ b/src/ui/hash.ts @@ -172,7 +172,7 @@ export class Hash { const pitch = +(hash[4] || 0); return zoom >= this._map.getMinZoom() && zoom <= this._map.getMaxZoom() && - bearing >= 0 && bearing <= 180 && + bearing >= -180 && bearing <= 180 && pitch >= this._map.getMinPitch() && pitch <= this._map.getMaxPitch(); }; }