Sidebar.tsx 5.31 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import React from "react";
import {
    createStyles,
    CssBaseline,
    Divider,
    Drawer,
    Fab,
    IconButton,
    Theme,
    Tooltip, withStyles
} from "@material-ui/core";
import clsx from "clsx";
import {Map} from "./Map";
import MenuIcon from "@material-ui/icons/Menu";
import ChevronLeftIcon from "@material-ui/icons/ChevronLeft";
import {OGC3DContainerLayer} from "./layers/OGC3DContainerLayer";
import {STALayer} from "./layers/STALayer";

const SIDEBAR_WIDTH = 300;

const styles = (theme: Theme) => createStyles({
    root: {
        display: "flex",
        width: "100%"
    },
    menuButton: {
        position: "absolute",
        "z-index": 1000,
        left: 30,
        top: 14,
        backgroundColor: "ghostwhite"
    },
    hide: {
        display: "none",
    },
    drawer: {
        width: SIDEBAR_WIDTH,
        flexShrink: 0
    },
    drawerPaper: {
        width: SIDEBAR_WIDTH,
        backgroundColor: "#f6f6f6"
    },
    drawerHeader: {
        display: "flex",
        alignItems: "center",
        padding: theme.spacing(0, 1),
        // necessary for content to be below app bar
        justifyContent: "flex-end",
    },
    content: {
        flexGrow: 1,
        backgroundColor: "#defff4",
        transition: theme.transitions.create("margin", {
            easing: theme.transitions.easing.sharp,
            duration: theme.transitions.duration.leavingScreen,
        }),
        marginLeft: -SIDEBAR_WIDTH,
    },
    contentShift: {
        transition: theme.transitions.create("margin", {
            easing: theme.transitions.easing.easeOut,
            duration: theme.transitions.duration.enteringScreen
        }),
        marginLeft: 0
    },
});

type SidebarProps = { classes: any }
type SidebarState = {
    isOpen: boolean;
    map: Map | null
};

class SidebarClass extends React.Component<SidebarProps, SidebarState> {

    constructor(props: SidebarProps) {
        super(props);
        this.state = {
            isOpen: false,
            map: null
        };
    }

    private handleDrawerToggle() {
        this.setState(state => ({isOpen: !state.isOpen}));
    }

    render() {
        return (<div className={this.props.classes.root}>
            <CssBaseline/>
            <Tooltip title="Menu">
                <Fab
                    color="inherit"
                    size={"small"}
                    aria-label="open drawer"
                    onClick={this.handleDrawerToggle.bind(this)}
                    className={clsx(this.props.classes.menuButton, this.state.isOpen && this.props.classes.hide)}
                >
                    <MenuIcon/>
                </Fab>
            </Tooltip>
            <Drawer
                className={this.props.classes.drawer}
                classes={{
                    paper: this.props.classes.drawerPaper,
                }}
                variant={"persistent"}
                anchor={"left"}
                open={this.state.isOpen}
                onClose={this.handleDrawerToggle.bind(this)}
                ModalProps={{
                    keepMounted: true, // Better open performance on mobile.
                }}
            >
                <div className={this.props.classes.drawerHeader}>
                    <IconButton onClick={this.handleDrawerToggle.bind(this)}>
                        <ChevronLeftIcon/>
                    </IconButton>
                </div>
                <Divider/>
                {this.state.map ?
                    [
                        <OGC3DContainerLayer
                            key={"ogc-layer"}
                            onTilesetAdded={this.state.map.showTileset.bind(this.state.map)}
                            onTilesetRemoved={this.state.map.hideTileset.bind(this.state.map)}
                            getVisibleItemsIds={this.state.map.getVisibleItemsIds.bind(this.state.map)}
                            flyToTileset={this.state.map.flyToTileset.bind(this.state.map)}
                        />,
                        <STALayer
                            key={"traffic-layer"}
                            onTrafficLayerAdded={this.state.map.showTrafficLayer.bind(this.state.map)}
                            onTrafficLayerRemoved={this.state.map.hideTrafficLayer.bind(this.state.map)}
                            onColorByStrategyChanged={this.state.map.onColorByStrategyChanged.bind(this.state.map)}
                            onColorByAqiChanged={this.state.map.onColorByAqiChanged.bind(this.state.map)}
                            onPMLayerAdded={this.state.map.showPMLayer.bind(this.state.map)}
                            addLoadingId={this.state.map.addCustomLoadingId.bind(this.state.map)}
                            removeLoadingId={this.state.map.removeLoadingId.bind(this.state.map)}
                            showSnackbar={this.state.map.showSnackbar.bind(this.state.map)}
                        />
                    ]
                    : null}
            </Drawer>
            <main
                className={clsx(this.props.classes.content, {
                    [this.props.classes.contentShift]: this.state.isOpen
                })}>
                <Map ref={map => {
                    if (map && !this.state.map)
                        this.setState({map});
                }}/>
            </main>
        </div>);
    }
}

export const Sidebar
    = withStyles(styles)(SidebarClass);