forked from hpi-sam/digital-fuesim-manv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatering-lines-feature-manager.ts
118 lines (109 loc) · 4.16 KB
/
catering-lines-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
import type { Store } from '@ngrx/store';
import type { MapBrowserEvent } from 'ol';
import { Feature } from 'ol';
import LineString from 'ol/geom/LineString';
import type { TranslateEvent } from 'ol/interaction/Translate';
import type VectorLayer from 'ol/layer/Vector';
import type OlMap from 'ol/Map';
import type VectorSource from 'ol/source/Vector';
import type { Subject } from 'rxjs';
import { rgbColorPalette } from 'src/app/shared/functions/colors';
import type { CateringLine } from 'src/app/shared/types/catering-line';
import type { AppState } from 'src/app/state/app.state';
import { selectVisibleCateringLines } from 'src/app/state/application/selectors/shared.selectors';
// eslint-disable-next-line @typescript-eslint/no-shadow
import type { Element } from 'digital-fuesim-manv-shared';
import type { FeatureManager } from '../utility/feature-manager';
import type { OlMapInteractionsManager } from '../utility/ol-map-interactions-manager';
import { LineStyleHelper } from '../utility/style-helper/line-style-helper';
import { ElementManager } from './element-manager';
export class CateringLinesFeatureManager
extends ElementManager<CateringLine, LineString>
implements FeatureManager<LineString>
{
private readonly lineStyleHelper = new LineStyleHelper(
(feature) => ({
color: rgbColorPalette.cyan,
}),
0.05
);
public readonly layer: VectorLayer<VectorSource<LineString>>;
constructor(
private readonly store: Store<AppState>,
private readonly olMap: OlMap
) {
super();
this.layer = super.createElementLayer<LineString>();
this.layer.setStyle((feature, currentZoom) =>
this.lineStyleHelper.getStyle(feature as Feature, currentZoom)
);
}
register(
destroy$: Subject<void>,
mapInteractionsManager: OlMapInteractionsManager
) {
this.olMap.addLayer(this.layer);
mapInteractionsManager.addFeatureLayer(this.layer);
// Propagate the changes on an element to the featureManager
this.registerChangeHandlers(
this.store.select(selectVisibleCateringLines),
destroy$,
(element) => this.onElementCreated(element),
(element) => this.onElementDeleted(element),
(oldElement, newElement) =>
this.onElementChanged(oldElement, newElement)
);
}
public isFeatureTranslatable(feature: Feature<LineString>) {
return false;
}
createFeature(element: CateringLine): Feature<LineString> {
const feature = new Feature(
new LineString([
[element.catererPosition.x, element.catererPosition.y],
[element.patientPosition.x, element.patientPosition.y],
])
);
feature.setId(element.id);
this.layer.getSource()!.addFeature(feature);
return feature;
}
deleteFeature(
element: CateringLine,
elementFeature: Feature<LineString>
): void {
this.layer.getSource()!.removeFeature(elementFeature);
}
changeFeature(
oldElement: CateringLine,
newElement: CateringLine,
changedProperties: ReadonlySet<keyof CateringLine>,
elementFeature: Feature<LineString>
): void {
// Rendering the line again is expensive, so we only do it if we must
if (
changedProperties.has('catererPosition') ||
changedProperties.has('patientPosition')
) {
elementFeature.getGeometry()!.setCoordinates([
[newElement.catererPosition.x, newElement.catererPosition.y],
[newElement.patientPosition.x, newElement.patientPosition.y],
]);
}
}
onFeatureClicked(
event: MapBrowserEvent<any>,
feature: Feature<LineString>
// eslint-disable-next-line @typescript-eslint/no-empty-function
) {}
onFeatureDrop(
droppedElement: Element,
droppedOnFeature: Feature<LineString>,
dropEvent?: TranslateEvent
) {
return false;
}
getFeatureFromElement(element: CateringLine) {
return this.layer.getSource()!.getFeatureById(element.id) ?? undefined;
}
}