mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +08:00
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import type { Map } from "leaflet";
|
|
import library_loader from "../services/library_loader.js";
|
|
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
|
|
|
const TPL = `\
|
|
<div class="geo-map-widget">
|
|
<style>
|
|
.note-detail-geo-map,
|
|
.geo-map-widget,
|
|
.geo-map-container {
|
|
height: 100%;
|
|
overflow: hidden;
|
|
}
|
|
</style>
|
|
|
|
<div class="geo-map-container"></div>
|
|
</div>`
|
|
|
|
export default class GeoMapWidget extends NoteContextAwareWidget {
|
|
|
|
map?: Map;
|
|
private initCallback?: () => void;
|
|
|
|
constructor(widgetMode: "type", initCallback?: () => void) {
|
|
super();
|
|
this.initCallback = initCallback;
|
|
}
|
|
|
|
doRender() {
|
|
this.$widget = $(TPL);
|
|
|
|
const $container = this.$widget.find(".geo-map-container");
|
|
|
|
library_loader.requireLibrary(library_loader.LEAFLET)
|
|
.then(async () => {
|
|
const L = (await import("leaflet")).default;
|
|
|
|
const map = L.map($container[0], {
|
|
|
|
});
|
|
|
|
this.map = map;
|
|
if (this.initCallback) {
|
|
this.initCallback();
|
|
}
|
|
|
|
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
}).addTo(map);
|
|
});
|
|
}
|
|
|
|
}
|