Files
FarmMapsLib/projects/common-map/src/fm-map/components/if-zoom-to-show/if-zoom-to-show.directive.ts
Willem Dantuma 321d34870e
Some checks failed
FarmMaps.Develop/FarmMapsLib/pipeline/head There was a failure building this commit
Add zoom to show alert
2021-01-29 11:25:37 +01:00

39 lines
1.1 KiB
TypeScript

import { Directive, ViewContainerRef,TemplateRef,OnInit,Input, OnChanges } from '@angular/core';
import { layer } from 'ol';
import { MapComponent } from 'ngx-openlayers';
@Directive({
selector: '[fm-map-ifZoomToShow]',
})
export class ifZoomToShowDirective implements OnInit,OnChanges {
@Input('fm-map-ifZoomToShow') layer$:layer;
constructor(private templateRef$: TemplateRef<any>,private viewContainerRef$: ViewContainerRef,private map$: MapComponent) { }
private showView = false;
ngOnInit() {
this.map$.instance.on('moveend', (e) => {
this.checkZoom();
});
}
ngOnChanges() {
this.checkZoom();
}
checkZoom() {
if(this.layer$ && this.map$.instance) {
let minZoom = this.layer$.getMinZoom();
let currentZoom = this.map$.instance.getView().getZoom();
let view = currentZoom < minZoom;
if(view!= this.showView) {
this.showView=view;
if ( !this.showView) {
this.viewContainerRef$.clear();
} else {
this.viewContainerRef$.createEmbeddedView(this.templateRef$);
}
}
}
}
}