refactor(geo_map): extract build icon into method

This commit is contained in:
Elian Doran 2025-02-02 11:07:28 +02:00
parent 6cd2a16155
commit 3911c0c22b
No known key found for this signature in database

View File

@ -204,9 +204,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
const xmlResponse = await server.get<XMLDocument>(`notes/${note.noteId}/open`); const xmlResponse = await server.get<XMLDocument>(`notes/${note.noteId}/open`);
const stringResponse = new XMLSerializer().serializeToString(xmlResponse); const stringResponse = new XMLSerializer().serializeToString(xmlResponse);
const track = new this.L.GPX(stringResponse, { const track = new this.L.GPX(stringResponse, {});
});
track.addTo(this.geoMapWidget.map); track.addTo(this.geoMapWidget.map);
this.currentTrackData[note.noteId] = track; this.currentTrackData[note.noteId] = track;
} }
@ -219,15 +217,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
const [ lat, lng ] = latLng.split(",", 2).map((el) => parseFloat(el)); const [ lat, lng ] = latLng.split(",", 2).map((el) => parseFloat(el));
const L = this.L; const L = this.L;
const icon = L.divIcon({ const icon = this.#buildIcon(note.getIcon(), note.title);
html: `\
<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" />
<span class="bx ${note.getIcon()}"></span>
<span class="title-label">${note.title}</span>`,
iconSize: [ 25, 41 ],
iconAnchor: [ 12, 41 ]
})
const marker = L.marker(L.latLng(lat, lng), { const marker = L.marker(L.latLng(lat, lng), {
icon, icon,
@ -254,6 +244,18 @@ export default class GeoMapTypeWidget extends TypeWidget {
this.currentMarkerData[note.noteId] = marker; this.currentMarkerData[note.noteId] = marker;
} }
#buildIcon(bxIconClass: string, title: string) {
return this.L.divIcon({
html: `\
<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" />
<span class="bx ${bxIconClass}"></span>
<span class="title-label">${title}</span>`,
iconSize: [ 25, 41 ],
iconAnchor: [ 12, 41 ]
})
}
#changeState(newState: State) { #changeState(newState: State) {
this._state = newState; this._state = newState;
this.geoMapWidget.$container.toggleClass("placing-note", newState === State.NewNote); this.geoMapWidget.$container.toggleClass("placing-note", newState === State.NewNote);