|
1 | 1 | import { FontAwesomeControl } from "src/controls/controls";
|
2 | 2 | import t from "src/l10n/locale";
|
3 | 3 | import { Marker } from "src/layer";
|
4 |
| -import { getId } from "src/utils"; |
| 4 | +import { MODIFIER_KEY, getId } from "src/utils"; |
5 | 5 | import { LeafletSymbol } from "src/utils/leaflet-import";
|
6 | 6 | import { BaseDrawControl } from "./base";
|
7 | 7 | import { DrawingController } from "./controller";
|
8 | 8 | import { DrawControl } from "./controls";
|
9 | 9 | import { Shape, ShapeProperties } from "./shape";
|
10 | 10 | import { Vertex, VertexProperties } from "./vertex";
|
| 11 | +import { popup } from "src/map"; |
| 12 | +import { Notice } from "obsidian"; |
11 | 13 |
|
12 | 14 | const L = window[LeafletSymbol];
|
13 | 15 |
|
@@ -44,6 +46,32 @@ export class Polyline extends Shape<L.Polyline> {
|
44 | 46 | if (this.reversed) this.reverseArrows();
|
45 | 47 | this.redraw();
|
46 | 48 | }
|
| 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 | + }); |
47 | 75 | }
|
48 | 76 | triangleEl = L.SVG.create("marker");
|
49 | 77 | pathEl = L.SVG.create("path");
|
|
0 commit comments