Make it so geojson can be toggled

This commit is contained in:
Edward Betts 2021-05-09 08:18:20 +02:00
parent 9e12f66cc6
commit 5cad18c393

View file

@ -13,6 +13,7 @@ if (start_lat || start_lng) {
var map = L.map("map", options);
var group = L.featureGroup();
var items = {};
var wikidata_items = {};
var osm_objects = {};
var wikidata_loaded = false;
@ -218,8 +219,15 @@ function checkbox_change() {
});
}
if(items[qid]) {
items[qid].geojson.forEach(geojson => {
if (intersection.length) {
geojson.addTo(map);
} else {
geojson.removeFrom(map);
}
});
}
}
}
@ -262,35 +270,11 @@ function set_isa_list(isa_count) {
});
}
function load_wikidata_items() {
var checkbox_list = document.getElementsByClassName('isa-checkbox');
for (const checkbox of checkbox_list)
checkbox.checked = true;
checkbox_change();
loading.classList.remove("visually-hidden");
load_text.classList.add("visually-hidden");
var bounds = map.getBounds();
console.log("map moved", bounds.toBBoxString());
// var items_to_check = [];
var params = {bounds: bounds.toBBoxString()};
var items_url = "/api/1/items";
axios.get(items_url, {params: params}).then(response => {
set_isa_list(response.data.isa_count);
var items = response.data.items;
items.forEach(item => {
if (item.qid in wikidata_items)
return;
item.markers.forEach(marker_data => {
// var icon = marker.tagged ? greenMarker : blueMarker;
function add_wikidata_marker(item, marker_data) {
var icon = blueMarker;
var label = `${item.label} (${item.qid})`
var marker = L.marker(marker_data, {title: label, icon: icon});
var marker = L.marker(marker_data, {icon: icon});
// var tooltip = marker.bindTooltip(item.qid, {permanent: true, direction: 'bottom', opacity: 0.5});
var wd_url = 'https://www.wikidata.org/wiki/' + item.qid;
var popup = '<p><strong>Wikidata item</strong><br>'
popup += `<a href="${wd_url}" target="_blank">${item.label}</a> (${item.qid})`
@ -312,20 +296,39 @@ function load_wikidata_items() {
marker.bindPopup(popup);
marker.addTo(group);
marker_data.marker = marker;
});
}
function load_wikidata_items() {
var checkbox_list = document.getElementsByClassName('isa-checkbox');
for (const checkbox of checkbox_list)
checkbox.checked = true;
checkbox_change();
loading.classList.remove("visually-hidden");
load_text.classList.add("visually-hidden");
var bounds = map.getBounds();
console.log("map moved", bounds.toBBoxString());
var params = {bounds: bounds.toBBoxString()};
var items_url = "/api/1/items";
axios.get(items_url, {params: params}).then(response => {
set_isa_list(response.data.isa_count);
var items = response.data.items;
items.forEach(item => {
if (item.qid in wikidata_items)
return;
item.markers.forEach(marker_data => add_wikidata_marker(item, marker_data));
wikidata_items[item.qid] = item;
// items_to_check.push(item);
});
wikidata_loaded = true;
isa_card.classList.remove("visually-hidden");
update_wikidata();
// duration_span.innerText = response.data.duration;
// check_items(items_to_check);
});
var osm_objects_url = "/api/1/osm";
axios.get(osm_objects_url, {params: params}).then(response => {
@ -355,7 +358,13 @@ function load_wikidata_items() {
var geojson = L.geoJSON(null, {style: mapStyle});
geojson.addTo(map);
geojson.addData(osm.geojson);
console.log(osm.geojson);
if (items[qid] === undefined)
items[qid] = {};
if (items[qid].geojson === undefined)
items[qid].geojson = [];
items[qid].geojson.push(geojson);
}
});