Skip to content

Commit 51dcf86

Browse files
committed
Remove the "new note" marker when the user clicks somewhere else
1 parent b97fe91 commit 51dcf86

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

app/assets/javascripts/index/notes.js.erb

+18-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ $(document).ready(function () {
2424

2525
var noteLayer = new L.LayerGroup();
2626
var notes = {};
27+
var newNote;
2728

2829
map.on("layeradd", function (e) {
2930
if (e.layer == noteLayer) {
@@ -39,6 +40,14 @@ $(document).ready(function () {
3940
}
4041
});
4142

43+
map.on("popupclose", function (e) {
44+
if (e.popup == newNote._popup) {
45+
$(newNote).oneTime(10, "removenote", function () {
46+
map.removeLayer(newNote);
47+
});
48+
}
49+
});
50+
4251
if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
4352
map.layersControl.addOverlay(noteLayer, I18n.t("browse.start_rjs.notes_layer_name"));
4453

@@ -217,7 +226,7 @@ $(document).ready(function () {
217226
markerPosition = [mapSize.x / 2, mapSize.y];
218227
}
219228

220-
var marker = L.marker(map.containerPointToLatLng(markerPosition), {
229+
newNote = L.marker(map.containerPointToLatLng(markerPosition), {
221230
icon: noteIcons["new"],
222231
opacity: 0.7,
223232
draggable: true
@@ -237,18 +246,20 @@ $(document).ready(function () {
237246

238247
popupContent.find("input[type=submit]").on("click", function (e) {
239248
e.preventDefault();
240-
createNote(marker, e.target.form, $(e.target).data("url"));
249+
createNote(newNote, e.target.form, $(e.target).data("url"));
241250
});
242251

243-
marker.addTo(noteLayer).bindPopup(popupContent[0], popupOptions()).openPopup();
244-
245-
$(".leaflet-popup-close-button").on("click.close", function (e) {
246-
map.removeLayer(marker);
252+
newNote.addTo(noteLayer).bindPopup(popupContent[0], popupOptions()).openPopup();
247253

254+
newNote.on("remove", function (e) {
248255
$("#createnoteanchor").removeClass("disabled").addClass("geolink");
249256
});
250257

251-
marker.on("dragend", function (e) {
258+
newNote.on("dragstart", function (e) {
259+
$(newNote).stopTime("removenote");
260+
});
261+
262+
newNote.on("dragend", function (e) {
252263
e.target.openPopup();
253264
});
254265
});

0 commit comments

Comments
 (0)