60 lines
2.5 KiB
TypeScript
60 lines
2.5 KiB
TypeScript
|
import { Component, Input, OnInit, ComponentFactoryResolver, ViewChild, SimpleChanges, ComponentFactory, Inject, Type} from '@angular/core';
|
||
|
import { Feature } from 'ol';
|
||
|
import { FeatureListComponent,AbstractFeatureListComponent } from '../feature-list/feature-list.component';
|
||
|
import { WidgetHostDirective } from '../widget-host/widget-host.directive';
|
||
|
import {IQueryState } from '../../models/query.state';
|
||
|
import * as mapReducers from '../../reducers/map.reducer';
|
||
|
import * as mapActions from '../../actions/map.actions';
|
||
|
import { Store } from '@ngrx/store';
|
||
|
|
||
|
|
||
|
@Component({
|
||
|
selector: 'feature-list-container',
|
||
|
templateUrl: './feature-list-container.component.html',
|
||
|
styleUrls: ['./feature-list-container.component.scss']
|
||
|
})
|
||
|
export class FeatureListContainerComponent {
|
||
|
|
||
|
constructor(private store: Store<mapReducers.State>,private componentFactoryResolver: ComponentFactoryResolver, @Inject(AbstractFeatureListComponent) public featureLists: AbstractFeatureListComponent[] ) {
|
||
|
}
|
||
|
|
||
|
@Input() features: Array<Feature>
|
||
|
@Input() queryState: IQueryState;
|
||
|
|
||
|
@ViewChild(WidgetHostDirective) widgetHost: WidgetHostDirective;
|
||
|
|
||
|
loadComponent(queryState:IQueryState) {
|
||
|
var componentFactory: ComponentFactory<AbstractFeatureListComponent> = this.componentFactoryResolver.resolveComponentFactory(FeatureListComponent); // default
|
||
|
var selected = -1;
|
||
|
for (var i = 0; i < this.featureLists.length; i++) {
|
||
|
if (this.featureLists[i]['forItemType'] == queryState.itemType && this.featureLists[i]['forChild'] && queryState.parentCode && queryState.parentCode != "") {
|
||
|
selected = i;
|
||
|
break;
|
||
|
} else if (this.featureLists[i]['forItemType'] == queryState.itemType) {
|
||
|
selected = i;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (selected >= 0) {
|
||
|
componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.featureLists[i]['constructor'] as any);
|
||
|
if (this.featureLists[selected]['collapseSearch'] === true) {
|
||
|
this.store.dispatch(new mapActions.CollapseSearch());
|
||
|
}
|
||
|
}
|
||
|
const viewContainerRef = this.widgetHost.viewContainerRef;
|
||
|
viewContainerRef.clear();
|
||
|
|
||
|
const componentRef = viewContainerRef.createComponent(componentFactory);
|
||
|
(<AbstractFeatureListComponent>componentRef.instance).features = this.features;
|
||
|
(<AbstractFeatureListComponent>componentRef.instance).queryState = this.queryState;
|
||
|
}
|
||
|
|
||
|
ngOnChanges(changes: SimpleChanges) {
|
||
|
if (changes["features"] && changes["features"].currentValue) {
|
||
|
if (this.queryState) {
|
||
|
this.loadComponent(this.queryState);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|