-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtransfer-point-feature-manager.ts
More file actions
187 lines (178 loc) · 6.87 KB
/
transfer-point-feature-manager.ts
File metadata and controls
187 lines (178 loc) · 6.87 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import type { Store } from '@ngrx/store';
// eslint-disable-next-line @typescript-eslint/no-shadow
import type { UUID, Element, TransferPoint } from 'fuesim-digital-shared';
import {
newTransferStartPoint,
transferPointImage,
} from 'fuesim-digital-shared';
import type { Feature, MapBrowserEvent } from 'ol';
import type Point from 'ol/geom/Point';
import type { TranslateEvent } from 'ol/interaction/Translate';
import type OlMap from 'ol/Map';
import type { Subject } from 'rxjs';
import { ChooseTransferTargetPopupComponent } from '../shared/choose-transfer-target-popup/choose-transfer-target-popup.component';
import { TransferPointPopupComponent } from '../shared/transfer-point-popup/transfer-point-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 type { ExerciseService } from '../../../../../../core/exercise.service';
import type { AppState } from '../../../../../../state/app.state';
import {
selectVisibleTransferPoints,
selectCurrentMainRole,
} from '../../../../../../state/application/selectors/shared.selectors';
import { selectStateSnapshot } from '../../../../../../state/get-state-snapshot';
import { MoveableFeatureManager } from './moveable-feature-manager';
export class TransferPointFeatureManager extends MoveableFeatureManager<TransferPoint> {
private readonly popupHelper = new ImagePopupHelper(this.olMap, this.layer);
constructor(
olMap: OlMap,
private readonly store: Store<AppState>,
private readonly exerciseService: ExerciseService,
private readonly popupService: PopupService
) {
super(
olMap,
async (targetPosition, transferPoint) =>
exerciseService.proposeAction(
{
type: '[TransferPoint] Move TransferPoint',
transferPointId: transferPoint.id,
targetPosition,
},
true
),
new PointGeometryHelper(),
600
);
this.layer.setStyle((thisFeature, currentZoom) => [
this.imageStyleHelper.getStyle(
thisFeature as Feature<Point>,
currentZoom
),
this.nameStyleHelper.getStyle(
thisFeature as Feature<Point>,
currentZoom
),
]);
}
public register(
destroy$: Subject<void>,
mapInteractionsManager: OlMapInteractionsManager
) {
super.registerFeatureElementManager(
this.store.select(selectVisibleTransferPoints),
destroy$,
mapInteractionsManager
);
}
private readonly imageStyleHelper = new ImageStyleHelper(
(feature: Feature) => transferPointImage
);
private readonly nameStyleHelper = new NameStyleHelper(
(feature: Feature) => ({
name: (this.getElementFromFeature(feature) as TransferPoint)
.internalName,
offsetY: 0,
}),
0.2,
'middle'
);
public override onFeatureDrop(
droppedElement: Element | undefined,
droppedOnFeature: Feature<Point>,
dropEvent?: TranslateEvent
) {
// TODO: droppedElement isn't necessarily a transfer point -> fix getElementFromFeature typings
const droppedOnTransferPoint = this.getElementFromFeature(
droppedOnFeature
) as TransferPoint | undefined;
if (!droppedElement || !droppedOnTransferPoint) {
console.error('Could not find element for the features');
return false;
}
if (
droppedElement.type !== 'vehicle' &&
droppedElement.type !== 'personnel'
) {
return false;
}
// Always show the chooseTransferPopup
// Show a popup to choose the transferPoint or hospital
this.popupService.openPopup(
this.popupHelper.getPopupOptions(
ChooseTransferTargetPopupComponent,
droppedOnFeature,
[droppedOnTransferPoint.id, droppedElement.id],
[],
[],
[],
{
transferPointId: droppedOnTransferPoint.id,
droppedElementType: droppedElement.type,
transferToCallback: (
targetId: UUID,
targetType: 'hospital' | 'transferPoint'
) => {
if (targetType === 'hospital') {
this.exerciseService.proposeAction(
{
type: '[Hospital] Transport patient to hospital',
hospitalId: targetId,
vehicleId: droppedElement.id,
},
true
);
return;
}
this.exerciseService.proposeAction(
{
type: '[Transfer] Add to transfer',
elementType: droppedElement.type,
elementId: droppedElement.id,
startPoint: newTransferStartPoint(
droppedOnTransferPoint.id
),
targetTransferPointId: targetId,
},
true
);
},
}
)
);
return true;
}
public override onFeatureClicked(
event: MapBrowserEvent<any>,
feature: Feature<any>
): void {
super.onFeatureClicked(event, feature);
if (
selectStateSnapshot(selectCurrentMainRole, this.store) !== 'trainer'
) {
return;
}
this.popupService.openPopup(
this.popupHelper.getPopupOptions(
TransferPointPopupComponent,
feature,
[feature.getId() as UUID],
[],
[],
[],
{
transferPointId: feature.getId() as UUID,
}
)
);
}
override isFeatureTranslatable(feature: Feature<Point>): boolean {
return (
selectStateSnapshot(selectCurrentMainRole, this.store) === 'trainer'
);
}
}