@@ -56,14 +56,8 @@ export interface Options {
56
56
export default class TrackManager < POIMeta > {
57
57
58
58
private map_ : Map ;
59
- get map ( ) : Map {
60
- return this . map ;
61
- }
62
59
private source_ : VectorSource ;
63
60
private trackLayer_ : VectorLayer < VectorSource > ;
64
- get trackLayer ( ) : VectorLayer < VectorSource > {
65
- return this . trackLayer_ ;
66
- }
67
61
private shadowTrackLayer_ : VectorLayer < VectorSource > ;
68
62
private hitTolerance_ : number ;
69
63
public snapping = true ;
@@ -73,18 +67,14 @@ export default class TrackManager<POIMeta> {
73
67
private trackChangeEventListeners_ : Function [ ] = [ ] ;
74
68
// eslint-disable-next-line @typescript-eslint/ban-types
75
69
private trackHoverEventListeners_ : Function [ ] = [ ] ;
76
- private trackData_ = new TrackData ( ) ;
70
+ // the data for the current line
71
+ private trackData_ : TrackData ;
77
72
private router_ : Router ;
78
- get router ( ) : Router {
79
- return this . router_ ;
80
- }
81
73
private profiler_ : Profiler ;
82
- get profiler ( ) : Profiler {
83
- return this . profiler_ ;
84
- }
85
74
private updater_ : TrackUpdater ;
86
75
private interaction_ : TrackInteraction ;
87
76
private historyManager_ = new HistoryManager < Feature < Point | LineString > [ ] > ( ) ;
77
+ parts : TrackData [ ] = [ ] ;
88
78
89
79
constructor ( options : Options ) {
90
80
this . map_ = options . map ;
@@ -96,6 +86,9 @@ export default class TrackManager<POIMeta> {
96
86
97
87
this . router_ = options . router ;
98
88
this . profiler_ = options . profiler ;
89
+
90
+ this . createNewPart ( ) ;
91
+
99
92
this . updater_ = new TrackUpdater ( {
100
93
profiler : this . profiler_ ,
101
94
router : this . router_ ,
@@ -113,16 +106,7 @@ export default class TrackManager<POIMeta> {
113
106
hitTolerance : this . hitTolerance_ ,
114
107
} ) ;
115
108
116
- // Hack to test profile synchro
117
- // this.closestPointGeom_ = new Point([0, 0]);
118
- // this.interaction_.modifyTrack_.overlay_.getSource().addFeature(new Feature({
119
- // geometry: this.closestPointGeom_,
120
- // type: 'controlPoint',
121
- // subtype: 'first',
122
- // }));
123
-
124
-
125
-
109
+ // add a new control point
126
110
// @ts -ignore too complicate to declare proper events
127
111
this . interaction_ . on ( 'drawend' ,
128
112
async ( event : DrawEvent ) => {
@@ -131,6 +115,7 @@ export default class TrackManager<POIMeta> {
131
115
if ( ! this . snapping ) {
132
116
feature . set ( 'snapped' , false ) ;
133
117
}
118
+ // add control point to the current trackData
134
119
const { pointFrom, pointTo, segment} = this . trackData_ . pushControlPoint ( feature ) ;
135
120
if ( segment ) {
136
121
this . source_ . addFeature ( segment ) ;
@@ -168,6 +153,7 @@ export default class TrackManager<POIMeta> {
168
153
}
169
154
} ) ;
170
155
156
+ // modify (move) a poi, control point or segment
171
157
this . interaction_ . on (
172
158
// @ts -ignore too complicate to declare proper events
173
159
'modifyend' ,
@@ -209,6 +195,7 @@ export default class TrackManager<POIMeta> {
209
195
}
210
196
} ) ;
211
197
198
+ // delete a poi or control point
212
199
this . interaction_ . on (
213
200
// @ts -ignore too complicate to declare proper events
214
201
'select' ,
@@ -262,6 +249,22 @@ export default class TrackManager<POIMeta> {
262
249
} ) ;
263
250
}
264
251
252
+ get map ( ) : Map {
253
+ return this . map ;
254
+ }
255
+
256
+ get trackLayer ( ) : VectorLayer < VectorSource > {
257
+ return this . trackLayer_ ;
258
+ }
259
+
260
+ get router ( ) : Router {
261
+ return this . router_ ;
262
+ }
263
+
264
+ get profiler ( ) : Profiler {
265
+ return this . profiler_ ;
266
+ }
267
+
265
268
private pushNewStateToHistoryManager_ ( ) {
266
269
const segments = this . getSegments ( ) ;
267
270
const controlPoints = this . getControlPoints ( ) ;
@@ -568,4 +571,11 @@ export default class TrackManager<POIMeta> {
568
571
this . source_ . changed ( ) ;
569
572
this . shadowTrackLayer_ . getSource ( ) . changed ( ) ;
570
573
}
571
- }
574
+
575
+ // Add a new line string and set it add the "current" line string
576
+ createNewPart ( ) {
577
+ this . trackData_ = new TrackData ( ) ;
578
+
579
+ this . parts . push ( this . trackData_ ) ;
580
+ }
581
+ }
0 commit comments