@octanejs/react-map-gl 0.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 +62 -0
- package/README.md +112 -0
- package/UPSTREAM.md +216 -0
- package/package.json +61 -0
- package/src/components/attribution-control.ts +27 -0
- package/src/components/fullscreen-control.ts +35 -0
- package/src/components/geolocate-control.ts +88 -0
- package/src/components/layer.ts +135 -0
- package/src/components/map.tsrx +173 -0
- package/src/components/marker.ts +217 -0
- package/src/components/navigation-control.ts +27 -0
- package/src/components/popup.ts +100 -0
- package/src/components/scale-control.ts +44 -0
- package/src/components/source.tsrx +146 -0
- package/src/components/use-control.ts +73 -0
- package/src/components/use-map.tsrx +64 -0
- package/src/index.ts +33 -0
- package/src/mapbox/create-ref.ts +114 -0
- package/src/mapbox/mapbox.ts +714 -0
- package/src/mapbox/proxy-transform.ts +155 -0
- package/src/types/common.ts +41 -0
- package/src/types/events.ts +130 -0
- package/src/types/internal.ts +20 -0
- package/src/types/lib.ts +70 -0
- package/src/types/octane.ts +27 -0
- package/src/types/style-spec.ts +51 -0
- package/src/utils/apply-react-style.ts +26 -0
- package/src/utils/assert.ts +10 -0
- package/src/utils/children.ts +26 -0
- package/src/utils/compare-class-names.ts +34 -0
- package/src/utils/deep-equal.ts +66 -0
- package/src/utils/set-globals.ts +62 -0
- package/src/utils/style-utils.ts +65 -0
- package/src/utils/transform.ts +115 -0
- package/src/utils/use-isomorphic-layout-effect.ts +7 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @ts-nocheck — byte-exact reuse of @vis.gl/react-mapbox 8.1.2. Upstream compiles
|
|
2
|
+
// without strictNullChecks or noImplicitAny; this repository is strict. The copy
|
|
3
|
+
// under upstream/ is typechecked with upstream's own configuration instead, so
|
|
4
|
+
// nothing here is unchecked, only checked at the settings its authors chose.
|
|
5
|
+
// Every line below this four-line banner is byte-identical to upstream.
|
|
6
|
+
export type GlobalSettings = {
|
|
7
|
+
/** The map's default API URL for requesting tiles, styles, sprites, and glyphs. */
|
|
8
|
+
baseApiUrl?: string;
|
|
9
|
+
/** The maximum number of images (raster tiles, sprites, icons) to load in parallel.
|
|
10
|
+
* @default 16
|
|
11
|
+
*/
|
|
12
|
+
maxParallelImageRequests?: number;
|
|
13
|
+
/** The map's RTL text plugin. Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left. */
|
|
14
|
+
RTLTextPlugin?: string | false;
|
|
15
|
+
/** 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.
|
|
16
|
+
Takes precedence over `workerUrl`. */
|
|
17
|
+
workerClass?: any;
|
|
18
|
+
/** The number of web workers instantiated on a page with mapbox-gl maps.
|
|
19
|
+
* @default 2
|
|
20
|
+
*/
|
|
21
|
+
workerCount?: number;
|
|
22
|
+
/** Provides an interface for loading mapbox-gl's WebWorker bundle from a self-hosted URL.
|
|
23
|
+
* This is useful if your site needs to operate in a strict CSP (Content Security Policy) environment
|
|
24
|
+
* wherein you are not allowed to load JavaScript code from a Blob URL, which is default behavior. */
|
|
25
|
+
workerUrl?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const globalSettings = [
|
|
29
|
+
'baseApiUrl',
|
|
30
|
+
'maxParallelImageRequests',
|
|
31
|
+
'workerClass',
|
|
32
|
+
'workerCount',
|
|
33
|
+
'workerUrl'
|
|
34
|
+
] as const;
|
|
35
|
+
|
|
36
|
+
export default function setGlobals(mapLib: any, props: GlobalSettings) {
|
|
37
|
+
for (const key of globalSettings) {
|
|
38
|
+
if (key in props) {
|
|
39
|
+
mapLib[key] = props[key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
RTLTextPlugin = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js'
|
|
45
|
+
} = props;
|
|
46
|
+
if (
|
|
47
|
+
RTLTextPlugin &&
|
|
48
|
+
mapLib.getRTLTextPluginStatus &&
|
|
49
|
+
mapLib.getRTLTextPluginStatus() === 'unavailable'
|
|
50
|
+
) {
|
|
51
|
+
mapLib.setRTLTextPlugin(
|
|
52
|
+
RTLTextPlugin,
|
|
53
|
+
(error?: Error) => {
|
|
54
|
+
if (error) {
|
|
55
|
+
// eslint-disable-next-line
|
|
56
|
+
console.error(error);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
true
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// @ts-nocheck — byte-exact reuse of @vis.gl/react-mapbox 8.1.2. Upstream compiles
|
|
2
|
+
// without strictNullChecks or noImplicitAny; this repository is strict. The copy
|
|
3
|
+
// under upstream/ is typechecked with upstream's own configuration instead, so
|
|
4
|
+
// nothing here is unchecked, only checked at the settings its authors chose.
|
|
5
|
+
// Every line below this four-line banner is byte-identical to upstream.
|
|
6
|
+
import {ImmutableLike} from '../types/common';
|
|
7
|
+
import {StyleSpecification} from '../types/style-spec';
|
|
8
|
+
|
|
9
|
+
const refProps = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];
|
|
10
|
+
|
|
11
|
+
// Prepare a map style object for diffing
|
|
12
|
+
// If immutable - convert to plain object
|
|
13
|
+
// Work around some issues in older styles that would fail Mapbox's diffing
|
|
14
|
+
export function normalizeStyle(
|
|
15
|
+
style: string | StyleSpecification | ImmutableLike<StyleSpecification>
|
|
16
|
+
): string | StyleSpecification {
|
|
17
|
+
if (!style) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
if (typeof style === 'string') {
|
|
21
|
+
return style;
|
|
22
|
+
}
|
|
23
|
+
if ('toJS' in style) {
|
|
24
|
+
style = style.toJS();
|
|
25
|
+
}
|
|
26
|
+
if (!style.layers) {
|
|
27
|
+
return style;
|
|
28
|
+
}
|
|
29
|
+
const layerIndex = {};
|
|
30
|
+
|
|
31
|
+
for (const layer of style.layers) {
|
|
32
|
+
layerIndex[layer.id] = layer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const layers = style.layers.map(layer => {
|
|
36
|
+
let normalizedLayer: typeof layer = null;
|
|
37
|
+
|
|
38
|
+
if ('interactive' in layer) {
|
|
39
|
+
normalizedLayer = Object.assign({}, layer);
|
|
40
|
+
// Breaks style diffing :(
|
|
41
|
+
// @ts-ignore legacy field not typed
|
|
42
|
+
delete normalizedLayer.interactive;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Style diffing doesn't work with refs so expand them out manually before diffing.
|
|
46
|
+
// @ts-ignore legacy field not typed
|
|
47
|
+
const layerRef = layerIndex[layer.ref];
|
|
48
|
+
if (layerRef) {
|
|
49
|
+
normalizedLayer = normalizedLayer || Object.assign({}, layer);
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
delete normalizedLayer.ref;
|
|
52
|
+
// https://github.com/mapbox/mapbox-gl-js/blob/master/src/style-spec/deref.js
|
|
53
|
+
for (const propName of refProps) {
|
|
54
|
+
if (propName in layerRef) {
|
|
55
|
+
normalizedLayer[propName] = layerRef[propName];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return normalizedLayer || layer;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Do not mutate the style object provided by the user
|
|
64
|
+
return {...style, layers};
|
|
65
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @ts-nocheck — byte-exact reuse of @vis.gl/react-mapbox 8.1.2. Upstream compiles
|
|
2
|
+
// without strictNullChecks or noImplicitAny; this repository is strict. The copy
|
|
3
|
+
// under upstream/ is typechecked with upstream's own configuration instead, so
|
|
4
|
+
// nothing here is unchecked, only checked at the settings its authors chose.
|
|
5
|
+
// Every line below this four-line banner is byte-identical to upstream.
|
|
6
|
+
import type {ViewState} from '../types/common';
|
|
7
|
+
import type {Transform} from '../types/internal';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Capture a transform's current state
|
|
11
|
+
* @param transform
|
|
12
|
+
* @returns descriptor of the view state
|
|
13
|
+
*/
|
|
14
|
+
export function transformToViewState(tr: Transform): ViewState {
|
|
15
|
+
return {
|
|
16
|
+
longitude: tr.center.lng,
|
|
17
|
+
latitude: tr.center.lat,
|
|
18
|
+
zoom: tr._seaLevelZoom ?? tr.zoom,
|
|
19
|
+
pitch: tr.pitch,
|
|
20
|
+
bearing: tr.bearing,
|
|
21
|
+
padding: tr.padding,
|
|
22
|
+
elevation: tr._centerAltitude
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Returns `true` if the given props can potentially override view state updates */
|
|
27
|
+
export function isViewStateControlled(v: Partial<ViewState>): boolean {
|
|
28
|
+
return (
|
|
29
|
+
Number.isFinite(v.longitude) ||
|
|
30
|
+
Number.isFinite(v.latitude) ||
|
|
31
|
+
Number.isFinite(v.zoom) ||
|
|
32
|
+
Number.isFinite(v.pitch) ||
|
|
33
|
+
Number.isFinite(v.bearing)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns `true` if transform needs to be updated to match view state
|
|
39
|
+
*/
|
|
40
|
+
export function compareViewStateWithTransform(tr: Transform, v: Partial<ViewState>): boolean {
|
|
41
|
+
if (Number.isFinite(v.longitude) && tr.center.lng !== v.longitude) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (Number.isFinite(v.latitude) && tr.center.lat !== v.latitude) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (Number.isFinite(v.bearing) && tr.bearing !== v.bearing) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (Number.isFinite(v.pitch) && tr.pitch !== v.pitch) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if (Number.isFinite(v.zoom) && (tr._seaLevelZoom ?? tr.zoom) !== v.zoom) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (v.padding && !tr.isPaddingEqual(v.padding)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function noOp() {}
|
|
63
|
+
|
|
64
|
+
/* eslint-disable complexity */
|
|
65
|
+
/**
|
|
66
|
+
* Mutate a transform to match the given view state. Should reverse `transformToViewState`
|
|
67
|
+
* @param transform
|
|
68
|
+
* @param viewState
|
|
69
|
+
*/
|
|
70
|
+
export function applyViewStateToTransform(tr: Transform, v: Partial<ViewState>) {
|
|
71
|
+
// prevent constrain from running until all properties are set
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
73
|
+
const constrain = tr._constrain;
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
75
|
+
const calcMatrices = tr._calcMatrices;
|
|
76
|
+
tr._constrain = noOp;
|
|
77
|
+
tr._calcMatrices = noOp;
|
|
78
|
+
|
|
79
|
+
if (Number.isFinite(v.bearing)) {
|
|
80
|
+
tr.bearing = v.bearing;
|
|
81
|
+
}
|
|
82
|
+
if (Number.isFinite(v.pitch)) {
|
|
83
|
+
tr.pitch = v.pitch;
|
|
84
|
+
}
|
|
85
|
+
if (v.padding && !tr.isPaddingEqual(v.padding)) {
|
|
86
|
+
tr.padding = v.padding;
|
|
87
|
+
}
|
|
88
|
+
if (Number.isFinite(v.longitude) || Number.isFinite(v.latitude)) {
|
|
89
|
+
const center = tr.center;
|
|
90
|
+
// @ts-expect-error LngLat constructor is not typed
|
|
91
|
+
tr._center = new center.constructor(v.longitude ?? center.lng, v.latitude ?? center.lat);
|
|
92
|
+
}
|
|
93
|
+
if (Number.isFinite(v.zoom)) {
|
|
94
|
+
tr._centerAltitude = v.elevation ?? 0;
|
|
95
|
+
if (tr.elevation) {
|
|
96
|
+
tr._seaLevelZoom = v.zoom;
|
|
97
|
+
const mercatorElevation = (tr.pixelsPerMeter / tr.worldSize) * tr._centerAltitude;
|
|
98
|
+
const altitude = tr._mercatorZfromZoom(v.zoom);
|
|
99
|
+
const minHeight = tr._mercatorZfromZoom(tr._maxZoom);
|
|
100
|
+
const height = Math.max(altitude - mercatorElevation, minHeight);
|
|
101
|
+
tr._setZoom(tr._zoomFromMercatorZ(height));
|
|
102
|
+
} else {
|
|
103
|
+
tr._seaLevelZoom = null;
|
|
104
|
+
tr.zoom = v.zoom;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// restore methods
|
|
109
|
+
tr._constrain = constrain;
|
|
110
|
+
tr._calcMatrices = calcMatrices;
|
|
111
|
+
if (!tr._unmodified) {
|
|
112
|
+
tr._constrain();
|
|
113
|
+
tr._calcMatrices();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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 'octane';
|
|
4
|
+
|
|
5
|
+
const useIsomorphicLayoutEffect = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
|
|
6
|
+
|
|
7
|
+
export default useIsomorphicLayoutEffect;
|