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.
- package/LICENSE +21 -0
- package/README.md +172 -18
- package/dist/index.cjs +671 -736
- 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/index.d.ts +4 -0
- package/dist/styles/react-bkoi-gl.css +1 -1
- package/package.json +84 -36
- package/bkoi-gl/package.json +0 -6
- package/dist/components/attribution-control.d.ts +0 -11
- package/dist/components/attribution-control.js +0 -19
- package/dist/components/attribution-control.js.map +0 -1
- package/dist/components/fullscreen-control.d.ts +0 -14
- 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 -37
- package/dist/components/geolocate-control.js +0 -46
- package/dist/components/geolocate-control.js.map +0 -1
- package/dist/components/layer.d.ts +0 -17
- package/dist/components/layer.js +0 -99
- package/dist/components/layer.js.map +0 -1
- package/dist/components/map.d.ts +0 -23
- package/dist/components/map.js +0 -102
- package/dist/components/map.js.map +0 -1
- package/dist/components/marker.d.ts +0 -41
- package/dist/components/marker.js +0 -98
- package/dist/components/marker.js.map +0 -1
- package/dist/components/navigation-control.d.ts +0 -11
- package/dist/components/navigation-control.js +0 -19
- package/dist/components/navigation-control.js.map +0 -1
- package/dist/components/popup.d.ts +0 -33
- package/dist/components/popup.js +0 -79
- package/dist/components/popup.js.map +0 -1
- package/dist/components/scale-control.d.ts +0 -13
- package/dist/components/scale-control.js +0 -31
- package/dist/components/scale-control.js.map +0 -1
- package/dist/components/source.d.ts +0 -7
- package/dist/components/source.js +0 -97
- package/dist/components/source.js.map +0 -1
- package/dist/components/use-control.d.ts +0 -9
- package/dist/components/use-control.js +0 -31
- package/dist/components/use-control.js.map +0 -1
- package/dist/components/use-map.d.ts +0 -20
- package/dist/components/use-map.js +0 -54
- package/dist/components/use-map.js.map +0 -1
- package/dist/exports-bkoi-gl.cjs +0 -1512
- package/dist/exports-bkoi-gl.d.ts +0 -89
- package/dist/exports-bkoi-gl.js +0 -36
- package/dist/exports-bkoi-gl.js.map +0 -1
- package/dist/exports-mapbox.d.ts +0 -139
- package/dist/exports-mapbox.js +0 -36
- package/dist/exports-mapbox.js.map +0 -1
- package/dist/mapbox/create-ref.d.ts +0 -9
- package/dist/mapbox/create-ref.js +0 -64
- package/dist/mapbox/create-ref.js.map +0 -1
- package/dist/mapbox/mapbox.d.ts +0 -81
- package/dist/mapbox/mapbox.js +0 -476
- package/dist/mapbox/mapbox.js.map +0 -1
- package/dist/types/common.d.ts +0 -78
- package/dist/types/common.js +0 -2
- package/dist/types/common.js.map +0 -1
- package/dist/types/events-bkoi-gl.d.ts +0 -49
- package/dist/types/events-bkoi-gl.js +0 -2
- package/dist/types/events-bkoi-gl.js.map +0 -1
- package/dist/types/events-mapbox.d.ts +0 -49
- package/dist/types/events-mapbox.js +0 -2
- package/dist/types/events-mapbox.js.map +0 -1
- package/dist/types/events.d.ts +0 -39
- package/dist/types/events.js +0 -2
- package/dist/types/events.js.map +0 -1
- package/dist/types/index.d.ts +0 -70
- package/dist/types/index.js +0 -5
- package/dist/types/index.js.map +0 -1
- package/dist/types/lib.d.ts +0 -224
- package/dist/types/lib.js +0 -2
- package/dist/types/lib.js.map +0 -1
- package/dist/types/public.d.ts +0 -2
- package/dist/types/public.js +0 -2
- package/dist/types/public.js.map +0 -1
- package/dist/types/style-spec-bkoi-gl.d.ts +0 -9
- package/dist/types/style-spec-bkoi-gl.js +0 -2
- package/dist/types/style-spec-bkoi-gl.js.map +0 -1
- package/dist/types/style-spec-mapbox.d.ts +0 -7
- package/dist/types/style-spec-mapbox.js +0 -2
- package/dist/types/style-spec-mapbox.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/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 -22
- package/dist/utils/set-globals.js +0 -19
- package/dist/utils/set-globals.js.map +0 -1
- package/dist/utils/style-utils.d.ts +0 -2
- package/dist/utils/style-utils.js +0 -42
- package/dist/utils/style-utils.js.map +0 -1
- package/dist/utils/transform.d.ts +0 -26
- package/dist/utils/transform.js +0 -56
- 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 -32
- package/src/components/fullscreen-control.tsx +0 -37
- package/src/components/geolocate-control.ts +0 -90
- package/src/components/layer.ts +0 -133
- package/src/components/map.tsx +0 -155
- package/src/components/marker.ts +0 -137
- package/src/components/navigation-control.ts +0 -29
- package/src/components/popup.ts +0 -116
- package/src/components/scale-control.ts +0 -46
- package/src/components/source.ts +0 -158
- package/src/components/use-control.ts +0 -64
- package/src/components/use-map.tsx +0 -69
- package/src/exports-bkoi-gl.ts +0 -156
- package/src/exports-mapbox.ts +0 -159
- package/src/index.ts +0 -2
- package/src/mapbox/create-ref.ts +0 -118
- package/src/mapbox/mapbox.ts +0 -742
- package/src/types/common.ts +0 -94
- package/src/types/events-bkoi-gl.ts +0 -78
- package/src/types/events-mapbox.ts +0 -76
- package/src/types/events.ts +0 -73
- package/src/types/index.ts +0 -93
- package/src/types/lib.ts +0 -279
- package/src/types/public.ts +0 -9
- package/src/types/style-spec-bkoi-gl.ts +0 -81
- package/src/types/style-spec-mapbox.ts +0 -80
- package/src/utils/apply-react-style.ts +0 -20
- package/src/utils/assert.ts +0 -5
- package/src/utils/deep-equal.ts +0 -61
- package/src/utils/set-globals.ts +0 -57
- package/src/utils/style-utils.ts +0 -59
- package/src/utils/transform.ts +0 -86
- package/src/utils/use-isomorphic-layout-effect.ts +0 -7
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Maplibre Style Specification types
|
|
3
|
-
* Type names are aligned with mapbox
|
|
4
|
-
*/
|
|
5
|
-
import type {
|
|
6
|
-
BackgroundLayerSpecification as BackgroundLayer,
|
|
7
|
-
CircleLayerSpecification as CircleLayer,
|
|
8
|
-
FillLayerSpecification as FillLayer,
|
|
9
|
-
FillExtrusionLayerSpecification as FillExtrusionLayer,
|
|
10
|
-
HeatmapLayerSpecification as HeatmapLayer,
|
|
11
|
-
HillshadeLayerSpecification as HillshadeLayer,
|
|
12
|
-
LineLayerSpecification as LineLayer,
|
|
13
|
-
RasterLayerSpecification as RasterLayer,
|
|
14
|
-
SymbolLayerSpecification as SymbolLayer,
|
|
15
|
-
GeoJSONSourceSpecification as GeoJSONSourceRaw,
|
|
16
|
-
VideoSourceSpecification as VideoSourceRaw,
|
|
17
|
-
ImageSourceSpecification as ImageSourceRaw,
|
|
18
|
-
VectorSourceSpecification as VectorSourceRaw,
|
|
19
|
-
RasterSourceSpecification as RasterSource,
|
|
20
|
-
RasterDEMSourceSpecification as RasterDemSource
|
|
21
|
-
} from '@maplibre/maplibre-gl-style-spec';
|
|
22
|
-
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
// eslint-disable-next-line import/no-unresolved
|
|
25
|
-
import {CanvasSourceSpecification as CanvasSourceRaw} from 'bkoi-gl';
|
|
26
|
-
|
|
27
|
-
// Layers
|
|
28
|
-
export type {
|
|
29
|
-
BackgroundLayer,
|
|
30
|
-
CircleLayer,
|
|
31
|
-
FillLayer,
|
|
32
|
-
FillExtrusionLayer,
|
|
33
|
-
HeatmapLayer,
|
|
34
|
-
HillshadeLayer,
|
|
35
|
-
LineLayer,
|
|
36
|
-
RasterLayer,
|
|
37
|
-
SymbolLayer
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type AnyLayer =
|
|
41
|
-
| BackgroundLayer
|
|
42
|
-
| CircleLayer
|
|
43
|
-
| FillLayer
|
|
44
|
-
| FillExtrusionLayer
|
|
45
|
-
| HeatmapLayer
|
|
46
|
-
| HillshadeLayer
|
|
47
|
-
| LineLayer
|
|
48
|
-
| RasterLayer
|
|
49
|
-
| SymbolLayer;
|
|
50
|
-
|
|
51
|
-
// Sources
|
|
52
|
-
export type {
|
|
53
|
-
GeoJSONSourceRaw,
|
|
54
|
-
VideoSourceRaw,
|
|
55
|
-
ImageSourceRaw,
|
|
56
|
-
CanvasSourceRaw,
|
|
57
|
-
VectorSourceRaw,
|
|
58
|
-
RasterSource,
|
|
59
|
-
RasterDemSource
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export type AnySource =
|
|
63
|
-
| GeoJSONSourceRaw
|
|
64
|
-
| VideoSourceRaw
|
|
65
|
-
| ImageSourceRaw
|
|
66
|
-
| CanvasSourceRaw
|
|
67
|
-
| VectorSourceRaw
|
|
68
|
-
| RasterSource
|
|
69
|
-
| RasterDemSource;
|
|
70
|
-
|
|
71
|
-
// Other style types
|
|
72
|
-
|
|
73
|
-
export type {
|
|
74
|
-
StyleSpecification as MapStyle,
|
|
75
|
-
LightSpecification as Light,
|
|
76
|
-
TerrainSpecification as Terrain
|
|
77
|
-
} from '@maplibre/maplibre-gl-style-spec';
|
|
78
|
-
|
|
79
|
-
// The following types are not yet supported by maplibre
|
|
80
|
-
export type Fog = never;
|
|
81
|
-
export type Projection = never;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Mapbox Style Specification types
|
|
3
|
-
*/
|
|
4
|
-
// Layers
|
|
5
|
-
import type {
|
|
6
|
-
BackgroundLayer,
|
|
7
|
-
SkyLayer,
|
|
8
|
-
CircleLayer,
|
|
9
|
-
FillLayer,
|
|
10
|
-
FillExtrusionLayer,
|
|
11
|
-
HeatmapLayer,
|
|
12
|
-
HillshadeLayer,
|
|
13
|
-
LineLayer,
|
|
14
|
-
RasterLayer,
|
|
15
|
-
SymbolLayer
|
|
16
|
-
} from 'mapbox-gl';
|
|
17
|
-
|
|
18
|
-
export type AnyLayer =
|
|
19
|
-
| BackgroundLayer
|
|
20
|
-
| CircleLayer
|
|
21
|
-
| FillExtrusionLayer
|
|
22
|
-
| FillLayer
|
|
23
|
-
| HeatmapLayer
|
|
24
|
-
| HillshadeLayer
|
|
25
|
-
| LineLayer
|
|
26
|
-
| RasterLayer
|
|
27
|
-
| SymbolLayer
|
|
28
|
-
| SkyLayer;
|
|
29
|
-
|
|
30
|
-
export type {
|
|
31
|
-
BackgroundLayer,
|
|
32
|
-
SkyLayer,
|
|
33
|
-
CircleLayer,
|
|
34
|
-
FillLayer,
|
|
35
|
-
FillExtrusionLayer,
|
|
36
|
-
HeatmapLayer,
|
|
37
|
-
HillshadeLayer,
|
|
38
|
-
LineLayer,
|
|
39
|
-
RasterLayer,
|
|
40
|
-
SymbolLayer
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// Sources
|
|
44
|
-
import type {
|
|
45
|
-
GeoJSONSourceRaw,
|
|
46
|
-
VideoSourceRaw,
|
|
47
|
-
ImageSourceRaw,
|
|
48
|
-
VectorSource as VectorSourceRaw,
|
|
49
|
-
RasterSource,
|
|
50
|
-
CanvasSourceRaw,
|
|
51
|
-
RasterDemSource
|
|
52
|
-
} from 'mapbox-gl';
|
|
53
|
-
|
|
54
|
-
export type AnySource =
|
|
55
|
-
| GeoJSONSourceRaw
|
|
56
|
-
| VideoSourceRaw
|
|
57
|
-
| ImageSourceRaw
|
|
58
|
-
| CanvasSourceRaw
|
|
59
|
-
| VectorSourceRaw
|
|
60
|
-
| RasterSource
|
|
61
|
-
| RasterDemSource;
|
|
62
|
-
|
|
63
|
-
export type {
|
|
64
|
-
GeoJSONSourceRaw,
|
|
65
|
-
VideoSourceRaw,
|
|
66
|
-
ImageSourceRaw,
|
|
67
|
-
CanvasSourceRaw,
|
|
68
|
-
VectorSourceRaw,
|
|
69
|
-
RasterSource,
|
|
70
|
-
RasterDemSource
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Other
|
|
74
|
-
export type {
|
|
75
|
-
Style as MapStyle,
|
|
76
|
-
Light,
|
|
77
|
-
Fog,
|
|
78
|
-
TerrainSpecification as Terrain,
|
|
79
|
-
Projection
|
|
80
|
-
} from 'mapbox-gl';
|
|
@@ -1,20 +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 = /box|flex|grid|column|lineHeight|fontWeight|opacity|order|tabSize|zIndex/;
|
|
5
|
-
|
|
6
|
-
export function applyReactStyle(element: HTMLElement, styles: React.CSSProperties) {
|
|
7
|
-
if (!element || !styles) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const style = element.style;
|
|
11
|
-
|
|
12
|
-
for (const key in styles) {
|
|
13
|
-
const value = styles[key];
|
|
14
|
-
if (Number.isFinite(value) && !unitlessNumber.test(key)) {
|
|
15
|
-
style[key] = `${value}px`;
|
|
16
|
-
} else {
|
|
17
|
-
style[key] = value;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/utils/assert.ts
DELETED
package/src/utils/deep-equal.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type {PointLike} from '../types';
|
|
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,57 +0,0 @@
|
|
|
1
|
-
export type GlobalSettings = {
|
|
2
|
-
/** The map's default API URL for requesting tiles, styles, sprites, and glyphs. */
|
|
3
|
-
baseApiUrl?: string;
|
|
4
|
-
/** The maximum number of images (raster tiles, sprites, icons) to load in parallel.
|
|
5
|
-
* @default 16
|
|
6
|
-
*/
|
|
7
|
-
maxParallelImageRequests?: number;
|
|
8
|
-
/** The map's RTL text plugin. Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left. */
|
|
9
|
-
RTLTextPlugin?: string | false;
|
|
10
|
-
/** Provides an interface for external module bundlers such as Webpack or Rollup to package mapbox-gl's WebWorker into a separate class and integrate it with the library.
|
|
11
|
-
Takes precedence over `workerUrl`. */
|
|
12
|
-
workerClass?: any;
|
|
13
|
-
/** The number of web workers instantiated on a page with mapbox-gl maps.
|
|
14
|
-
* @default 2
|
|
15
|
-
*/
|
|
16
|
-
workerCount?: number;
|
|
17
|
-
/** Provides an interface for loading mapbox-gl's WebWorker bundle from a self-hosted URL.
|
|
18
|
-
* This is useful if your site needs to operate in a strict CSP (Content Security Policy) environment
|
|
19
|
-
* wherein you are not allowed to load JavaScript code from a Blob URL, which is default behavior. */
|
|
20
|
-
workerUrl?: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const globalSettings = [
|
|
24
|
-
'baseApiUrl',
|
|
25
|
-
'maxParallelImageRequests',
|
|
26
|
-
'workerClass',
|
|
27
|
-
'workerCount',
|
|
28
|
-
'workerUrl'
|
|
29
|
-
] as const;
|
|
30
|
-
|
|
31
|
-
export default function setGlobals(mapLib: any, props: GlobalSettings) {
|
|
32
|
-
for (const key of globalSettings) {
|
|
33
|
-
if (key in props) {
|
|
34
|
-
mapLib[key] = props[key];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const {
|
|
39
|
-
RTLTextPlugin = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js'
|
|
40
|
-
} = props;
|
|
41
|
-
if (
|
|
42
|
-
RTLTextPlugin &&
|
|
43
|
-
mapLib.getRTLTextPluginStatus &&
|
|
44
|
-
mapLib.getRTLTextPluginStatus() === 'unavailable'
|
|
45
|
-
) {
|
|
46
|
-
mapLib.setRTLTextPlugin(
|
|
47
|
-
RTLTextPlugin,
|
|
48
|
-
(error?: Error) => {
|
|
49
|
-
if (error) {
|
|
50
|
-
// eslint-disable-next-line
|
|
51
|
-
console.error(error);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
true
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
}
|
package/src/utils/style-utils.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import {ImmutableLike, MapStyle} from '../types';
|
|
2
|
-
|
|
3
|
-
const refProps = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];
|
|
4
|
-
|
|
5
|
-
// Prepare a map style object for diffing
|
|
6
|
-
// If immutable - convert to plain object
|
|
7
|
-
// Work around some issues in older styles that would fail Mapbox's diffing
|
|
8
|
-
export function normalizeStyle(
|
|
9
|
-
style: string | MapStyle | ImmutableLike<MapStyle>
|
|
10
|
-
): string | MapStyle {
|
|
11
|
-
if (!style) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
if (typeof style === 'string') {
|
|
15
|
-
return style;
|
|
16
|
-
}
|
|
17
|
-
if ('toJS' in style) {
|
|
18
|
-
style = style.toJS();
|
|
19
|
-
}
|
|
20
|
-
if (!style.layers) {
|
|
21
|
-
return style;
|
|
22
|
-
}
|
|
23
|
-
const layerIndex = {};
|
|
24
|
-
|
|
25
|
-
for (const layer of style.layers) {
|
|
26
|
-
layerIndex[layer.id] = layer;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const layers = style.layers.map(layer => {
|
|
30
|
-
let normalizedLayer: typeof layer = null;
|
|
31
|
-
|
|
32
|
-
if ('interactive' in layer) {
|
|
33
|
-
normalizedLayer = Object.assign({}, layer);
|
|
34
|
-
// Breaks style diffing :(
|
|
35
|
-
// @ts-ignore legacy field not typed
|
|
36
|
-
delete normalizedLayer.interactive;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Style diffing doesn't work with refs so expand them out manually before diffing.
|
|
40
|
-
// @ts-ignore legacy field not typed
|
|
41
|
-
const layerRef = layerIndex[layer.ref];
|
|
42
|
-
if (layerRef) {
|
|
43
|
-
normalizedLayer = normalizedLayer || Object.assign({}, layer);
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
delete normalizedLayer.ref;
|
|
46
|
-
// https://github.com/mapbox/mapbox-gl-js/blob/master/src/style-spec/deref.js
|
|
47
|
-
for (const propName of refProps) {
|
|
48
|
-
if (propName in layerRef) {
|
|
49
|
-
normalizedLayer[propName] = layerRef[propName];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return normalizedLayer || layer;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Do not mutate the style object provided by the user
|
|
58
|
-
return {...style, layers};
|
|
59
|
-
}
|
package/src/utils/transform.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type {MapboxProps} from '../mapbox/mapbox';
|
|
2
|
-
import type {Transform, ViewState} from '../types';
|
|
3
|
-
import {deepEqual} from './deep-equal';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Make a copy of a transform
|
|
7
|
-
* @param tr
|
|
8
|
-
*/
|
|
9
|
-
export function cloneTransform(tr: Transform): Transform {
|
|
10
|
-
const newTransform = tr.clone();
|
|
11
|
-
// Work around mapbox bug - this value is not assigned in clone(), only in resize()
|
|
12
|
-
newTransform.pixelsToGLUnits = tr.pixelsToGLUnits;
|
|
13
|
-
return newTransform;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Copy projection from one transform to another. This only applies to mapbox-gl transforms
|
|
18
|
-
* @param src the transform to copy projection settings from
|
|
19
|
-
* @param dest to transform to copy projection settings to
|
|
20
|
-
*/
|
|
21
|
-
export function syncProjection(src: Transform, dest: Transform): void {
|
|
22
|
-
if (!src.getProjection) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const srcProjection = src.getProjection();
|
|
26
|
-
const destProjection = dest.getProjection();
|
|
27
|
-
|
|
28
|
-
if (!deepEqual(srcProjection, destProjection)) {
|
|
29
|
-
dest.setProjection(srcProjection);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Capture a transform's current state
|
|
35
|
-
* @param transform
|
|
36
|
-
* @returns descriptor of the view state
|
|
37
|
-
*/
|
|
38
|
-
export function transformToViewState(tr: Transform): ViewState {
|
|
39
|
-
return {
|
|
40
|
-
longitude: tr.center.lng,
|
|
41
|
-
latitude: tr.center.lat,
|
|
42
|
-
zoom: tr.zoom,
|
|
43
|
-
pitch: tr.pitch,
|
|
44
|
-
bearing: tr.bearing,
|
|
45
|
-
padding: tr.padding
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/* eslint-disable complexity */
|
|
50
|
-
/**
|
|
51
|
-
* Mutate a transform to match the given view state
|
|
52
|
-
* @param transform
|
|
53
|
-
* @param viewState
|
|
54
|
-
* @returns true if the transform has changed
|
|
55
|
-
*/
|
|
56
|
-
export function applyViewStateToTransform(tr: Transform, props: MapboxProps): boolean {
|
|
57
|
-
const v: Partial<ViewState> = props.viewState || props;
|
|
58
|
-
let changed = false;
|
|
59
|
-
|
|
60
|
-
if ('zoom' in v) {
|
|
61
|
-
const zoom = tr.zoom;
|
|
62
|
-
tr.zoom = v.zoom;
|
|
63
|
-
changed = changed || zoom !== tr.zoom;
|
|
64
|
-
}
|
|
65
|
-
if ('bearing' in v) {
|
|
66
|
-
const bearing = tr.bearing;
|
|
67
|
-
tr.bearing = v.bearing;
|
|
68
|
-
changed = changed || bearing !== tr.bearing;
|
|
69
|
-
}
|
|
70
|
-
if ('pitch' in v) {
|
|
71
|
-
const pitch = tr.pitch;
|
|
72
|
-
tr.pitch = v.pitch;
|
|
73
|
-
changed = changed || pitch !== tr.pitch;
|
|
74
|
-
}
|
|
75
|
-
if (v.padding && !tr.isPaddingEqual(v.padding)) {
|
|
76
|
-
changed = true;
|
|
77
|
-
tr.padding = v.padding;
|
|
78
|
-
}
|
|
79
|
-
if ('longitude' in v && 'latitude' in v) {
|
|
80
|
-
const center = tr.center;
|
|
81
|
-
// @ts-ignore
|
|
82
|
-
tr.center = new center.constructor(v.longitude, v.latitude);
|
|
83
|
-
changed = changed || center !== tr.center;
|
|
84
|
-
}
|
|
85
|
-
return changed;
|
|
86
|
-
}
|
|
@@ -1,7 +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 = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
|
|
6
|
-
|
|
7
|
-
export default useIsomorphicLayoutEffect;
|