forked from keplergl/kepler.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap-control.tsx
More file actions
144 lines (129 loc) · 4.06 KB
/
Copy pathmap-control.tsx
File metadata and controls
144 lines (129 loc) · 4.06 KB
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
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
import React from 'react';
import styled from 'styled-components';
import KeplerGlLogo from '../common/logo';
// factories
import SplitMapButtonFactory from './split-map-button';
import Toggle3dButtonFactory from './toggle-3d-button';
import LayerSelectorPanelFactory from './layer-selector-panel';
import MapLegendPanelFactory from './map-legend-panel';
import MapDrawPanelFactory from './map-draw-panel';
import LocalePanelFactory from './locale-panel';
import {Layer} from '@kepler.gl/layers';
import {Editor, LayerVisConfig, MapControls, MapState} from '@kepler.gl/types';
import {Datasets} from '@kepler.gl/table';
import {MapStateActions, UIStateActions} from '@kepler.gl/actions';
interface StyledMapControlProps {
$top?: number;
}
const StyledMapControl = styled.div<StyledMapControlProps>`
right: 0;
padding: ${props => props.theme.mapControl.padding}px;
z-index: 10;
margin-top: ${props => props.$top || 0}px;
position: absolute;
display: grid;
row-gap: 8px;
justify-items: end;
pointer-events: none; /* prevent padding from blocking input */
& > * {
/* all children should allow input */
pointer-events: all;
}
`;
const LegendLogo = <KeplerGlLogo version={false} appName="kepler.gl" />;
export type MapControlProps = {
datasets: Datasets;
dragRotate: boolean;
isSplit: boolean;
primary: boolean;
layers: Layer[];
layersToRender: {[key: string]: boolean};
mapIndex: number;
mapControls: MapControls;
onTogglePerspective: () => void;
onToggleSplitMap: typeof MapStateActions.toggleSplitMap;
onToggleSplitMapViewport: ({
isViewportSynced,
isZoomLocked
}: {
isViewportSynced: boolean;
isZoomLocked: boolean;
}) => void;
onMapToggleLayer: (layerId: string) => void;
onToggleMapControl: (control: string) => void;
onSetEditorMode: (mode: string) => void;
onToggleEditorVisibility: () => void;
onLayerVisConfigChange: (oldLayer: Layer, newVisConfig: Partial<LayerVisConfig>) => void;
onToggleLayerVisibility?: (layer: Layer) => void;
top: number;
onSetLocale: typeof UIStateActions.setLocale;
availableLocales: string[];
locale: string;
logoComponent?: React.FC | React.ReactNode;
isExport?: boolean;
setMapControlSettings: typeof UIStateActions.setMapControlSettings;
activeSidePanel: string | null;
// optional
mapState?: MapState;
readOnly?: boolean;
scale?: number;
mapLayers?: {[key: string]: boolean};
editor: Editor;
actionComponents?: React.ComponentType<any>[];
mapHeight?: number;
};
MapControlFactory.deps = [
SplitMapButtonFactory,
Toggle3dButtonFactory,
LayerSelectorPanelFactory,
MapLegendPanelFactory,
MapDrawPanelFactory,
LocalePanelFactory
];
function MapControlFactory(
SplitMapButton: ReturnType<typeof SplitMapButtonFactory>,
Toggle3dButton: ReturnType<typeof Toggle3dButtonFactory>,
LayerSelectorPanel: ReturnType<typeof LayerSelectorPanelFactory>,
MapLegendPanel: ReturnType<typeof MapLegendPanelFactory>,
MapDrawPanel: ReturnType<typeof MapDrawPanelFactory>,
LocalePanel: ReturnType<typeof LocalePanelFactory>
) {
const DEFAULT_ACTIONS = [
SplitMapButton,
LayerSelectorPanel,
Toggle3dButton,
MapDrawPanel,
LocalePanel,
MapLegendPanel
];
const MapControl: React.FC<MapControlProps> & {
defaultActionComponents: MapControlProps['actionComponents'];
} = ({
actionComponents = DEFAULT_ACTIONS,
isSplit = false,
top = 0,
mapIndex = 0,
logoComponent = LegendLogo,
...restProps
}) => {
const actionComponentProps = {
isSplit,
mapIndex,
logoComponent,
...restProps
};
return (
<StyledMapControl className="map-control" $top={top}>
{actionComponents.map((ActionComponent, index) => (
<ActionComponent key={index} className="map-control-action" {...actionComponentProps} />
))}
</StyledMapControl>
);
};
MapControl.defaultActionComponents = DEFAULT_ACTIONS;
MapControl.displayName = 'MapControl';
return MapControl;
}
export default MapControlFactory;