From c6df521a4f99a7b6e29a5146c591c7f54823e7ff Mon Sep 17 00:00:00 2001 From: cbourget Date: Thu, 17 Oct 2019 13:21:58 -0400 Subject: [PATCH 1/2] fix(geometry): properly destroy geometry input --- .../geometry-form-field-input.component.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts index 83c5cc0dd0..6307bd7a55 100644 --- a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts +++ b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts @@ -10,7 +10,7 @@ import { } from '@angular/core'; import { NgControl, ControlValueAccessor } from '@angular/forms'; -import { Subscription } from 'rxjs'; +import { Subject, Subscription } from 'rxjs'; import * as OlStyle from 'ol/style'; import OlGeoJSON from 'ol/format/GeoJSON'; @@ -123,8 +123,9 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr */ @Input() set value(value: GeoJSONGeometry) { + this._value = value; + if (this.ready === false) { - this._value = value; return; } @@ -134,7 +135,6 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr this.olOverlaySource.clear(); } - this._value = value; this.onChange(value); this.toggleControl(); this.cdRef.detectChanges(); @@ -179,10 +179,12 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr this.createMeasureTooltip(); this.createDrawControl(); this.createModifyControl(); + if (this.value) { this.addGeoJSONToOverlay(this.value); } this.toggleControl(); + this.ready = true; } @@ -191,6 +193,12 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr * @internal */ ngOnDestroy() { + // This is mandatory when the form control is reused after + // this component has been destroyed. It seems like the control + // keeps a reference to this component even after it's destroyed + // and it attempts to set it's value + this.ready = false; + this.deactivateControl(); this.olOverlaySource.clear(); this.map.ol.removeLayer(this.olOverlayLayer); @@ -267,6 +275,7 @@ export class GeometryFormFieldInputComponent implements OnInit, OnDestroy, Contr */ private toggleControl() { this.deactivateControl(); + if (!this.value && this.geometryType) { this.activateControl(this.drawControl); } else { From e31accbe6d290dbbda2fb43963047f4d22ca26d8 Mon Sep 17 00:00:00 2001 From: cbourget Date: Thu, 17 Oct 2019 13:32:13 -0400 Subject: [PATCH 2/2] style(import): remove unused import --- .../geometry-form-field/geometry-form-field-input.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts index 6307bd7a55..b8c2512e6a 100644 --- a/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts +++ b/packages/geo/src/lib/geometry/geometry-form-field/geometry-form-field-input.component.ts @@ -10,7 +10,7 @@ import { } from '@angular/core'; import { NgControl, ControlValueAccessor } from '@angular/forms'; -import { Subject, Subscription } from 'rxjs'; +import { Subscription } from 'rxjs'; import * as OlStyle from 'ol/style'; import OlGeoJSON from 'ol/format/GeoJSON';