Skip to content

Commit 2c917c7

Browse files
author
jannik brack
committed
Fixxing error, and modifying Toolbar
1 parent 7289aed commit 2c917c7

File tree

5 files changed

+93
-162
lines changed

5 files changed

+93
-162
lines changed

multi_tab/src/App.tsx

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,43 @@
11
import "./App.css";
2-
import {MapLibreMap} from "@mapcomponents/react-maplibre";
2+
import {MapLibreMap, TopToolbar} from "@mapcomponents/react-maplibre";
33
import LayerManager from "./components/LayerManager.jsx";
44
import {Button} from "@mui/material";
5-
import Toolbar from "@mui/material/Toolbar";
6-
import AppBar from "@mui/material/AppBar";
7-
import Box from "@mui/material/Box";
85
import {useState} from "react";
96

107
function App() {
118
const [openSidebar, setOpenSidebar] = useState(true);
12-
const ghPagesUrl = 'https://mapcomponents.github.io/react-map-components-maplibre/';
13-
const logoUrl = ghPagesUrl + 'assets/WG-MapComponents-Logo_rgb.svg';
14-
159

1610
const openTable = () => {
1711
const newUrl = `${window.location.href}#/table`;
1812
window.open(newUrl, "_blank", "popup");
1913
}
2014
return (
2115
<>
22-
<AppBar
23-
sx={{
24-
minHeight: '62px',
25-
width: '100vw',
26-
position: 'absolute',
27-
backgroundColor: 'white',
28-
zIndex: 1300,
29-
top: 0,
30-
}}
31-
>
32-
<Toolbar disableGutters>
33-
<Box
16+
<TopToolbar buttons={
17+
<>
18+
<Button
3419
sx={{
35-
marginLeft: '25px',
36-
display: {xs: 'none', md: 'flex'},
37-
flexGrow: {md: '30'},
20+
color: openSidebar ? "#009EE0" : "white",
21+
backgroundColor: openSidebar ? "#fff" : '#009EE0',
22+
marginRight: {xs: '0px', sm: '10px'}
23+
}}
24+
variant={openSidebar ? 'outlined' : 'contained'}
25+
onClick={() => {
26+
setOpenSidebar(!openSidebar);
3827
}}
3928
>
40-
<img
41-
src={logoUrl}
42-
style={{width: '100%', maxWidth: '250px'}}
43-
alt={"MapComponentsLogo"}
44-
/>
45-
<Button
46-
sx={{
47-
left: 'calc(100% - 520px)',
48-
color: '#238ee5'
49-
}}
50-
disabled={openSidebar}
51-
variant='outlined'
52-
onClick={() => {
53-
setOpenSidebar(!openSidebar);
54-
}}
55-
>
56-
Open Sidebar
57-
</Button>
29+
Sidebar
30+
</Button>
5831

59-
<Button
60-
sx={{
61-
left: 'calc(100% - 510px)',
62-
color: '#238ee5'
63-
}}
64-
variant='outlined'
65-
onClick={() => openTable()}
66-
>show table</Button>
67-
</Box>
68-
</Toolbar>
69-
</AppBar>
32+
<Button
33+
sx={{
34+
background: '#009EE0'
35+
}}
36+
variant='contained'
37+
onClick={() => openTable()}
38+
>show table</Button>
39+
</>
40+
}/>
7041
<MapLibreMap
7142
options={{
7243
style: "https://wms.wheregroup.com/tileserver/style/osm-bright.json",
@@ -75,7 +46,7 @@ function App() {
7546
}}
7647
style={{position: "absolute", top: 0, bottom: 0, left: 0, right: 0}}
7748
/>
78-
<LayerManager setOpenSidebar={setOpenSidebar} openSidebar={openSidebar} />
49+
<LayerManager setOpenSidebar={setOpenSidebar} openSidebar={openSidebar}/>
7950
</>
8051
);
8152
}

multi_tab/src/components/DataTableManager.jsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Box} from "@mui/material";
22
import React, {useContext, useEffect, useState} from "react";
3-
import TopToolBar from "./UI_Components/TopToolbar.tsx";
3+
import TopToolBar from "./UI_Components/TableToolbar.tsx";
44
import CreateTable from "./UI_Components/DataTable.jsx";
55
import {DataContext} from "../contexts/DataContext.tsx";
66

