react-bkoi-gl 1.0.7 → 2.0.0

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 (167) hide show
  1. package/README.md +163 -18
  2. package/dist/components/attribution-control.d.ts +4 -6
  3. package/dist/components/attribution-control.js +6 -5
  4. package/dist/components/attribution-control.js.map +1 -1
  5. package/dist/components/fullscreen-control.d.ts +4 -6
  6. package/dist/components/fullscreen-control.js +4 -4
  7. package/dist/components/fullscreen-control.js.map +1 -1
  8. package/dist/components/geolocate-control.d.ts +10 -26
  9. package/dist/components/geolocate-control.js +11 -11
  10. package/dist/components/geolocate-control.js.map +1 -1
  11. package/dist/components/layer.d.ts +7 -6
  12. package/dist/components/layer.js +8 -9
  13. package/dist/components/layer.js.map +1 -1
  14. package/dist/components/logo-control.d.ts +9 -0
  15. package/dist/components/logo-control.js +28 -0
  16. package/dist/components/logo-control.js.map +1 -0
  17. package/dist/components/map.d.ts +20 -16
  18. package/dist/components/map.js +38 -32
  19. package/dist/components/map.js.map +1 -1
  20. package/dist/components/marker.d.ts +10 -33
  21. package/dist/components/marker.js +22 -15
  22. package/dist/components/marker.js.map +1 -1
  23. package/dist/components/navigation-control.d.ts +4 -6
  24. package/dist/components/navigation-control.js +4 -4
  25. package/dist/components/navigation-control.js.map +1 -1
  26. package/dist/components/popup.d.ts +7 -25
  27. package/dist/components/popup.js +17 -28
  28. package/dist/components/popup.js.map +1 -1
  29. package/dist/components/scale-control.d.ts +4 -6
  30. package/dist/components/scale-control.js +4 -4
  31. package/dist/components/scale-control.js.map +1 -1
  32. package/dist/components/source.d.ts +3 -4
  33. package/dist/components/source.js +20 -22
  34. package/dist/components/source.js.map +1 -1
  35. package/dist/components/terrain-control.d.ts +10 -0
  36. package/dist/components/terrain-control.js +19 -0
  37. package/dist/components/terrain-control.js.map +1 -0
  38. package/dist/components/use-control.d.ts +6 -6
  39. package/dist/components/use-control.js +4 -5
  40. package/dist/components/use-control.js.map +1 -1
  41. package/dist/components/use-map.d.ts +8 -9
  42. package/dist/components/use-map.js +5 -5
  43. package/dist/components/use-map.js.map +1 -1
  44. package/dist/exports-maplibre-gl.d.ts +33 -0
  45. package/dist/exports-maplibre-gl.js +21 -0
  46. package/dist/exports-maplibre-gl.js.map +1 -0
  47. package/dist/index.cjs +590 -681
  48. package/dist/index.d.ts +2 -2
  49. package/dist/index.js +2 -2
  50. package/dist/index.js.map +1 -1
  51. package/dist/{mapbox → maplibre}/create-ref.d.ts +6 -6
  52. package/dist/maplibre/create-ref.js +30 -0
  53. package/dist/maplibre/create-ref.js.map +1 -0
  54. package/dist/maplibre/maplibre.d.ts +81 -0
  55. package/dist/maplibre/maplibre.js +387 -0
  56. package/dist/maplibre/maplibre.js.map +1 -0
  57. package/dist/styles/index.d.ts +4 -0
  58. package/dist/styles/react-bkoi-gl.css +1 -1
  59. package/dist/styles.d.js +2 -0
  60. package/dist/styles.d.js.map +1 -0
  61. package/dist/tsconfig.build.tsbuildinfo +1 -0
  62. package/dist/types/common.d.ts +2 -60
  63. package/dist/types/common.js.map +1 -1
  64. package/dist/types/events.d.ts +64 -23
  65. package/dist/types/events.js.map +1 -1
  66. package/dist/types/internal.d.ts +14 -0
  67. package/dist/types/internal.js +2 -0
  68. package/dist/types/internal.js.map +1 -0
  69. package/dist/types/lib.d.ts +16 -200
  70. package/dist/types/lib.js.map +1 -1
  71. package/dist/types/style-spec.d.ts +1 -0
  72. package/dist/types/style-spec.js +2 -0
  73. package/dist/types/style-spec.js.map +1 -0
  74. package/dist/utils/apply-react-style.d.ts +1 -1
  75. package/dist/utils/apply-react-style.js.map +1 -1
  76. package/dist/utils/compare-class-names.d.ts +2 -0
  77. package/dist/utils/compare-class-names.js +23 -0
  78. package/dist/utils/compare-class-names.js.map +1 -0
  79. package/dist/utils/deep-equal.d.ts +1 -1
  80. package/dist/utils/deep-equal.js +1 -1
  81. package/dist/utils/deep-equal.js.map +1 -1
  82. package/dist/utils/set-globals.d.ts +6 -8
  83. package/dist/utils/set-globals.js +22 -10
  84. package/dist/utils/set-globals.js.map +1 -1
  85. package/dist/utils/style-utils.d.ts +3 -2
  86. package/dist/utils/style-utils.js +4 -4
  87. package/dist/utils/style-utils.js.map +1 -1
  88. package/dist/utils/transform.d.ts +11 -19
  89. package/dist/utils/transform.js +13 -36
  90. package/dist/utils/transform.js.map +1 -1
  91. package/dist/utils/use-isomorphic-layout-effect.d.ts +1 -1
  92. package/dist/utils/use-isomorphic-layout-effect.js +2 -2
  93. package/dist/utils/use-isomorphic-layout-effect.js.map +1 -1
  94. package/package.json +42 -26
  95. package/src/components/attribution-control.ts +40 -16
  96. package/src/components/fullscreen-control.ts +40 -0
  97. package/src/components/geolocate-control.ts +45 -39
  98. package/src/components/layer.ts +37 -29
  99. package/src/components/logo-control.ts +44 -0
  100. package/src/components/map.tsx +86 -75
  101. package/src/components/marker.ts +141 -123
  102. package/src/components/navigation-control.ts +11 -12
  103. package/src/components/popup.ts +94 -97
  104. package/src/components/scale-control.ts +12 -14
  105. package/src/components/source.ts +58 -57
  106. package/src/components/terrain-control.ts +29 -0
  107. package/src/components/use-control.ts +21 -17
  108. package/src/components/use-map.tsx +26 -24
  109. package/src/exports-maplibre-gl.ts +37 -0
  110. package/src/index.ts +3 -2
  111. package/src/maplibre/create-ref.ts +70 -0
  112. package/src/maplibre/maplibre.ts +624 -0
  113. package/src/styles.d.ts +4 -0
  114. package/src/types/common.ts +12 -72
  115. package/src/types/events.ts +102 -42
  116. package/src/types/internal.ts +26 -0
  117. package/src/types/lib.ts +65 -260
  118. package/src/types/style-spec.ts +34 -0
  119. package/src/utils/apply-react-style.ts +7 -3
  120. package/src/utils/compare-class-names.ts +29 -0
  121. package/src/utils/deep-equal.ts +2 -2
  122. package/src/utils/set-globals.ts +22 -28
  123. package/src/utils/style-utils.ts +18 -9
  124. package/src/utils/transform.ts +32 -60
  125. package/src/utils/use-isomorphic-layout-effect.ts +3 -2
  126. package/bkoi-gl/package.json +0 -6
  127. package/dist/exports-bkoi-gl.cjs +0 -1512
  128. package/dist/exports-bkoi-gl.d.ts +0 -89
  129. package/dist/exports-bkoi-gl.js +0 -36
  130. package/dist/exports-bkoi-gl.js.map +0 -1
  131. package/dist/exports-mapbox.d.ts +0 -139
  132. package/dist/exports-mapbox.js +0 -36
  133. package/dist/exports-mapbox.js.map +0 -1
  134. package/dist/mapbox/create-ref.js +0 -64
  135. package/dist/mapbox/create-ref.js.map +0 -1
  136. package/dist/mapbox/mapbox.d.ts +0 -81
  137. package/dist/mapbox/mapbox.js +0 -476
  138. package/dist/mapbox/mapbox.js.map +0 -1
  139. package/dist/types/events-bkoi-gl.d.ts +0 -49
  140. package/dist/types/events-bkoi-gl.js +0 -2
  141. package/dist/types/events-bkoi-gl.js.map +0 -1
  142. package/dist/types/events-mapbox.d.ts +0 -49
  143. package/dist/types/events-mapbox.js +0 -2
  144. package/dist/types/events-mapbox.js.map +0 -1
  145. package/dist/types/index.d.ts +0 -70
  146. package/dist/types/index.js +0 -5
  147. package/dist/types/index.js.map +0 -1
  148. package/dist/types/public.d.ts +0 -2
  149. package/dist/types/public.js +0 -2
  150. package/dist/types/public.js.map +0 -1
  151. package/dist/types/style-spec-bkoi-gl.d.ts +0 -9
  152. package/dist/types/style-spec-bkoi-gl.js +0 -2
  153. package/dist/types/style-spec-bkoi-gl.js.map +0 -1
  154. package/dist/types/style-spec-mapbox.d.ts +0 -7
  155. package/dist/types/style-spec-mapbox.js +0 -2
  156. package/dist/types/style-spec-mapbox.js.map +0 -1
  157. package/src/components/fullscreen-control.tsx +0 -37
  158. package/src/exports-bkoi-gl.ts +0 -156
  159. package/src/exports-mapbox.ts +0 -159
  160. package/src/mapbox/create-ref.ts +0 -118
  161. package/src/mapbox/mapbox.ts +0 -742
  162. package/src/types/events-bkoi-gl.ts +0 -78
  163. package/src/types/events-mapbox.ts +0 -76
  164. package/src/types/index.ts +0 -93
  165. package/src/types/public.ts +0 -9
  166. package/src/types/style-spec-bkoi-gl.ts +0 -81
  167. package/src/types/style-spec-mapbox.ts +0 -80
