1 OSM.initializeNotesLayer = function (map) {
3 const noteLayer = map.noteLayer;
8 iconUrl: OSM.NEW_NOTE_MARKER,
13 iconUrl: OSM.OPEN_NOTE_MARKER,
18 iconUrl: OSM.CLOSED_NOTE_MARKER,
24 noteLayer.on("add", () => {
26 map.on("moveend", loadNotes);
27 map.fire("overlayadd", { layer: noteLayer });
28 }).on("remove", () => {
29 if (noteLoader) noteLoader.abort();
31 map.off("moveend", loadNotes);
32 noteLayer.clearLayers();
34 map.fire("overlayremove", { layer: noteLayer });
35 }).on("click", function (e) {
37 OSM.router.route("/note/" + e.layer.id);
41 function updateMarker(old_marker, feature) {
42 let marker = old_marker;
44 marker.setIcon(noteIcons[feature.properties.status]);
47 const description = feature.properties.comments[0];
49 if (description?.action === "opened") {
50 title = description.text;
53 marker = L.marker(feature.geometry.coordinates.reverse(), {
54 icon: noteIcons[feature.properties.status],
59 marker.id = feature.properties.id;
60 marker.addTo(noteLayer);
65 noteLayer.getLayerId = function (marker) {
69 function loadNotes() {
70 const bounds = map.getBounds();
71 const size = bounds.getSize();
73 if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
74 const url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
76 if (noteLoader) noteLoader.abort();
78 noteLoader = new AbortController();
79 fetch(url, { signal: noteLoader.signal })
80 .then(response => response.json())
83 .finally(() => noteLoader = null);
86 function success(json) {
87 const oldNotes = notes;
89 for (const feature of json.features) {
90 const marker = oldNotes[feature.properties.id];
91 delete oldNotes[feature.properties.id];
92 notes[feature.properties.id] = updateMarker(marker, feature);
95 for (const id in oldNotes) {
96 noteLayer.removeLayer(oldNotes[id]);