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(location, text, callback) {
40 url: "/api/0.6/notes.json",
52 function addCreatedNoteMarker(feature) {
53 var marker = L.marker(feature.geometry.coordinates.reverse(), {
54 icon: noteIcons[feature.properties.status],
58 marker.id = feature.properties.id;
59 marker.addTo(noteLayer);
62 function addHalo(latlng) {
63 if (halo) map.removeLayer(halo);
65 halo = L.circleMarker(latlng, {
75 function removeHalo() {
76 if (halo) map.removeLayer(halo);
80 page.pushstate = page.popstate = function (path) {
81 OSM.loadSidebarContent(path, function () {
86 page.load = function (path) {
87 if (addNoteButton.hasClass("disabled")) return;
88 if (addNoteButton.hasClass("active")) return;
90 addNoteButton.addClass("active");
92 map.addLayer(noteLayer);
94 var params = Qs.parse(path.substring(path.indexOf("?") + 1));
97 if (params.lat && params.lon) {
98 markerLatlng = L.latLng(params.lat, params.lon);
100 markerLatlng = map.getCenter();
103 map.panInside(markerLatlng, {
107 newNoteMarker = L.marker(markerLatlng, {
113 newNoteMarker.on("dragstart dragend", function (a) {
115 if (a.type !== "dragstart") {
116 addHalo(newNoteMarker.getLatLng());
120 newNoteMarker.addTo(map);
121 addHalo(newNoteMarker.getLatLng());
123 newNoteMarker.on("remove", function () {
124 addNoteButton.removeClass("active");
125 }).on("dragend", function () {
126 content.find("textarea").focus();
129 content.find("textarea")
130 .on("input", disableWhenBlank)
133 function disableWhenBlank(e) {
134 $(e.target.form.add).prop("disabled", $(e.target).val() === "");
137 content.find("input[type=submit]").on("click", function (e) {
138 const location = newNoteMarker.getLatLng().wrap();
139 const text = content.find("textarea").val();
142 $(this).prop("disabled", true);
143 newNoteMarker.options.draggable = false;
144 newNoteMarker.dragging.disable();
146 createNote(location, text, (feature) => {
147 content.find("textarea").val("");
148 addCreatedNoteMarker(feature);
149 map.removeLayer(newNoteMarker);
150 newNoteMarker = null;
151 addNoteButton.removeClass("active");
152 OSM.router.route("/note/" + feature.properties.id);
156 return map.getState();
159 page.unload = function () {
160 if (newNoteMarker) map.removeLayer(newNoteMarker);
162 addNoteButton.removeClass("active");