@@ -0,0 +1,29 @@
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
+ }
@@ -1,4 +1,4 @@
1
- import type {PointLike} from '../types';
1
+ import type { PointLike } from "../types/common";
2
2
 
3
3
  /**
4
4
  * Compare two points
@@ -41,7 +41,7 @@ export function deepEqual(a: any, b: any): boolean {
41
41
  } else if (Array.isArray(b)) {
42
42
  return false;
43
43
  }
44
- if (typeof a === 'object' && typeof b === 'object') {
44
+ if (typeof a === "object" && typeof b === "object") {
45
45
  const aKeys = Object.keys(a);
46
46
  const bKeys = Object.keys(b);
47
47
  if (aKeys.length !== bKeys.length) {
@@ -1,57 +1,51 @@
1
1
  export type GlobalSettings = {
2
- /** The map's default API URL for requesting tiles, styles, sprites, and glyphs. */
3
- baseApiUrl?: string;
4
2
  /** The maximum number of images (raster tiles, sprites, icons) to load in parallel.
5
3
  * @default 16
6
4
  */
7
5
  maxParallelImageRequests?: number;
8
6
  /** 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.
7
+ RTLTextPlugin?: string | { pluginUrl: string; lazy?: boolean };
8
+ /** The number of web workers instantiated on a page with maplibre-gl maps.
14
9
  * @default 2
15
10
  */
