mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-03 14:19:58 +08:00
refactor(geo_map): move marker processing to dedicated method
This commit is contained in:
parent
bd638b689f
commit
211b557920
@ -159,9 +159,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async #reloadMarkers() {
|
async #reloadMarkers() {
|
||||||
const map = this.geoMapWidget.map;
|
if (!this.note) {
|
||||||
|
|
||||||
if (!this.note || !map) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,48 +171,55 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
// Add the new markers.
|
// Add the new markers.
|
||||||
this.currentMarkerData = {};
|
this.currentMarkerData = {};
|
||||||
const childNotes = await this.note.getChildNotes();
|
const childNotes = await this.note.getChildNotes();
|
||||||
const L = this.L;
|
|
||||||
for (const childNote of childNotes) {
|
for (const childNote of childNotes) {
|
||||||
const latLng = childNote.getAttributeValue("label", LOCATION_ATTRIBUTE);
|
const latLng = childNote.getAttributeValue("label", LOCATION_ATTRIBUTE);
|
||||||
if (!latLng) {
|
if (latLng) {
|
||||||
continue;
|
this.#processNoteWithMarker(childNote, latLng);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const [ lat, lng ] = latLng.split(",", 2).map((el) => parseFloat(el));
|
#processNoteWithMarker(note: FNote, latLng: string) {
|
||||||
const icon = L.divIcon({
|
const map = this.geoMapWidget.map;
|
||||||
html: `\
|
if (!map) {
|
||||||
<img class="icon" src="${asset_path}/node_modules/leaflet/dist/images/marker-icon.png" />
|
return;
|
||||||
<img class="icon-shadow" src="${asset_path}/node_modules/leaflet/dist/images/marker-shadow.png" />
|
}
|
||||||
<span class="bx ${childNote.getIcon()}"></span>
|
|
||||||
<span class="title-label">${childNote.title}</span>`,
|
|
||||||
iconSize: [ 25, 41 ],
|
|
||||||
iconAnchor: [ 12, 41 ]
|
|
||||||
})
|
|
||||||
|
|
||||||
const marker = L.marker(L.latLng(lat, lng), {
|
const [ lat, lng ] = latLng.split(",", 2).map((el) => parseFloat(el));
|
||||||
icon,
|
const L = this.L;
|
||||||
draggable: true,
|
const icon = L.divIcon({
|
||||||
autoPan: true,
|
html: `\
|
||||||
autoPanSpeed: 5,
|
<img class="icon" src="${asset_path}/node_modules/leaflet/dist/images/marker-icon.png" />
|
||||||
})
|
<img class="icon-shadow" src="${asset_path}/node_modules/leaflet/dist/images/marker-shadow.png" />
|
||||||
.addTo(map)
|
<span class="bx ${note.getIcon()}"></span>
|
||||||
.on("moveend", e => {
|
<span class="title-label">${note.title}</span>`,
|
||||||
this.moveMarker(childNote.noteId, (e.target as Marker).getLatLng());
|
iconSize: [ 25, 41 ],
|
||||||
});
|
iconAnchor: [ 12, 41 ]
|
||||||
|
})
|
||||||
|
|
||||||
marker.on("contextmenu", (e) => {
|
const marker = L.marker(L.latLng(lat, lng), {
|
||||||
openContextMenu(childNote.noteId, e.originalEvent);
|
icon,
|
||||||
|
draggable: true,
|
||||||
|
autoPan: true,
|
||||||
|
autoPanSpeed: 5,
|
||||||
|
})
|
||||||
|
.addTo(map)
|
||||||
|
.on("moveend", e => {
|
||||||
|
this.moveMarker(note.noteId, (e.target as Marker).getLatLng());
|
||||||
});
|
});
|
||||||
|
|
||||||
const el = marker.getElement();
|
marker.on("contextmenu", (e) => {
|
||||||
if (el) {
|
openContextMenu(note.noteId, e.originalEvent);
|
||||||
const $el = $(el);
|
});
|
||||||
$el.attr("data-href", `#${childNote.noteId}`);
|
|
||||||
note_tooltip.setupElementTooltip($($el));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.currentMarkerData[childNote.noteId] = marker;
|
const el = marker.getElement();
|
||||||
|
if (el) {
|
||||||
|
const $el = $(el);
|
||||||
|
$el.attr("data-href", `#${note.noteId}`);
|
||||||
|
note_tooltip.setupElementTooltip($($el));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.currentMarkerData[note.noteId] = marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
#changeState(newState: State) {
|
#changeState(newState: State) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user