function deckMap({
initialViewState={
latitude:0,
longitude:0,
zoom:0
},
geography={},
data={},
colorBins=[],
breaks=[],
ordinalLabels=[],
controller=true,
geographyIdVariable='',
dataIdVariable='',
colorVariable='',
width=500,
height=500,
customDeckParams={},
title='',
strokeColor="#999999"
}){
const container = html `<div style="height:${height}px;width:${width}px"></div>`
const dataById = d3.map(data, d => d[dataIdVariable]);
const deckgl = new deck.DeckGL({
container: container,
map: false,
initialViewState,
controller,
glOptions: {
preserveDrawingBuffer: true
},
});
const colorScale = d3.scaleThreshold(breaks, colorBins)
const layer = new deck.GeoJsonLayer({
id: `geojson`,
data: geography,
getFillColor: f => {
if (dataById.has(f.properties[geographyIdVariable])) {
const datum = dataById.get(f.properties[geographyIdVariable]);
return hexToRgb(colorScale(datum[colorVariable]));
} else {
return [240,240,240]
}
},
getLineColor: hexToRgb(strokeColor),
lineWidthScale: 1,
lineWidthMinPixels: 1,
getLineWidth: 1,
...customDeckParams
});
deckgl.setProps({layers: [layer]});
const mapLegend = ordinalLabels.length
? swatches({color: d3.scaleOrdinal(ordinalLabels, colorBins), columns: 1})
: legend({color: colorScale, width: width/3})
return html`<div style="height:${height}px;width:${width}px">
<span id="meta" style="z-index:5">
<h2>${title}</h2>
${mapLegend}
</span>
${container}
</div>`
}