1
+ // FIXME: move pois outside of track data
2
+
1
3
import Feature from 'ol/Feature.js' ;
2
4
import Point from 'ol/geom/Point.js' ;
3
5
@@ -73,7 +75,7 @@ export default class TrackManager<POIMeta> {
73
75
private trackChangeEventListeners_ : Function [ ] = [ ] ;
74
76
// eslint-disable-next-line @typescript-eslint/ban-types
75
77
private trackHoverEventListeners_ : Function [ ] = [ ] ;
76
- private trackData_ = new TrackData ( ) ;
78
+ private trackData_ : TrackData ;
77
79
private router_ : Router ;
78
80
get router ( ) : Router {
79
81
return this . router_ ;
@@ -85,6 +87,7 @@ export default class TrackManager<POIMeta> {
85
87
private updater_ : TrackUpdater ;
86
88
private interaction_ : TrackInteraction ;
87
89
private historyManager_ = new HistoryManager < Feature < Point | LineString > [ ] > ( ) ;
90
+ private parts : TrackData [ ] = [ ] ;
88
91
89
92
constructor ( options : Options ) {
90
93
this . map_ = options . map ;
@@ -96,15 +99,14 @@ export default class TrackManager<POIMeta> {
96
99
97
100
this . router_ = options . router ;
98
101
this . profiler_ = options . profiler ;
102
+
99
103
this . updater_ = new TrackUpdater ( {
100
104
profiler : this . profiler_ ,
101
105
router : this . router_ ,
102
- trackData : this . trackData_
103
106
} ) ;
104
107
105
108
this . interaction_ = new TrackInteraction ( {
106
109
style : options . style ,
107
- trackData : this . trackData_ ,
108
110
trackLayer : this . trackLayer_ ,
109
111
map : this . map_ ,
110
112
deleteCondition : options . deleteCondition ,
@@ -113,6 +115,8 @@ export default class TrackManager<POIMeta> {
113
115
hitTolerance : this . hitTolerance_ ,
114
116
} ) ;
115
117
118
+ this . createNewPart ( ) ;
119
+
116
120
// Hack to test profile synchro
117
121
// this.closestPointGeom_ = new Point([0, 0]);
118
122
// this.interaction_.modifyTrack_.overlay_.getSource().addFeature(new Feature({
@@ -131,9 +135,12 @@ export default class TrackManager<POIMeta> {
131
135
if ( ! this . snapping ) {
132
136
feature . set ( 'snapped' , false ) ;
133
137
}
138
+ feature . set ( 'part' , this . trackData_ . part ) ;
139
+ // this is what we want: the new point is added to the current part
134
140
const { pointFrom, pointTo, segment} = this . trackData_ . pushControlPoint ( feature ) ;
135
141
if ( segment ) {
136
142
this . source_ . addFeature ( segment ) ;
143
+ segment . set ( 'part' , this . trackData_ . part ) ;
137
144
await this . router_ . snapSegment ( segment , pointFrom , pointTo ) ;
138
145
this . updater_ . equalizeCoordinates ( pointFrom ) ;
139
146
await this . profiler_ . computeProfile ( segment ) ;
@@ -145,6 +152,7 @@ export default class TrackManager<POIMeta> {
145
152
146
153
const debouncedMapToProfileUpdater = debounce (
147
154
( coordinate : Coordinate , hover : boolean ) => {
155
+ // FIXME multi lines: check this
148
156
if ( hover && this . trackData_ . getSegments ( ) . length > 0 ) {
149
157
const segments = this . trackData_ . getSegments ( ) . map ( feature => feature . get ( 'profile' ) ) ;
150
158
const best = findClosestPointInLines ( segments , coordinate , { tolerance : 1 , interpolate : true } ) ;
@@ -176,22 +184,26 @@ export default class TrackManager<POIMeta> {
176
184
const type = event . feature . get ( 'type' ) as FeatureType ;
177
185
178
186
if ( type === 'POI' ) {
179
- this . trackData_ . updatePOIIndexes ( ) ;
187
+ // FIXME multi lines: check this
188
+ this . trackData_ . updatePOIIndexes ( ) ;
180
189
this . onTrackChanged_ ( ) ;
181
190
} else if ( type === 'controlPoint' ) {
182
191
const feature = event . feature as Feature < Point > ;
183
192
await this . updater_ . updateAdjacentSegmentsGeometries ( feature , this . snapping ) ;
184
193
this . updater_ . changeAdjacentSegmentsStyling ( feature , '' ) ;
185
194
await this . updater_ . computeAdjacentSegmentsProfile ( feature ) ;
195
+ // FIXME multi lines: check this
186
196
this . trackData_ . updatePOIIndexes ( ) ;
187
197
this . onTrackChanged_ ( ) ;
188
198
} else if ( type === 'segment' ) {
189
199
const feature = event . feature as Feature < LineString > ;
200
+ // FIXME multi lines: check this
190
201
const indexOfSegment = this . trackData_ . getSegments ( ) . indexOf ( feature ) ;
191
202
192
203
console . assert ( indexOfSegment >= 0 ) ;
193
204
const controlPoint = new Feature ( {
194
- geometry : new Point ( event . coordinate )
205
+ geometry : new Point ( event . coordinate ) ,
206
+ part : this . trackData_ . part ,
195
207
} ) ;
196
208
this . source_ . addFeature ( controlPoint ) ;
197
209
const removed = this . trackData_ . insertControlPointAt ( controlPoint , indexOfSegment + 1 ) ;
@@ -200,11 +212,14 @@ export default class TrackManager<POIMeta> {
200
212
201
213
const { before, after} = this . trackData_ . getAdjacentSegments ( controlPoint ) ;
202
214
console . assert ( ! ! before && ! ! after ) ;
215
+ before . set ( 'part' , this . trackData_ . part ) ;
216
+ after . set ( 'part' , this . trackData_ . part ) ;
203
217
this . source_ . addFeatures ( [ before , after ] ) ;
204
218
205
219
await this . updater_ . updateAdjacentSegmentsGeometries ( controlPoint , this . snapping ) ;
206
220
this . updater_ . changeAdjacentSegmentsStyling ( controlPoint , '' ) ;
207
221
await this . updater_ . computeAdjacentSegmentsProfile ( controlPoint ) ;
222
+ // FIXME multi lines: check this
208
223
this . trackData_ . updatePOIIndexes ( ) ;
209
224
this . onTrackChanged_ ( ) ;
210
225
}
@@ -220,11 +235,13 @@ export default class TrackManager<POIMeta> {
220
235
console . assert ( selected . getGeometry ( ) . getType ( ) === 'Point' ) ;
221
236
const type = selected . get ( 'type' ) as FeatureType ;
222
237
if ( type === 'POI' ) {
238
+ // FIXME multi lines: check this
223
239
this . trackData_ . deletePOI ( selected ) ;
224
240
this . source_ . removeFeature ( selected ) ;
225
241
this . onTrackChanged_ ( ) ;
226
242
} else {
227
243
// control point
244
+ // FIXME multi lines: check this
228
245
const { deleted, pointBefore, pointAfter, newSegment} = this . trackData_ . deleteControlPoint ( selected ) ;
229
246
230
247
// remove deleted features from source
@@ -329,7 +346,8 @@ export default class TrackManager<POIMeta> {
329
346
330
347
deleteLastPoint ( ) {
331
348
if ( this . mode_ ) {
332
- if ( this . trackData_ . getControlPoints ( ) . length > 0 ) {
349
+ // FIXME multi lines: check this
350
+ if ( this . trackData_ . getControlPoints ( ) . length > 0 ) {
333
351
const deletedFeatures = this . trackData_ . deleteLastControlPoint ( ) ;
334
352
deletedFeatures . forEach ( feature => this . source_ . removeFeature ( feature ) ) ;
335
353
this . onTrackChanged_ ( ) ;
@@ -364,6 +382,7 @@ export default class TrackManager<POIMeta> {
364
382
private clearInternal_ ( ) {
365
383
this . source_ . clear ( ) ;
366
384
this . trackData_ . clear ( ) ;
385
+ // FIXME multi lines: remove all parts ?
367
386
}
368
387
369
388
/**
@@ -388,7 +407,6 @@ export default class TrackManager<POIMeta> {
388
407
}
389
408
390
409
async restoreFeatures ( features : Feature < Point | LineString > [ ] ) : Promise < void > {
391
- this . clearInternal_ ( ) ;
392
410
await this . restoreFeaturesInternal_ ( features ) ;
393
411
this . onTrackChanged_ ( ) ;
394
412
}
@@ -574,4 +592,32 @@ export default class TrackManager<POIMeta> {
574
592
this . source_ . changed ( ) ;
575
593
this . shadowTrackLayer_ . getSource ( ) . changed ( ) ;
576
594
}
577
- }
595
+
596
+ createNewPart ( ) : number {
597
+ this . trackData_ = new TrackData ( this . parts . length ) ;
598
+ this . parts . push ( this . trackData_ ) ;
599
+ this . updater_ . setTrackData ( this . trackData_ ) ;
600
+ this . interaction_ . setTrackData ( this . trackData_ ) ;
601
+
602
+ return this . trackData_ . part ;
603
+ }
604
+
605
+ activePart ( ) : number {
606
+ return this . trackData_ . part ;
607
+ }
608
+
609
+ partsCount ( ) : number {
610
+ return this . parts . length ;
611
+ }
612
+
613
+ workOnPart ( index : number ) {
614
+ this . trackData_ = this . parts [ index ] ;
615
+ this . updater_ . setTrackData ( this . trackData_ ) ;
616
+ this . interaction_ . setTrackData ( this . trackData_ ) ;
617
+ }
618
+
619
+ getParts ( ) : TrackData [ ] {
620
+ return this . parts ;
621
+ }
622
+
623
+ }
0 commit comments