Public
Edited
Oct 16, 2023
Paused
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
coords = refresh
? new Promise((resolve, reject) => {
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(
(pos) => resolve(pos.coords),
(err) => reject(Error(err.message))
);
else reject(Error("this browser does not support geolocation."));
})
: new Promise((resolve, reject) => {
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(
(pos) => resolve(pos.coords),
(err) => reject(Error(err.message))
);
else reject(Error("this browser does not support geolocation."));
})
Insert cell
sparql = `SELECT DISTINCT ?item ?itemLabel ?article WHERE {
SERVICE wikibase:around {
?item wdt:P625 ?location.
bd:serviceParam wikibase:center "Point(${coords.longitude} ${
coords.latitude
})"^^geo:wktLiteral;
wikibase:radius "${radius * 1.60934}";
wikibase:distance ?distance.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?article schema:about ?item ; schema:isPartOf <https://en.wikipedia.org/> ;
}
ORDER BY (?distance)
`
Insert cell
raw_data = fetch(
`https://query.wikidata.org/sparql?query=${encodeURIComponent(sparql)}`,
{ headers: { accept: "application/sparql-results+json" } }
).then((response) => response.json())
Insert cell
data = raw_data
? raw_data.results.bindings.map((d) => ({
item: d.itemLabel.value,
article_url: d.article.value
}))
: []
Insert cell
data_list = data
.map((d) => `* <a href="${d.article_url}">${d.item}</a>`)
.join("\n")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more