16
11
  workerCount?: number;
17
- /** Provides an interface for loading mapbox-gl's WebWorker bundle from a self-hosted URL.
12
+ /** Provides an interface for loading maplibre-gl's WebWorker bundle from a self-hosted URL.
18
13
  * This is useful if your site needs to operate in a strict CSP (Content Security Policy) environment
19
14
  * wherein you are not allowed to load JavaScript code from a Blob URL, which is default behavior. */
20
15
  workerUrl?: string;
21
16
  };
22
17
 
23
- const globalSettings = [
24
- 'baseApiUrl',
25
- 'maxParallelImageRequests',
26
- 'workerClass',
27
- 'workerCount',
28
- 'workerUrl'
29
- ] as const;
30
-
31
18
  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;
19
+ const { RTLTextPlugin, maxParallelImageRequests, workerCount, workerUrl } =
20
+ props;
41
21
  if (
42
22
  RTLTextPlugin &&
43
23
  mapLib.getRTLTextPluginStatus &&
44
- mapLib.getRTLTextPluginStatus() === 'unavailable'
24
+ mapLib.getRTLTextPluginStatus() === "unavailable"
45
25
  ) {
26
+ const { pluginUrl, lazy = true } =
27
+ typeof RTLTextPlugin === "string"
28
+ ? { pluginUrl: RTLTextPlugin }
29
+ : RTLTextPlugin;
30
+
46
31
  mapLib.setRTLTextPlugin(
47
- RTLTextPlugin,
32
+ pluginUrl,
48
33
  (error?: Error) => {
49
34
  if (error) {
50
35
  // eslint-disable-next-line
51
36
  console.error(error);
52
37
  }
53
38
  },
54
- true
39
+ lazy,
55
40
  );
56
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
+ }
57
51
  }
@@ -1,20 +1,29 @@
1
- import {ImmutableLike, MapStyle} from '../types';
1
+ import type { StyleSpecification } from "../types/style-spec";
2
+ import type { ImmutableLike } from "../types/common";
2
3
 
3
- const refProps = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];
4
+ const refProps = [
5
+ "type",
6
+ "source",
7
+ "source-layer",
8
+ "minzoom",
9
+ "maxzoom",
10
+ "filter",
11
+ "layout",
12
+ ];
4
13
 
5
14
  // Prepare a map style object for diffing
6
15
  // If immutable - convert to plain object
7
16
  // Work around some issues in older styles that would fail Mapbox's diffing
