-
Notifications
You must be signed in to change notification settings - Fork 0
/
InfoBox.tsx
58 lines (49 loc) · 1.6 KB
/
InfoBox.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { MapControl, MapControlProps, withLeaflet } from "react-leaflet";
import { Control, DomUtil } from "leaflet";
import { CensusMapData, ColumnData } from "./Types";
import React from "react";
import ReactDOM from "react-dom";
interface InfoBoxProps extends MapControlProps {
column: string;
columnData: ColumnData;
data?: CensusMapData;
}
export class InfoBoxContainer extends MapControl {
createLeafletElement(props: any) { return new Control(); }
div?: HTMLElement;
componentDidMount() {
const legend = new Control({ position: "topright" });
const _this = this;
legend.onAdd = () => {
_this.div = DomUtil.create('div', 'info');
_this.div.setAttribute('id', 'info-box');
return _this.div;
};
if (this.props.leaflet) {
const { map } = this.props.leaflet;
if (map) {
legend.addTo(map);
}
}
}
}
export function InfoBox(props: InfoBoxProps) {
const parent = document.getElementById('info-box');
const data = props.data;
const subtitle = data ? <h4>{data.NAME} {data.LSAD}, {data.STATE_NAME}</h4> : <></>
const body = data ? <>{data[props.column]} {props.columnData.units}</>: <></>;
if (parent) {
return ReactDOM.createPortal(
<>
<div id="variable-changer"></div>
<div id="county-info">
{subtitle}
{body}
</div>
</>,
parent
);
}
return <></>
}
export default withLeaflet(InfoBoxContainer);