Skip to content

Dynamic map defaults#7692

Draft
palmerusaf wants to merge 4 commits intoplotly:masterfrom
palmerusaf:dynamic-map-defaults
Draft

Dynamic map defaults#7692
palmerusaf wants to merge 4 commits intoplotly:masterfrom
palmerusaf:dynamic-map-defaults

Conversation

@palmerusaf
Copy link

This is for issue #7674. This uses a custom algo to get the bounds, then uses mapLibre to set the zoom/center via fitBounds. Turf.js doesn't handle the anti-meridian correctly. If you'd like I can add the helper functions to geo location utils to knock out a TODO there. I just need to refactor the signatures.

@palmerusaf
Copy link
Author

Also I wasn't sure how to handle if the user provides center or zoom. Right now it will simply not do box fitting if either of those params are provided.

@emilykl
Copy link
Contributor

emilykl commented Feb 18, 2026

Hi @palmerusaf ! Sincere apologies for my delay in getting back to you.

I think this approach makes sense at a high level. My only concern is the performance; could you do a basic benchmark of the time to compute getMinBoundLon(lon) for inputs of length, say, 10^2 up through 10^7?

If there's a noticeable performance impact, maybe we could still pursue this approach but provide a way to disable auto-fitting of bounds. Or maybe the fact that it can be skipped by manually setting center or zoom is enough.

I'll leave a few other small comments on the code. The implementation isn't expected to be working quite yet, correct?

var { minLat, maxLat } = getMinBoundLat(lat);
// this param is called bounds in mapLibre ctor
// not to be confused with maxBounds aliased below
containerOut.fitBounds = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefix this property with an underscore since it's an internal property, not part of the plot schema.

Suggested change
containerOut.fitBounds = {
containerOut._fitBounds = {

containerOut._input = containerIn;
}

function getMinBoundLon(lon) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function getMinBoundLon(lon) {
function getLonBounds(lon) {

}
}

function getMinBoundLat(lat) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function getMinBoundLat(lat) {
function getLatBounds(lat) {

pitch: opts.pitch,
bounds: fitBounds,
fitBoundsOptions: {
padding: 20,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this padding is used twice, define it as a constant in map/constants.js.

Will these fitBoundsOptions have any effect if bounds is null?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments