From: Anton Khorev Date: Wed, 29 Jan 2025 14:57:26 +0000 (+0300) Subject: Show only description as a marker tooltip in note layer X-Git-Tag: live~42^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/db0858732511ee56d8d94f3b56cdaf3cd18d6ad8 Show only description as a marker tooltip in note layer --- diff --git a/app/assets/javascripts/index/layers/notes.js b/app/assets/javascripts/index/layers/notes.js index c0ba35d7e..1068472d5 100644 --- a/app/assets/javascripts/index/layers/notes.js +++ b/app/assets/javascripts/index/layers/notes.js @@ -40,9 +40,16 @@ OSM.initializeNotesLayer = function (map) { if (marker) { marker.setIcon(noteIcons[feature.properties.status]); } else { + let title; + const description = feature.properties.comments[0]; + + if (description?.action === "opened") { + title = description.text; + } + marker = L.marker(feature.geometry.coordinates.reverse(), { icon: noteIcons[feature.properties.status], - title: feature.properties.comments[0].text, + title, opacity: 0.8, interactive: true }); diff --git a/test/system/note_layer_test.rb b/test/system/note_layer_test.rb new file mode 100644 index 000000000..792c3416d --- /dev/null +++ b/test/system/note_layer_test.rb @@ -0,0 +1,40 @@ +require "application_system_test_case" + +class NoteLayerTest < ApplicationSystemTestCase + test "note marker should have description as a title" do + position = (1.1 * GeoRecord::SCALE).to_i + create(:note, :latitude => position, :longitude => position) do |note| + create(:note_comment, :note => note, :body => "Note description") + end + + visit root_path(:anchor => "map=18/1.1/1.1&layers=N") + all "img.leaflet-marker-icon", :count => 1 do |marker| + assert_equal "Note description", marker["title"] + end + end + + test "note marker should not have a title if the note has no visible description" do + position = (1.1 * GeoRecord::SCALE).to_i + create(:note, :latitude => position, :longitude => position) do |note| + create(:note_comment, :note => note, :body => "Note description is hidden", :visible => false) + create(:note_comment, :note => note, :body => "Note comment visible", :event => "commented") + end + + visit root_path(:anchor => "map=18/1.1/1.1&layers=N") + all "img.leaflet-marker-icon", :count => 1 do |marker| + assert_equal "", marker["title"] + end + end + + test "note marker should not have a title if the note has no visible description and comments" do + position = (1.1 * GeoRecord::SCALE).to_i + create(:note, :latitude => position, :longitude => position) do |note| + create(:note_comment, :note => note, :body => "Note description is hidden", :visible => false) + end + + visit root_path(:anchor => "map=18/1.1/1.1&layers=N") + all "img.leaflet-marker-icon", :count => 1 do |marker| + assert_equal "", marker["title"] + end + end +end