react-bkoi-gl 2.0.0 → 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.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/index.cjs +137 -111
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +370 -0
- package/dist/index.d.ts +370 -2
- package/dist/index.js +1434 -2
- package/dist/index.js.map +1 -1
- package/dist/styles/react-bkoi-gl.css +1 -1
- package/package.json +62 -30
- 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/types/events.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import type { Point, LngLat, MapGeoJSONFeature, ViewState } from "./common";
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
Map,
|
|
5
|
-
Marker,
|
|
6
|
-
Popup,
|
|
7
|
-
GeolocateControl,
|
|
8
|
-
MapLibreEvent,
|
|
9
|
-
MapMouseEvent as _MapMouseEvent,
|
|
10
|
-
MapLayerMouseEvent,
|
|
11
|
-
MapTouchEvent,
|
|
12
|
-
MapLayerTouchEvent,
|
|
13
|
-
MapStyleDataEvent,
|
|
14
|
-
MapSourceDataEvent,
|
|
15
|
-
MapWheelEvent,
|
|
16
|
-
MapLibreZoomEvent as MapBoxZoomEvent,
|
|
17
|
-
} from "maplibre-gl";
|
|
18
|
-
|
|
19
|
-
export type {
|
|
20
|
-
MapLibreEvent as MapEvent,
|
|
21
|
-
MapLayerMouseEvent,
|
|
22
|
-
MapTouchEvent,
|
|
23
|
-
MapLayerTouchEvent,
|
|
24
|
-
MapStyleDataEvent,
|
|
25
|
-
MapSourceDataEvent,
|
|
26
|
-
MapWheelEvent,
|
|
27
|
-
MapBoxZoomEvent,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type MapCallbacks = {
|
|
31
|
-
onMouseDown?: (e: MapLayerMouseEvent) => void;
|
|
32
|
-
onMouseUp?: (e: MapLayerMouseEvent) => void;
|
|
33
|
-
onMouseOver?: (e: MapLayerMouseEvent) => void;
|
|
34
|
-
onMouseMove?: (e: MapLayerMouseEvent) => void;
|
|
35
|
-
onClick?: (e: MapLayerMouseEvent) => void;
|
|
36
|
-
onDblClick?: (e: MapLayerMouseEvent) => void;
|
|
37
|
-
onMouseEnter?: (e: MapLayerMouseEvent) => void;
|
|
38
|
-
onMouseLeave?: (e: MapLayerMouseEvent) => void;
|
|
39
|
-
onMouseOut?: (e: MapLayerMouseEvent) => void;
|
|
40
|
-
onContextMenu?: (e: MapLayerMouseEvent) => void;
|
|
41
|
-
onTouchStart?: (e: MapLayerTouchEvent) => void;
|
|
42
|
-
onTouchEnd?: (e: MapLayerTouchEvent) => void;
|
|
43
|
-
onTouchMove?: (e: MapLayerTouchEvent) => void;
|
|
44
|
-
onTouchCancel?: (e: MapLayerTouchEvent) => void;
|
|
45
|
-
|
|
46
|
-
onMoveStart?: (e: ViewStateChangeEvent) => void;
|
|
47
|
-
onMove?: (e: ViewStateChangeEvent) => void;
|
|
48
|
-
onMoveEnd?: (e: ViewStateChangeEvent) => void;
|
|
49
|
-
onDragStart?: (e: ViewStateChangeEvent) => void;
|
|
50
|
-
onDrag?: (e: ViewStateChangeEvent) => void;
|
|
51
|
-
onDragEnd?: (e: ViewStateChangeEvent) => void;
|
|
52
|
-
onZoomStart?: (e: ViewStateChangeEvent) => void;
|
|
53
|
-
onZoom?: (e: ViewStateChangeEvent) => void;
|
|
54
|
-
onZoomEnd?: (e: ViewStateChangeEvent) => void;
|
|
55
|
-
onRotateStart?: (e: ViewStateChangeEvent) => void;
|
|
56
|
-
onRotate?: (e: ViewStateChangeEvent) => void;
|
|
57
|
-
onRotateEnd?: (e: ViewStateChangeEvent) => void;
|
|
58
|
-
onPitchStart?: (e: ViewStateChangeEvent) => void;
|
|
59
|
-
onPitch?: (e: ViewStateChangeEvent) => void;
|
|
60
|
-
onPitchEnd?: (e: ViewStateChangeEvent) => void;
|
|
61
|
-
|
|
62
|
-
onWheel?: (e: MapWheelEvent) => void;
|
|
63
|
-
onBoxZoomStart?: (e: MapBoxZoomEvent) => void;
|
|
64
|
-
onBoxZoomEnd?: (e: MapBoxZoomEvent) => void;
|
|
65
|
-
onBoxZoomCancel?: (e: MapBoxZoomEvent) => void;
|
|
66
|
-
|
|
67
|
-
onResize?: (e: MapLibreEvent) => void;
|
|
68
|
-
onLoad?: (e: MapLibreEvent) => void;
|
|
69
|
-
onRender?: (e: MapLibreEvent) => void;
|
|
70
|
-
onIdle?: (e: MapLibreEvent) => void;
|
|
71
|
-
onError?: (e: ErrorEvent) => void;
|
|
72
|
-
onRemove?: (e: MapLibreEvent) => void;
|
|
73
|
-
onData?: (e: MapStyleDataEvent | MapSourceDataEvent) => void;
|
|
74
|
-
onStyleData?: (e: MapStyleDataEvent) => void;
|
|
75
|
-
onSourceData?: (e: MapSourceDataEvent) => void;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
interface MapEvent<SourceT, OriginalEventT = undefined> {
|
|
79
|
-
type: string;
|
|
80
|
-
target: SourceT;
|
|
81
|
-
originalEvent: OriginalEventT;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export type ErrorEvent = MapEvent<Map> & {
|
|
85
|
-
type: "error";
|
|
86
|
-
error: Error;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export type MapMouseEvent = _MapMouseEvent & {
|
|
90
|
-
point: Point;
|
|
91
|
-
lngLat: LngLat;
|
|
92
|
-
features?: MapGeoJSONFeature[];
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export type ViewStateChangeEvent =
|
|
96
|
-
| (MapEvent<Map, MouseEvent | TouchEvent | WheelEvent | undefined> & {
|
|
97
|
-
type: "movestart" | "move" | "moveend" | "zoomstart" | "zoom" | "zoomend";
|
|
98
|
-
viewState: ViewState;
|
|
99
|
-
})
|
|
100
|
-
| (MapEvent<Map, MouseEvent | TouchEvent | undefined> & {
|
|
101
|
-
type:
|
|
102
|
-
| "rotatestart"
|
|
103
|
-
| "rotate"
|
|
104
|
-
| "rotateend"
|
|
105
|
-
| "dragstart"
|
|
106
|
-
| "drag"
|
|
107
|
-
| "dragend"
|
|
108
|
-
| "pitchstart"
|
|
109
|
-
| "pitch"
|
|
110
|
-
| "pitchend";
|
|
111
|
-
viewState: ViewState;
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
export type PopupEvent = {
|
|
115
|
-
type: "open" | "close";
|
|
116
|
-
target: Popup;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export type MarkerEvent<OriginalEventT = undefined> = MapEvent<
|
|
120
|
-
Marker,
|
|
121
|
-
OriginalEventT
|
|
122
|
-
>;
|
|
123
|
-
|
|
124
|
-
export type MarkerDragEvent = MarkerEvent & {
|
|
125
|
-
type: "dragstart" | "drag" | "dragend";
|
|
126
|
-
lngLat: LngLat;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export type GeolocateEvent = MapEvent<GeolocateControl>;
|
|
130
|
-
|
|
131
|
-
export type GeolocateResultEvent = GeolocateEvent & GeolocationPosition;
|
|
132
|
-
|
|
133
|
-
export type GeolocateErrorEvent = GeolocateEvent & GeolocationPositionError;
|
package/src/types/internal.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// Internal types
|
|
2
|
-
import type { LngLat, PaddingOptions } from "maplibre-gl";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* maplibre's Transform interface / CameraUpdateTransformFunction argument
|
|
6
|
-
*/
|
|
7
|
-
export type TransformLike = {
|
|
8
|
-
center: LngLat;
|
|
9
|
-
zoom: number;
|
|
10
|
-
roll?: number;
|
|
11
|
-
pitch: number;
|
|
12
|
-
bearing: number;
|
|
13
|
-
elevation: number;
|
|
14
|
-
padding?: PaddingOptions;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type {
|
|
18
|
-
GeoJSONSource as GeoJSONSourceImplementation,
|
|
19
|
-
ImageSource as ImageSourceImplementation,
|
|
20
|
-
CanvasSource as CanvasSourceImplementation,
|
|
21
|
-
VectorTileSource as VectorSourceImplementation,
|
|
22
|
-
RasterTileSource as RasterSourceImplementation,
|
|
23
|
-
RasterDEMTileSource as RasterDemSourceImplementation,
|
|
24
|
-
VideoSource as VideoSourceImplementation,
|
|
25
|
-
Source as AnySourceImplementation,
|
|
26
|
-
} from "maplibre-gl";
|
package/src/types/lib.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Map,
|
|
3
|
-
MapOptions,
|
|
4
|
-
Marker,
|
|
5
|
-
MarkerOptions,
|
|
6
|
-
Popup,
|
|
7
|
-
PopupOptions,
|
|
8
|
-
AttributionControl,
|
|
9
|
-
AttributionControlOptions,
|
|
10
|
-
FullscreenControl,
|
|
11
|
-
FullscreenControlOptions,
|
|
12
|
-
GeolocateControl,
|
|
13
|
-
GeolocateControlOptions,
|
|
14
|
-
NavigationControl,
|
|
15
|
-
NavigationControlOptions,
|
|
16
|
-
ScaleControl,
|
|
17
|
-
ScaleControlOptions,
|
|
18
|
-
TerrainControl,
|
|
19
|
-
TerrainSpecification,
|
|
20
|
-
LogoControl,
|
|
21
|
-
LogoControlOptions,
|
|
22
|
-
} from "maplibre-gl";
|
|
23
|
-
|
|
24
|
-
export type {
|
|
25
|
-
ControlPosition,
|
|
26
|
-
IControl,
|
|
27
|
-
Map,
|
|
28
|
-
MapOptions,
|
|
29
|
-
Marker,
|
|
30
|
-
MarkerOptions,
|
|
31
|
-
Popup,
|
|
32
|
-
PopupOptions,
|
|
33
|
-
AttributionControl,
|
|
34
|
-
AttributionControlOptions,
|
|
35
|
-
FullscreenControl,
|
|
36
|
-
FullscreenControlOptions,
|
|
37
|
-
GeolocateControl,
|
|
38
|
-
GeolocateControlOptions,
|
|
39
|
-
NavigationControl,
|
|
40
|
-
NavigationControlOptions,
|
|
41
|
-
ScaleControl,
|
|
42
|
-
ScaleControlOptions,
|
|
43
|
-
TerrainControl,
|
|
44
|
-
LogoControl,
|
|
45
|
-
LogoControlOptions,
|
|
46
|
-
CustomLayerInterface,
|
|
47
|
-
} from "maplibre-gl";
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* A user-facing type that represents the minimal intersection between Mapbox and Maplibre
|
|
51
|
-
* User provided `mapLib` is supposed to implement this interface
|
|
52
|
-
* Only losely typed for compatibility
|
|
53
|
-
*/
|
|
54
|
-
export interface MapLib {
|
|
55
|
-
supported?: (options: any) => boolean;
|
|
56
|
-
|
|
57
|
-
Map: { new (options: MapOptions): Map };
|
|
58
|
-
|
|
59
|
-
Marker: { new (options: MarkerOptions): Marker };
|
|
60
|
-
|
|
61
|
-
Popup: { new (options: PopupOptions): Popup };
|
|
62
|
-
|
|
63
|
-
AttributionControl: {
|
|
64
|
-
new (options: AttributionControlOptions): AttributionControl;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
FullscreenControl: {
|
|
68
|
-
new (options: FullscreenControlOptions): FullscreenControl;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
GeolocateControl: {
|
|
72
|
-
new (options: GeolocateControlOptions): GeolocateControl;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
NavigationControl: {
|
|
76
|
-
new (options: NavigationControlOptions): NavigationControl;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
ScaleControl: { new (options: ScaleControlOptions): ScaleControl };
|
|
80
|
-
|
|
81
|
-
TerrainControl: { new (options: TerrainSpecification): TerrainControl };
|
|
82
|
-
|
|
83
|
-
LogoControl: { new (options: LogoControlOptions): LogoControl };
|
|
84
|
-
}
|
package/src/types/style-spec.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Maplibre Style Specification types
|
|
3
|
-
* Type names are aligned with mapbox
|
|
4
|
-
*/
|
|
5
|
-
export type {
|
|
6
|
-
// Layers
|
|
7
|
-
LayerSpecification,
|
|
8
|
-
FillLayerSpecification,
|
|
9
|
-
LineLayerSpecification,
|
|
10
|
-
SymbolLayerSpecification,
|
|
11
|
-
CircleLayerSpecification,
|
|
12
|
-
HeatmapLayerSpecification,
|
|
13
|
-
FillExtrusionLayerSpecification,
|
|
14
|
-
RasterLayerSpecification,
|
|
15
|
-
HillshadeLayerSpecification,
|
|
16
|
-
BackgroundLayerSpecification,
|
|
17
|
-
|
|
18
|
-
// Sources
|
|
19
|
-
SourceSpecification,
|
|
20
|
-
VectorSourceSpecification,
|
|
21
|
-
RasterSourceSpecification,
|
|
22
|
-
RasterDEMSourceSpecification,
|
|
23
|
-
GeoJSONSourceSpecification,
|
|
24
|
-
VideoSourceSpecification,
|
|
25
|
-
ImageSourceSpecification,
|
|
26
|
-
CanvasSourceSpecification,
|
|
27
|
-
|
|
28
|
-
// Style
|
|
29
|
-
StyleSpecification,
|
|
30
|
-
SkySpecification,
|
|
31
|
-
LightSpecification,
|
|
32
|
-
TerrainSpecification,
|
|
33
|
-
ProjectionSpecification,
|
|
34
|
-
} from "maplibre-gl";
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
// This is a simplified version of
|
|
3
|
-
// https://github.com/facebook/react/blob/4131af3e4bf52f3a003537ec95a1655147c81270/src/renderers/dom/shared/CSSPropertyOperations.js#L62
|
|
4
|
-
const unitlessNumber =
|
|
5
|
-
/box|flex|grid|column|lineHeight|fontWeight|opacity|order|tabSize|zIndex/;
|
|
6
|
-
|
|
7
|
-
export function applyReactStyle(
|
|
8
|
-
element: HTMLElement,
|
|
9
|
-
styles: React.CSSProperties,
|
|
10
|
-
) {
|
|
11
|
-
if (!element || !styles) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const style = element.style;
|
|
15
|
-
|
|
16
|
-
for (const key in styles) {
|
|
17
|
-
const value = styles[key];
|
|
18
|
-
if (Number.isFinite(value) && !unitlessNumber.test(key)) {
|
|
19
|
-
style[key] = `${value}px`;
|
|
20
|
-
} else {
|
|
21
|
-
style[key] = value;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/utils/assert.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/** Compare two classNames string and return the difference */
|
|
2
|
-
export function compareClassNames(
|
|
3
|
-
prevClassName: string | undefined,
|
|
4
|
-
nextClassName: string | undefined,
|
|
5
|
-
): string[] | null {
|
|
6
|
-
if (prevClassName === nextClassName) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const prevClassList = getClassList(prevClassName);
|
|
11
|
-
const nextClassList = getClassList(nextClassName);
|
|
12
|
-
const diff: string[] = [];
|
|
13
|
-
|
|
14
|
-
for (const c of nextClassList) {
|
|
15
|
-
if (!prevClassList.has(c)) {
|
|
16
|
-
diff.push(c);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
for (const c of prevClassList) {
|
|
20
|
-
if (!nextClassList.has(c)) {
|
|
21
|
-
diff.push(c);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return diff.length === 0 ? null : diff;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getClassList(className: string | undefined) {
|
|
28
|
-
return new Set(className ? className.trim().split(/\s+/) : []);
|
|
29
|
-
}
|
package/src/utils/deep-equal.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { PointLike } from "../types/common";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Compare two points
|
|
5
|
-
* @param a
|
|
6
|
-
* @param b
|
|
7
|
-
* @returns true if the points are equal
|
|
8
|
-
*/
|
|
9
|
-
export function arePointsEqual(a?: PointLike, b?: PointLike): boolean {
|
|
10
|
-
const ax = Array.isArray(a) ? a[0] : a ? a.x : 0;
|
|
11
|
-
const ay = Array.isArray(a) ? a[1] : a ? a.y : 0;
|
|
12
|
-
const bx = Array.isArray(b) ? b[0] : b ? b.x : 0;
|
|
13
|
-
const by = Array.isArray(b) ? b[1] : b ? b.y : 0;
|
|
14
|
-
return ax === bx && ay === by;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/* eslint-disable complexity */
|
|
18
|
-
/**
|
|
19
|
-
* Compare any two objects
|
|
20
|
-
* @param a
|
|
21
|
-
* @param b
|
|
22
|
-
* @returns true if the objects are deep equal
|
|
23
|
-
*/
|
|
24
|
-
export function deepEqual(a: any, b: any): boolean {
|
|
25
|
-
if (a === b) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
if (!a || !b) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
if (Array.isArray(a)) {
|
|
32
|
-
if (!Array.isArray(b) || a.length !== b.length) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
for (let i = 0; i < a.length; i++) {
|
|
36
|
-
if (!deepEqual(a[i], b[i])) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
} else if (Array.isArray(b)) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
if (typeof a === "object" && typeof b === "object") {
|
|
45
|
-
const aKeys = Object.keys(a);
|
|
46
|
-
const bKeys = Object.keys(b);
|
|
47
|
-
if (aKeys.length !== bKeys.length) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
for (const key of aKeys) {
|
|
51
|
-
if (!b.hasOwnProperty(key)) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
if (!deepEqual(a[key], b[key])) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
}
|
package/src/utils/set-globals.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export type GlobalSettings = {
|
|
2
|
-
/** The maximum number of images (raster tiles, sprites, icons) to load in parallel.
|
|
3
|
-
* @default 16
|
|
4
|
-
*/
|
|
5
|
-
maxParallelImageRequests?: number;
|
|
6
|
-
/** The map's RTL text plugin. Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left. */
|
|
7
|
-
RTLTextPlugin?: string | { pluginUrl: string; lazy?: boolean };
|
|
8
|
-
/** The number of web workers instantiated on a page with maplibre-gl maps.
|
|
9
|
-
* @default 2
|
|
10
|
-
*/
|
|
11
|
-
workerCount?: number;
|
|
12
|
-
/** Provides an interface for loading maplibre-gl's WebWorker bundle from a self-hosted URL.
|
|
13
|
-
* This is useful if your site needs to operate in a strict CSP (Content Security Policy) environment
|
|
14
|
-
* wherein you are not allowed to load JavaScript code from a Blob URL, which is default behavior. */
|
|
15
|
-
workerUrl?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default function setGlobals(mapLib: any, props: GlobalSettings) {
|
|
19
|
-
const { RTLTextPlugin, maxParallelImageRequests, workerCount, workerUrl } =
|
|
20
|
-
props;
|
|
21
|
-
if (
|
|
22
|
-
RTLTextPlugin &&
|
|
23
|
-
mapLib.getRTLTextPluginStatus &&
|
|
24
|
-
mapLib.getRTLTextPluginStatus() === "unavailable"
|
|
25
|
-
) {
|
|
26
|
-
const { pluginUrl, lazy = true } =
|
|
27
|
-
typeof RTLTextPlugin === "string"
|
|
28
|
-
? { pluginUrl: RTLTextPlugin }
|
|
29
|
-
: RTLTextPlugin;
|
|
30
|
-
|
|
31
|
-
mapLib.setRTLTextPlugin(
|
|
32
|
-
pluginUrl,
|
|
33
|
-
(error?: Error) => {
|
|
34
|
-
if (error) {
|
|
35
|
-
// eslint-disable-next-line
|
|
36
|
-
console.error(error);
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
lazy,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (maxParallelImageRequests !== undefined) {
|
|
43
|
-
mapLib.setMaxParallelImageRequests(maxParallelImageRequests);
|
|
44
|
-
}
|
|
45
|
-
if (workerCount !== undefined) {
|
|
46
|
-
mapLib.setWorkerCount(workerCount);
|
|
47
|
-
}
|
|
48
|
-
if (workerUrl !== undefined) {
|
|
49
|
-
mapLib.setWorkerUrl(workerUrl);
|
|
50
|
-
}
|
|
51
|
-
}
|
package/src/utils/style-utils.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { StyleSpecification } from "../types/style-spec";
|
|
2
|
-
import type { ImmutableLike } from "../types/common";
|
|
3
|
-
|
|
4
|
-
const refProps = [
|
|
5
|
-
"type",
|
|
6
|
-
"source",
|
|
7
|
-
"source-layer",
|
|
8
|
-
"minzoom",
|
|
9
|
-
"maxzoom",
|
|
10
|
-
"filter",
|
|
11
|
-
"layout",
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
// Prepare a map style object for diffing
|
|
15
|
-
// If immutable - convert to plain object
|
|
16
|
-
// Work around some issues in older styles that would fail Mapbox's diffing
|
|
17
|
-
export function normalizeStyle(
|
|
18
|
-
style: string | StyleSpecification | ImmutableLike<StyleSpecification>,
|
|
19
|
-
): string | StyleSpecification {
|
|
20
|
-
if (!style) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
if (typeof style === "string") {
|
|
24
|
-
return style;
|
|
25
|
-
}
|
|
26
|
-
if ("toJS" in style) {
|
|
27
|
-
style = style.toJS();
|
|
28
|
-
}
|
|
29
|
-
if (!style.layers) {
|
|
30
|
-
return style;
|
|
31
|
-
}
|
|
32
|
-
const layerIndex = {};
|
|
33
|
-
|
|
34
|
-
for (const layer of style.layers) {
|
|
35
|
-
layerIndex[layer.id] = layer;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const layers = style.layers.map((layer) => {
|
|
39
|
-
let normalizedLayer: typeof layer = null;
|
|
40
|
-
|
|
41
|
-
if ("interactive" in layer) {
|
|
42
|
-
normalizedLayer = Object.assign({}, layer);
|
|
43
|
-
// Breaks style diffing :(
|
|
44
|
-
// @ts-ignore legacy field not typed
|
|
45
|
-
delete normalizedLayer.interactive;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Style diffing doesn't work with refs so expand them out manually before diffing.
|
|
49
|
-
// @ts-ignore legacy field not typed
|
|
50
|
-
const layerRef = layerIndex[layer.ref];
|
|
51
|
-
if (layerRef) {
|
|
52
|
-
normalizedLayer = normalizedLayer || Object.assign({}, layer);
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
delete normalizedLayer.ref;
|
|
55
|
-
// https://github.com/mapbox/mapbox-gl-js/blob/master/src/style-spec/deref.js
|
|
56
|
-
for (const propName of refProps) {
|
|
57
|
-
if (propName in layerRef) {
|
|
58
|
-
normalizedLayer[propName] = layerRef[propName];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return normalizedLayer || layer;
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Do not mutate the style object provided by the user
|
|
67
|
-
return { ...style, layers };
|
|
68
|
-
}
|
package/src/utils/transform.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { MaplibreProps } from "../maplibre/maplibre";
|
|
2
|
-
import type { ViewState } from "../types/common";
|
|
3
|
-
import type { TransformLike } from "../types/internal";
|
|
4
|
-
import { deepEqual } from "./deep-equal";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Capture a transform's current state
|
|
8
|
-
* @param transform
|
|
9
|
-
* @returns descriptor of the view state
|
|
10
|
-
*/
|
|
11
|
-
export function transformToViewState(tr: TransformLike): ViewState {
|
|
12
|
-
return {
|
|
13
|
-
longitude: tr.center.lng,
|
|
14
|
-
latitude: tr.center.lat,
|
|
15
|
-
zoom: tr.zoom,
|
|
16
|
-
pitch: tr.pitch,
|
|
17
|
-
bearing: tr.bearing,
|
|
18
|
-
padding: tr.padding,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/* eslint-disable complexity */
|
|
23
|
-
/**
|
|
24
|
-
* Applies requested view state to a transform
|
|
25
|
-
* @returns an object containing detected changes
|
|
26
|
-
*/
|
|
27
|
-
export function applyViewStateToTransform(
|
|
28
|
-
/** An object that describes Maplibre's camera state */
|
|
29
|
-
tr: TransformLike,
|
|
30
|
-
/** Props from Map component */
|
|
31
|
-
props: MaplibreProps,
|
|
32
|
-
): Partial<TransformLike> {
|
|
33
|
-
const v: Partial<ViewState> = props.viewState || props;
|
|
34
|
-
const changes: Partial<TransformLike> = {};
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
"longitude" in v &&
|
|
38
|
-
"latitude" in v &&
|
|
39
|
-
(v.longitude !== tr.center.lng || v.latitude !== tr.center.lat)
|
|
40
|
-
) {
|
|
41
|
-
const LngLat = tr.center.constructor;
|
|
42
|
-
// @ts-expect-error we should not import LngLat class from maplibre-gl because we don't know the source of mapLib
|
|
43
|
-
changes.center = new LngLat(v.longitude, v.latitude);
|
|
44
|
-
}
|
|
45
|
-
if ("zoom" in v && v.zoom !== tr.zoom) {
|
|
46
|
-
changes.zoom = v.zoom;
|
|
47
|
-
}
|
|
48
|
-
if ("bearing" in v && v.bearing !== tr.bearing) {
|
|
49
|
-
changes.bearing = v.bearing;
|
|
50
|
-
}
|
|
51
|
-
if ("pitch" in v && v.pitch !== tr.pitch) {
|
|
52
|
-
changes.pitch = v.pitch;
|
|
53
|
-
}
|
|
54
|
-
if (v.padding && tr.padding && !deepEqual(v.padding, tr.padding)) {
|
|
55
|
-
changes.padding = v.padding;
|
|
56
|
-
}
|
|
57
|
-
return changes;
|
|
58
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// From https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts
|
|
2
|
-
// useLayoutEffect but does not trigger warning in server-side rendering
|
|
3
|
-
import { useEffect, useLayoutEffect } from "react";
|
|
4
|
-
|
|
5
|
-
const useIsomorphicLayoutEffect =
|
|
6
|
-
typeof document !== "undefined" ? useLayoutEffect : useEffect;
|
|
7
|
-
|
|
8
|
-
export default useIsomorphicLayoutEffect;
|