-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdelete-feature-manager.ts
More file actions
148 lines (143 loc) · 5.22 KB
/
delete-feature-manager.ts
File metadata and controls
148 lines (143 loc) · 5.22 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
import type { Store } from '@ngrx/store';
import type { MapBrowserEvent, View } from 'ol';
import { Feature } from 'ol';
import { getTopRight } from 'ol/extent';
import { Point } from 'ol/geom';
import type { TranslateEvent } from 'ol/interaction/Translate';
import VectorLayer from 'ol/layer/Vector';
import type OlMap from 'ol/Map';
import VectorSource from 'ol/source/Vector';
import Icon from 'ol/style/Icon';
import Style from 'ol/style/Style';
import type { Subject } from 'rxjs';
// eslint-disable-next-line @typescript-eslint/no-shadow
import type { Element } from 'fuesim-digital-shared';
import type { FeatureManager } from '../utility/feature-manager';
import type { OlMapInteractionsManager } from '../utility/ol-map-interactions-manager';
import type { ExerciseService } from '../../../../../../core/exercise.service';
import type { AppState } from '../../../../../../state/app.state';
import { selectCurrentMainRole } from '../../../../../../state/application/selectors/shared.selectors';
import { selectStateSnapshot } from '../../../../../../state/get-state-snapshot';
function calculateTopRightViewPoint(view: View) {
const extent = getTopRight(view.calculateExtent());
return new Point([extent[0]!, extent[1]!]);
}
export class DeleteFeatureManager implements FeatureManager<Point> {
readonly layer: VectorLayer;
constructor(
private readonly store: Store<AppState>,
private readonly olMap: OlMap,
private readonly exerciseService: ExerciseService
) {
this.layer = new VectorLayer({
// These two settings prevent clipping during animation/interaction but cause a performance hit -> disable if needed
updateWhileAnimating: true,
updateWhileInteracting: true,
renderBuffer: 250,
source: new VectorSource<Feature<Point>>(),
});
}
register(
destroy$: Subject<void>,
mapInteractionsManager: OlMapInteractionsManager
) {
this.olMap.addLayer(this.layer);
mapInteractionsManager.addFeatureLayer(this.layer);
if (
selectStateSnapshot(selectCurrentMainRole, this.store) === 'trainer'
) {
this.makeVisible();
}
}
public makeVisible() {
this.layer.setStyle(
new Style({
image: new Icon({
opacity: 0.8,
anchorOrigin: 'top-right',
anchor: [-0.25, -0.25],
src: '/assets/trash-can.svg',
scale: 3,
}),
})
);
const view = this.olMap.getView();
const point = calculateTopRightViewPoint(view);
const deleteFeature = new Feature(point);
this.layer.getSource()!.addFeature(deleteFeature);
view.on(['change:resolution', 'change:center'], () => {
deleteFeature.setGeometry(
calculateTopRightViewPoint(this.olMap.getView())
);
});
}
public onFeatureClicked(
event: MapBrowserEvent<any>,
feature: Feature<any>
// eslint-disable-next-line @typescript-eslint/no-empty-function
): void {}
public isFeatureTranslatable(feature: Feature<Point>) {
return false;
}
public onFeatureDrop(
droppedElement: Element,
droppedOnFeature: Feature<Point>,
dropEvent: MouseEvent | TranslateEvent
) {
const id = droppedElement.id;
switch (droppedElement.type) {
case 'patient': {
this.exerciseService.proposeAction({
type: '[Patient] Remove patient',
patientId: id,
});
return true;
}
case 'vehicle': {
this.exerciseService.proposeAction({
type: '[Vehicle] Remove vehicle',
vehicleId: id,
});
return true;
}
case 'mapImage': {
this.exerciseService.proposeAction({
type: '[MapImage] Remove MapImage',
mapImageId: id,
});
return true;
}
case 'viewport': {
this.exerciseService.proposeAction({
type: '[Viewport] Remove viewport',
viewportId: id,
});
return true;
}
case 'transferPoint': {
this.exerciseService.proposeAction({
type: '[TransferPoint] Remove TransferPoint',
transferPointId: id,
});
return true;
}
case 'simulatedRegion': {
this.exerciseService.proposeAction({
type: '[SimulatedRegion] Remove simulated region',
simulatedRegionId: id,
});
return true;
}
case 'restrictedZone': {
this.exerciseService.proposeAction({
type: '[RestrictedZone] Remove restricted zone',
restrictedZoneId: id,
});
return true;
}
default: {
return false;
}
}
}
}