import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core'; import { Feature } from 'ol'; import { SourceVectorComponent } from './sources/vector.component'; @Component({ selector: 'aol-feature', template: ` `, }) export class FeatureComponent implements OnInit, OnDestroy, OnChanges { @Input() id: string | number | undefined; componentType = 'feature'; instance: Feature; constructor(private host: SourceVectorComponent) {} ngOnInit() { this.instance = new Feature(); if (this.id !== undefined) { this.instance.setId(this.id); } this.host.instance.addFeature(this.instance); } ngOnDestroy() { this.host.instance.removeFeature(this.instance); } ngOnChanges(changes: SimpleChanges) { if (this.instance) { this.instance.setId(this.id); } } }