Public
Edited
Jan 24, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof map = {
let container = html`<div style='height:600px;' />`;

// Give the container dimensions.
yield container;

// set the targomo client
const client = tgmCoreClient("westcentraleurope");

// Create the "map" object with the mapboxgl.Map constructor, referencing
// the container div
let map = new mapboxgl.Map({
container,
center: source,
zoom: 11,
style: client.basemaps.getGLStyleURL("Light"),
// scrollZoom: false,
attributionControl: false
})
.addControl(new mapboxgl.NavigationControl())
.addControl(
new mapboxgl.AttributionControl({
compact: true,
customAttribution: attribution
})
);

const marker = new mapboxgl.Marker({
//draggable: true
})
.setLngLat(source)
.addTo(map);

map.on("load", async () => {
container.value = map;
container.dispatchEvent(new CustomEvent("input"));
});
}
Insert cell
map
Insert cell
viewof cellSizePixels = Inputs.range([4, 20], {
label: html`<strong>Cell Size</strong>`,
step: 2,
value: 10
})
Insert cell
viewof cellMarginPixels = Inputs.range([0, 5], {
label: html`<strong>Cell Margin</strong>`,
step: 1,
value: 1
})
Insert cell
viewof travelMode = Inputs.radio(
[
{ label: "Walk", value: "walk" },
{ label: "Bike", value: "bike" },
{ label: "Car", value: "car" },
{ label: "Transit", value: "transit" }
],
{
label: html`<strong>Select mode of transport</strong>`,
value: "transit",
format: (d) => d.label,
valueof: (d) => d.value
}
)
Insert cell
Insert cell
Insert cell
data = {
// here we're deciding that we want transit coverage, 30 minutes (1800s), nodes (as we are aggregating with deckGL)
const multigraphOptions = {
edgeWeight: "time",
travelType: travelMode,
maxEdgeWeight: 1800,
multigraph: {
layer: { type: "identity" },
domain: { type: "node" },
serialization: { format: "geojson" },
aggregation: { type: "routing_union" }
}
};

// set the targomo client
const client = tgmCoreClient("westcentraleurope");
const mg = await client.multigraph.fetch([source], multigraphOptions);

return mg.data.features.map((f) => {
return {
lng: f.geometry.coordinates[0],
lat: f.geometry.coordinates[1],
w: f.properties.w
};
});
}
Insert cell
deckLayer = {
if (map.getLayer("heatmap")) {
map.removeLayer("heatmap");
}
const _deckLayer = new deck.MapboxLayer({
id: "heatmap",
type: deck.ScreenGridLayer,
colorRange: COLOR_RANGE,
data,
getPosition: (d) => [Number(d.lng), Number(d.lat)],
getWeight: (d) => d.w,
aggregation: "MEAN",
opacity: 0.3,
cellSizePixels,
cellMarginPixels
});
map.addLayer(_deckLayer, "place_other");
return _deckLayer;
}
Insert cell
html`
<style>
.panel {
display: grid;
grid-template-columns: repeat(2,auto);
column-gap: 20px;
row-gap: 20px;
}
</style>`
Insert cell
Insert cell
Insert cell
// deck = require.alias({
// h3: {},
// s2Geometry: {}
// })("deck.gl@8.4.1/dist.min.js")
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