Unlisted
Edited
Feb 13, 2024
1 fork
Insert cell
Insert cell
viewof qid = Inputs.text({
label: "Choisir un élément Wikidata ",
value: "Q3392",
placeholder: "eg fr, en, de",
submit: true
})
Insert cell
query = `
SELECT ?item ?itemLabel ?coord
WHERE {
?item wdt:P206 wd:${qid};
wdt:P625 ?coord;
rdfs:label ?itemLabel .

FILTER(LANG(?itemLabel) = "fr")

} `
Insert cell
url = `https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`
Insert cell
data = fetch(url, {
headers: { accept: "application/sparql-results+json" }
}).then((response) => response.json())
Insert cell
array = data.results.bindings.map((d) => ({
item: d.item.value,
itemLabel: d.itemLabel.value,
coord: d.coord?.value
}))
Insert cell
geo = require("geotoolbox@2")
Insert cell
geoarray = geo.coords2geo(array, {
coords: "coord",
reverse: true
})
Insert cell
d3 = require("d3@7", "d3-geo-projection@4")
Insert cell
viz = require("geoviz@0.4.4")
Insert cell
{
// Conteneur SVG
let svg = viz.create({
zoomable: true,
projection: d3.geoMercator()
});

// Fond de carte
svg.tile();
// Basemap

// Cercles
svg.circle({
data: geoarray,
r: 6,
fill: "#365486",
dodge: true,
tip: (d) => `${d.properties.itemLabel}`
});

// Render
return svg.render();
}
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