Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL hash with wrong coordinates throws Error #5131

Closed
mattesCZ opened this issue Nov 28, 2024 · 5 comments · Fixed by #5241
Closed

URL hash with wrong coordinates throws Error #5131

mattesCZ opened this issue Nov 28, 2024 · 5 comments · Fixed by #5241
Labels
enhancement New feature or request PR is more than welcomed Extra attention is needed

Comments

@mattesCZ
Copy link
Contributor

mattesCZ commented Nov 28, 2024

maplibre-gl-js version: 4.7.1

browser: Chrome 131

Steps to Trigger Behavior

  1. Create a copy of example at https://maplibre.org/maplibre-gl-js/docs/examples/hash-router/
  2. Create map with center: [36, 129], swapped order means latitude > 90
  3. Map won't load, console is full of Error: Invalid LngLat latitude value: must be between -90 and 90

The same happens if center is set correctly, but the hash is incorrect.

Link to Demonstration

https://codepen.io/mattesCZ/pen/gbYbOKm

Expected Behavior

I think at least URL hash should be checked if it's valid coordinate and fallback to some valid coordinate like [0, 0] and zoom 0 if it's invalid.

Actual Behavior

It shows empty map if coordinate is incorrect and throws errors in console.

@HarelM
Copy link
Collaborator

HarelM commented Nov 28, 2024

Hi, thanks for taking the time to report this issue.
What's the actual use case for this issue?

@HarelM HarelM added the need more info Further information is requested label Nov 28, 2024
@mattesCZ
Copy link
Contributor Author

I can imagine this: App uses Hash routing, so users can save or edit URLs to their locations, but can accidentally create URL with incorrect coordinates. I think the map should not fail, but fallback somehow.

I know the app developers can also check it before it falls down to MapLibre, but I think it would be nice if the MapLibre will fail more gracefully.

@HarelM
Copy link
Collaborator

HarelM commented Nov 28, 2024

Feel free to sumbit a PR. I think the hash control is mainly for testing and development, but you are welcome to improve it.

@HarelM HarelM added enhancement New feature or request PR is more than welcomed Extra attention is needed and removed need more info Further information is requested labels Nov 28, 2024
@mattesCZ
Copy link
Contributor Author

I think it's useful for any application like openstreetmap.org or Google Maps to add hash with coordinates. It makes it really easy to reload or share the map view with others. I guess there is a lot of such examples that uses MapLibre (osmapp.org,...).

I'm not very familiar with MapLibre code. Can you please point me quickly where I should start to investigate the code for parsing hash on map load or even check if mapOptions.center is valid? I will try to create a PR then.

@HarelM
Copy link
Collaborator

HarelM commented Nov 28, 2024

The hash related code is here:

export class Hash {

@mattesCZ mattesCZ mentioned this issue Dec 18, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR is more than welcomed Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants