react-bkoi-gl 1.0.7 → 2.0.1

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.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +172 -18
  3. package/dist/index.cjs +671 -736
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +370 -0
  6. package/dist/index.d.ts +370 -2
  7. package/dist/index.js +1434 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/styles/index.d.ts +4 -0
  10. package/dist/styles/react-bkoi-gl.css +1 -1
  11. package/package.json +84 -36
  12. package/bkoi-gl/package.json +0 -6
  13. package/dist/components/attribution-control.d.ts +0 -11
  14. package/dist/components/attribution-control.js +0 -19
  15. package/dist/components/attribution-control.js.map +0 -1
  16. package/dist/components/fullscreen-control.d.ts +0 -14
  17. package/dist/components/fullscreen-control.js +0 -21
  18. package/dist/components/fullscreen-control.js.map +0 -1
  19. package/dist/components/geolocate-control.d.ts +0 -37
  20. package/dist/components/geolocate-control.js +0 -46
  21. package/dist/components/geolocate-control.js.map +0 -1
  22. package/dist/components/layer.d.ts +0 -17
  23. package/dist/components/layer.js +0 -99
  24. package/dist/components/layer.js.map +0 -1
  25. package/dist/components/map.d.ts +0 -23
  26. package/dist/components/map.js +0 -102
  27. package/dist/components/map.js.map +0 -1
  28. package/dist/components/marker.d.ts +0 -41
  29. package/dist/components/marker.js +0 -98
  30. package/dist/components/marker.js.map +0 -1
  31. package/dist/components/navigation-control.d.ts +0 -11
  32. package/dist/components/navigation-control.js +0 -19
  33. package/dist/components/navigation-control.js.map +0 -1
  34. package/dist/components/popup.d.ts +0 -33
  35. package/dist/components/popup.js +0 -79
  36. package/dist/components/popup.js.map +0 -1
  37. package/dist/components/scale-control.d.ts +0 -13
  38. package/dist/components/scale-control.js +0 -31
  39. package/dist/components/scale-control.js.map +0 -1
  40. package/dist/components/source.d.ts +0 -7
  41. package/dist/components/source.js +0 -97
  42. package/dist/components/source.js.map +0 -1
  43. package/dist/components/use-control.d.ts +0 -9
  44. package/dist/components/use-control.js +0 -31
  45. package/dist/components/use-control.js.map +0 -1
  46. package/dist/components/use-map.d.ts +0 -20
  47. package/dist/components/use-map.js +0 -54
  48. package/dist/components/use-map.js.map +0 -1
  49. package/dist/exports-bkoi-gl.cjs +0 -1512
  50. package/dist/exports-bkoi-gl.d.ts +0 -89
  51. package/dist/exports-bkoi-gl.js +0 -36
  52. package/dist/exports-bkoi-gl.js.map +0 -1
  53. package/dist/exports-mapbox.d.ts +0 -139
  54. package/dist/exports-mapbox.js +0 -36
  55. package/dist/exports-mapbox.js.map +0 -1
  56. package/dist/mapbox/create-ref.d.ts +0 -9
  57. package/dist/mapbox/create-ref.js +0 -64
  58. package/dist/mapbox/create-ref.js.map +0 -1
  59. package/dist/mapbox/mapbox.d.ts +0 -81
  60. package/dist/mapbox/mapbox.js +0 -476
  61. package/dist/mapbox/mapbox.js.map +0 -1
  62. package/dist/types/common.d.ts +0 -78
  63. package/dist/types/common.js +0 -2
  64. package/dist/types/common.js.map +0 -1
  65. package/dist/types/events-bkoi-gl.d.ts +0 -49
  66. package/dist/types/events-bkoi-gl.js +0 -2
  67. package/dist/types/events-bkoi-gl.js.map +0 -1
  68. package/dist/types/events-mapbox.d.ts +0 -49
  69. package/dist/types/events-mapbox.js +0 -2
  70. package/dist/types/events-mapbox.js.map +0 -1
  71. package/dist/types/events.d.ts +0 -39
  72. package/dist/types/events.js +0 -2
  73. package/dist/types/events.js.map +0 -1
  74. package/dist/types/index.d.ts +0 -70
  75. package/dist/types/index.js +0 -5
  76. package/dist/types/index.js.map +0 -1
  77. package/dist/types/lib.d.ts +0 -224
  78. package/dist/types/lib.js +0 -2
  79. package/dist/types/lib.js.map +0 -1
  80. package/dist/types/public.d.ts +0 -2
  81. package/dist/types/public.js +0 -2
  82. package/dist/types/public.js.map +0 -1
  83. package/dist/types/style-spec-bkoi-gl.d.ts +0 -9
  84. package/dist/types/style-spec-bkoi-gl.js +0 -2
  85. package/dist/types/style-spec-bkoi-gl.js.map +0 -1
  86. package/dist/types/style-spec-mapbox.d.ts +0 -7
  87. package/dist/types/style-spec-mapbox.js +0 -2
  88. package/dist/types/style-spec-mapbox.js.map +0 -1
  89. package/dist/utils/apply-react-style.d.ts +0 -2
  90. package/dist/utils/apply-react-style.js +0 -16
  91. package/dist/utils/apply-react-style.js.map +0 -1
  92. package/dist/utils/assert.d.ts +0 -1
  93. package/dist/utils/assert.js +0 -6
  94. package/dist/utils/assert.js.map +0 -1
  95. package/dist/utils/deep-equal.d.ts +0 -15
  96. package/dist/utils/deep-equal.js +0 -46
  97. package/dist/utils/deep-equal.js.map +0 -1
  98. package/dist/utils/set-globals.d.ts +0 -22
  99. package/dist/utils/set-globals.js +0 -19
  100. package/dist/utils/set-globals.js.map +0 -1
  101. package/dist/utils/style-utils.d.ts +0 -2
  102. package/dist/utils/style-utils.js +0 -42
  103. package/dist/utils/style-utils.js.map +0 -1
  104. package/dist/utils/transform.d.ts +0 -26
  105. package/dist/utils/transform.js +0 -56
  106. package/dist/utils/transform.js.map +0 -1
  107. package/dist/utils/use-isomorphic-layout-effect.d.ts +0 -3
  108. package/dist/utils/use-isomorphic-layout-effect.js +0 -4
  109. package/dist/utils/use-isomorphic-layout-effect.js.map +0 -1
  110. package/src/components/attribution-control.ts +0 -32
  111. package/src/components/fullscreen-control.tsx +0 -37
  112. package/src/components/geolocate-control.ts +0 -90
  113. package/src/components/layer.ts +0 -133
  114. package/src/components/map.tsx +0 -155
  115. package/src/components/marker.ts +0 -137
  116. package/src/components/navigation-control.ts +0 -29
  117. package/src/components/popup.ts +0 -116
  118. package/src/components/scale-control.ts +0 -46
  119. package/src/components/source.ts +0 -158
  120. package/src/components/use-control.ts +0 -64
  121. package/src/components/use-map.tsx +0 -69
  122. package/src/exports-bkoi-gl.ts +0 -156
  123. package/src/exports-mapbox.ts +0 -159
  124. package/src/index.ts +0 -2
  125. package/src/mapbox/create-ref.ts +0 -118
  126. package/src/mapbox/mapbox.ts +0 -742
  127. package/src/types/common.ts +0 -94
  128. package/src/types/events-bkoi-gl.ts +0 -78
  129. package/src/types/events-mapbox.ts +0 -76
  130. package/src/types/events.ts +0 -73
  131. package/src/types/index.ts +0 -93
  132. package/src/types/lib.ts +0 -279
  133. package/src/types/public.ts +0 -9
  134. package/src/types/style-spec-bkoi-gl.ts +0 -81
  135. package/src/types/style-spec-mapbox.ts +0 -80
  136. package/src/utils/apply-react-style.ts +0 -20
  137. package/src/utils/assert.ts +0 -5
  138. package/src/utils/deep-equal.ts +0 -61
  139. package/src/utils/set-globals.ts +0 -57
  140. package/src/utils/style-utils.ts +0 -59
  141. package/src/utils/transform.ts +0 -86
  142. package/src/utils/use-isomorphic-layout-effect.ts +0 -7
