Skip to content

Commit 519a7ca

Browse files
committed
wip: add multi line support
1 parent 523fd2d commit 519a7ca

File tree

5 files changed

+44
-34
lines changed

5 files changed

+44
-34
lines changed

demos/simple/demo.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ function main() {
124124
}
125125
trackManager.addPOI(poiOverlay, onAddListener)
126126
});
127+
128+
document.querySelector('#createNewPart').addEventListener('click', () => {
129+
trackManager.createNewPart();
130+
});
127131
}
128132

129133
main();

demos/simple/simple.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
<button id="poiCancel">Cancel</button>
5757
<button id="poiSave">Save</button>
5858
</div>
59+
<br />
60+
<a href="#" id="createNewPart">Add a new line string</a>
5961
</div>
6062
<div id="map"></div>
6163
</main>

src/interaction/TrackInteraction.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {FALSE} from 'ol/functions';
88
import type {Feature, Map, MapBrowserEvent} from 'ol';
99
import VectorLayer from 'ol/layer/Vector';
1010
import VectorSource from 'ol/source/Vector';
11-
import TrackData from './TrackData';
1211
import type {StyleLike} from 'ol/style/Style';
1312
import type {FlatStyleLike} from 'ol/style/flat';
1413
import type {Pixel} from 'ol/pixel';
14+
import type TrackData from './TrackData';
1515
import type {FeatureType} from './TrackData';
1616
import {Point} from 'ol/geom';
1717

@@ -168,12 +168,9 @@ export default class TrackInteraction extends Interaction {
168168
}
169169

170170
setActive(active: boolean) {
171-
// Hack: the Interaction constructor calls setActive...
172-
if (this.drawTrack_) {
173-
this.drawTrack_.setActive(active);
174-
this.modifyTrack_.setActive(active);
175-
this.deletePoint_.setActive(active);
176-
}
171+
this.drawTrack_?.setActive(active);
172+
this.modifyTrack_?.setActive(active);
173+
this.deletePoint_?.setActive(active);
177174
super.setActive(active);
178175
}
179176
}

src/interaction/TrackInteractionModify.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ export default class Modify extends PointerInteraction {
6666
private overlay_: VectorLayer<VectorSource<Feature>>;
6767
private lastPixel_ = [0, 0];
6868
private trackData_: Options['trackData'];
69-
/**
70-
* @type {Feature<Point>}
71-
*/
7269
private pointAtCursorFeature_ = new Feature({
7370
geometry: new Point([0, 0]),
7471
type: 'sketch',

src/interaction/TrackManager.ts

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ export interface Options {
5656
export default class TrackManager<POIMeta> {
5757

5858
private map_: Map;
59-
get map(): Map {
60-
return this.map;
61-
}
6259
private source_: VectorSource;
6360
private trackLayer_: VectorLayer<VectorSource>;
64-
get trackLayer(): VectorLayer<VectorSource> {
65-
return this.trackLayer_;
66-
}
6761
private shadowTrackLayer_: VectorLayer<VectorSource>;
6862
private hitTolerance_: number;
6963
public snapping = true;
@@ -73,18 +67,14 @@ export default class TrackManager<POIMeta> {
7367
private trackChangeEventListeners_: Function[] = [];
7468
// eslint-disable-next-line @typescript-eslint/ban-types
7569
private trackHoverEventListeners_: Function[] = [];
76-
private trackData_ = new TrackData();
70+
// the data for the current line
71+
private trackData_: TrackData;
7772
private router_: Router;
78-
get router(): Router {
79-
return this.router_;
80-
}
8173
private profiler_: Profiler;
82-
get profiler(): Profiler {
83-
return this.profiler_;
84-
}
8574
private updater_: TrackUpdater;
8675
private interaction_: TrackInteraction;
8776
private historyManager_ = new HistoryManager<Feature<Point|LineString>[]>();
77+
parts: TrackData[] = [];
8878

8979
constructor(options: Options) {
9080
this.map_ = options.map;
@@ -96,6 +86,9 @@ export default class TrackManager<POIMeta> {
9686

9787
this.router_ = options.router;
9888
this.profiler_ = options.profiler;
89+
90+
this.createNewPart();
91+
9992
this.updater_ = new TrackUpdater({
10093
profiler: this.profiler_,
10194
router: this.router_,
@@ -113,16 +106,7 @@ export default class TrackManager<POIMeta> {
113106
hitTolerance: this.hitTolerance_,
114107
});
115108

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
126110
// @ts-ignore too complicate to declare proper events
127111
this.interaction_.on('drawend',
128112
async (event: DrawEvent) => {
@@ -131,6 +115,7 @@ export default class TrackManager<POIMeta> {
131115
if (!this.snapping) {
132116
feature.set('snapped', false);
133117
}
118+
// add control point to the current trackData
134119
const {pointFrom, pointTo, segment} = this.trackData_.pushControlPoint(feature);
135120
if (segment) {
136121
this.source_.addFeature(segment);
@@ -168,6 +153,7 @@ export default class TrackManager<POIMeta> {
168153
}
169154
});
170155

156+
// modify (move) a poi, control point or segment
171157
this.interaction_.on(
172158
// @ts-ignore too complicate to declare proper events
173159
'modifyend',
@@ -209,6 +195,7 @@ export default class TrackManager<POIMeta> {
209195
}
210196
});
211197

198+
// delete a poi or control point
212199
this.interaction_.on(
213200
// @ts-ignore too complicate to declare proper events
214201
'select',
@@ -262,6 +249,22 @@ export default class TrackManager<POIMeta> {
262249
});
263250
}
264251

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+
265268
private pushNewStateToHistoryManager_() {
266269
const segments = this.getSegments();
267270
const controlPoints = this.getControlPoints();
@@ -568,4 +571,11 @@ export default class TrackManager<POIMeta> {
568571
this.source_.changed();
569572
this.shadowTrackLayer_.getSource().changed();
570573
}
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

Comments
 (0)