/
share-map-binding.directive.ts
56 lines (50 loc) · 2.11 KB
/
share-map-binding.directive.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Directive, Self, OnInit, Optional } from '@angular/core';
import { LayerListService } from '@igo2/geo';
import { ShareMapComponent } from './share-map.component';
import { RouteService } from '@igo2/core';
@Directive({
selector: '[igoShareMapBinding]'
})
export class ShareMapBindingDirective implements OnInit {
private component: ShareMapComponent;
constructor(
@Self() component: ShareMapComponent,
private layerListService: LayerListService,
@Optional() private route: RouteService
) {
this.component = component;
}
ngOnInit() {
this.initRoutes();
}
private initRoutes() {
if (
this.route &&
(this.route.options.llcKKey || this.route.options.llcAKey ||
this.route.options.llcVKey || this.route.options.llcVKey)) {
this.route.queryParams.subscribe(params => {
const keywordFromUrl = params[this.route.options.llcKKey as string];
const sortedAplhaFromUrl = params[this.route.options.llcAKey as string];
const onlyVisibleFromUrl = params[this.route.options.llcVKey as string];
const onlyInRangeFromUrl = params[this.route.options.llcRKey as string];
if (keywordFromUrl && !this.layerListService.keywordInitialized) {
this.layerListService.keyword = keywordFromUrl;
this.layerListService.keywordInitialized = true;
}
if (sortedAplhaFromUrl && !this.layerListService.sortedAlphaInitialized) {
this.layerListService.sortedAlpha = sortedAplhaFromUrl === '1' ? true : false;
this.layerListService.sortedAlphaInitialized = true;
}
if (onlyVisibleFromUrl && !this.layerListService.onlyVisibleInitialized) {
this.layerListService.onlyVisible = onlyVisibleFromUrl === '1' ? true : false;
this.layerListService.onlyVisibleInitialized = true;
}
if (onlyInRangeFromUrl && !this.layerListService.onlyInRangeInitialized) {
this.layerListService.onlyInRange = onlyInRangeFromUrl === '1' ? true : false;
this.layerListService.onlyInRangeInitialized = true;
}
this.component.resetUrl();
});
}
}
}