-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpersonnel-feature-manager.ts
126 lines (119 loc) · 4.4 KB
/
personnel-feature-manager.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import type { Store } from '@ngrx/store';
import type { Personnel, UUID } from 'digital-fuesim-manv-shared';
import { normalZoom } from 'digital-fuesim-manv-shared';
import type { Feature, MapBrowserEvent } from 'ol';
import type OlMap from 'ol/Map';
import type { Subject } from 'rxjs';
import type { ExerciseService } from 'src/app/core/exercise.service';
import type { AppState } from 'src/app/state/app.state';
import { selectVisiblePersonnel } from 'src/app/state/application/selectors/shared.selectors';
import Fill from 'ol/style/Fill';
import Stroke from 'ol/style/Stroke';
import { PersonnelPopupComponent } from '../shared/personnel-popup/personnel-popup.component';
import type { OlMapInteractionsManager } from '../utility/ol-map-interactions-manager';
import { PointGeometryHelper } from '../utility/point-geometry-helper';
import { ImagePopupHelper } from '../utility/popup-helper';
import { ImageStyleHelper } from '../utility/style-helper/image-style-helper';
import { NameStyleHelper } from '../utility/style-helper/name-style-helper';
import type { PopupService } from '../utility/popup.service';
import { CircleStyleHelper } from '../utility/style-helper/circle-style-helper';
import { MoveableFeatureManager } from './moveable-feature-manager';
export class PersonnelFeatureManager extends MoveableFeatureManager<Personnel> {
public register(
destroy$: Subject<void>,
mapInteractionsManager: OlMapInteractionsManager
): void {
super.registerFeatureElementManager(
this.store.select(selectVisiblePersonnel),
destroy$,
mapInteractionsManager
);
}
private readonly imageStyleHelper = new ImageStyleHelper(
(feature) => (this.getElementFromFeature(feature) as Personnel).image
);
private readonly nameStyleHelper = new NameStyleHelper(
(feature) => {
const personnel = this.getElementFromFeature(feature) as Personnel;
return {
name: personnel.vehicleName,
offsetY: personnel.image.height / 2 / normalZoom,
};
},
0.025,
'top'
);
private readonly popupHelper = new ImagePopupHelper(this.olMap, this.layer);
private readonly openPopupCircleStyleHelper = new CircleStyleHelper(
(_) => ({
radius: 75,
fill: new Fill({
color: '#00000000',
}),
stroke: new Stroke({
color: 'orange',
width: 10,
}),
}),
0.025,
(_) => [0, 0]
);
constructor(
olMap: OlMap,
private readonly store: Store<AppState>,
exerciseService: ExerciseService,
private readonly popupService: PopupService
) {
super(
olMap,
(targetPosition, personnel) => {
exerciseService.proposeAction({
type: '[Personnel] Move personnel',
personnelId: personnel.id,
targetPosition,
});
},
new PointGeometryHelper()
);
this.layer.setStyle((feature, resolution) => {
const styles = [
this.nameStyleHelper.getStyle(feature as Feature, resolution),
this.imageStyleHelper.getStyle(feature as Feature, resolution),
];
this.addMarking(
feature,
styles,
this.popupService,
this.store,
this.openPopupCircleStyleHelper.getStyle(
feature as Feature,
resolution
)
);
return styles;
});
}
public override onFeatureClicked(
event: MapBrowserEvent<any>,
feature: Feature<any>
): void {
super.onFeatureClicked(event, feature);
this.popupService.openPopup(
this.popupHelper.getPopupOptions(
PersonnelPopupComponent,
feature,
[feature.getId() as UUID],
[
feature.getId() as UUID,
(this.getElementFromFeature(feature) as Personnel)
.vehicleId,
],
[feature.getId() as UUID],
['personnel', 'vehicle'],
{
personnelId: feature.getId() as UUID,
}
)
);
}
}