fix: fit and recenter map when section is expanded
This commit is contained in:
parent
ba22512191
commit
79aaf072bd
1 changed files with 17 additions and 8 deletions
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue