diff --git a/projects/common-map/src/fm-map/components/if-zoom-to-show/if-zoom-to-show.directive.ts b/projects/common-map/src/fm-map/components/if-zoom-to-show/if-zoom-to-show.directive.ts index 6856a35..b2b8b4e 100644 --- a/projects/common-map/src/fm-map/components/if-zoom-to-show/if-zoom-to-show.directive.ts +++ b/projects/common-map/src/fm-map/components/if-zoom-to-show/if-zoom-to-show.directive.ts @@ -3,35 +3,55 @@ import { layer } from 'ol'; import { MapComponent } from 'ngx-openlayers'; @Directive({ - selector: '[fm-map-ifZoomToShow]', + selector: '[fmMapIfZoomToShow]', }) -export class ifZoomToShowDirective implements OnInit,OnChanges { - @Input('fm-map-ifZoomToShow') layer$:layer; +export class ifZoomToShowDirective implements OnInit { + @Input() + set fmMapIfZoomToShow(layer:layer) { + this.layer$=layer; + this.checkZoom(); + } - constructor(private templateRef$: TemplateRef,private viewContainerRef$: ViewContainerRef,private map$: MapComponent) { } + @Input() + set fmMapIfZoomToShowThen(templateRef: TemplateRef) { + this.thenTemplate$ = templateRef; + this.checkZoom(); + } + + @Input() + set fmMapIfZoomToShowElse(templateRef: TemplateRef) { + this.elseTemplate$ = templateRef; + this.checkZoom(); + } + + private layer$:layer; + private thenTemplate$:TemplateRef; + private elseTemplate$:TemplateRef; private showView = false; + constructor(private templateRef$: TemplateRef,private viewContainerRef$: ViewContainerRef,private map$: MapComponent) { + this.thenTemplate$ = templateRef$; + this.checkZoom(); + } + 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.viewContainerRef$.clear(); this.showView=view; - if ( !this.showView) { - this.viewContainerRef$.clear(); - } else { - this.viewContainerRef$.createEmbeddedView(this.templateRef$); + if (this.showView && this.thenTemplate$ ) { + this.viewContainerRef$.createEmbeddedView(this.templateRef$); + } else if(this.elseTemplate$ ) { + this.viewContainerRef$.createEmbeddedView(this.elseTemplate$); } } } diff --git a/projects/common-map/src/fm-map/components/zoom-to-show-alert/zoom-to-show-alert.component.ts b/projects/common-map/src/fm-map/components/zoom-to-show-alert/zoom-to-show-alert.component.ts index 5fe8a1f..5babded 100644 --- a/projects/common-map/src/fm-map/components/zoom-to-show-alert/zoom-to-show-alert.component.ts +++ b/projects/common-map/src/fm-map/components/zoom-to-show-alert/zoom-to-show-alert.component.ts @@ -3,7 +3,7 @@ import { layer } from 'ol'; @Component({ selector: 'fm-map-zoom-to-show-alert', - template: '
 Zoom in to show layer
' + template: '
 Zoom in to show layer
' }) export class ZoomToShowAlert { @Input() layer: layer;