1 OSM.NewNote = function(map) {
2 var noteLayer = map.noteLayer,
3 content = $('#sidebar_content'),
5 addNoteButton = $(".control-note .control-button"),
11 iconUrl: OSM.NEW_NOTE_MARKER,
16 iconUrl: OSM.OPEN_NOTE_MARKER,
21 iconUrl: OSM.CLOSED_NOTE_MARKER,
27 addNoteButton.on("click", function (e) {
31 if ($(this).hasClass('disabled')) return;
33 OSM.router.route('/note/new');
36 function createNote(marker, form, url) {
37 var location = marker.getLatLng().wrap();
39 marker.options.draggable = false;
40 marker.dragging.disable();
42 $(form).find("input[type=submit]").prop("disabled", true);
51 text: $(form.text).val()
53 success: function (feature) {
54 noteCreated(feature, marker);
58 function noteCreated(feature, marker) {
59 content.find("textarea").val("");
60 updateMarker(feature);
62 noteLayer.removeLayer(marker);
63 addNoteButton.removeClass("active");
64 OSM.router.route('/note/' + feature.properties.id);
68 function updateMarker(feature) {
69 var marker = L.marker(feature.geometry.coordinates.reverse(), {
70 icon: noteIcons[feature.properties.status],
74 marker.id = feature.properties.id;
75 marker.addTo(noteLayer);
79 page.pushstate = page.popstate = function (path) {
80 OSM.loadSidebarContent(path, page.load);
83 function newHalo(loc, a) {
84 if (a === 'dragstart' && map.hasLayer(halo)) {
85 map.removeLayer(halo);
87 if (map.hasLayer(halo)) map.removeLayer(halo);
89 halo = L.circleMarker(loc, {
100 page.load = function () {
101 if (addNoteButton.hasClass("disabled")) return;
102 if (addNoteButton.hasClass("active")) return;
104 addNoteButton.addClass("active");
106 map.addLayer(noteLayer);
108 var mapSize = map.getSize();
111 markerPosition = [mapSize.x / 2, mapSize.y / 2];
113 newNote = L.marker(map.containerPointToLatLng(markerPosition), {
114 icon: noteIcons["new"],
119 newNote.on("dragstart dragend", function(a) {
120 newHalo(newNote.getLatLng(), a.type);
123 newNote.addTo(noteLayer);
124 newHalo(newNote.getLatLng());
126 newNote.on("remove", function () {
127 addNoteButton.removeClass("active");
128 }).on("dragstart",function () {
129 $(newNote).stopTime("removenote");
130 }).on("dragend", function () {
131 content.find("textarea").focus();
134 content.find("textarea")
135 .on("input", disableWhenBlank)
138 function disableWhenBlank(e) {
139 $(e.target.form.add).prop("disabled", $(e.target).val() === "");
142 content.find('input[type=submit]').on('click', function (e) {
144 createNote(newNote, e.target.form, '/api/0.6/notes.json');
147 return map.getState();
150 page.unload = function () {
151 noteLayer.removeLayer(newNote);
152 map.removeLayer(halo);
153 addNoteButton.removeClass("active");