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],
48 title: feature.properties.comments[0].text,
52 marker.id = feature.properties.id;
53 marker.addTo(noteLayer);
58 noteLayer.getLayerId = function(marker) {
64 function loadNotes() {
65 var bounds = map.getBounds();
66 var size = bounds.getSize();
68 if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
69 var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
71 if (noteLoader) noteLoader.abort();
79 function success(json) {
82 json.features.forEach(updateMarkers);
84 function updateMarkers(feature) {
85 var marker = oldNotes[feature.properties.id];
86 delete oldNotes[feature.properties.id];
87 notes[feature.properties.id] = updateMarker(marker, feature);
90 for (var id in oldNotes) {
91 noteLayer.removeLayer(oldNotes[id]);