8
17
  export function normalizeStyle(
9
- style: string | MapStyle | ImmutableLike<MapStyle>
10
- ): string | MapStyle {
18
+ style: string | StyleSpecification | ImmutableLike<StyleSpecification>,
19
+ ): string | StyleSpecification {
11
20
  if (!style) {
12
21
  return null;
13
22
  }
14
- if (typeof style === 'string') {
23
+ if (typeof style === "string") {
15
24
  return style;
16
25
  }
17
- if ('toJS' in style) {
26
+ if ("toJS" in style) {
18
27
  style = style.toJS();
19
28
  }
20
29
  if (!style.layers) {
@@ -26,10 +35,10 @@ export function normalizeStyle(
26
35
  layerIndex[layer.id] = layer;
27
36
  }
28
37
 
29
- const layers = style.layers.map(layer => {
38
+ const layers = style.layers.map((layer) => {
30
39
  let normalizedLayer: typeof layer = null;
31
40
 
32
- if ('interactive' in layer) {
41
+ if ("interactive" in layer) {
33
42
  normalizedLayer = Object.assign({}, layer);
34
43
  // Breaks style diffing :(
35
44
  // @ts-ignore legacy field not typed
@@ -55,5 +64,5 @@ export function normalizeStyle(
55
64
  });
56
65
 
57
66
  // Do not mutate the style object provided by the user
58
- return {...style, layers};
67
+ return { ...style, layers };
59
68
  }
@@ -1,86 +1,58 @@
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
- }
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";
32
5
 
33
6
  /**
34
7
  * Capture a transform's current state
35
8
  * @param transform
36
9
  * @returns descriptor of the view state
37
10
  */
38
- export function transformToViewState(tr: Transform): ViewState {
11
+ export function transformToViewState(tr: TransformLike): ViewState {
39
12
  return {
40
13
  longitude: tr.center.lng,
41
14
  latitude: tr.center.lat,
42
15
  zoom: tr.zoom,
43
16
  pitch: tr.pitch,
44
17
  bearing: tr.bearing,
45
- padding: tr.padding
18
+ padding: tr.padding,
46
19
  };
47
20
  }
48
21
 
49
22
  /* eslint-disable complexity */
50
23
  /**
51
- * Mutate a transform to match the given view state
52
- * @param transform
53
- * @param viewState
54
- * @returns true if the transform has changed
24
+ * Applies requested view state to a transform
25
+ * @returns an object containing detected changes
55
26
  */
56
- export function applyViewStateToTransform(tr: Transform, props: MapboxProps): boolean {
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> {
57
33
  const v: Partial<ViewState> = props.viewState || props;
58
- let changed = false;
34
+ const changes: Partial<TransformLike> = {};
59
35
 
60
- if ('zoom' in v) {
61
- const zoom = tr.zoom;
62
- tr.zoom = v.zoom;
63
- changed = changed || zoom !== tr.zoom;
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);
64
44
  }
65
- if ('bearing' in v) {
66
- const bearing = tr.bearing;
67
- tr.bearing = v.bearing;
68
- changed = changed || bearing !== tr.bearing;
45
+ if ("zoom" in v && v.zoom !== tr.zoom) {
46
+ changes.zoom = v.zoom;
69
47
  }
70
- if ('pitch' in v) {
71
- const pitch = tr.pitch;
72
- tr.pitch = v.pitch;
73
- changed = changed || pitch !== tr.pitch;
48
+ if ("bearing" in v && v.bearing !== tr.bearing) {
49
+ changes.bearing = v.bearing;
74
50
  }
75
- if (v.padding && !tr.isPaddingEqual(v.padding)) {
76
- changed = true;
77
- tr.padding = v.padding;
51
+ if ("pitch" in v && v.pitch !== tr.pitch) {
52
+ changes.pitch = v.pitch;
78
53
  }
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;
54
+ if (v.padding && tr.padding && !deepEqual(v.padding, tr.padding)) {
55
+ changes.padding = v.padding;
84
56
  }
85
- return changed;
57
+ return changes;
86
58
  }
@@ -1,7 +1,8 @@
1
1
  // From https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts
2
2
  // useLayoutEffect but does not trigger warning in server-side rendering
3
- import {useEffect, useLayoutEffect} from 'react';
3
+ import { useEffect, useLayoutEffect } from "react";
4
4
 
5
- const useIsomorphicLayoutEffect = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
5
+ const useIsomorphicLayoutEffect =
6
+ typeof document !== "undefined" ? useLayoutEffect : useEffect;
6
7
 
7
8
  export default useIsomorphicLayoutEffect;
@@ -1,6 +0,0 @@
1
- {
2
- "internal": true,
3
- "main": "../dist/exports-bkoi-gl.cjs",
4
- "module": "../dist/exports-bkoi-gl.js",
5
- "types": "../dist/exports-bkoi-gl.d.ts"
6
- }