react-bkoi-gl 1.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.
- package/README.md +96 -0
- package/bkoi-gl/package.json +6 -0
- package/dist/components/attribution-control.d.ts +11 -0
- package/dist/components/attribution-control.js +19 -0
- package/dist/components/attribution-control.js.map +1 -0
- package/dist/components/fullscreen-control.d.ts +14 -0
- package/dist/components/fullscreen-control.js +21 -0
- package/dist/components/fullscreen-control.js.map +1 -0
- package/dist/components/geolocate-control.d.ts +37 -0
- package/dist/components/geolocate-control.js +51 -0
- package/dist/components/geolocate-control.js.map +1 -0
- package/dist/components/layer.d.ts +17 -0
- package/dist/components/layer.js +99 -0
- package/dist/components/layer.js.map +1 -0
- package/dist/components/map.d.ts +23 -0
- package/dist/components/map.js +102 -0
- package/dist/components/map.js.map +1 -0
- package/dist/components/marker.d.ts +41 -0
- package/dist/components/marker.js +102 -0
- package/dist/components/marker.js.map +1 -0
- package/dist/components/navigation-control.d.ts +11 -0
- package/dist/components/navigation-control.js +19 -0
- package/dist/components/navigation-control.js.map +1 -0
- package/dist/components/popup.d.ts +33 -0
- package/dist/components/popup.js +81 -0
- package/dist/components/popup.js.map +1 -0
- package/dist/components/scale-control.d.ts +13 -0
- package/dist/components/scale-control.js +31 -0
- package/dist/components/scale-control.js.map +1 -0
- package/dist/components/source.d.ts +7 -0
- package/dist/components/source.js +98 -0
- package/dist/components/source.js.map +1 -0
- package/dist/components/use-control.d.ts +9 -0
- package/dist/components/use-control.js +31 -0
- package/dist/components/use-control.js.map +1 -0
- package/dist/components/use-map.d.ts +20 -0
- package/dist/components/use-map.js +55 -0
- package/dist/components/use-map.js.map +1 -0
- package/dist/exports-bkoi-gl.cjs +1512 -0
- package/dist/exports-bkoi-gl.d.ts +89 -0
- package/dist/exports-bkoi-gl.js +36 -0
- package/dist/exports-bkoi-gl.js.map +1 -0
- package/dist/exports-mapbox.d.ts +139 -0
- package/dist/exports-mapbox.js +36 -0
- package/dist/exports-mapbox.js.map +1 -0
- package/dist/index.cjs +1514 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/mapbox/create-ref.d.ts +9 -0
- package/dist/mapbox/create-ref.js +64 -0
- package/dist/mapbox/create-ref.js.map +1 -0
- package/dist/mapbox/mapbox.d.ts +81 -0
- package/dist/mapbox/mapbox.js +477 -0
- package/dist/mapbox/mapbox.js.map +1 -0
- package/dist/styles/react-bkoi-gl.css +1 -0
- package/dist/types/common.d.ts +78 -0
- package/dist/types/common.js +2 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/events-bkoi-gl.d.ts +49 -0
- package/dist/types/events-bkoi-gl.js +2 -0
- package/dist/types/events-bkoi-gl.js.map +1 -0
- package/dist/types/events-mapbox.d.ts +49 -0
- package/dist/types/events-mapbox.js +2 -0
- package/dist/types/events-mapbox.js.map +1 -0
- package/dist/types/events.d.ts +39 -0
- package/dist/types/events.js +2 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +70 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/lib.d.ts +224 -0
- package/dist/types/lib.js +2 -0
- package/dist/types/lib.js.map +1 -0
- package/dist/types/public.d.ts +2 -0
- package/dist/types/public.js +2 -0
- package/dist/types/public.js.map +1 -0
- package/dist/types/style-spec-bkoi-gl.d.ts +9 -0
- package/dist/types/style-spec-bkoi-gl.js +2 -0
- package/dist/types/style-spec-bkoi-gl.js.map +1 -0
- package/dist/types/style-spec-mapbox.d.ts +7 -0
- package/dist/types/style-spec-mapbox.js +2 -0
- package/dist/types/style-spec-mapbox.js.map +1 -0
- package/dist/utils/apply-react-style.d.ts +2 -0
- package/dist/utils/apply-react-style.js +16 -0
- package/dist/utils/apply-react-style.js.map +1 -0
- package/dist/utils/assert.d.ts +1 -0
- package/dist/utils/assert.js +6 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/deep-equal.d.ts +15 -0
- package/dist/utils/deep-equal.js +46 -0
- package/dist/utils/deep-equal.js.map +1 -0
- package/dist/utils/set-globals.d.ts +22 -0
- package/dist/utils/set-globals.js +19 -0
- package/dist/utils/set-globals.js.map +1 -0
- package/dist/utils/style-utils.d.ts +2 -0
- package/dist/utils/style-utils.js +42 -0
- package/dist/utils/style-utils.js.map +1 -0
- package/dist/utils/transform.d.ts +26 -0
- package/dist/utils/transform.js +56 -0
- package/dist/utils/transform.js.map +1 -0
- package/dist/utils/use-isomorphic-layout-effect.d.ts +3 -0
- package/dist/utils/use-isomorphic-layout-effect.js +4 -0
- package/dist/utils/use-isomorphic-layout-effect.js.map +1 -0
- package/package.json +78 -0
- package/src/components/attribution-control.ts +32 -0
- package/src/components/fullscreen-control.tsx +37 -0
- package/src/components/geolocate-control.ts +90 -0
- package/src/components/layer.ts +133 -0
- package/src/components/map.tsx +155 -0
- package/src/components/marker.ts +137 -0
- package/src/components/navigation-control.ts +29 -0
- package/src/components/popup.ts +116 -0
- package/src/components/scale-control.ts +46 -0
- package/src/components/source.ts +158 -0
- package/src/components/use-control.ts +64 -0
- package/src/components/use-map.tsx +69 -0
- package/src/exports-bkoi-gl.ts +156 -0
- package/src/exports-mapbox.ts +159 -0
- package/src/index.ts +2 -0
- package/src/mapbox/create-ref.ts +118 -0
- package/src/mapbox/mapbox.ts +742 -0
- package/src/types/common.ts +94 -0
- package/src/types/events-bkoi-gl.ts +78 -0
- package/src/types/events-mapbox.ts +76 -0
- package/src/types/events.ts +73 -0
- package/src/types/index.ts +93 -0
- package/src/types/lib.ts +279 -0
- package/src/types/public.ts +9 -0
- package/src/types/style-spec-bkoi-gl.ts +81 -0
- package/src/types/style-spec-mapbox.ts +80 -0
- package/src/utils/apply-react-style.ts +20 -0
- package/src/utils/assert.ts +5 -0
- package/src/utils/deep-equal.ts +61 -0
- package/src/utils/set-globals.ts +57 -0
- package/src/utils/style-utils.ts +59 -0
- package/src/utils/transform.ts +86 -0
- package/src/utils/use-isomorphic-layout-effect.ts +7 -0
|
@@ -0,0 +1,159 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
}
|