From 4a811e978edd94525bb923584af3c7736d8b308e Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Fri, 28 Mar 2025 18:35:06 +0200 Subject: [PATCH] UI: Fix map settings not updating when switching between different map type widgets --- .../common/map/map-settings.component.ts | 21 +++++++++++++++++-- .../map/map-widget-settings.component.ts | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.ts index f38f2a042c..5b949bae75 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { Component, DestroyRef, forwardRef, Input, OnInit } from '@angular/core'; +import { Component, DestroyRef, forwardRef, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; import { ControlValueAccessor, NG_VALIDATORS, @@ -70,7 +70,7 @@ import { MatDialog } from '@angular/material/dialog'; } ] }) -export class MapSettingsComponent implements OnInit, ControlValueAccessor, Validator { +export class MapSettingsComponent implements OnInit, ControlValueAccessor, Validator, OnChanges { mapControlPositions = mapControlPositions; @@ -205,6 +205,23 @@ export class MapSettingsComponent implements OnInit, ControlValueAccessor, Valid } } + ngOnChanges(changes: SimpleChanges) { + if (changes.trip) { + const tripChange = changes.trip; + if (!tripChange.firstChange && tripChange.currentValue !== tripChange.previousValue) { + if (this.trip) { + this.dataLayerMode = 'trips' + this.mapSettingsFormGroup.addControl('trips', this.fb.control(this.modelValue.trips), {emitEvent: false}); + this.mapSettingsFormGroup.addControl('tripTimeline', this.fb.control(this.modelValue.tripTimeline), {emitEvent: false}); + } else { + this.dataLayerMode = 'markers'; + this.mapSettingsFormGroup.removeControl('trips', {emitEvent: false}); + this.mapSettingsFormGroup.removeControl('tripTimeline', {emitEvent: false}); + } + } + } + } + writeValue(value: MapSetting): void { this.modelValue = value; this.mapSettingsFormGroup.patchValue( diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-widget-settings.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-widget-settings.component.ts index 3dc10f34cf..f301219045 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-widget-settings.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/map/map-widget-settings.component.ts @@ -47,6 +47,8 @@ export class MapWidgetSettingsComponent extends WidgetSettingsComponent { const params = widgetConfig.typeParameters as any; if (isDefinedAndNotNull(params.trip)) { this.trip = params.trip === true; + } else { + this.trip = false; } }