Skip to content

Commit 6bc541f

Browse files
committed
feat: can alt-click to measure polylines from drawing
1 parent 2095f33 commit 6bc541f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/draw/polyline.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { FontAwesomeControl } from "src/controls/controls";
22
import t from "src/l10n/locale";
33
import { Marker } from "src/layer";
4-
import { getId } from "src/utils";
4+
import { MODIFIER_KEY, getId } from "src/utils";
55
import { LeafletSymbol } from "src/utils/leaflet-import";
66
import { BaseDrawControl } from "./base";
77
import { DrawingController } from "./controller";
88
import { DrawControl } from "./controls";
99
import { Shape, ShapeProperties } from "./shape";
1010
import { Vertex, VertexProperties } from "./vertex";
11+
import { popup } from "src/map";
12+
import { Notice } from "obsidian";
1113

1214
const L = window[LeafletSymbol];
1315

@@ -44,6 +46,32 @@ export class Polyline extends Shape<L.Polyline> {
4446
if (this.reversed) this.reverseArrows();
4547
this.redraw();
4648
}
49+
this.leafletInstance.on("click", (evt: L.LeafletMouseEvent) => {
50+
console.log("🚀 ~ file: polyline.ts:48 ~ evt:", evt);
51+
if (
52+
evt.originalEvent.getModifierState(MODIFIER_KEY) &&
53+
this.vertices.length > 1
54+
) {
55+
const notice = [];
56+
let total = 0;
57+
for (let i = 1; i < this.vertices.length; i++) {
58+
let dist = this.map.distance(
59+
this.vertices[i - 1].latlng,
60+
this.vertices[i].latlng
61+
);
62+
notice.push(dist);
63+
total += Number(dist.replace(/[^\d\.]/g, ""));
64+
}
65+
if (notice.length) {
66+
new Notice(
67+
`${notice.join("\n")}\n\nTotal: ${total} ${
68+
this.map.unit
69+
}`
70+
);
71+
}
72+
this.map.distanceDisplay.setText(`${total} ${this.map.unit}`);
73+
}
74+
});
4775
}
4876
triangleEl = L.SVG.create("marker");
4977
pathEl = L.SVG.create("path");

0 commit comments

Comments
 (0)