maputnik icon indicating copy to clipboard operation
maputnik copied to clipboard

Opening a Style should set the correct map extend using the stylefiles center and zoom (if available)

Open lukasalexanderweber opened this issue 3 weeks ago • 8 comments

Hi,

thank you for this awesome editor :)

One feature request I have is that opening a opening a style should set the correct map extend using the stylefiles center and zoom.

I think that this might be rather easy: After opening the style we have zoom and center in the StyleSpecification.

onStyleOpen could call onStyleChanged and afterwards alter the state of the map view.

This is relevant for our use case as we only host tiles for cities and small regions. We can use the seach or add the info to the url (0.77/0/0) to find the correct map view but this feature would make things way easier of cause

lukasalexanderweber avatar Nov 28 '25 08:11 lukasalexanderweber

Thanks for taking the time to open this feature request. Feel free to open a PR to add this feature. Don't forget to add the relevant tests. Thanks!

HarelM avatar Nov 28 '25 08:11 HarelM

As the maintainer of a few region-specific styles, I can fully relate to your request.

I would like, however, to suggest that the proposed behavior would only be used when the current map is empty, such as after opening Maputnik in a new tab.

Frequently, I switch between styles as I want to see their differences at a particular zoom and location within the region.
For example,

  • To compare the published version of the style with an experimental change
  • To compare the my style with one of the public styles
  • When performing a related change to multiple styles I maintain.

When the current map is empty, it is clear that the current zoom and center coordinates can be ignored. Potential criteria for this situation could be:

  • An empty sources array
  • An empty layers array
  • The "Empty Style" style name (my least favorite criterion)

P.S., As a workaround and for convenience I have created bookmarks, such as the following, to open Maputnik with a specific style at my preferred zoom and location, regardless of the style's defaults:

https://maplibre.org/maputnik/?style=https://raw.githubusercontent.com/IsraelHikingMap/VectorMap/master/Styles/IHM.json#10.11/31.7932/35.0633

zstadler avatar Nov 28 '25 12:11 zstadler

Ok @zstadler thanks for your remark and the hint with the bookmarks 👍

For me its mostly important when launching a new server with --file, and there is a empty map anyway

lukasalexanderweber avatar Nov 28 '25 13:11 lukasalexanderweber

I'm happy to see that my proposal is acceptable by you.

zstadler avatar Nov 28 '25 16:11 zstadler

Hi @HarelM @zstadler,

I've tried around a bit, but updating the map view state does not change the map (somehow I assumed it would).

This renderer thingy is more complicated then I expected. I assumed I'll have a map instance where I can call e.g. setCenter.

Could you maybe point me into the right direction to proceed? :)

lukasalexanderweber avatar Dec 01 '25 15:12 lukasalexanderweber

I'm not sure, you'll have to dig into it. Maybe pass that to the maplibregl component? I think onStyleChange is probably the right place to start with...

HarelM avatar Dec 01 '25 16:12 HarelM

Hi @HarelM,

thanks for the hint of passing the prop into the maplibre component. It works now as expected. Maybe you can give me a hint on where tests would be appropriate

lukasalexanderweber avatar Dec 02 '25 10:12 lukasalexanderweber

You should be able to find some e2e tests, there's a driver and helper to help with common use flow like opening a style etc. Let me know if you can't find those.

HarelM avatar Dec 02 '25 10:12 HarelM