KEMBAR78
feat: zoom to fit the provided features in the viewport by sissbruecker · Pull Request #8082 · vaadin/flow-components · GitHub
Skip to content

Conversation

@sissbruecker
Copy link
Contributor

@sissbruecker sissbruecker commented Sep 26, 2025

Description

Adds a zoomToFit method to the Map component that allows to fit the provided features within the viewport. The options allow to configure a padding for the viewport and an animation duration.

Closes #3137

Type of change

  • Feature

* @param features
* the features to fit in the viewport
*/
public void zoomToFit(List<Feature> features) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would also be available on the View instance of the map. However, none of the configuration objects have any reference to the Map element to trigger JS calls. I'm not sure about adding one at the moment, as technically configuration objects can be shared between multiple map instances (though sharing the view seems extremely unlikely).

Still, I think it's fine to start only with this for now. The new API at least fits with having setCenter and setZoom methods on the Map. If this turns out to be an issue, we can spend more time on making it work through the view instance.

Comment on lines +360 to +368
// In order to allow calling this method before the map, or the view
// that contains it, is attached to the UI, this needs to be delayed
// with beforeClientResponse to ensure that the client-side connector
// has been initialized beforehand.
getElement().getNode()
.runWhenAttached(ui -> ui.beforeClientResponse(this,
context -> getElement().executeJs(
"this.$connector.zoomToFit($0, $1)", featureIds,
options)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not find a better approach. In some form this needs to run after onAttach, which is responsible for creating the connector.

@sissbruecker sissbruecker marked this pull request as ready for review September 29, 2025 07:46
@ugur-vaadin ugur-vaadin changed the title feat: zoom to fit the provides features in the viewport feat: zoom to fit the provided features in the viewport Sep 29, 2025
@sissbruecker sissbruecker enabled auto-merge (squash) September 29, 2025 11:40
@sonarqubecloud
Copy link

@sissbruecker sissbruecker merged commit cbc0f79 into main Sep 29, 2025
4 of 5 checks passed
@sissbruecker sissbruecker deleted the feat/map-zoom-to-fit branch September 29, 2025 11:54
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 25.0.0-alpha12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "zoomToContent" method or similar

3 participants