X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/6618cb9019687c8c2edf74698f84b385c0d9edd6..e4504399ae55525f22a7fb47e0c47434cef8cf0a:/app/assets/javascripts/index/notes.js.erb diff --git a/app/assets/javascripts/index/notes.js.erb b/app/assets/javascripts/index/notes.js.erb index 93b60c3e7..75ca5ad50 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -1,7 +1,7 @@ //= require templates/notes/show //= require templates/notes/new -function initializeNotes(map, params) { +function initializeNotes(map) { var noteLayer = map.noteLayer, notes = {}, newNote; @@ -48,23 +48,17 @@ function initializeNotes(map, params) { } }); - if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') { - if (params.layers.indexOf(noteLayer.options.code) >= 0) { - map.addLayer(noteLayer); - } - - if (params.note) { - $.ajax({ - url: "/api/" + OSM.API_VERSION + "/notes/" + params.note + ".json", - success: function (feature) { - var marker = updateMarker(notes[feature.properties.id], feature); - notes[feature.properties.id] = marker; - map.addLayer(noteLayer); - marker.openPopup(); - } - }); - } - } + noteLayer.showNote = function(id) { + $.ajax({ + url: "/api/" + OSM.API_VERSION + "/notes/" + id + ".json", + success: function (feature) { + var marker = updateMarker(notes[feature.properties.id], feature); + notes[feature.properties.id] = marker; + map.addLayer(noteLayer); + marker.openPopup(); + } + }); + }; function updateMarker(marker, feature) { if (marker) { @@ -78,6 +72,7 @@ function initializeNotes(map, params) { icon: noteIcons[feature.properties.status], opacity: 0.9 }); + marker.id = feature.properties.id; marker.addTo(noteLayer).bindPopup( createPopupContent(marker, feature.properties), popupOptions() @@ -86,6 +81,10 @@ function initializeNotes(map, params) { return marker; } + noteLayer.getLayerId = function(marker) { + return marker.id; + }; + var noteLoader; function loadNotes() { @@ -190,7 +189,7 @@ function initializeNotes(map, params) { notes[feature.properties.id] = updateMarker(marker, feature); newNote = null; - addNoteButton.removeClass("disabled").addClass("geolink"); + addNoteButton.removeClass("active"); } } @@ -224,8 +223,9 @@ function initializeNotes(map, params) { e.stopPropagation(); if (addNoteButton.hasClass("disabled")) return; + if (addNoteButton.hasClass("active")) return; - addNoteButton.removeClass("geolink").addClass("disabled"); + addNoteButton.addClass("active"); map.addLayer(noteLayer); @@ -262,7 +262,7 @@ function initializeNotes(map, params) { newNote.addTo(noteLayer).bindPopup(popupContent[0], popupOptions()).openPopup(); newNote.on("remove", function (e) { - addNoteButton.removeClass("disabled").addClass("geolink"); + addNoteButton.removeClass("active"); }).on("dragstart", function (e) { $(newNote).stopTime("removenote"); }).on("dragend", function (e) {