react-bkoi-gl 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1429 -176
- package/dist/index.cjs +1299 -266
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +870 -0
- package/dist/index.d.ts +870 -2
- package/dist/index.js +2420 -2
- package/dist/index.js.map +1 -1
- package/dist/styles/react-bkoi-gl.css +95 -1
- package/package.json +83 -31
- package/dist/components/attribution-control.d.ts +0 -9
- package/dist/components/attribution-control.js +0 -20
- package/dist/components/attribution-control.js.map +0 -1
- package/dist/components/fullscreen-control.d.ts +0 -12
- package/dist/components/fullscreen-control.js +0 -21
- package/dist/components/fullscreen-control.js.map +0 -1
- package/dist/components/geolocate-control.d.ts +0 -21
- package/dist/components/geolocate-control.js +0 -46
- package/dist/components/geolocate-control.js.map +0 -1
- package/dist/components/layer.d.ts +0 -18
- package/dist/components/layer.js +0 -98
- package/dist/components/layer.js.map +0 -1
- package/dist/components/logo-control.d.ts +0 -9
- package/dist/components/logo-control.js +0 -28
- package/dist/components/logo-control.js.map +0 -1
- package/dist/components/map.d.ts +0 -27
- package/dist/components/map.js +0 -108
- package/dist/components/map.js.map +0 -1
- package/dist/components/marker.d.ts +0 -18
- package/dist/components/marker.js +0 -105
- package/dist/components/marker.js.map +0 -1
- package/dist/components/navigation-control.d.ts +0 -9
- package/dist/components/navigation-control.js +0 -19
- package/dist/components/navigation-control.js.map +0 -1
- package/dist/components/popup.d.ts +0 -15
- package/dist/components/popup.js +0 -68
- package/dist/components/popup.js.map +0 -1
- package/dist/components/scale-control.d.ts +0 -11
- package/dist/components/scale-control.js +0 -31
- package/dist/components/scale-control.js.map +0 -1
- package/dist/components/source.d.ts +0 -6
- package/dist/components/source.js +0 -95
- package/dist/components/source.js.map +0 -1
- package/dist/components/terrain-control.d.ts +0 -10
- package/dist/components/terrain-control.js +0 -19
- package/dist/components/terrain-control.js.map +0 -1
- package/dist/components/use-control.d.ts +0 -9
- package/dist/components/use-control.js +0 -30
- package/dist/components/use-control.js.map +0 -1
- package/dist/components/use-map.d.ts +0 -19
- package/dist/components/use-map.js +0 -54
- package/dist/components/use-map.js.map +0 -1
- package/dist/exports-maplibre-gl.d.ts +0 -33
- package/dist/exports-maplibre-gl.js +0 -21
- package/dist/exports-maplibre-gl.js.map +0 -1
- package/dist/maplibre/create-ref.d.ts +0 -9
- package/dist/maplibre/create-ref.js +0 -30
- package/dist/maplibre/create-ref.js.map +0 -1
- package/dist/maplibre/maplibre.d.ts +0 -81
- package/dist/maplibre/maplibre.js +0 -387
- package/dist/maplibre/maplibre.js.map +0 -1
- package/dist/styles.d.js +0 -2
- package/dist/styles.d.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/common.d.ts +0 -20
- package/dist/types/common.js +0 -2
- package/dist/types/common.js.map +0 -1
- package/dist/types/events.d.ts +0 -80
- package/dist/types/events.js +0 -2
- package/dist/types/events.js.map +0 -1
- package/dist/types/internal.d.ts +0 -14
- package/dist/types/internal.js +0 -2
- package/dist/types/internal.js.map +0 -1
- package/dist/types/lib.d.ts +0 -40
- package/dist/types/lib.js +0 -2
- package/dist/types/lib.js.map +0 -1
- package/dist/types/style-spec.d.ts +0 -1
- package/dist/types/style-spec.js +0 -2
- package/dist/types/style-spec.js.map +0 -1
- package/dist/utils/apply-react-style.d.ts +0 -2
- package/dist/utils/apply-react-style.js +0 -16
- package/dist/utils/apply-react-style.js.map +0 -1
- package/dist/utils/assert.d.ts +0 -1
- package/dist/utils/assert.js +0 -6
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/compare-class-names.d.ts +0 -2
- package/dist/utils/compare-class-names.js +0 -23
- package/dist/utils/compare-class-names.js.map +0 -1
- package/dist/utils/deep-equal.d.ts +0 -15
- package/dist/utils/deep-equal.js +0 -46
- package/dist/utils/deep-equal.js.map +0 -1
- package/dist/utils/set-globals.d.ts +0 -20
- package/dist/utils/set-globals.js +0 -31
- package/dist/utils/set-globals.js.map +0 -1
- package/dist/utils/style-utils.d.ts +0 -3
- package/dist/utils/style-utils.js +0 -42
- package/dist/utils/style-utils.js.map +0 -1
- package/dist/utils/transform.d.ts +0 -18
- package/dist/utils/transform.js +0 -33
- package/dist/utils/transform.js.map +0 -1
- package/dist/utils/use-isomorphic-layout-effect.d.ts +0 -3
- package/dist/utils/use-isomorphic-layout-effect.js +0 -4
- package/dist/utils/use-isomorphic-layout-effect.js.map +0 -1
- package/src/components/attribution-control.ts +0 -56
- package/src/components/fullscreen-control.ts +0 -40
- package/src/components/geolocate-control.ts +0 -96
- package/src/components/layer.ts +0 -141
- package/src/components/logo-control.ts +0 -44
- package/src/components/map.tsx +0 -166
- package/src/components/marker.ts +0 -155
- package/src/components/navigation-control.ts +0 -28
- package/src/components/popup.ts +0 -113
- package/src/components/scale-control.ts +0 -44
- package/src/components/source.ts +0 -159
- package/src/components/terrain-control.ts +0 -29
- package/src/components/use-control.ts +0 -68
- package/src/components/use-map.tsx +0 -71
- package/src/exports-maplibre-gl.ts +0 -37
- package/src/index.ts +0 -3
- package/src/maplibre/create-ref.ts +0 -70
- package/src/maplibre/maplibre.ts +0 -624
- package/src/styles.d.ts +0 -4
- package/src/types/common.ts +0 -34
- package/src/types/events.ts +0 -133
- package/src/types/internal.ts +0 -26
- package/src/types/lib.ts +0 -84
- package/src/types/style-spec.ts +0 -34
- package/src/utils/apply-react-style.ts +0 -24
- package/src/utils/assert.ts +0 -5
- package/src/utils/compare-class-names.ts +0 -29
- package/src/utils/deep-equal.ts +0 -61
- package/src/utils/set-globals.ts +0 -51
- package/src/utils/style-utils.ts +0 -68
- package/src/utils/transform.ts +0 -58
- package/src/utils/use-isomorphic-layout-effect.ts +0 -8
package/src/components/source.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
useContext,
|
|
4
|
-
useEffect,
|
|
5
|
-
useMemo,
|
|
6
|
-
useState,
|
|
7
|
-
useRef,
|
|
8
|
-
cloneElement,
|
|
9
|
-
} from "react";
|
|
10
|
-
import { MapContext } from "./map";
|
|
11
|
-
import assert from "../utils/assert";
|
|
12
|
-
import { deepEqual } from "../utils/deep-equal";
|
|
13
|
-
|
|
14
|
-
import type {
|
|
15
|
-
GeoJSONSourceImplementation,
|
|
16
|
-
ImageSourceImplementation,
|
|
17
|
-
AnySourceImplementation,
|
|
18
|
-
} from "../types/internal";
|
|
19
|
-
import type { SourceSpecification } from "../types/style-spec";
|
|
20
|
-
import type { Map as MapInstance } from "../types/lib";
|
|
21
|
-
|
|
22
|
-
export type SourceProps = SourceSpecification & {
|
|
23
|
-
id?: string;
|
|
24
|
-
children?: any;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
let sourceCounter = 0;
|
|
28
|
-
|
|
29
|
-
function createSource(map: MapInstance, id: string, props: SourceProps) {
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
if (map.style && map.style._loaded) {
|
|
32
|
-
const options = { ...props };
|
|
33
|
-
delete options.id;
|
|
34
|
-
delete options.children;
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
map.addSource(id, options);
|
|
37
|
-
return map.getSource(id);
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/* eslint-disable complexity */
|
|
43
|
-
function updateSource(
|
|
44
|
-
source: AnySourceImplementation,
|
|
45
|
-
props: SourceProps,
|
|
46
|
-
prevProps: SourceProps,
|
|
47
|
-
) {
|
|
48
|
-
assert(props.id === prevProps.id, "source id changed");
|
|
49
|
-
assert(props.type === prevProps.type, "source type changed");
|
|
50
|
-
|
|
51
|
-
let changedKey = "";
|
|
52
|
-
let changedKeyCount = 0;
|
|
53
|
-
|
|
54
|
-
for (const key in props) {
|
|
55
|
-
if (
|
|
56
|
-
key !== "children" &&
|
|
57
|
-
key !== "id" &&
|
|
58
|
-
!deepEqual(prevProps[key], props[key])
|
|
59
|
-
) {
|
|
60
|
-
changedKey = key;
|
|
61
|
-
changedKeyCount++;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!changedKeyCount) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const type = props.type;
|
|
70
|
-
|
|
71
|
-
if (type === "geojson") {
|
|
72
|
-
(source as GeoJSONSourceImplementation).setData(props.data);
|
|
73
|
-
} else if (type === "image") {
|
|
74
|
-
(source as ImageSourceImplementation).updateImage({
|
|
75
|
-
url: props.url,
|
|
76
|
-
coordinates: props.coordinates,
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
switch (changedKey) {
|
|
80
|
-
case "coordinates":
|
|
81
|
-
// @ts-ignore
|
|
82
|
-
source.setCoordinates?.(props.coordinates);
|
|
83
|
-
break;
|
|
84
|
-
case "url":
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
source.setUrl?.(props.url);
|
|
87
|
-
break;
|
|
88
|
-
case "tiles":
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
source.setTiles?.(props.tiles);
|
|
91
|
-
break;
|
|
92
|
-
default:
|
|
93
|
-
// eslint-disable-next-line
|
|
94
|
-
console.warn(`Unable to update <Source> prop: ${changedKey}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/* eslint-enable complexity */
|
|
99
|
-
|
|
100
|
-
export function Source(props: SourceProps) {
|
|
101
|
-
const map = useContext(MapContext).map.getMap();
|
|
102
|
-
const propsRef = useRef(props);
|
|
103
|
-
const [, setStyleLoaded] = useState(0);
|
|
104
|
-
|
|
105
|
-
const id = useMemo(() => props.id || `jsx-source-${sourceCounter++}`, []);
|
|
106
|
-
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
if (map) {
|
|
109
|
-
/* global setTimeout */
|
|
110
|
-
const forceUpdate = () =>
|
|
111
|
-
setTimeout(() => setStyleLoaded((version) => version + 1), 0);
|
|
112
|
-
map.on("styledata", forceUpdate);
|
|
113
|
-
forceUpdate();
|
|
114
|
-
|
|
115
|
-
return () => {
|
|
116
|
-
map.off("styledata", forceUpdate);
|
|
117
|
-
// @ts-ignore
|
|
118
|
-
if (map.style && map.style._loaded && map.getSource(id)) {
|
|
119
|
-
// Parent effects are destroyed before child ones, see
|
|
120
|
-
// https://github.com/facebook/react/issues/16728
|
|
121
|
-
// Source can only be removed after all child layers are removed
|
|
122
|
-
const allLayers = map.getStyle()?.layers;
|
|
123
|
-
if (allLayers) {
|
|
124
|
-
for (const layer of allLayers) {
|
|
125
|
-
// @ts-ignore (2339) source does not exist on all layer types
|
|
126
|
-
if (layer.source === id) {
|
|
127
|
-
map.removeLayer(layer.id);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
map.removeSource(id);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
return undefined;
|
|
136
|
-
}, [map]);
|
|
137
|
-
|
|
138
|
-
// @ts-ignore
|
|
139
|
-
let source = map && map.style && map.getSource(id);
|
|
140
|
-
if (source) {
|
|
141
|
-
updateSource(source, props, propsRef.current);
|
|
142
|
-
} else {
|
|
143
|
-
source = createSource(map, id, props);
|
|
144
|
-
}
|
|
145
|
-
propsRef.current = props;
|
|
146
|
-
|
|
147
|
-
return (
|
|
148
|
-
(source &&
|
|
149
|
-
React.Children.map(
|
|
150
|
-
props.children,
|
|
151
|
-
(child) =>
|
|
152
|
-
child &&
|
|
153
|
-
cloneElement(child, {
|
|
154
|
-
source: id,
|
|
155
|
-
}),
|
|
156
|
-
)) ||
|
|
157
|
-
null
|
|
158
|
-
);
|
|
159
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useEffect, memo } from "react";
|
|
3
|
-
import { applyReactStyle } from "../utils/apply-react-style";
|
|
4
|
-
import { useControl } from "./use-control";
|
|
5
|
-
|
|
6
|
-
import type { ControlPosition } from "../types/lib";
|
|
7
|
-
import type { TerrainSpecification } from "../types/style-spec";
|
|
8
|
-
|
|
9
|
-
export type TerrainControlProps = TerrainSpecification & {
|
|
10
|
-
/** Placement of the control relative to the map. */
|
|
11
|
-
position?: ControlPosition;
|
|
12
|
-
/** CSS style override, applied to the control's container */
|
|
13
|
-
style?: React.CSSProperties;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
function _TerrainControl(props: TerrainControlProps) {
|
|
17
|
-
const ctrl = useControl(({ mapLib }) => new mapLib.TerrainControl(props), {
|
|
18
|
-
position: props.position,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
applyReactStyle(ctrl._container, props.style);
|
|
23
|
-
}, [props.style]);
|
|
24
|
-
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const TerrainControl: React.FC<TerrainControlProps> =
|
|
29
|
-
memo(_TerrainControl);
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { useContext, useMemo, useEffect } from "react";
|
|
2
|
-
import type { IControl, ControlPosition } from "../types/lib";
|
|
3
|
-
import { MapContext } from "./map";
|
|
4
|
-
import type { MapContextValue } from "./map";
|
|
5
|
-
|
|
6
|
-
type ControlOptions = {
|
|
7
|
-
position?: ControlPosition;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function useControl<T extends IControl>(
|
|
11
|
-
onCreate: (context: MapContextValue) => T,
|
|
12
|
-
opts?: ControlOptions,
|
|
13
|
-
): T;
|
|
14
|
-
|
|
15
|
-
export function useControl<T extends IControl>(
|
|
16
|
-
onCreate: (context: MapContextValue) => T,
|
|
17
|
-
onRemove: (context: MapContextValue) => void,
|
|
18
|
-
opts?: ControlOptions,
|
|
19
|
-
): T;
|
|
20
|
-
|
|
21
|
-
export function useControl<T extends IControl>(
|
|
22
|
-
onCreate: (context: MapContextValue) => T,
|
|
23
|
-
onAdd: (context: MapContextValue) => void,
|
|
24
|
-
onRemove: (context: MapContextValue) => void,
|
|
25
|
-
opts?: ControlOptions,
|
|
26
|
-
): T;
|
|
27
|
-
|
|
28
|
-
export function useControl<T extends IControl>(
|
|
29
|
-
onCreate: (context: MapContextValue) => T,
|
|
30
|
-
arg1?: ((context: MapContextValue) => void) | ControlOptions,
|
|
31
|
-
arg2?: ((context: MapContextValue) => void) | ControlOptions,
|
|
32
|
-
arg3?: ControlOptions,
|
|
33
|
-
): T {
|
|
34
|
-
const context = useContext(MapContext);
|
|
35
|
-
const ctrl = useMemo(() => onCreate(context), []);
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
const opts = (arg3 || arg2 || arg1) as ControlOptions;
|
|
39
|
-
const onAdd =
|
|
40
|
-
typeof arg1 === "function" && typeof arg2 === "function" ? arg1 : null;
|
|
41
|
-
const onRemove =
|
|
42
|
-
typeof arg2 === "function"
|
|
43
|
-
? arg2
|
|
44
|
-
: typeof arg1 === "function"
|
|
45
|
-
? arg1
|
|
46
|
-
: null;
|
|
47
|
-
|
|
48
|
-
const { map } = context;
|
|
49
|
-
if (!map.hasControl(ctrl)) {
|
|
50
|
-
map.addControl(ctrl, opts?.position);
|
|
51
|
-
if (onAdd) {
|
|
52
|
-
onAdd(context);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return () => {
|
|
57
|
-
if (onRemove) {
|
|
58
|
-
onRemove(context);
|
|
59
|
-
}
|
|
60
|
-
// Map might have been removed (parent effects are destroyed before child ones)
|
|
61
|
-
if (map.hasControl(ctrl)) {
|
|
62
|
-
map.removeControl(ctrl);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}, []);
|
|
66
|
-
|
|
67
|
-
return ctrl;
|
|
68
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useState, useCallback, useMemo, useContext } from "react";
|
|
3
|
-
|
|
4
|
-
import { MapRef } from "../maplibre/create-ref";
|
|
5
|
-
import { MapContext } from "./map";
|
|
6
|
-
|
|
7
|
-
type MountedMapsContextValue = {
|
|
8
|
-
maps: { [id: string]: MapRef };
|
|
9
|
-
onMapMount: (map: MapRef, id: string) => void;
|
|
10
|
-
onMapUnmount: (id: string) => void;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const MountedMapsContext =
|
|
14
|
-
React.createContext<MountedMapsContextValue>(null);
|
|
15
|
-
|
|
16
|
-
export const MapProvider: React.FC<{ children?: React.ReactNode }> = (
|
|
17
|
-
props,
|
|
18
|
-
) => {
|
|
19
|
-
const [maps, setMaps] = useState<{ [id: string]: MapRef }>({});
|
|
20
|
-
|
|
21
|
-
const onMapMount = useCallback((map: MapRef, id: string = "default") => {
|
|
22
|
-
setMaps((currMaps) => {
|
|
23
|
-
if (id === "current") {
|
|
24
|
-
throw new Error("'current' cannot be used as map id");
|
|
25
|
-
}
|
|
26
|
-
if (currMaps[id]) {
|
|
27
|
-
throw new Error(`Multiple maps with the same id: ${id}`);
|
|
28
|
-
}
|
|
29
|
-
return { ...currMaps, [id]: map };
|
|
30
|
-
});
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
const onMapUnmount = useCallback((id: string = "default") => {
|
|
34
|
-
setMaps((currMaps) => {
|
|
35
|
-
if (currMaps[id]) {
|
|
36
|
-
const nextMaps = { ...currMaps };
|
|
37
|
-
delete nextMaps[id];
|
|
38
|
-
return nextMaps;
|
|
39
|
-
}
|
|
40
|
-
return currMaps;
|
|
41
|
-
});
|
|
42
|
-
}, []);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<MountedMapsContext.Provider
|
|
46
|
-
value={{
|
|
47
|
-
maps,
|
|
48
|
-
onMapMount,
|
|
49
|
-
onMapUnmount,
|
|
50
|
-
}}
|
|
51
|
-
>
|
|
52
|
-
{props.children}
|
|
53
|
-
</MountedMapsContext.Provider>
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export type MapCollection = {
|
|
58
|
-
[id: string]: MapRef | undefined;
|
|
59
|
-
current?: MapRef;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export function useMap(): MapCollection {
|
|
63
|
-
const maps = useContext(MountedMapsContext)?.maps;
|
|
64
|
-
const currentMap = useContext(MapContext);
|
|
65
|
-
|
|
66
|
-
const mapsWithCurrent = useMemo(() => {
|
|
67
|
-
return { ...maps, current: currentMap?.map };
|
|
68
|
-
}, [maps, currentMap]);
|
|
69
|
-
|
|
70
|
-
return mapsWithCurrent as MapCollection;
|
|
71
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Map } from "./components/map";
|
|
2
|
-
export { Map };
|
|
3
|
-
export default Map;
|
|
4
|
-
|
|
5
|
-
export { Marker } from "./components/marker";
|
|
6
|
-
export { Popup } from "./components/popup";
|
|
7
|
-
export { AttributionControl } from "./components/attribution-control";
|
|
8
|
-
export { FullscreenControl } from "./components/fullscreen-control";
|
|
9
|
-
export { GeolocateControl } from "./components/geolocate-control";
|
|
10
|
-
export { NavigationControl } from "./components/navigation-control";
|
|
11
|
-
export { ScaleControl } from "./components/scale-control";
|
|
12
|
-
export { TerrainControl } from "./components/terrain-control";
|
|
13
|
-
export { LogoControl } from "./components/logo-control";
|
|
14
|
-
export { Source } from "./components/source";
|
|
15
|
-
export { Layer } from "./components/layer";
|
|
16
|
-
export { useControl } from "./components/use-control";
|
|
17
|
-
export { MapProvider, useMap } from "./components/use-map";
|
|
18
|
-
|
|
19
|
-
export type { MapProps } from "./components/map";
|
|
20
|
-
export type { MapRef } from "./maplibre/create-ref";
|
|
21
|
-
export type { MarkerProps } from "./components/marker";
|
|
22
|
-
export type { PopupProps } from "./components/popup";
|
|
23
|
-
export type { AttributionControlProps } from "./components/attribution-control";
|
|
24
|
-
export type { FullscreenControlProps } from "./components/fullscreen-control";
|
|
25
|
-
export type { GeolocateControlProps } from "./components/geolocate-control";
|
|
26
|
-
export type { NavigationControlProps } from "./components/navigation-control";
|
|
27
|
-
export type { ScaleControlProps } from "./components/scale-control";
|
|
28
|
-
export type { TerrainControlProps } from "./components/terrain-control";
|
|
29
|
-
export type { LogoControlProps } from "./components/logo-control";
|
|
30
|
-
export type { SourceProps } from "./components/source";
|
|
31
|
-
export type { LayerProps } from "./components/layer";
|
|
32
|
-
|
|
33
|
-
// Types
|
|
34
|
-
export * from "./types/common";
|
|
35
|
-
export * from "./types/events";
|
|
36
|
-
export * from "./types/lib";
|
|
37
|
-
export * from "./types/style-spec";
|
package/src/index.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { Map as MapInstance } from "../types/lib";
|
|
2
|
-
import type Maplibre from "./maplibre";
|
|
3
|
-
|
|
4
|
-
/** These methods may break the react binding if called directly */
|
|
5
|
-
const skipMethods = [
|
|
6
|
-
"setMaxBounds",
|
|
7
|
-
"setMinZoom",
|
|
8
|
-
"setMaxZoom",
|
|
9
|
-
"setMinPitch",
|
|
10
|
-
"setMaxPitch",
|
|
11
|
-
"setRenderWorldCopies",
|
|
12
|
-
"setProjection",
|
|
13
|
-
"setStyle",
|
|
14
|
-
"addSource",
|
|
15
|
-
"removeSource",
|
|
16
|
-
"addLayer",
|
|
17
|
-
"removeLayer",
|
|
18
|
-
"setLayerZoomRange",
|
|
19
|
-
"setFilter",
|
|
20
|
-
"setPaintProperty",
|
|
21
|
-
"setLayoutProperty",
|
|
22
|
-
"setLight",
|
|
23
|
-
"setTerrain",
|
|
24
|
-
"setFog",
|
|
25
|
-
"remove",
|
|
26
|
-
] as const;
|
|
27
|
-
|
|
28
|
-
export type MapRef = {
|
|
29
|
-
getMap(): MapInstance;
|
|
30
|
-
} & Omit<MapInstance, (typeof skipMethods)[number]>;
|
|
31
|
-
|
|
32
|
-
export default function createRef(mapInstance: Maplibre): MapRef | null {
|
|
33
|
-
if (!mapInstance) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const map = mapInstance.map;
|
|
38
|
-
const result: any = {
|
|
39
|
-
getMap: () => map,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
for (const key of getMethodNames(map)) {
|
|
43
|
-
// @ts-expect-error
|
|
44
|
-
if (!(key in result) && !skipMethods.includes(key)) {
|
|
45
|
-
result[key] = map[key].bind(map);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function getMethodNames(obj: Object) {
|
|
53
|
-
const result = new Set<string>();
|
|
54
|
-
|
|
55
|
-
let proto = obj;
|
|
56
|
-
while (proto) {
|
|
57
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
58
|
-
if (
|
|
59
|
-
key[0] !== "_" &&
|
|
60
|
-
typeof obj[key] === "function" &&
|
|
61
|
-
key !== "fire" &&
|
|
62
|
-
key !== "setEventedParent"
|
|
63
|
-
) {
|
|
64
|
-
result.add(key);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
proto = Object.getPrototypeOf(proto);
|
|
68
|
-
}
|
|
69
|
-
return Array.from(result);
|
|
70
|
-
}
|