1 function initializeNotes(map) {
2 var noteLayer = map.noteLayer,
7 iconUrl: "<%= image_path 'new_note_marker.png' %>",
12 iconUrl: "<%= image_path 'open_note_marker.png' %>",
17 iconUrl: "<%= image_path 'closed_note_marker.png' %>",
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) {
37 OSM.router.route('/note/' + e.layer.id);
40 function updateMarker(marker, feature) {
42 marker.setIcon(noteIcons[feature.properties.status]);
44 marker = L.marker(feature.geometry.coordinates.reverse(), {
45 icon: noteIcons[feature.properties.status],
49 marker.id = feature.properties.id;
50 marker.addTo(noteLayer);
55 noteLayer.getLayerId = function(marker) {
61 function loadNotes() {
62 var bounds = map.getBounds();
63 var size = bounds.getSize();
65 if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
66 var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
68 if (noteLoader) noteLoader.abort();
76 function success(json) {
79 json.features.forEach(updateMarkers);
81 function updateMarkers(feature) {
82 var marker = oldNotes[feature.properties.id];
83 delete oldNotes[feature.properties.id];
84 notes[feature.properties.id] = updateMarker(marker, feature);
87 for (var id in oldNotes) {
88 noteLayer.removeLayer(oldNotes[id]);