FlowLayerV2 = {
const {CompositeLayer} = deck;
class FlowLayer extends CompositeLayer {
static defaultProps = defaultProps
static layerName = 'FlowLayer' + Date.now()
updateState({changeFlags, props}) {
if (changeFlags.dataChanged) {
const locationById = {}
for (const loc of props.data.locations) {
locationById[loc.id] = {...loc, count: 0}
}
for (const flow of props.data.flows) {
const origin = locationById[flow.origin]
const dest = locationById[flow.dest]
origin.count += Number(flow.count)
dest.count += Number(flow.count)
}
this.setState({locationById})
}
}
renderLayers() {
const {locations, flows} = this.props.data
const {getNodeColor, getEdgeColor, nodeSizeScale, edgeWidthScale} = this.props
const {locationById} = this.state
return [
new deck.ScatterplotLayer(this.getSubLayerProps({
id: 'locations',
data: locations,
getPosition: d => [Number(d.lon), Number(d.lat)],
getFillColor: getNodeColor,
getRadius: d => {
const loc = locationById[d.id]
return Math.sqrt(loc.count)
},
radiusScale: nodeSizeScale
})),
new deck.ArcLayer(this.getSubLayerProps({
id: 'flows',
data: flows,
getSourcePosition: d => {
const loc = locationById[d.origin]
return [Number(loc.lon), Number(loc.lat)]
},
getTargetPosition: d => {
const loc = locationById[d.dest]
return [Number(loc.lon), Number(loc.lat)]
},
getWidth: d => Number(d.count),
getTilt: 15,
widthUnits: 'meters',
widthScale: edgeWidthScale,
getSourceColor: getEdgeColor,
getTargetColor: getEdgeColor
}))
]
}
}
return FlowLayer
}