Skip to content

Commit 1120a46

Browse files
committed
feat: add multi line support
1 parent 7574a4b commit 1120a46

11 files changed

Lines changed: 284 additions & 353 deletions

File tree

demos/simple/demo.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ function main() {
6060
style: styleRules,
6161
deleteCondition: deleteCondition,
6262
hitTolerance: 10,
63-
densifier
63+
densifier,
64+
switchPartOnDrag: true,
6465
});
6566

6667
window.trackManager = trackManager;
@@ -133,6 +134,18 @@ function main() {
133134
trackManager.addPOI(event.coordinate);
134135
});
135136
});
137+
138+
document.querySelector('#createNewPart').addEventListener('click', () => {
139+
trackManager.createNewPart();
140+
});
141+
document.querySelector('#changeActivePart').addEventListener('click', () => {
142+
const nextPart = (trackManager.activePart() + 1) % trackManager.partsCount();
143+
trackManager.workOnPart(nextPart);
144+
});
145+
document.querySelector('#deleteActivePart').addEventListener('click', () => {
146+
const activePart = trackManager.activePart();
147+
trackManager.deletePart(activePart);
148+
});
136149
}
137150

138151
main();

demos/simple/simple.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@
5353
<a href="#" id="reverse_no_routing">reverse without re-routing</a>
5454
<br />
5555
<a href="#" id="addPoi">Add poi</a>
56-
</div>
56+
<br />
57+
<a href="#" id="createNewPart">Add a new line string</a>
58+
<br />
59+
<a href="#" id="changeActivePart">Change active line string</a>
60+
<br />
61+
<a href="#" id="deleteActivePart">Delete active line string</a>
62+
</div>
5763
<div id="map"></div>
5864
</main>
5965
</body>

demos/simple/style.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export const sketchControlPoint = {
1111

1212
export const trackLine = {
1313
"stroke-width": 6,
14-
"stroke-color": "purple",
14+
"stroke-color": ["case", ["==", ["get", "active"], false], "#00883c80", "#00883cff"],
15+
"text-value": ["concat", "", ["get", "part"]],
16+
"text-fill-color": "#fff",
1517
};
1618

1719
export const trackLineModifying = {
@@ -27,25 +29,25 @@ export const poiPoint = {
2729
"text-font": "bold 11px Inter",
2830
"text-fill-color": "#000",
2931
// use 'concat' to convert number to string
30-
"text-value": ["concat", ["get", "index"], ""],
32+
"text-value": ["concat", "", ["get", "part"]],
3133
};
3234

3335
export const numberedControlPoint = {
3436
...controlPoint,
3537
"circle-fill-color": "#ffffffdd",
3638
"text-color": "blue",
3739
// use 'concat' to convert number to string
38-
"text-value": ["concat", ["get", "index"], ""],
40+
"text-value": ["concat", "", ["get", "part"]],
3941
};
4042

4143
export const snappedTrue = {
4244
...controlPoint,
43-
"circle-fill-color": "green",
45+
"circle-fill-color": ["case", ["==", ["get", "active"], false], "#0071ec80", "#0071ecff"],
4446
};
4547

4648
export const snappedFalse = {
4749
...controlPoint,
48-
"circle-fill-color": "red",
50+
"circle-fill-color": ["case", ["==", ["get", "active"], false], "#b45f0480", "#b45f04ff"],
4951
};
5052

5153
export const sketchLabel = {

0 commit comments

Comments
 (0)