1 OSM.initializeNotesLayer = function (map) {
2 var noteLayer = map.noteLayer,
7 iconUrl: OSM.NEW_NOTE_MARKER,
12 iconUrl: OSM.OPEN_NOTE_MARKER,
17 iconUrl: OSM.CLOSED_NOTE_MARKER,
23 noteLayer.on("add", () => {
25 map.on("moveend", loadNotes);
26 map.fire("overlayadd", { layer: noteLayer });
27 }).on("remove", () => {
28 map.off("moveend", loadNotes);
29 noteLayer.clearLayers();
31 map.fire("overlayremove", { layer: noteLayer });
32 }).on("click", function (e) {
34 OSM.router.route("/note/" + e.layer.id);
38 function updateMarker(old_marker, feature) {
39 var marker = old_marker;
41 marker.setIcon(noteIcons[feature.properties.status]);
44 const description = feature.properties.comments[0];
46 if (description?.action === "opened") {
47 title = description.text;
50 marker = L.marker(feature.geometry.coordinates.reverse(), {
51 icon: noteIcons[feature.properties.status],
56 marker.id = feature.properties.id;
57 marker.addTo(noteLayer);
62 noteLayer.getLayerId = function (marker) {
68 function loadNotes() {
69 var bounds = map.getBounds();
70 var size = bounds.getSize();
72 if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
73 var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
75 if (noteLoader) noteLoader.abort();
83 function success(json) {
86 json.features.forEach(updateMarkers);
88 function updateMarkers(feature) {
89 var marker = oldNotes[feature.properties.id];
90 delete oldNotes[feature.properties.id];
91 notes[feature.properties.id] = updateMarker(marker, feature);
94 for (var id in oldNotes) {
95 noteLayer.removeLayer(oldNotes[id]);