@@ -11,8 +11,6 @@ export default function DataTableManager() {
1111
const [selected, setSelected] = useState();
1212
const [selectedLayer, setSelectedLayer] = useState("all");
1313
const [tableSplit, setTableSplit] = useState(false);
14-
const [parksVisible, setParksVisible] = useState(true);
15-
const [restaurantsVisible, setRestaurantsVisible] = useState(true);
1614
/*const [showOnlyVisibleObjects, setShowOnlyVisibleObjects] = useState(true);*/
1715

1816
useEffect(() => {
@@ -27,17 +25,14 @@ export default function DataTableManager() {
2725
setSelected(message.selected);
2826
break;
2927
case"visibleLayers":
30-
console.log(message);
31-
setParksVisible(message.parksShown);
32-
setRestaurantsVisible(message.restaurantsShown);
3328
setSelectedLayer(
3429
message.parksShown && message.restaurantsShown
3530
? 'all'
3631
: message.restaurantsShown
3732
? 'restaurant'
3833
: message.parksShown
3934
? 'park'
40-
: ''
35+
: 'all'
4136
);
4237

4338
break;

multi_tab/src/components/LayerManager.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export default function LayerManager(props) {
131131

132132
useEffect(() => {
133133
if (!mapHook.map) return;
134+
console.log("send")
134135

135136
sendMessageToServiceWorker({
136137
type: "visibleLayers",
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import * as React from 'react';
2+
import {useContext} from 'react';
3+
import {Button, MenuItem, Select, SelectChangeEvent} from "@mui/material";
4+
import {DataContext} from "../../contexts/DataContext";
5+
import {TopToolbar} from "@mapcomponents/react-maplibre";
6+
7+
export interface TopToolbarProps {
8+
children?: React.ReactNode;
9+
unmovableButtons?: React.ReactNode;
10+
buttons?: React.ReactNode;
11+
logo?: React.ReactNode;
12+
selectedLayer: string;
13+
setSelectedLayer: (layer: string) => void;
14+
tableSplit: boolean;
15+
setTableSplit: (split: boolean) => void;
16+
}
17+
18+
function TableToolbar(props: TopToolbarProps) {
19+
const data = useContext(DataContext);
20+
21+
const layers = data
22+
? Object.keys(data).map(layerName => layerName.replace(".json", ""))
23+
: [];
24+
25+
const handleLayerSelect = (event: SelectChangeEvent) => {
26+
props.setSelectedLayer(event.target.value as string);
27+
}
28+
29+
const handleTableSplit = () => {
30+
const newTableSplit = !props.tableSplit;
31+
props.setTableSplit(newTableSplit);
32+
}
33+
34+
return (
35+
<TopToolbar buttons={
36+
<>
37+
<Select
38+
variant={'outlined'}
39+
value={props.selectedLayer}
40+
onChange={handleLayerSelect}
41+
size={"small"}
42+
sx={{
43+
width: '122px',
44+
marginRight: {xs: '0px', sm: '10px'}
45+
}}
46+
>
47+
<MenuItem value={"all"}>all</MenuItem>
48+
{layers.map(layerName => (
49+
<MenuItem value={layerName} key={layerName}>{layerName}</MenuItem>
50+
))}
51+
</Select>
52+
<Button
53+
variant={'contained'}
54+
onClick={handleTableSplit}
55+
sx={{
56+
backgroundColor: '#009EE0'
57+
}}
58+
>
59+
{props.tableSplit ? ("merge table") : ("split table")}
60+
</Button>
61+
</>
62+
}/>
63+
64+
);
65+
}
66+
67+
export default TableToolbar;

multi_tab/src/components/UI_Components/TopToolbar.tsx

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)