1 OSM.initializeNotes = 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 map.on("layeradd", function (e) {
24 if (e.layer === noteLayer) {
26 map.on("moveend", loadNotes);
28 }).on("layerremove", function (e) {
29 if (e.layer === noteLayer) {
30 map.off("moveend", loadNotes);
31 noteLayer.clearLayers();
36 noteLayer.on("click", function (e) {
38 OSM.router.route("/note/" + e.layer.id);
42 function updateMarker(old_marker, feature) {
43 var marker = old_marker;
45 marker.setIcon(noteIcons[feature.properties.status]);
47 marker = L.marker(feature.geometry.coordinates.reverse(), {
48 icon: noteIcons[feature.properties.status],
49 title: feature.properties.comments[0].text,
53 marker.id = feature.properties.id;
54 marker.addTo(noteLayer);
59 noteLayer.getLayerId = function (marker) {
65 function loadNotes() {
66 var bounds = map.getBounds();
67 var size = bounds.getSize();
69 if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
70 var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
72 if (noteLoader) noteLoader.abort();
80 function success(json) {
83 json.features.forEach(updateMarkers);
85 function updateMarkers(feature) {
86 var marker = oldNotes[feature.properties.id];
87 delete oldNotes[feature.properties.id];
88 notes[feature.properties.id] = updateMarker(marker, feature);
91 for (var id in oldNotes) {
92 noteLayer.removeLayer(oldNotes[id]);