From 4cb91efaaffc033d926adb5837d2d129d2de5423 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Mon, 2 Dec 2024 19:03:52 +0100 Subject: [PATCH] [Map] Fix default values of Stimulus Map Controller --- src/Map/assets/dist/abstract_map_controller.d.ts | 7 +++++++ src/Map/assets/dist/abstract_map_controller.js | 6 +++++- src/Map/assets/src/abstract_map_controller.ts | 14 +++++++++++++- .../Bridge/Google/assets/dist/map_controller.js | 10 +++++++--- .../src/Bridge/Google/assets/src/map_controller.ts | 4 ++-- .../Bridge/Leaflet/assets/dist/map_controller.js | 10 +++++++--- .../Bridge/Leaflet/assets/src/map_controller.ts | 4 ++-- 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/Map/assets/dist/abstract_map_controller.d.ts b/src/Map/assets/dist/abstract_map_controller.d.ts index 308613a998..99920e5f4d 100644 --- a/src/Map/assets/dist/abstract_map_controller.d.ts +++ b/src/Map/assets/dist/abstract_map_controller.d.ts @@ -56,6 +56,13 @@ export default abstract class>; polylinesValue: Array>; optionsValue: MapOptions; + hasCenterValue: boolean; + hasZoomValue: boolean; + hasFitBoundsToMarkersValue: boolean; + hasMarkersValue: boolean; + hasPolygonsValue: boolean; + hasPolylinesValue: boolean; + hasOptionsValue: boolean; protected map: Map; protected markers: globalThis.Map; protected polygons: globalThis.Map; diff --git a/src/Map/assets/dist/abstract_map_controller.js b/src/Map/assets/dist/abstract_map_controller.js index 60f5cb4523..2627b65df2 100644 --- a/src/Map/assets/dist/abstract_map_controller.js +++ b/src/Map/assets/dist/abstract_map_controller.js @@ -15,7 +15,11 @@ class default_1 extends Controller { this.createMarker = this.createDrawingFactory('marker', this.markers, this.doCreateMarker.bind(this)); this.createPolygon = this.createDrawingFactory('polygon', this.polygons, this.doCreatePolygon.bind(this)); this.createPolyline = this.createDrawingFactory('polyline', this.polylines, this.doCreatePolyline.bind(this)); - this.map = this.doCreateMap({ center: this.centerValue, zoom: this.zoomValue, options }); + this.map = this.doCreateMap({ + center: this.hasCenterValue ? this.centerValue : null, + zoom: this.hasZoomValue ? this.zoomValue : null, + options, + }); this.markersValue.forEach((definition) => this.createMarker({ definition })); this.polygonsValue.forEach((definition) => this.createPolygon({ definition })); this.polylinesValue.forEach((definition) => this.createPolyline({ definition })); diff --git a/src/Map/assets/src/abstract_map_controller.ts b/src/Map/assets/src/abstract_map_controller.ts index e9e7797ad2..63b227af8d 100644 --- a/src/Map/assets/src/abstract_map_controller.ts +++ b/src/Map/assets/src/abstract_map_controller.ts @@ -112,6 +112,14 @@ export default abstract class< declare polylinesValue: Array>; declare optionsValue: MapOptions; + declare hasCenterValue: boolean; + declare hasZoomValue: boolean; + declare hasFitBoundsToMarkersValue: boolean; + declare hasMarkersValue: boolean; + declare hasPolygonsValue: boolean; + declare hasPolylinesValue: boolean; + declare hasOptionsValue: boolean; + protected map: Map; protected markers = new Map(); protected polygons = new Map(); @@ -140,7 +148,11 @@ export default abstract class< this.createPolygon = this.createDrawingFactory('polygon', this.polygons, this.doCreatePolygon.bind(this)); this.createPolyline = this.createDrawingFactory('polyline', this.polylines, this.doCreatePolyline.bind(this)); - this.map = this.doCreateMap({ center: this.centerValue, zoom: this.zoomValue, options }); + this.map = this.doCreateMap({ + center: this.hasCenterValue ? this.centerValue : null, + zoom: this.hasZoomValue ? this.zoomValue : null, + options, + }); this.markersValue.forEach((definition) => this.createMarker({ definition })); this.polygonsValue.forEach((definition) => this.createPolygon({ definition })); this.polylinesValue.forEach((definition) => this.createPolyline({ definition })); diff --git a/src/Map/src/Bridge/Google/assets/dist/map_controller.js b/src/Map/src/Bridge/Google/assets/dist/map_controller.js index 00317a50a2..3ce719b79e 100644 --- a/src/Map/src/Bridge/Google/assets/dist/map_controller.js +++ b/src/Map/src/Bridge/Google/assets/dist/map_controller.js @@ -16,7 +16,11 @@ class default_1 extends Controller { this.createMarker = this.createDrawingFactory('marker', this.markers, this.doCreateMarker.bind(this)); this.createPolygon = this.createDrawingFactory('polygon', this.polygons, this.doCreatePolygon.bind(this)); this.createPolyline = this.createDrawingFactory('polyline', this.polylines, this.doCreatePolyline.bind(this)); - this.map = this.doCreateMap({ center: this.centerValue, zoom: this.zoomValue, options }); + this.map = this.doCreateMap({ + center: this.hasCenterValue ? this.centerValue : null, + zoom: this.hasZoomValue ? this.zoomValue : null, + options, + }); this.markersValue.forEach((definition) => this.createMarker({ definition })); this.polygonsValue.forEach((definition) => this.createPolygon({ definition })); this.polylinesValue.forEach((definition) => this.createPolyline({ definition })); @@ -121,12 +125,12 @@ class map_controller extends default_1 { super.connect(); } centerValueChanged() { - if (this.map && this.centerValue) { + if (this.map && this.hasCenterValue && this.centerValue) { this.map.setCenter(this.centerValue); } } zoomValueChanged() { - if (this.map && this.zoomValue) { + if (this.map && this.hasZoomValue && this.zoomValue) { this.map.setZoom(this.zoomValue); } } diff --git a/src/Map/src/Bridge/Google/assets/src/map_controller.ts b/src/Map/src/Bridge/Google/assets/src/map_controller.ts index 6f5b9939fa..3dcd91e68b 100644 --- a/src/Map/src/Bridge/Google/assets/src/map_controller.ts +++ b/src/Map/src/Bridge/Google/assets/src/map_controller.ts @@ -86,13 +86,13 @@ export default class extends AbstractMapController< } public centerValueChanged(): void { - if (this.map && this.centerValue) { + if (this.map && this.hasCenterValue && this.centerValue) { this.map.setCenter(this.centerValue); } } public zoomValueChanged(): void { - if (this.map && this.zoomValue) { + if (this.map && this.hasZoomValue && this.zoomValue) { this.map.setZoom(this.zoomValue); } } diff --git a/src/Map/src/Bridge/Leaflet/assets/dist/map_controller.js b/src/Map/src/Bridge/Leaflet/assets/dist/map_controller.js index f5bf72b5ff..0628c8dafe 100644 --- a/src/Map/src/Bridge/Leaflet/assets/dist/map_controller.js +++ b/src/Map/src/Bridge/Leaflet/assets/dist/map_controller.js @@ -17,7 +17,11 @@ class default_1 extends Controller { this.createMarker = this.createDrawingFactory('marker', this.markers, this.doCreateMarker.bind(this)); this.createPolygon = this.createDrawingFactory('polygon', this.polygons, this.doCreatePolygon.bind(this)); this.createPolyline = this.createDrawingFactory('polyline', this.polylines, this.doCreatePolyline.bind(this)); - this.map = this.doCreateMap({ center: this.centerValue, zoom: this.zoomValue, options }); + this.map = this.doCreateMap({ + center: this.hasCenterValue ? this.centerValue : null, + zoom: this.hasZoomValue ? this.zoomValue : null, + options, + }); this.markersValue.forEach((definition) => this.createMarker({ definition })); this.polygonsValue.forEach((definition) => this.createPolygon({ definition })); this.polylinesValue.forEach((definition) => this.createPolyline({ definition })); @@ -112,12 +116,12 @@ class map_controller extends default_1 { super.connect(); } centerValueChanged() { - if (this.map && this.centerValue && this.zoomValue) { + if (this.map && this.hasCenterValue && this.centerValue && this.hasZoomValue && this.zoomValue) { this.map.setView(this.centerValue, this.zoomValue); } } zoomValueChanged() { - if (this.map && this.zoomValue) { + if (this.map && this.hasZoomValue && this.zoomValue) { this.map.setZoom(this.zoomValue); } } diff --git a/src/Map/src/Bridge/Leaflet/assets/src/map_controller.ts b/src/Map/src/Bridge/Leaflet/assets/src/map_controller.ts index f0c796371f..54e10b4d6a 100644 --- a/src/Map/src/Bridge/Leaflet/assets/src/map_controller.ts +++ b/src/Map/src/Bridge/Leaflet/assets/src/map_controller.ts @@ -48,13 +48,13 @@ export default class extends AbstractMapController< } public centerValueChanged(): void { - if (this.map && this.centerValue && this.zoomValue) { + if (this.map && this.hasCenterValue && this.centerValue && this.hasZoomValue && this.zoomValue) { this.map.setView(this.centerValue, this.zoomValue); } } public zoomValueChanged(): void { - if (this.map && this.zoomValue) { + if (this.map && this.hasZoomValue && this.zoomValue) { this.map.setZoom(this.zoomValue); } }