forked from toggle-corp/re-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.ts
57 lines (45 loc) · 1.62 KB
/
context.ts
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
import React from 'react';
import mapboxgl from 'mapbox-gl';
import { Source, Layer } from './type';
interface MapChildState {
map?: mapboxgl.Map;
mapStyle?: mapboxgl.MapboxOptions['style'];
mapContainerRef?: React.RefObject<HTMLDivElement>;
setSource: (source: Source) => void;
getSource: (sourceKey: string) => Source | undefined;
removeSource: (sourceKey: string) => void;
isSourceDefined: (sourceKey: string) => boolean;
isMapDestroyed: () => boolean;
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};
const initialMapChildState: MapChildState = {
map: undefined,
mapContainerRef: undefined,
mapStyle: 'mapbox://styles/mapbox/streets-v11',
setSource: noop,
getSource: () => undefined,
removeSource: noop,
isSourceDefined: () => false,
isMapDestroyed: () => false,
};
export const MapChildContext = React.createContext(initialMapChildState);
interface SourceChildState {
map?: mapboxgl.Map;
mapStyle?: mapboxgl.MapboxOptions['style'];
sourceKey?: string;
isMapDestroyed: () => boolean;
setLayer: (layerKey: string, method: (layer: Layer | undefined) => Layer | undefined) => void;
getLayer: (layerKey: string) => Layer | undefined;
removeLayer: (layerKey: string) => void;
}
const initialSourceChildState: SourceChildState = {
map: undefined,
mapStyle: 'mapbox://styles/mapbox/streets-v11',
sourceKey: undefined,
isMapDestroyed: () => false,
setLayer: noop,
getLayer: () => undefined,
removeLayer: noop,
};
export const SourceChildContext = React.createContext(initialSourceChildState);