Skip to content

Commit e7c9d97

Browse files
authored
Add rotate option (#1528)
2 parents f2997f9 + ac51059 commit e7c9d97

File tree

5 files changed

+81
-45
lines changed

5 files changed

+81
-45
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Button, ButtonGroup, Stack } from "@mui/material";
2+
import { Minus, Plus, RotateCwSquare } from "lucide-react";
3+
import Circle from "../../assets/icons/circle.svg?react";
4+
import { theme } from "../../AppTheme";
5+
6+
const MapControls = ({ onZoomIn, onZoomOut, onFitToExtent, onRotate }) => {
7+
return (
8+
<Stack
9+
sx={{
10+
position: "absolute",
11+
top: theme.spacing(2),
12+
right: theme.spacing(2),
13+
zIndex: "500",
14+
gap: 1,
15+
}}>
16+
<ButtonGroup variant="contained" orientation="vertical">
17+
<Button data-cy="zoom-in-button" variant="text" color="secondary" onClick={onZoomIn}>
18+
<Plus />
19+
</Button>
20+
<Button data-cy="fit-to-extent-button" variant="text" color="secondary" onClick={onFitToExtent}>
21+
<Circle />
22+
</Button>
23+
<Button data-cy="zoom-out-button" variant="text" color="secondary" onClick={onZoomOut}>
24+
<Minus />
25+
</Button>
26+
</ButtonGroup>
27+
{!!onRotate && (
28+
<Button
29+
variant="text"
30+
onClick={onRotate}
31+
sx={{
32+
height: "44px",
33+
boxShadow:
34+
"0px 3px 1px -2px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12)",
35+
}}>
36+
<RotateCwSquare />
37+
</Button>
38+
)}
39+
</Stack>
40+
);
41+
};
42+
43+
export default MapControls;

src/client/src/components/buttons/zoomControls.jsx

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

src/client/src/components/map/mapComponent.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import { register } from "ol/proj/proj4";
2020
import proj4 from "proj4";
2121
import { getGeojson } from "../../api-lib";
2222
import { Box } from "@mui/material";
23-
import ZoomControls from "../buttons/zoomControls.jsx";
23+
import MapControls from "../buttons/mapControls.jsx";
2424
import NamePopup from "./namePopup.jsx";
2525
import { BasemapSelector } from "../basemapSelector/basemapSelector.tsx";
2626
import { swissExtent, updateBasemap } from "../basemapSelector/basemaps.ts";
2727
import { BasemapContext } from "../basemapSelector/basemapContext.tsx";
2828
import { clusterStyleFunction, drawStyle, styleFunction } from "./mapStyleFunctions.js";
2929
import { projections } from "./mapProjections.js";
3030
import { theme } from "../../AppTheme.ts";
31-
import Draw from "ol/interaction/Draw.js";
31+
import Draw from "ol/interaction/Draw";
3232
import { withTranslation } from "react-i18next";
3333

3434
class MapComponent extends React.Component {
@@ -653,7 +653,7 @@ class MapComponent extends React.Component {
653653
/>
654654
<NamePopup state={this.state}></NamePopup>
655655
<BasemapSelector marginBottom={"30px"} />
656-
<ZoomControls onZoomIn={this.onZoomIn} onZoomOut={this.onZoomOut} onFitToExtent={this.onFitToExtent} />
656+
<MapControls onZoomIn={this.onZoomIn} onZoomOut={this.onZoomOut} onFitToExtent={this.onFitToExtent} />
657657
</Box>
658658
);
659659
}

src/client/src/components/map/pointComponent.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import { Button, Icon, Label } from "semantic-ui-react";
1616
import { Box, Card } from "@mui/material";
1717
import { getHeight } from "../../api-lib";
1818
import { fetchApiV2 } from "../../api/fetchApiV2.js";
19-
import ZoomControls from "../buttons/zoomControls.jsx";
19+
import MapControls from "../buttons/mapControls.jsx";
2020
import { BasemapSelector } from "../basemapSelector/basemapSelector.tsx";
2121
import { attributions, crossOrigin, swissExtent, updateBasemap } from "../basemapSelector/basemaps.ts";
2222
import { BasemapContext } from "../basemapSelector/basemapContext.tsx";
2323
import { projections } from "./mapProjections.js";
2424
import { detailMapStyleFunction } from "./mapStyleFunctions.js";
25-
import TileLayer from "ol/layer/Tile.js";
26-
import XYZ from "ol/source/XYZ.js";
25+
import TileLayer from "ol/layer/Tile";
26+
import XYZ from "ol/source/XYZ";
2727

