Skip to content

Commit 9e95458

Browse files
committed
refactor: components splitting
1 parent 8c1142e commit 9e95458

File tree

8 files changed

+54
-49
lines changed

8 files changed

+54
-49
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Config } from "./types";
2+
3+
export const CONFIG: Config = {
4+
position: "bottomright",
5+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { FC } from "react";
2+
import { ZoomControl } from "react-leaflet";
3+
import { useSelector } from "react-redux";
4+
5+
import { CONFIG } from "./config";
6+
import { checkIsWithZoomControl } from "./selectors";
7+
8+
export const ZoomControls: FC = () => {
9+
const isWithZoomControl = useSelector(checkIsWithZoomControl);
10+
11+
if (!isWithZoomControl) {
12+
return null;
13+
}
14+
15+
return <ZoomControl {...CONFIG} />;
16+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { State } from "@/js/types";
2+
3+
export const checkIsWithZoomControl = (state: State) => {
4+
return state.geomapSettings.featuresConfiguration.isWithZoomControl;
5+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Control } from "leaflet";
2+
3+
export type Config = Control.ZoomOptions;

vis/js/templates/Geomap/config.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import { Config } from "./types";
22

33
export const CONFIG: Config = {
4-
MAP: {
5-
center: [45.1, 4.1],
6-
zoom: 4,
7-
maxZoom: 17,
8-
minZoom: 2,
9-
maxBounds: [
10-
[-85, -180],
11-
[85, 180],
12-
],
13-
maxBoundsViscosity: 1.0,
14-
worldCopyJump: true,
15-
keyboard: false,
16-
zoomControl: false,
17-
},
18-
ZOOM_CONTROL: {
19-
position: "bottomright",
20-
},
4+
center: [45.1, 4.1],
5+
zoom: 4,
6+
maxZoom: 17,
7+
minZoom: 2,
8+
maxBounds: [
9+
[-85, -180],
10+
[85, 180],
11+
],
12+
maxBoundsViscosity: 1.0,
13+
worldCopyJump: true,
14+
keyboard: false,
15+
zoomControl: false,
2116
};

vis/js/templates/Geomap/index.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
import "leaflet/dist/leaflet.css";
22

33
import { FC } from "react";
4-
import { MapContainer, ZoomControl } from "react-leaflet";
5-
import { useSelector } from "react-redux";
4+
import { MapContainer } from "react-leaflet";
65

76
import { CONFIG } from "./config";
87
import { HeightContainer } from "./HeightContainer";
98
import { Layer } from "./Layer";
109
import { Pins } from "./Pins";
11-
import { getGeomapFeaturesSettings } from "./selectors";
10+
import { ZoomControls } from "./ZoomControls";
1211

13-
const { MAP, ZOOM_CONTROL } = CONFIG;
14-
15-
export const Geomap: FC = () => {
16-
const { isWithZoomControl } = useSelector(getGeomapFeaturesSettings);
17-
18-
return (
19-
<HeightContainer>
20-
<MapContainer {...MAP} className="geomap_container">
21-
{isWithZoomControl && <ZoomControl {...ZOOM_CONTROL} />}
22-
<Layer />
23-
<Pins />
24-
</MapContainer>
25-
</HeightContainer>
26-
);
27-
};
12+
export const Geomap: FC = () => (
13+
<HeightContainer>
14+
<MapContainer {...CONFIG} className="geomap_container">
15+
<ZoomControls />
16+
<Layer />
17+
<Pins />
18+
</MapContainer>
19+
</HeightContainer>
20+
);

vis/js/templates/Geomap/selectors.ts

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

vis/js/templates/Geomap/types.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Control, MapOptions } from "leaflet";
1+
import { MapOptions } from "leaflet";
22

3-
type MapConfig = Required<
3+
export type Config = Required<
44
Pick<
55
MapOptions,
66
| "center"
@@ -14,10 +14,3 @@ type MapConfig = Required<
1414
| "zoomControl"
1515
>
1616
>;
17-
18-
type ZoomControlConfig = Control.ZoomOptions;
19-
20-
export interface Config {
21-
MAP: MapConfig;
22-
ZOOM_CONTROL: ZoomControlConfig;
23-
}

0 commit comments

Comments
 (0)