Skip to content

Commit

Permalink
Fix URL hash bearing validation range (#5462)
Browse files Browse the repository at this point in the history
* fix hash bearing validation range

* update changelog
  • Loading branch information
stanislawpuda-tomtom authored Feb 5, 2025
1 parent d269a5c commit e89b609
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions src/ui/hash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/ui/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}

0 comments on commit e89b609

Please sign in to comment.