@@ -1,69 +0,0 @@
1
- import * as React from 'react';
2
- import {useState, useCallback, useMemo, useContext} from 'react';
3
-
4
- import {MapRef} from '../mapbox/create-ref';
5
- import {MapContext} from './map';
6
- import {MapInstance} from '../types';
7
-
8
- type MountedMapsContextValue = {
9
- maps: {[id: string]: MapRef<MapInstance>};
10
- onMapMount: (map: MapRef<MapInstance>, id: string) => void;
11
- onMapUnmount: (id: string) => void;
12
- };
13
-
14
- export const MountedMapsContext = React.createContext<MountedMapsContextValue>(null);
15
-
16
- export const MapProvider: React.FC<{children?: React.ReactNode}> = props => {
17
- const [maps, setMaps] = useState<{[id: string]: MapRef<MapInstance>}>({});
18
-
19
- const onMapMount = useCallback((map: MapRef<MapInstance>, id: string = 'default') => {
20
- setMaps(currMaps => {
21
- if (id === 'current') {
22
- throw new Error("'current' cannot be used as map id");
23
- }
24
- if (currMaps[id]) {
25
- throw new Error(`Multiple maps with the same id: ${id}`);
26
- }
27
- return {...currMaps, [id]: map};
28
- });
29
- }, []);
30
-
31
- const onMapUnmount = useCallback((id: string = 'default') => {
32
- setMaps(currMaps => {
33
- if (currMaps[id]) {
34
- const nextMaps = {...currMaps};
35
- delete nextMaps[id];
36
- return nextMaps;
37
- }
38
- return currMaps;
39
- });
40
- }, []);
41
-
42
- return (
43
- <MountedMapsContext.Provider
44
- value={{
45
- maps,
46
- onMapMount,
47
- onMapUnmount
48
- }}
49
- >
50
- {props.children}
51
- </MountedMapsContext.Provider>
52
- );
53
- };
54
-
55
- export type MapCollection<MapT extends MapInstance> = {
56
- [id: string]: MapRef<MapT> | undefined;
57
- current?: MapRef<MapT>;
58
- };
59
-
60
- export function useMap<MapT extends MapInstance>(): MapCollection<MapT> {
61
- const maps = useContext(MountedMapsContext)?.maps;
62
- const currentMap = useContext(MapContext);
63
-
64
- const mapsWithCurrent = useMemo(() => {
65
- return {...maps, current: currentMap?.map};
66
- }, [maps, currentMap]);
67
-
68
- return mapsWithCurrent as MapCollection<MapT>;
69
- }
@@ -1,156 +0,0 @@
1
- import * as React from 'react';
2
- import {
3
- Map as BkoiMap,
4
- MapOptions,
5
- Marker as BkoiMarker,
6
- MarkerOptions,
7
- Popup as BkoiPopup,
8
- PopupOptions,
9
- AttributionControl as BkoiAttributionControl,
10
- FullscreenControl as BkoiFullscreenControl,
11
- GeolocateControl as BkoiGeolocateControl,
12
- NavigationControl as BkoiNavigationControl,
13
- ScaleControl as BkoiScaleControl
14
- // @ts-ignore
15
- // eslint-disable-next-line import/no-unresolved
16
- } from 'bkoi-gl';
17
- import { MapStyle, AnyLayer, AnySource } from './types/style-spec-bkoi-gl';
18
-
19
- import { default as _Map, MapProps as _MapProps } from './components/map';
20
- import { default as _Marker, MarkerProps as _MarkerProps } from './components/marker';
21
- import { default as _Popup, PopupProps as _PopupProps } from './components/popup';
22
- import {
23
- default as _AttributionControl,
24
- AttributionControlProps as _AttributionControlProps
25
- } from './components/attribution-control';
26
- import {
27
- default as _FullscreenControl,
28
- FullscreenControlProps as _FullscreenControlProps
29
- } from './components/fullscreen-control';
30
- import {
31
- default as _GeolocateControl,
32
- GeolocateControlProps as _GeolocateControlProps
33
- } from './components/geolocate-control';
34
- import {
35
- default as _NavigationControl,
36
- NavigationControlProps as _NavigationControlProps
37
- } from './components/navigation-control';
38
- import {
39
- default as _ScaleControl,
40
- ScaleControlProps as _ScaleControlProps
41
- } from './components/scale-control';
42
- import { default as _Layer, LayerProps as _LayerProps } from './components/layer';
43
- import { default as _Source, SourceProps as _SourceProps } from './components/source';
44
- import { useMap as _useMap } from './components/use-map';
45
- import type { MapRef as _MapRef } from './mapbox/create-ref';
46
- import type * as events from './types/events';
47
- import type { MapCallbacks } from './types/events-bkoi-gl';
48
-
49
- export function useMap() {
50
- return _useMap<BkoiMap>();
51
- }
52
-
53
- export type MapProps = _MapProps<MapOptions, MapStyle, MapCallbacks, BkoiMap>;
54
- export type MapRef = _MapRef<BkoiMap>;
55
- // @ts-ignore
56
- // eslint-disable-next-line import/no-unresolved
57
- const mapLib = import('bkoi-gl');
58
- export const Map = (() => {
59
- return React.forwardRef(function Map(props: MapProps, ref: React.Ref<MapRef>) {
60
- return _Map<MapOptions, MapStyle, MapCallbacks, BkoiMap>(props, ref, mapLib);
61
- });
62
- })();
63
-
64
- export type MarkerProps = _MarkerProps<MarkerOptions, BkoiMarker>;
65
- export const Marker = _Marker as (
66
- props: MarkerProps & React.RefAttributes<BkoiMarker>
67
- ) => React.ReactElement | null;
68
-
69
- export type PopupProps = _PopupProps<PopupOptions, BkoiPopup>;
70
- export const Popup = _Popup as (
71
- props: PopupProps & React.RefAttributes<BkoiPopup>
72
- ) => React.ReactElement | null;
73
-
74
- type AttributionControlOptions = ConstructorParameters<typeof BkoiAttributionControl>[0];
75
- export type AttributionControlProps = _AttributionControlProps<AttributionControlOptions>;
76
- export const AttributionControl = _AttributionControl as (
77
- props: AttributionControlProps
78
- ) => React.ReactElement | null;
79
-
80
- type FullscreenControlOptions = ConstructorParameters<typeof BkoiFullscreenControl>[0];
81
- export type FullscreenControlProps = _FullscreenControlProps<FullscreenControlOptions>;
82
- export const FullscreenControl = _FullscreenControl as (
83
- props: FullscreenControlProps
84
- ) => React.ReactElement | null;
85
-
86
- type NavigationControlOptions = ConstructorParameters<typeof BkoiNavigationControl>[0];
87
- export type NavigationControlProps = _NavigationControlProps<NavigationControlOptions>;
88
- export const NavigationControl = _NavigationControl as (
89
- props: NavigationControlProps
90
- ) => React.ReactElement | null;
91
-
92
- type GeolocateControlOptions = ConstructorParameters<typeof BkoiGeolocateControl>[0];
93
- export type GeolocateControlProps = _GeolocateControlProps<
94
- GeolocateControlOptions,
95
- BkoiGeolocateControl
96
- >;
97
- export const GeolocateControl = _GeolocateControl as (
98
- props: GeolocateControlProps & React.RefAttributes<BkoiGeolocateControl>
99
- ) => React.ReactElement | null;
100
-
101
- type ScaleControlOptions = ConstructorParameters<typeof BkoiScaleControl>[0];
102
- export type ScaleControlProps = _ScaleControlProps<ScaleControlOptions>;
103
- export const ScaleControl = _ScaleControl as (
104
- props: ScaleControlProps
105
- ) => React.ReactElement | null;
106
-
107
- export type LayerProps = _LayerProps<AnyLayer>;
108
- export const Layer = _Layer as (props: LayerProps) => React.ReactElement | null;
109
-
110
- export type SourceProps = _SourceProps<AnySource>;
111
- export const Source = _Source as (props: SourceProps) => React.ReactElement | null;
112
-
113
- export { default as useControl } from './components/use-control';
114
- export { MapProvider } from './components/use-map';
115
-
116
- export default Map;
117
-
118
- // Types
119
- export * from './types/public';
120
- export type { default as Point } from '@mapbox/point-geometry';
121
- // export type {
122
- // PointLike,
123
- // LngLat,
124
- // LngLatLike,
125
- // LngLatBounds,
126
- // LngLatBoundsLike,
127
- // PaddingOptions,
128
- // MapGeoJSONFeature,
129
- // GeoJSONSource,
130
- // VideoSource,
131
- // ImageSource,
132
- // CanvasSource,
133
- // VectorTileSource
134
- // } from 'maplibre-gl';
135
- export * from './types/style-spec-bkoi-gl';
136
-
137
- // Events
138
- export type {
139
- MapEvent,
140
- MapMouseEvent,
141
- MapLayerMouseEvent,
142
- MapTouchEvent,
143
- MapLayerTouchEvent,
144
- MapStyleDataEvent,
145
- MapSourceDataEvent,
146
- MapWheelEvent,
147
- MapBoxZoomEvent,
148
- ErrorEvent,
149
- ViewStateChangeEvent
150
- } from './types/events-bkoi-gl';
151
- export type PopupEvent = events.PopupEvent<BkoiPopup>;
152
- export type MarkerEvent = events.MarkerEvent<BkoiMarker>;
153
- export type MarkerDragEvent = events.MarkerDragEvent<BkoiMarker>;
154
- export type GeolocateEvent = events.GeolocateEvent<BkoiGeolocateControl>;
155
- export type GeolocateResultEvent = events.GeolocateResultEvent<BkoiGeolocateControl>;
156
- export type GeolocateErrorEvent = events.GeolocateErrorEvent<BkoiGeolocateControl>;
@@ -1,159 +0,0 @@
1
- import * as React from 'react';
2
- import type {
3
- Map as MapboxMap,
4
- MapboxOptions,
5
- Marker as MapboxMarker,
6
- MarkerOptions,
7
- Popup as MapboxPopup,
8
- PopupOptions,
9
- AttributionControl as MapboxAttributionControl,
10
- FullscreenControl as MapboxFullscreenControl,
11
- GeolocateControl as MapboxGeolocateControl,
12
- NavigationControl as MapboxNavigationControl,
13
- ScaleControl as MapboxScaleControl
14
- } from 'mapbox-gl';
15
- import {MapStyle, AnyLayer, AnySource} from './types/style-spec-mapbox';
16
-
17
- import {default as _Map, MapProps as _MapProps} from './components/map';
18
- import {default as _Marker, MarkerProps as _MarkerProps} from './components/marker';
19
- import {default as _Popup, PopupProps as _PopupProps} from './components/popup';
20
- import {
21
- default as _AttributionControl,
22
- AttributionControlProps as _AttributionControlProps
23
- } from './components/attribution-control';
24
- import {
25
- default as _FullscreenControl,
26
- FullscreenControlProps as _FullscreenControlProps
27
- } from './components/fullscreen-control';
28
- import {
29
- default as _GeolocateControl,
30
- GeolocateControlProps as _GeolocateControlProps
31
- } from './components/geolocate-control';
32
- import {
33
- default as _NavigationControl,
34
- NavigationControlProps as _NavigationControlProps
35
- } from './components/navigation-control';
36
- import {
37
- default as _ScaleControl,
38
- ScaleControlProps as _ScaleControlProps
39
- } from './components/scale-control';
40
- import {default as _Layer, LayerProps as _LayerProps} from './components/layer';
41
- import {default as _Source, SourceProps as _SourceProps} from './components/source';
42
- import {useMap as _useMap} from './components/use-map';
43
- import type {MapRef as _MapRef} from './mapbox/create-ref';
44
- import type * as events from './types/events';
45
- import type {MapCallbacks} from './types/events-mapbox';
46
-
47
- export function useMap() {
48
- return _useMap<MapboxMap>();
49
- }
50
-
51
- export type MapProps = _MapProps<MapboxOptions, MapStyle, MapCallbacks, MapboxMap>;
52
- export type MapRef = _MapRef<MapboxMap>;
53
- const mapLib = import('mapbox-gl');
54
- export const Map = (() => {
55
- return React.forwardRef(function Map(props: MapProps, ref: React.Ref<MapRef>) {
56
- return _Map<MapboxOptions, MapStyle, MapCallbacks, MapboxMap>(props, ref, mapLib);
57
- });
58
- })();
59
-
60
- export type MarkerProps = _MarkerProps<MarkerOptions, MapboxMarker>;
61
- export const Marker = _Marker as (
62
- props: MarkerProps & React.RefAttributes<MapboxMarker>
63
- ) => React.ReactElement | null;
64
-
65
- export type PopupProps = _PopupProps<PopupOptions, MapboxPopup>;
66
- export const Popup = _Popup as (
67
- props: PopupProps & React.RefAttributes<MapboxPopup>
68
- ) => React.ReactElement | null;
69
-
70
- type AttributionControlOptions = ConstructorParameters<typeof MapboxAttributionControl>[0];
71
- export type AttributionControlProps = _AttributionControlProps<AttributionControlOptions>;
72
- export const AttributionControl = _AttributionControl as (
73
- props: AttributionControlProps
74
- ) => React.ReactElement | null;
75
-
76
- type FullscreenControlOptions = ConstructorParameters<typeof MapboxFullscreenControl>[0];
77
- export type FullscreenControlProps = _FullscreenControlProps<FullscreenControlOptions>;
78
- export const FullscreenControl = _FullscreenControl as (
79
- props: FullscreenControlProps
80
- ) => React.ReactElement | null;
81
-
82
- type NavigationControlOptions = ConstructorParameters<typeof MapboxNavigationControl>[0];
83
- export type NavigationControlProps = _NavigationControlProps<NavigationControlOptions>;
84
- export const NavigationControl = _NavigationControl as (
85
- props: NavigationControlProps
86
- ) => React.ReactElement | null;
87
-
88
- type GeolocateControlOptions = ConstructorParameters<typeof MapboxGeolocateControl>[0];
89
- export type GeolocateControlProps = _GeolocateControlProps<
90
- GeolocateControlOptions,
91
- MapboxGeolocateControl
92
- >;
93
- export const GeolocateControl = _GeolocateControl as (
94
- props: GeolocateControlProps & React.RefAttributes<MapboxGeolocateControl>
95
- ) => React.ReactElement | null;
96
-
97
- type ScaleControlOptions = ConstructorParameters<typeof MapboxScaleControl>[0];
98
- export type ScaleControlProps = _ScaleControlProps<ScaleControlOptions>;
99
- export const ScaleControl = _ScaleControl as (
100
- props: ScaleControlProps
101
- ) => React.ReactElement | null;
102
-
103
- export type LayerProps = _LayerProps<AnyLayer>;
104
- export const Layer = _Layer as (props: LayerProps) => React.ReactElement | null;
105
-
106
- export type SourceProps = _SourceProps<AnySource>;
107
- export const Source = _Source as (props: SourceProps) => React.ReactElement | null;
108
-
109
- export {default as useControl} from './components/use-control';
110
- export {MapProvider} from './components/use-map';
111
-
112
- export default Map;
113
-
114
- // Types
115
- export * from './types/public';
116
- export type {
117
- Point,
118
- PointLike,
119
- LngLat,
120
- LngLatLike,
121
- LngLatBounds,
122
- LngLatBoundsLike,
123
- PaddingOptions,
124
- MapboxGeoJSONFeature as MapGeoJSONFeature,
125
- GeoJSONSource,
126
- VideoSource,
127
- ImageSource,
128
- CanvasSource,
129
- VectorSourceImpl as VectorTileSource
130
- } from 'mapbox-gl';
131
- export * from './types/style-spec-mapbox';
132
-
133
- // Events
134
- export type {
135
- MapEvent,
136
- MapMouseEvent,
137
- MapLayerMouseEvent,
138
- MapTouchEvent,
139
- MapLayerTouchEvent,
140
- MapStyleDataEvent,
141
- MapSourceDataEvent,
142
- MapWheelEvent,
143
- MapBoxZoomEvent,
144
- ErrorEvent,
145
- ViewStateChangeEvent
146
- } from './types/events-mapbox';
147
- export type PopupEvent = events.PopupEvent<MapboxPopup>;
148
- export type MarkerEvent = events.MarkerEvent<MapboxMarker>;
149
- export type MarkerDragEvent = events.MarkerDragEvent<MapboxMarker>;
150
- export type GeolocateEvent = events.GeolocateEvent<MapboxGeolocateControl>;
151
- export type GeolocateResultEvent = events.GeolocateResultEvent<MapboxGeolocateControl>;
152
- export type GeolocateErrorEvent = events.GeolocateErrorEvent<MapboxGeolocateControl>;
153
-
154
- // v7.0 backward compatibility
155
-
156
- /** @deprecated use `MapStyle` */
157
- export type MapboxStyle = MapStyle;
158
-
159
- export type {Map as MapboxMap, MapboxEvent, MapboxGeoJSONFeature} from 'mapbox-gl';
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './exports-mapbox';
2
- export {default as default} from './exports-mapbox';
@@ -1,118 +0,0 @@
1
- import type {
2
- MapInstance,
3
- MapInstanceInternal,
4
- MapStyle,
5
- Callbacks,
6
- LngLatLike,
7
- PointLike
8
- } from '../types';
9
- import type Mapbox from './mapbox';
10
-
11
- /** These methods may break the react binding if called directly */
12
- const skipMethods = [
13
- 'setMaxBounds',
14
- 'setMinZoom',
15
- 'setMaxZoom',
16
- 'setMinPitch',
17
- 'setMaxPitch',
18
- 'setRenderWorldCopies',
19
- 'setProjection',
20
- 'setStyle',
21
- 'addSource',
22
- 'removeSource',
23
- 'addLayer',
24
- 'removeLayer',
25
- 'setLayerZoomRange',
26
- 'setFilter',
27
- 'setPaintProperty',
28
- 'setLayoutProperty',
29
- 'setLight',
30
- 'setTerrain',
31
- 'setFog',
32
- 'remove'
33
- ] as const;
34
-
35
- export type MapRef<MapT extends MapInstance> = {
36
- getMap(): MapT;
37
- } & Omit<MapT, typeof skipMethods[number]>;
38
-
39
- export default function createRef<
40
- StyleT extends MapStyle,
41
- CallbacksT extends Callbacks,
42
- MapT extends MapInstance
43
- >(mapInstance: Mapbox<StyleT, CallbacksT, MapT>): MapRef<MapT> | null {
44
- if (!mapInstance) {
45
- return null;
46
- }
47
-
48
- const map = mapInstance.map as MapInstanceInternal<MapT>;
49
- const result: any = {
50
- getMap: () => map,
51
-
52
- // Overwrite getters to use our shadow transform
53
- getCenter: () => mapInstance.transform.center,
54
- getZoom: () => mapInstance.transform.zoom,
55
- getBearing: () => mapInstance.transform.bearing,
56
- getPitch: () => mapInstance.transform.pitch,
57
- getPadding: () => mapInstance.transform.padding,
58
- getBounds: () => mapInstance.transform.getBounds(),
59
- project: (lnglat: LngLatLike) => {
60
- const tr = map.transform;
61
- map.transform = mapInstance.transform;
62
- const result = map.project(lnglat);
63
- map.transform = tr;
64
- return result;
65
- },
66
- unproject: (point: PointLike) => {
67
- const tr = map.transform;
68
- map.transform = mapInstance.transform;
69
- const result = map.unproject(point);
70
- map.transform = tr;
71
- return result;
72
- },
73
- // options diverge between mapbox and maplibre
74
- queryTerrainElevation: (lnglat: LngLatLike, options?: any) => {
75
- const tr = map.transform;
76
- map.transform = mapInstance.transform;
77
- const result = map.queryTerrainElevation(lnglat, options);
78
- map.transform = tr;
79
- return result;
80
- },
81
- queryRenderedFeatures: (geometry?: any, options?: any) => {
82
- const tr = map.transform;
83
- map.transform = mapInstance.transform;
84
- const result = map.queryRenderedFeatures(geometry, options);
85
- map.transform = tr;
86
- return result;
87
- }
88
- };
89
-
90
- for (const key of getMethodNames(map)) {
91
- // @ts-expect-error
92
- if (!(key in result) && !skipMethods.includes(key)) {
93
- result[key] = map[key].bind(map);
94
- }
95
- }
96
-
97
- return result;
98
- }
99
-
100
- function getMethodNames(obj: Object) {
101
- const result = new Set<string>();
102
-
103
- let proto = obj;
104
- while (proto) {
105
- for (const key of Object.getOwnPropertyNames(proto)) {
106
- if (
107
- key[0] !== '_' &&
108
- typeof obj[key] === 'function' &&
109
- key !== 'fire' &&
110
- key !== 'setEventedParent'
111
- ) {
112
- result.add(key);
113
- }
114
- }
115
- proto = Object.getPrototypeOf(proto);
116
- }
117
- return Array.from(result);
118
- }