fix: fit and recenter map when section is expanded

This commit is contained in:
barredterra 2023-06-03 14:17:59 +02:00
parent ba22512191
commit 79aaf072bd

View file

@ -73,15 +73,8 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f
})
);
this.add_non_group_layers(data_layers, this.editableLayers);
try {
this.map.fitBounds(this.editableLayers.getBounds(), {
padding: [50, 50],
});
} catch (err) {
// suppress error if layer has a point.
}
this.editableLayers.addTo(this.map);
this.map.invalidateSize();
this.fit_and_recenter_map();
}
bind_leaflet_map() {
@ -205,4 +198,20 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f
this.editableLayers.removeLayer(l);
});
}
fit_and_recenter_map() {
// Spread map across the wrapper, recenter and zoom w.r.t bounds
try {
this.map.invalidateSize();
this.map.fitBounds(this.editableLayers.getBounds(), {
padding: [50, 50],
});
} catch (err) {
// suppress error if layer has a point.
}
}
on_section_collapse(hide) {
!hide && this.fit_and_recenter_map();
}
};