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 var 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 var bounds = map.getBounds();
71 var size = bounds.getSize();
73 if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
74 var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
76 if (noteLoader) noteLoader.abort();
84 function success(json) {
87 json.features.forEach(updateMarkers);
89 function updateMarkers(feature) {
90 var marker = oldNotes[feature.properties.id];
91 delete oldNotes[feature.properties.id];
92 notes[feature.properties.id] = updateMarker(marker, feature);
95 for (var id in oldNotes) {
96 noteLayer.removeLayer(oldNotes[id]);