map = {
const container = html`<div style="height:600px;">`;
yield container;
const map = L.map(container).setView([38.0400822,-78.5200792], 12);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: "© <a href=https://www.openstreetmap.org/copyright>OpenStreetMap</a> contributors"
}).addTo(map);
const tracts = await FileAttachment("tl_2020_51_tract10.geojson").json();
const onEachFeature = (feature, layer) => {
layer.on({
click: (e) => {
const workID = feature.properties.GEOID10;
const map = mode === "by work" ? countsByWork : countsByHome;
if (map[workID]) {
const values = Object.values(map[workID]);
const scale = chroma.scale(['yellow', '008ae5']).domain([Math.min(...values), Math.max(...values)]);
geoJSONLayer.eachLayer(layer => {
const homeID = layer.feature.properties.GEOID10;
const value = map[workID][homeID];
layer.unbindTooltip();
if (value) {
layer.setStyle({fillColor: scale(value)});
layer.bindTooltip(`Tract ${homeID}: ${value}`);
} else {
layer.setStyle({fillColor: "white"});
}
})
}
}
});
}
const geoJSONLayer = L.geoJSON(tracts, {
onEachFeature: onEachFeature,
style: (feature) => {
return {
color: "black",
fillColor: "white",
fillOpacity: 0.4,
weight: 1
};
}
}).addTo(map);
}