From 321d34870ec7b2b9085e25fcdb2d23772032035c Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Fri, 29 Jan 2021 11:25:37 +0100 Subject: [PATCH] Add zoom to show alert --- .../src/fm-map/common-map.module.ts | 10 +++-- .../feature-list/feature-list.component.html | 2 +- .../if-zoom-to-show.directive.ts | 44 ++++++++++++------- .../selected-item-geotiff.component.html | 1 + .../selected-item-shape.component.html | 1 + .../selected-item-temporal.component.html | 1 + .../selected-item-temporal.component.ts | 5 +++ .../zoom-to-show-alert.component.ts | 11 +++++ 8 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 projects/common-map/src/fm-map/components/zoom-to-show-alert/zoom-to-show-alert.component.ts diff --git a/projects/common-map/src/fm-map/common-map.module.ts b/projects/common-map/src/fm-map/common-map.module.ts index bab0d79..055d45b 100644 --- a/projects/common-map/src/fm-map/common-map.module.ts +++ b/projects/common-map/src/fm-map/common-map.module.ts @@ -68,6 +68,7 @@ import {LayerSwitcher} from './components/layer-switcher/layer-switcher.componen import {HistogramDetailsComponent} from './components/legend/histogram-details/histogram-details.component'; import {StatisticsDetailsComponent} from './components/legend/statistics-details/statistics-details.component'; import { ifZoomToShowDirective} from './components/if-zoom-to-show/if-zoom-to-show.directive'; +import { ZoomToShowAlert} from './components/zoom-to-show-alert/zoom-to-show-alert.component'; export function LocalStorageSync(reducer: ActionReducer): ActionReducer { const r = function(state, action) { @@ -149,7 +150,8 @@ export { ForPackage , ITemporalItemLayer, TemporalItemLayer, - ifZoomToShowDirective + ifZoomToShowDirective, + ZoomToShowAlert } @NgModule({ @@ -202,7 +204,8 @@ export { LayerSwitcher, HistogramDetailsComponent, StatisticsDetailsComponent, - ifZoomToShowDirective + ifZoomToShowDirective, + ZoomToShowAlert ], entryComponents: [ FeatureListComponent, @@ -255,7 +258,8 @@ export { FeatureListCropfieldComponent, FeatureListFeatureContainerComponent, ZoomToExtentComponent, - ifZoomToShowDirective + ifZoomToShowDirective, + ZoomToShowAlert ], providers: [ FeatureIconService, diff --git a/projects/common-map/src/fm-map/components/feature-list/feature-list.component.html b/projects/common-map/src/fm-map/components/feature-list/feature-list.component.html index 6ab3b13..3e396a0 100644 --- a/projects/common-map/src/fm-map/components/feature-list/feature-list.component.html +++ b/projects/common-map/src/fm-map/components/feature-list/feature-list.component.html @@ -1,5 +1,5 @@
- > +
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 587e1be..6856a35 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 @@ -1,25 +1,39 @@ -import { Directive, ViewContainerRef,TemplateRef,OnInit,Input } from '@angular/core'; -import { IItemLayer } from '../../models/item.layer'; +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 { - @Input('fm-map-ifZoomToShow') itemLayer$:IItemLayer; +export class ifZoomToShowDirective implements OnInit,OnChanges { + @Input('fm-map-ifZoomToShow') layer$:layer; constructor(private templateRef$: TemplateRef,private viewContainerRef$: ViewContainerRef,private map$: MapComponent) { } - private hasView = false; - ngOnInit() { - let minZoom = this.itemLayer$.layer.getMinZoom(); - let currentZoom = this.map$.instance.getView().getZoom(); + private showView = false; - if ( currentZoom < minZoom ) { - this.viewContainerRef$.createEmbeddedView(this.templateRef$); - this.hasView=true; - } else if (this.hasView) { - this.viewContainerRef$.clear(); - this.hasView = 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$); + } + } + } } } \ No newline at end of file diff --git a/projects/common-map/src/fm-map/components/selected-item-geotiff/selected-item-geotiff.component.html b/projects/common-map/src/fm-map/components/selected-item-geotiff/selected-item-geotiff.component.html index 19d7136..5925d3e 100644 --- a/projects/common-map/src/fm-map/components/selected-item-geotiff/selected-item-geotiff.component.html +++ b/projects/common-map/src/fm-map/components/selected-item-geotiff/selected-item-geotiff.component.html @@ -27,6 +27,7 @@
+ diff --git a/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.html b/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.html index de3bd58..0f7b94f 100644 --- a/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.html +++ b/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.html @@ -26,6 +26,7 @@ + diff --git a/projects/common-map/src/fm-map/components/selected-item-temporal/selected-item-temporal.component.html b/projects/common-map/src/fm-map/components/selected-item-temporal/selected-item-temporal.component.html index 6339c73..6ac2c0f 100644 --- a/projects/common-map/src/fm-map/components/selected-item-temporal/selected-item-temporal.component.html +++ b/projects/common-map/src/fm-map/components/selected-item-temporal/selected-item-temporal.component.html @@ -22,6 +22,7 @@ +