From ba671ba166bce538ededc40a1ef3ee2a2381bda0 Mon Sep 17 00:00:00 2001 From: RyanBirtch-aot Date: Wed, 24 Jul 2024 17:04:39 +0000 Subject: [PATCH] Fixed default bug --- components/src/components/Map/Component.ts | 6 ++++-- .../components/Map/editForm/Component.edit.data.ts | 2 +- components/src/components/Map/services/MapService.ts | 11 ++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/components/src/components/Map/Component.ts b/components/src/components/Map/Component.ts index ba079b97f..c55cbc7f5 100644 --- a/components/src/components/Map/Component.ts +++ b/components/src/components/Map/Component.ts @@ -71,8 +71,9 @@ export default class Component extends (FieldComponent as any) { drawOptions[this.component.markerType] = true; // set marker type from user choice } - const { numPoints, defaultZoom, readOnlyMap, center } = this.component; - + const { numPoints, defaultZoom, readOnlyMap, center, defaultValue } = + this.component; + console.log(defaultValue); let parsedCenter; if (center) { parsedCenter = JSON.parse(center).latlng; @@ -86,6 +87,7 @@ export default class Component extends (FieldComponent as any) { numPoints, defaultZoom, readOnlyMap, + defaultValue, onDrawnItemsChange: this.saveDrawnItems.bind(this), }); diff --git a/components/src/components/Map/editForm/Component.edit.data.ts b/components/src/components/Map/editForm/Component.edit.data.ts index 6dbf7d242..74f60d61f 100644 --- a/components/src/components/Map/editForm/Component.edit.data.ts +++ b/components/src/components/Map/editForm/Component.edit.data.ts @@ -63,7 +63,7 @@ export default { numPoints: 1, tableView: false, markerType: 'marker', - defaultZoom: 13, + defaultZoom: 5, readOnlyMap: false, description: 'Please select the desired default center using a single marker', diff --git a/components/src/components/Map/services/MapService.ts b/components/src/components/Map/services/MapService.ts index 3ad22e8ba..a4174dc09 100644 --- a/components/src/components/Map/services/MapService.ts +++ b/components/src/components/Map/services/MapService.ts @@ -6,7 +6,7 @@ const DEFAULT_MAP_LAYER_URL = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; const DEFAULT_LAYER_ATTRIBUTION = '© OpenStreetMap contributors'; -const DEFAULT_MAP_ZOOM = 13; +const DEFAULT_MAP_ZOOM = 5; const DECIMALS_LATLNG = 5; // the number of decimals of latitude and longitude to be displayed in the marker popup const COMPONENT_EDIT_CLASS = 'component-edit-tabs'; const FORM_REVIEW_CLASS = 'review-form'; @@ -35,6 +35,12 @@ class MapService { this.bindPopupToLayer(layer); options.onDrawnItemsChange(drawnItems.getLayers()); }); + map.on(L.Draw.Event.DELETED, (e) => { + options.onDrawnItemsChange(drawnItems.getLayers()); + }); + map.on(L.Draw.Event.EDITED, (e) => { + options.onDrawnItemsChange(drawnItems.getLayers()); + }); } } initializeMap(options) { @@ -72,13 +78,12 @@ class MapService { document.getElementsByClassName(COMPONENT_EDIT_CLASS); if (form) { if (form[0]?.classList.contains('formbuilder')) { + map.invalidateSize(); map.dragging.disable(); map.scrollWheelZoom.disable(); if (this.hasChildNode(componentEditNode[0], mapContainer)) { map.dragging.enable(); map.scrollWheelZoom.enable(); - console.log(map); - map.invalidateSize(true); } } }