Tidy map.js

This commit is contained in:
Edward Betts 2021-05-09 19:33:02 +02:00
parent 23a58485de
commit 02563beb65

View file

@ -21,11 +21,20 @@ var osm_loaded = false;
var loading = document.getElementById("loading"); var loading = document.getElementById("loading");
var load_text = document.getElementById("load-text"); var load_text = document.getElementById("load-text");
var isa_card = document.getElementById("isa-card"); var isa_card = document.getElementById("isa-card");
var checkbox_list = document.getElementsByClassName("isa-checkbox");
var isa_labels = {}; var isa_labels = {};
var connections = {}; var connections = {};
map.addLayer(group); map.addLayer(group);
map.zoomControl.setPosition("topright"); map.zoomControl.setPosition("topright");
map.on("moveend", function (e) {
var zoom = map.getZoom();
var c = map.getCenter();
var lat = c.lat.toFixed(5);
var lng = c.lng.toFixed(5);
history.replaceState(null, null, `/map/${zoom}/${lat}/${lng}`);
});
var blueMarker = L.ExtraMarkers.icon({ var blueMarker = L.ExtraMarkers.icon({
icon: "fa-wikidata", icon: "fa-wikidata",
markerColor: "blue", markerColor: "blue",
@ -74,16 +83,17 @@ var osm = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
osm.addTo(map); osm.addTo(map);
function load_complete() {
loading.classList.add("visually-hidden");
load_text.classList.remove("visually-hidden");
}
function update_wikidata() { function update_wikidata() {
if ( if (
Object.keys(wikidata_items).length === 0 || Object.keys(wikidata_items).length === 0 ||
Object.keys(osm_objects).length === 0 Object.keys(osm_objects).length === 0
) { ) {
if (wikidata_loaded && osm_loaded) { if (wikidata_loaded && osm_loaded) load_complete();
loading.classList.add("visually-hidden");
load_text.classList.remove("visually-hidden");
}
return; return;
} }
@ -116,8 +126,7 @@ function update_wikidata() {
}); });
} }
loading.classList.add("visually-hidden"); load_complete();
load_text.classList.remove("visually-hidden");
} }
function isa_only(e) { function isa_only(e) {
@ -125,8 +134,6 @@ function isa_only(e) {
var this_id = e.target.parentNode.childNodes[0].id; var this_id = e.target.parentNode.childNodes[0].id;
var checkbox_list = document.getElementsByClassName("isa-checkbox");
for (const checkbox of checkbox_list) { for (const checkbox of checkbox_list) {
checkbox.checked = checkbox.id == this_id; checkbox.checked = checkbox.id == this_id;
} }
@ -136,7 +143,7 @@ function isa_only(e) {
function show_all_isa(e) { function show_all_isa(e) {
e.preventDefault(); e.preventDefault();
var checkbox_list = document.getElementsByClassName("isa-checkbox");
for (const checkbox of checkbox_list) { for (const checkbox of checkbox_list) {
checkbox.checked = true; checkbox.checked = true;
} }
@ -145,12 +152,9 @@ function show_all_isa(e) {
} }
function checkbox_change() { function checkbox_change() {
var checkbox_list = document.getElementsByClassName("isa-checkbox");
var ticked = []; var ticked = [];
for (const checkbox of checkbox_list) { for (const checkbox of checkbox_list) {
if (checkbox.checked) { if (checkbox.checked) ticked.push(checkbox.id.substr(4));
ticked.push(checkbox.id.substr(4));
}
} }
for (const qid in wikidata_items) { for (const qid in wikidata_items) {
@ -340,14 +344,7 @@ function load_wikidata_items() {
}); });
} }
document.getElementById("show-all-isa").onclick = show_all_isa; document.getElementById("search-form").onsubmit = function (e) {
var load_btn = document.getElementById("load-btn");
load_btn.onclick = load_wikidata_items;
var search_btn = document.getElementById("search-btn");
var search_form = document.getElementById("search-form");
search_form.onsubmit = function (e) {
e.preventDefault(); e.preventDefault();
var search_text = document.getElementById("search-text").value.trim(); var search_text = document.getElementById("search-text").value.trim();
if (!search_text) return; if (!search_text) return;
@ -373,10 +370,5 @@ search_form.onsubmit = function (e) {
}); });
}; };
map.on("moveend", function (e) { document.getElementById("load-btn").onclick = load_wikidata_items;
var zoom = map.getZoom(); document.getElementById("show-all-isa").onclick = show_all_isa;
var c = map.getCenter();
var lat = c.lat.toFixed(5);
var lng = c.lng.toFixed(5);
history.replaceState(null, null, `/map/${zoom}/${lat}/${lng}`);
});