From ac8466d3d8b217a30b79bbb6eda2c99be2a5e834 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Wed, 19 Jul 2023 10:27:41 +0200 Subject: [PATCH 1/3] refactor(Geolocation): customize_draw_controls Extract method `customize_draw_controls` from `bind_leaflet_map` --- frappe/public/js/frappe/form/controls/geolocation.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/form/controls/geolocation.js b/frappe/public/js/frappe/form/controls/geolocation.js index 84b1989400..acff3d6ce8 100644 --- a/frappe/public/js/frappe/form/controls/geolocation.js +++ b/frappe/public/js/frappe/form/controls/geolocation.js @@ -35,6 +35,7 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f } make_map(value) { + this.customize_draw_controls(); this.bind_leaflet_map(); if (this.disabled) { this.map.dragging.disable(); @@ -113,7 +114,7 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f */ on_each_feature(feature, layer) {} - bind_leaflet_map() { + customize_draw_controls() { const circleToGeoJSON = L.Circle.prototype.toGeoJSON; L.Circle.include({ toGeoJSON: function () { @@ -138,6 +139,9 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f }); L.Icon.Default.imagePath = "/assets/frappe/images/leaflet/"; + } + + bind_leaflet_map() { this.map = L.map(this.map_id); this.map.setView(frappe.utils.map_defaults.center, frappe.utils.map_defaults.zoom); From 819f18acb47240a3bb25ca11139d051ca4b9f790 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Wed, 19 Jul 2023 10:32:23 +0200 Subject: [PATCH 2/3] refactor(Geolocation): image path via map defaults Move the default path for icons to map_defaults instead of hardcoding it in the control --- frappe/public/js/frappe/form/controls/geolocation.js | 2 +- frappe/public/js/frappe/utils/utils.js | 1 + frappe/public/js/frappe/views/map/map_view.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/geolocation.js b/frappe/public/js/frappe/form/controls/geolocation.js index acff3d6ce8..10ac21a5fb 100644 --- a/frappe/public/js/frappe/form/controls/geolocation.js +++ b/frappe/public/js/frappe/form/controls/geolocation.js @@ -138,7 +138,7 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f }, }); - L.Icon.Default.imagePath = "/assets/frappe/images/leaflet/"; + L.Icon.Default.imagePath = frappe.utils.map_defaults.image_path; } bind_leaflet_map() { diff --git a/frappe/public/js/frappe/utils/utils.js b/frappe/public/js/frappe/utils/utils.js index 4a8e519978..e4cae790f2 100644 --- a/frappe/public/js/frappe/utils/utils.js +++ b/frappe/public/js/frappe/utils/utils.js @@ -1203,6 +1203,7 @@ Object.assign(frappe.utils, { attribution: '© OpenStreetMap contributors', }, + image_path: "/assets/frappe/images/leaflet/", }, icon(icon_name, size = "sm", icon_class = "", icon_style = "", svg_class = "") { diff --git a/frappe/public/js/frappe/views/map/map_view.js b/frappe/public/js/frappe/views/map/map_view.js index e9bd71e3fc..b54938bc87 100644 --- a/frappe/public/js/frappe/views/map/map_view.js +++ b/frappe/public/js/frappe/views/map/map_view.js @@ -32,7 +32,7 @@ frappe.views.MapView = class MapView extends frappe.views.ListView { this.$result.html(`
`); - L.Icon.Default.imagePath = "/assets/frappe/images/leaflet/"; + L.Icon.Default.imagePath = frappe.utils.map_defaults.image_path; this.map = L.map(this.map_id).setView( frappe.utils.map_defaults.center, frappe.utils.map_defaults.zoom From 5ed4e45f525e2fa8a576df1be4630ba365250d48 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Wed, 19 Jul 2023 10:36:19 +0200 Subject: [PATCH 3/3] refactor(Geolocation): provide less utils --- frappe/public/js/frappe/form/controls/geolocation.js | 2 +- frappe/public/js/frappe/views/map/map_view.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/geolocation.js b/frappe/public/js/frappe/form/controls/geolocation.js index 10ac21a5fb..56a8d2a073 100644 --- a/frappe/public/js/frappe/form/controls/geolocation.js +++ b/frappe/public/js/frappe/form/controls/geolocation.js @@ -1,4 +1,4 @@ -frappe.provide("frappe.utils.utils"); +frappe.provide("frappe.utils"); frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.form.ControlData { static horizontal = false; diff --git a/frappe/public/js/frappe/views/map/map_view.js b/frappe/public/js/frappe/views/map/map_view.js index b54938bc87..b86faf3edc 100644 --- a/frappe/public/js/frappe/views/map/map_view.js +++ b/frappe/public/js/frappe/views/map/map_view.js @@ -1,7 +1,7 @@ /** * frappe.views.MapView */ -frappe.provide("frappe.utils.utils"); +frappe.provide("frappe.utils"); frappe.provide("frappe.views"); frappe.views.MapView = class MapView extends frappe.views.ListView {