BuildingPopupContent.tsx 2.36 KB
Newer Older
Hanadi's avatar
Hanadi committed
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
import React from "react";
import {heatingColorGradient} from "../../common/ColorGradient";
import {BLACK_CSS, numberWithCommas} from "../../common/Helpers";
import {PopupDataInfo} from "./Popup";
import {PopupGrid, PopupGridItem} from "./PopupGrid";

type BuildingPopupState = {}
type BuildingPopupProps = {
    info: PopupDataInfo;
}

export class BuildingPopupContent extends React.Component<BuildingPopupProps, BuildingPopupState> {

    private getGridItems(): PopupGridItem[] {
        const {buildingInfo, trafficVisibilityMode} = this.props.info;
        if (!buildingInfo)
            return [];
        const {heatingInfo} = buildingInfo || {};
        const generalItems: PopupGridItem[] = [
            {key: "Id", value: buildingInfo?.id},
            {key: "Name", value: buildingInfo?.properties["name"]},
            {key: "Parent Id", value: buildingInfo?.properties["gml_parent_id"]},
            {key: "Description", value: buildingInfo?.properties["description"]},
            {key: "Longitude", value: buildingInfo?.properties["longitude"] || buildingInfo?.properties["longtitude"]},
            {key: "Latitude", value: buildingInfo?.properties["latitude"]},
        ];
        let heatingItems: PopupGridItem[] = [];
        if (trafficVisibilityMode === "co2" && heatingInfo) {
            const {spaceHeating, electricalAppliancesHeating, domesticWaterHeating} = heatingInfo;
            const totalHeating = spaceHeating + electricalAppliancesHeating + domesticWaterHeating;
            const textColor = heatingColorGradient.getColorAtAsCssHex(
                totalHeating,
                BLACK_CSS,
                true);
            const unit = "kgCO2eq/day";
            heatingItems = [
                {key: "Space Heating", value: numberWithCommas(spaceHeating), unit},
                {key: "Electrical Appliances Heating", value: numberWithCommas(electricalAppliancesHeating), unit},
                {key: "Domestic Water Heating", value: numberWithCommas(domesticWaterHeating), unit},
                {
                    key: "Total Heating",
                    value: numberWithCommas(totalHeating),
                    textColor,
                    unit
                },
            ];
        }

        return generalItems.concat(heatingItems);
    }

    render() {
        return <div>
            <PopupGrid items={this.getGridItems()}/>
        </div>;
    }
}