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, function () {
85 function newHalo(loc, a) {
86 if (a === "dragstart" && map.hasLayer(halo)) {
87 map.removeLayer(halo);
89 if (map.hasLayer(halo)) map.removeLayer(halo);
91 halo = L.circleMarker(loc, {
102 page.load = function (path) {
103 if (addNoteButton.hasClass("disabled")) return;
104 if (addNoteButton.hasClass("active")) return;
106 addNoteButton.addClass("active");
108 map.addLayer(noteLayer);
110 var params = querystring.parse(path.substring(path.indexOf("?") + 1));
113 if (params.lat && params.lon) {
114 markerLatlng = L.latLng(params.lat, params.lon);
116 markerLatlng = map.getCenter();
119 map.panInside(markerLatlng, {
123 newNote = L.marker(markerLatlng, {
129 newNote.on("dragstart dragend", function(a) {
130 newHalo(newNote.getLatLng(), a.type);
133 newNote.addTo(noteLayer);
134 newHalo(newNote.getLatLng());
136 newNote.on("remove", function () {
137 addNoteButton.removeClass("active");
138 }).on("dragstart",function () {
139 $(newNote).stopTime("removenote");
140 }).on("dragend", function () {
141 content.find("textarea").focus();
144 content.find("textarea")
145 .on("input", disableWhenBlank)
148 function disableWhenBlank(e) {
149 $(e.target.form.add).prop("disabled", $(e.target).val() === "");
152 content.find("input[type=submit]").on("click", function (e) {
154 createNote(newNote, e.target.form, "/api/0.6/notes.json");
157 return map.getState();
160 page.unload = function () {
161 noteLayer.removeLayer(newNote);
162 map.removeLayer(halo);
163 addNoteButton.removeClass("active");