1 OSM.initializeNotesLayer = function (map) {
 
   3   const noteLayer = map.noteLayer;
 
   6   noteLayer.on("add", () => {
 
   8     map.on("moveend", loadNotes);
 
   9     map.fire("overlayadd", { layer: noteLayer });
 
  10   }).on("remove", () => {
 
  11     if (noteLoader) noteLoader.abort();
 
  13     map.off("moveend", loadNotes);
 
  14     noteLayer.clearLayers();
 
  16     map.fire("overlayremove", { layer: noteLayer });
 
  17   }).on("click", function (e) {
 
  19       OSM.router.route("/note/" + e.layer.id);
 
  23   function updateMarker(old_marker, feature) {
 
  24     let marker = old_marker;
 
  26       marker.setIcon(OSM.getMarker({ icon: `${feature.properties.status}_NOTE_MARKER`, shadow: false, height: 40 }));
 
  29       const description = feature.properties.comments[0];
 
  31       if (description?.action === "opened") {
 
  32         title = description.text;
 
  35       marker = L.marker(feature.geometry.coordinates.reverse(), {
 
  36         icon: OSM.getMarker({ icon: `${feature.properties.status}_NOTE_MARKER`, shadow: false, height: 40 }),
 
  41       marker.id = feature.properties.id;
 
  42       marker.addTo(noteLayer);
 
  47   noteLayer.getLayerId = function (marker) {
 
  51   function loadNotes() {
 
  52     const bounds = map.getBounds();
 
  53     const size = bounds.getSize();
 
  55     if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
 
  56       const url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
 
  58       if (noteLoader) noteLoader.abort();
 
  60       noteLoader = new AbortController();
 
  61       fetch(url, { signal: noteLoader.signal })
 
  62         .then(response => response.json())
 
  65         .finally(() => noteLoader = null);
 
  68     function success(json) {
 
  69       const oldNotes = notes;
 
  71       for (const feature of json.features) {
 
  72         const marker = oldNotes[feature.properties.id];
 
  73         delete oldNotes[feature.properties.id];
 
  74         notes[feature.properties.id] = updateMarker(marker, feature);
 
  77       for (const id in oldNotes) {
 
  78         noteLayer.removeLayer(oldNotes[id]);