1 function initializeNotes(map) {
2 var noteLayer = map.noteLayer,
8 iconUrl: "<%= image_path 'new_note_marker.png' %>",
13 iconUrl: "<%= image_path 'open_note_marker.png' %>",
18 iconUrl: "<%= image_path 'closed_note_marker.png' %>",
24 map.on("layeradd", function (e) {
25 if (e.layer == noteLayer) {
27 map.on("moveend", loadNotes);
29 }).on("layerremove", function (e) {
30 if (e.layer == noteLayer) {
31 map.off("moveend", loadNotes);
32 noteLayer.clearLayers();
35 }).on("popupclose", function (e) {
36 if (newNote && e.popup == newNote._popup) {
37 $(newNote).oneTime(10, "removenote", function () {
38 map.removeLayer(newNote);
44 noteLayer.on('click', function(e) {
45 OSM.route('/browse/note/' + e.layer.id);
48 function updateMarker(marker, feature) {
50 marker.setIcon(noteIcons[feature.properties.status]);
52 marker = L.marker(feature.geometry.coordinates.reverse(), {
53 icon: noteIcons[feature.properties.status],
57 marker.id = feature.properties.id;
58 marker.addTo(noteLayer);
63 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 (id in oldNotes) {
96 noteLayer.removeLayer(oldNotes[id]);