Merge pull request #22797 from blaggacao/fix/geolocation-controller
This commit is contained in:
commit
71a1712e35
1 changed files with 35 additions and 24 deletions
|
|
@ -13,30 +13,41 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f
|
|||
if (!this.disp_area) {
|
||||
return;
|
||||
}
|
||||
if (!this.map_id) {
|
||||
this.map_id = frappe.dom.get_unique_id();
|
||||
this.map_area = $(
|
||||
`<div class="map-wrapper border">
|
||||
<div id="${this.map_id}" style="min-height: 400px; z-index: 1; max-width:100%"></div>
|
||||
</div>`
|
||||
);
|
||||
|
||||
this.map_id = frappe.dom.get_unique_id();
|
||||
this.map_area = $(
|
||||
`<div class="map-wrapper border">
|
||||
<div id="${this.map_id}" style="min-height: 400px; z-index: 1; max-width:100%"></div>
|
||||
</div>`
|
||||
);
|
||||
$(this.disp_area).html(this.map_area);
|
||||
}
|
||||
|
||||
$(this.disp_area).html(this.map_area);
|
||||
// show again on idempotent invocations
|
||||
$(this.disp_area).removeClass("like-disabled-input");
|
||||
$(this.disp_area).css("display", "block");
|
||||
|
||||
if (this.frm) {
|
||||
this.make_map(value);
|
||||
this.make_map();
|
||||
if (value) {
|
||||
this.bind_leaflet_data(value);
|
||||
}
|
||||
} else {
|
||||
$(document).on("frappe.ui.Dialog:shown", () => {
|
||||
this.make_map();
|
||||
if (value) {
|
||||
this.bind_leaflet_data(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
make_map(value) {
|
||||
this.customize_draw_controls();
|
||||
this.bind_leaflet_map();
|
||||
if (!this.map) {
|
||||
this.customize_draw_controls();
|
||||
this.bind_leaflet_map();
|
||||
}
|
||||
if (this.disabled) {
|
||||
this.map.dragging.disable();
|
||||
this.map.touchZoom.disable();
|
||||
|
|
@ -47,17 +58,17 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f
|
|||
this.map.zoomControl.remove();
|
||||
} else {
|
||||
this.bind_leaflet_draw_control();
|
||||
this.bind_leaflet_event_listeners();
|
||||
this.bind_leaflet_locate_control();
|
||||
this.bind_leaflet_data(value);
|
||||
if (!this.bound_event_listeners) {
|
||||
this.bind_leaflet_event_listeners();
|
||||
}
|
||||
if (!this.locate_control) {
|
||||
this.bind_leaflet_locate_control();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bind_leaflet_data(value) {
|
||||
/* render raw value from db into map */
|
||||
if (!this.map || !value) {
|
||||
return;
|
||||
}
|
||||
this.clear_editable_layers();
|
||||
|
||||
const data_layers = new L.FeatureGroup().addLayer(
|
||||
|
|
@ -159,15 +170,14 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f
|
|||
}
|
||||
|
||||
bind_leaflet_draw_control() {
|
||||
if (
|
||||
!frappe.perm.has_perm(this.doctype, this.df.permlevel, "write", this.doc) ||
|
||||
this.df.read_only
|
||||
) {
|
||||
return;
|
||||
if (!this.draw_control) {
|
||||
this.draw_control = this.get_leaflet_controls();
|
||||
}
|
||||
if (this.disp_status == "Write") {
|
||||
this.draw_control.addTo(this.map);
|
||||
} else {
|
||||
this.draw_control.remove();
|
||||
}
|
||||
|
||||
this.draw_control = this.get_leaflet_controls();
|
||||
this.map.addControl(this.draw_control);
|
||||
}
|
||||
|
||||
get_leaflet_controls() {
|
||||
|
|
@ -205,6 +215,7 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f
|
|||
}
|
||||
|
||||
bind_leaflet_event_listeners() {
|
||||
this.bound_event_listeners = true;
|
||||
this.map.on("draw:created", (e) => {
|
||||
var type = e.layerType,
|
||||
layer = e.layer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue