From 48ee6f9bd5f63d7e3b0b2da4d0e8fa0d02e82416 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 15 May 2021 16:07:29 +0200 Subject: [PATCH] Show OSM/Wikidata link status --- static/js/map.js | 64 +++++++++++++++++++++++++++++++++++++++++----- templates/map.html | 12 +++++++++ 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/static/js/map.js b/static/js/map.js index 936894b..195dc55 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -19,6 +19,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 link_status_card = document.getElementById("link-status-card"); var detail_card = document.getElementById("detail-card"); var detail = document.getElementById("detail"); var detail_header = document.getElementById("detail-header"); @@ -26,6 +27,10 @@ var search_and_isa = document.getElementById("search-and-isa"); var detail_qid; var candidates = document.getElementById("candidates"); var checkbox_list = document.getElementsByClassName("isa-checkbox"); + +var linked = document.getElementById("linked"); +var not_linked = document.getElementById("not-linked"); + var nearby_lookup = {}; var isa_labels = {}; var items_url = "/api/1/items"; @@ -168,6 +173,9 @@ function update_wikidata(check_for_missing = true) { } } + var linked_count = 0; + var not_linked_count = 0; + for (const qid in osm_objects) { var osm_list = osm_objects[qid]; @@ -191,15 +199,23 @@ function update_wikidata(check_for_missing = true) { }); } for (const qid in wikidata_items) { - if (osm_objects[qid]) continue; + if (osm_objects[qid]) { + linked_count += 1; + continue; + } + not_linked_count += 1; var item = wikidata_items[qid]; item.markers.forEach((marker_data) => { marker_data.marker.setIcon(redMarker); }); } + document.getElementById("linked-count").textContent = linked_count; + document.getElementById("not-linked-count").textContent = not_linked_count; + var isa_count_values = Object.values(isa_count); set_isa_list(isa_count_values); + link_status_card.classList.remove("d-none"); load_complete(); } @@ -234,14 +250,30 @@ 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; - const intersection = ticked.filter((isa_qid) => - item_isa_list.includes(isa_qid) - ); - if (intersection.length) { + var show_item = true; + + if (osm_objects[qid] && !linked.checked) { + show_item = false; + } + + if (!osm_objects[qid] && !not_linked.checked) { + show_item = false; + } + + if (show_item) { + const item_isa_list = item.isa_list; + const intersection = ticked.filter((isa_qid) => + item_isa_list.includes(isa_qid) + ); + + if (intersection.length == 0) { + show_item = false; + } + } + + if (show_item) { item.group.addTo(map); } else { item.group.removeFrom(map); @@ -249,6 +281,18 @@ function checkbox_change() { } } +function link_status_change() { + if (!linked.checked && !not_linked.checked) { + for (const qid in items) { + var item = items[qid]; + item.group.removeFrom(map); + } + } + + + +} + function set_isa_list(isa_count_list) { isa_count_list.sort((a, b) => b.count - a.count); @@ -543,6 +587,8 @@ function load_wikidata_items() { var checkbox_list = document.getElementsByClassName("isa-checkbox"); for (const checkbox of checkbox_list) checkbox.checked = true; + linked.checked = true; + not_linked.checked = true; checkbox_change(); @@ -566,6 +612,7 @@ function load_wikidata_items() { wikidata_loaded = true; isa_card.classList.remove("d-none"); + link_status_card.classList.remove("d-none"); update_wikidata(); }); @@ -647,6 +694,9 @@ document.getElementById("load-btn").onclick = load_wikidata_items; document.getElementById("show-all-isa").onclick = show_all_isa; document.getElementById("close-detail").onclick = close_detail; +linked.onchange = checkbox_change; +not_linked.onchange = checkbox_change; + detail_qid = qid_from_url(); update_map_path(); diff --git a/templates/map.html b/templates/map.html index 29e7730..c23d12d 100644 --- a/templates/map.html +++ b/templates/map.html @@ -37,6 +37,18 @@ + +
item types