From f29185c914eeae6f40978e3987d0e9b8ad804565 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 11 May 2021 19:33:42 +0200 Subject: [PATCH] Switch from marker popup to item detail card --- static/js/map.js | 30 ++++++++++++++++++++++++------ templates/map.html | 10 ++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/static/js/map.js b/static/js/map.js index bb70b6f..f295f98 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -20,6 +20,7 @@ var osm_loaded = false; var loading = document.getElementById("loading"); var load_text = document.getElementById("load-text"); var isa_card = document.getElementById("isa-card"); +var detail_card = document.getElementById("detail-card"); var checkbox_list = document.getElementsByClassName("isa-checkbox"); var isa_labels = {}; var items_url = "/api/1/items"; @@ -89,6 +90,7 @@ osm.addTo(map); function load_complete() { loading.classList.add("visually-hidden"); load_text.classList.remove("visually-hidden"); + detail_card.classList.add("visually-hidden"); } function add_to_feature_group(qid, thing) { @@ -199,6 +201,7 @@ function checkbox_change() { for (const qid in items) { var item = items[qid]; + if (item.group === undefined) continue; if (item.isa_list === undefined) continue; const item_isa_list = item.isa_list; @@ -206,7 +209,7 @@ function checkbox_change() { item_isa_list.includes(isa_qid) ); - if (item.group && intersection.length) { + if (intersection.length) { item.group.addTo(map); } else { item.group.removeFrom(map); @@ -256,7 +259,7 @@ function set_isa_list(isa_count_list) { }); } -function item_popup(item) { +function build_item_detail(item) { var wd_url = "https://www.wikidata.org/wiki/" + item.qid; var popup = "

Wikidata item
"; @@ -276,7 +279,7 @@ function item_popup(item) { popup += `
`; } if (item.street_address && item.street_address.length) { - popup += `
street address: ${item.street_address[0]["text"]}`; + popup += `
street address
${item.street_address[0]["text"]}`; } popup += "

"; @@ -314,6 +317,13 @@ function mouse_events(marker, qid) { marker.on("mouseout", function () { mouseout(item); }); + marker.on("click", function () { + isa_card.classList.add("visually-hidden"); + detail_card.classList.remove("visually-hidden"); + + var item_detail = build_item_detail(items[qid].wikidata); + detail.innerHTML = item_detail; + }); item.markers ||= []; item.markers.push(marker); @@ -326,12 +336,13 @@ function add_wikidata_marker(item, marker_data) { var marker = L.marker(marker_data, { icon: icon }); // var tooltip = marker.bindTooltip(item.qid, {permanent: true, direction: 'bottom', opacity: 0.5}); - var popup = item_popup(item); - marker.bindPopup(popup); + // var popup = item_popup(item); + // marker.bindPopup(popup); mouse_events(marker, qid); var group = add_to_feature_group(item.qid, marker); group.addTo(map); + items[qid].wikidata = item; marker_data.marker = marker; } @@ -356,6 +367,7 @@ function load_wikidata_items() { checkbox_change(); + detail_card.classList.add("visually-hidden"); loading.classList.remove("visually-hidden"); load_text.classList.add("visually-hidden"); @@ -394,7 +406,7 @@ function load_wikidata_items() {
Wikidata tag: ${qid}

`; - marker.bindPopup(popup); + // marker.bindPopup(popup); mouse_events(marker, qid); var group = add_to_feature_group(qid, marker); @@ -439,5 +451,11 @@ document.getElementById("search-form").onsubmit = function (e) { }); }; +function close_detail() { + isa_card.classList.remove("visually-hidden"); + detail_card.classList.add("visually-hidden"); +} + document.getElementById("load-btn").onclick = load_wikidata_items; document.getElementById("show-all-isa").onclick = show_all_isa; +document.getElementById("close-detail").onclick = close_detail; diff --git a/templates/map.html b/templates/map.html index b40b53c..bb0fb43 100644 --- a/templates/map.html +++ b/templates/map.html @@ -44,6 +44,16 @@ + +
+
+
item detail + +
+
+
+
+