2828
class PointComponent extends React.Component {
2929
static contextType = BasemapContext;
@@ -312,7 +312,7 @@ class PointComponent extends React.Component {
312312
height: 670,
313313
}}
314314
/>
315-
<ZoomControls onZoomIn={this.onZoomIn} onZoomOut={this.onZoomOut} onFitToExtent={this.onFitToExtent} />
315+
<MapControls onZoomIn={this.onZoomIn} onZoomOut={this.onZoomOut} onFitToExtent={this.onFitToExtent} />
316316
<Box sx={{ position: "absolute", right: 0, top: 645 }}>
317317
<BasemapSelector marginBottom="0px" />
318318
</Box>

src/client/src/pages/detail/labeling/labelingPanel.tsx

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import Map from "ol/Map.js";
1313
import Projection from "ol/proj/Projection.js";
1414
import Static from "ol/source/ImageStatic.js";
1515
import { getCenter } from "ol/extent.js";
16-
import ZoomControls from "../../../components/buttons/zoomControls";
16+
import MapControls from "../../../components/buttons/mapControls";
1717
import { ButtonSelect } from "../../../components/buttons/buttonSelect.tsx";
1818
import { defaults as defaultControls } from "ol/control/defaults";
1919
import { View } from "ol";
20+
import { DragRotate, PinchRotate } from "ol/interaction";
2021

2122
interface LabelingPanelProps {
2223
boreholeId: number;
@@ -98,6 +99,14 @@ const LabelingPanel: FC<LabelingPanelProps> = ({ boreholeId }) => {
9899
}
99100
};
100101

102+
const rotateImage = () => {
103+
if (map) {
104+
const view = map.getView();
105+
const rotation = view.getRotation();
106+
view.setRotation(rotation + Math.PI / 2);
107+
}
108+
};
109+
101110
useEffect(() => {
102111
if (files === undefined) {
103112
loadFiles();
@@ -112,8 +121,17 @@ const LabelingPanel: FC<LabelingPanelProps> = ({ boreholeId }) => {
112121
controls: defaultControls({
113122
attribution: false,
114123
zoom: false,
124+
rotate: false,
115125
}),
116126
});
127+
map
128+
.getInteractions()
129+
.getArray()
130+
.forEach(interaction => {
131+
if (interaction instanceof DragRotate || interaction instanceof PinchRotate) {
132+
map.removeInteraction(interaction);
133+
}
134+
});
117135
setMap(map);
118136
} else if (map && selectedFile) {
119137
getDataExtractionFileInfo(selectedFile.id, activePage).then(response => {
@@ -197,8 +215,8 @@ const LabelingPanel: FC<LabelingPanelProps> = ({ boreholeId }) => {
197215
exclusive
198216
sx={{
199217
position: "absolute",
200-
bottom: "16px",
201-
right: "16px",
218+
bottom: theme.spacing(2),
219+
right: theme.spacing(2),
202220
zIndex: "500",
203221
}}>
204222
<ToggleButton value="bottom" data-cy="labeling-panel-position-bottom">
@@ -214,8 +232,8 @@ const LabelingPanel: FC<LabelingPanelProps> = ({ boreholeId }) => {
214232
direction="row"
215233
sx={{
216234
position: "absolute",
217-
top: "16px",
218-
left: "16px",
235+
top: theme.spacing(2),
236+
left: theme.spacing(2),
219237
zIndex: "500",
220238
gap: 1,
221239
}}>
@@ -235,16 +253,20 @@ const LabelingPanel: FC<LabelingPanelProps> = ({ boreholeId }) => {
235253
setSelectedFile(files?.find(file => file.id === item.key));
236254
}
237255
}}
238-
sx={{ height: "44px" }}
256+
sx={{
257+
height: "44px",
258+
boxShadow:
259+
"0px 3px 1px -2px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12)",
260+
}}
239261
/>
240262
</Stack>
241-
<ZoomControls onZoomIn={zoomIn} onZoomOut={zoomOut} onFitToExtent={fitToExtent} />
263+
<MapControls onZoomIn={zoomIn} onZoomOut={zoomOut} onFitToExtent={fitToExtent} onRotate={rotateImage} />
242264
<ButtonGroup
243265
variant="contained"
244266
sx={{
245267
position: "absolute",
246-
bottom: "16px",
247-
left: "16px",
268+
bottom: theme.spacing(2),
269+
left: theme.spacing(2),
248270
zIndex: "500",
249271
height: "44px",
250272
}}>

0 commit comments

Comments
 (0)