-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
Emit baselayerchange
Event on layer changes via layer selector
#1493
Comments
Again : please provide a demo.
PlanPlugin != Leaftlet |
https://photo-sphere-viewer.js.org/api/classes/PlanPlugin.PlanPlugin.html#getLeaflet viewer.getPlugin('plan').getLeaflet().on('baselayerchange', (e) => {
console.log(e);
}); |
Can't provide you with a demo right now but what I'm doing is basically what You just mentioned but It doesn't work, nothing gets printed and the function is never called:
By the way, this is the same pattern I use to listen and handle every other event succesfuly ( |
So I made a demo https://codesandbox.io/p/sandbox/icy-bird-vwqlz4 And you just have to use "layeradd" event instead. Because as the docs says https://leafletjs.com/reference.html#map-baselayerchange the "baselayerchange" event is only called by the Leaflet Layers control, which is not what is used by my plugin. |
I've implemented your solution on my side and the event gets triggered a gazillion times, crashing the app. I've also created a mini-version of it on codesandbox to test there with the bare-minimum needed for the app to run, and It worked properly. So I must have something that makes the event get triggered multiple times that I need to figure out, on my side. |
Describe the feature
Currently, the
PlanPlugin
does not emit abaselayerchange
event when users switch layers. This makes it challenging to respond to layer changes programmatically, such as adjusting the map view to ensure the selected layer is immediately visible.Adding support for the
baselayerchange
event (or a similar custom event) would allow developers to listen for layer selection changes and trigger appropriate actions (e.g., auto-zooming or fitting bounds).Alternatives you've considered
I've tried listening to the
baselayerchange
event when the plan plugin is ready, but didn't get any luck. I also tried listening to theoverlayadd
map event with no luck.Additional context
Currently, when switching layers to a secured basemap layer I need to zoom out or move the map around before I get the layer rendered visible on the map. I understand this is what I need to do but the users don't know about that and complain that the map is not visible.
If only I could listen to
baselayerchange
event, I could add a zoom transition to trigger the rendering of the map an automatically.The text was updated successfully, but these errors were encountered: