IllinoisCovidMapES = {
const outerContainer = html`<div style="max-width: 700px;">${style()}</div>`;
const container = html`<div style="width: 100%; height:400px;"></div>`;
const lang = "es";
outerContainer.appendChild(header(lang));
outerContainer.appendChild(mapLegend(lang));
outerContainer.appendChild(container);
outerContainer.appendChild(footer(lang));
yield outerContainer;
const map = new mapboxgl.Map({
container,
style: "mapbox://styles/chicagoreporter/ck7z7c9fj1l5j1ipqgdoop32s",
scrollZoom: true
});
map.addControl(new mapboxgl.NavigationControl());
map.on("load", () => {
map.fitBounds(IllinoisBoundingBox);
setTimeout(d => {
const bounds = map.getBounds();
map.setMaxBounds(bounds);
}, 500);
map.addSource("counties", {
type: "geojson",
data: IllinoisCountyCovidGeoDataPolygons
});
map.addLayer({
id: "countiesFillLayer",
type: "fill",
source: "counties",
layout: {},
paint: {
"fill-color": "rgba(255, 255, 255, 0.01)"
}
});
// We use D3 to construct an equivalent scale in mapbox
const choroplethStops = [...breaks.slice(1), maxMeasure]
.map(d => [countColor(d - 1), d + 1])
.flat();
map.addLayer(
{
id: "dataLayer",
type: "fill",
source: "counties",
layout: {},
paint: {
'fill-color': [
'step',
['get', selectedMeasure],
"rgba(255, 255, 255, 1)",
1,
...choroplethStops.slice(0, choroplethStops.length - 1)
]
}
},
layerBefore
);
map.addLayer(
{
id: "countiesLayer",
type: "line",
source: "counties",
layout: {},
paint: {
"line-width": .9,
"line-color": "rgba(220, 220, 220, 0.7)"
}
},
layerBefore
);
// Create a popup, but don't add it to the map yet.
let popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});
map.on('mousemove', 'dataLayer', function(e) {
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = 'pointer';
const feature = e.features[0];
const popupContent = `
<h1>${feature.properties.County} ${
feature.properties.County === "Chicago" ? "" : "county"
}</h1>
<table>
<tr>
<th>${lang === "es" ? "Confirmado" : "Confirmed"}</th>
<td>${feature.properties.confirmed_cases}</td>
</tr>
<tr>
<th>${lang === "es" ? "Muerto" : "Deaths"}</th>
<td>${feature.properties.deaths}</td>
</tr>
<table>
`;
popup
.setLngLat(e.lngLat)
.setHTML(popupContent)
.addTo(map);
});
map.on('mouseleave', 'dataLayer', function() {
map.getCanvas().style.cursor = '';
popup.remove();
});
});
await triggerEmbedAnalytics("IL county map");
invalidation.then(() => map.remove());
// return outerContainer;
}