3 OSM.NewNote = function (map) {
4 var noteLayer = map.noteLayer,
5 content = $("#sidebar_content"),
7 addNoteButton = $(".control-note .control-button"),
13 iconUrl: OSM.NEW_NOTE_MARKER,
18 iconUrl: OSM.OPEN_NOTE_MARKER,
23 iconUrl: OSM.CLOSED_NOTE_MARKER,
29 addNoteButton.on("click", function (e) {
33 if ($(this).hasClass("disabled")) return;
35 OSM.router.route("/note/new");
38 function createNote(marker, form, url) {
39 var location = marker.getLatLng().wrap();
41 marker.options.draggable = false;
42 marker.dragging.disable();
44 $(form).find("input[type=submit]").prop("disabled", true);
53 text: $(form.text).val()
55 success: function (feature) {
56 noteCreated(feature, marker);
60 function noteCreated(feature, marker) {
61 content.find("textarea").val("");
62 updateMarker(feature);
64 noteLayer.removeLayer(marker);
65 addNoteButton.removeClass("active");
66 OSM.router.route("/note/" + feature.properties.id);
70 function updateMarker(feature) {
71 var marker = L.marker(feature.geometry.coordinates.reverse(), {
72 icon: noteIcons[feature.properties.status],
76 marker.id = feature.properties.id;
77 marker.addTo(noteLayer);
81 page.pushstate = page.popstate = function (path) {
82 OSM.loadSidebarContent(path, function () {
87 function newHalo(loc, a) {
88 if (a === "dragstart" && map.hasLayer(halo)) {
89 map.removeLayer(halo);
91 if (map.hasLayer(halo)) map.removeLayer(halo);
93 halo = L.circleMarker(loc, {
104 page.load = function (path) {
105 if (addNoteButton.hasClass("disabled")) return;
106 if (addNoteButton.hasClass("active")) return;
108 addNoteButton.addClass("active");
110 map.addLayer(noteLayer);
112 var params = Qs.parse(path.substring(path.indexOf("?") + 1));
115 if (params.lat && params.lon) {
116 markerLatlng = L.latLng(params.lat, params.lon);
118 markerLatlng = map.getCenter();
121 map.panInside(markerLatlng, {
125 newNote = L.marker(markerLatlng, {
131 newNote.on("dragstart dragend", function (a) {
132 newHalo(newNote.getLatLng(), a.type);
135 newNote.addTo(noteLayer);
136 newHalo(newNote.getLatLng());
138 newNote.on("remove", function () {
139 addNoteButton.removeClass("active");
140 }).on("dragstart", function () {
141 $(newNote).stopTime("removenote");
142 }).on("dragend", function () {
143 content.find("textarea").focus();
146 content.find("textarea")
147 .on("input", disableWhenBlank)
150 function disableWhenBlank(e) {
151 $(e.target.form.add).prop("disabled", $(e.target).val() === "");
154 content.find("input[type=submit]").on("click", function (e) {
156 createNote(newNote, e.target.form, "/api/0.6/notes.json");
159 return map.getState();
162 page.unload = function () {
163 noteLayer.removeLayer(newNote);
164 map.removeLayer(halo);
165 addNoteButton.removeClass("active");