Public
Edited
Dec 7, 2023
2 forks
2 stars
Also listed in…
Targomo Deep Dives
Insert cell
Insert cell
Insert cell
Insert cell
meta = fetch(
`https://api.targomo.com/statistics/collection/meta/79?key=${targomoKey()}`
).then((response) => response.json())
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
colorDef = {
const breakpoints = statistic.breakpoints
.sort((a, b) => b.min_zoom - a.min_zoom)
.find((d) => zoom > d.min_zoom)[color_dist].c7;

return [
"interpolate",
["linear"],
["get", `${statistic.statistic_id}`],
...breakpoints
.map((b, i) => {
return [b, color_scale.scale(breakpoints.length)[i]];
})
.flat()
];
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
// if the layer is already present, remove it and its source
if (map.getLayer(`statistics`)) {
map.removeLayer(`statistics`);
map.removeSource(`statistics`);
}

map.addLayer(
{
id: `statistics`,
type: "fill",
source: {
type: "vector",
tiles: [
`https://api.targomo.com/statistics/collections/tiles/79/{z}/{x}/{y}.mvt?columns=${
statistic.statistic_id
}&apiKey=${targomoKey()}&serviceUrl=https://api.targomo.com/westcentraleurope`
]
},
"source-layer": "statistics", // the layer name is always "statistics" for tiled MVTs
layout: {},
paint: {
"fill-opacity": 0.55,
"fill-color": "rgba(255,255,255,0)", // we'll be updating on zoom, so can set to transparent to begin
"fill-outline-color": "rgba(255,255,255,0)"
}
},
"place_other"
);
// set a new trigger value so layer can be updated with breakpoints
mutable styletrigger = new Date();
return md`_update tile mvt url if statistic is changed_`;
}
Insert cell
{
styletrigger;

if (map.getLayer(`statistics`)) {
map.setPaintProperty("statistics", "fill-color", colorDef);
}
return md`_update breakpoints based on zoom and selected statistic_`;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more