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(marker, feature) {
44 marker.setIcon(noteIcons[feature.properties.status]);
46 marker = L.marker(feature.geometry.coordinates.reverse(), {
47 icon: noteIcons[feature.properties.status],
51 marker.id = feature.properties.id;
52 marker.addTo(noteLayer);
57 noteLayer.getLayerId = function(marker) {
63 function loadNotes() {
64 var bounds = map.getBounds();
65 var size = bounds.getSize();
67 if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
68 var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
70 if (noteLoader) noteLoader.abort();
78 function success(json) {
81 json.features.forEach(updateMarkers);
83 function updateMarkers(feature) {
84 var marker = oldNotes[feature.properties.id];
85 delete oldNotes[feature.properties.id];
86 notes[feature.properties.id] = updateMarker(marker, feature);
89 for (var id in oldNotes) {
90 noteLayer.removeLayer(oldNotes[id]);