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.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +172 -18
  3. package/dist/index.cjs +671 -736
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +370 -0
  6. package/dist/index.d.ts +370 -2
  7. package/dist/index.js +1434 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/styles/index.d.ts +4 -0
  10. package/dist/styles/react-bkoi-gl.css +1 -1
  11. package/package.json +84 -36
  12. package/bkoi-gl/package.json +0 -6
  13. package/dist/components/attribution-control.d.ts +0 -11
  14. package/dist/components/attribution-control.js +0 -19
  15. package/dist/components/attribution-control.js.map +0 -1
  16. package/dist/components/fullscreen-control.d.ts +0 -14
  17. package/dist/components/fullscreen-control.js +0 -21
  18. package/dist/components/fullscreen-control.js.map +0 -1
  19. package/dist/components/geolocate-control.d.ts +0 -37
  20. package/dist/components/geolocate-control.js +0 -46
  21. package/dist/components/geolocate-control.js.map +0 -1
  22. package/dist/components/layer.d.ts +0 -17
  23. package/dist/components/layer.js +0 -99
  24. package/dist/components/layer.js.map +0 -1
  25. package/dist/components/map.d.ts +0 -23
  26. package/dist/components/map.js +0 -102
  27. package/dist/components/map.js.map +0 -1
  28. package/dist/components/marker.d.ts +0 -41
  29. package/dist/components/marker.js +0 -98
  30. package/dist/components/marker.js.map +0 -1
  31. package/dist/components/navigation-control.d.ts +0 -11
  32. package/dist/components/navigation-control.js +0 -19
  33. package/dist/components/navigation-control.js.map +0 -1
  34. package/dist/components/popup.d.ts +0 -33
  35. package/dist/components/popup.js +0 -79
  36. package/dist/components/popup.js.map +0 -1
  37. package/dist/components/scale-control.d.ts +0 -13
  38. package/dist/components/scale-control.js +0 -31
  39. package/dist/components/scale-control.js.map +0 -1
  40. package/dist/components/source.d.ts +0 -7
  41. package/dist/components/source.js +0 -97
  42. package/dist/components/source.js.map +0 -1
  43. package/dist/components/use-control.d.ts +0 -9
  44. package/dist/components/use-control.js +0 -31
  45. package/dist/components/use-control.js.map +0 -1
  46. package/dist/components/use-map.d.ts +0 -20
  47. package/dist/components/use-map.js +0 -54
  48. package/dist/components/use-map.js.map +0 -1
  49. package/dist/exports-bkoi-gl.cjs +0 -1512
  50. package/dist/exports-bkoi-gl.d.ts +0 -89
  51. package/dist/exports-bkoi-gl.js +0 -36
  52. package/dist/exports-bkoi-gl.js.map +0 -1
  53. package/dist/exports-mapbox.d.ts +0 -139
  54. package/dist/exports-mapbox.js +0 -36
  55. package/dist/exports-mapbox.js.map +0 -1
  56. package/dist/mapbox/create-ref.d.ts +0 -9
  57. package/dist/mapbox/create-ref.js +0 -64
  58. package/dist/mapbox/create-ref.js.map +0 -1
  59. package/dist/mapbox/mapbox.d.ts +0 -81
  60. package/dist/mapbox/mapbox.js +0 -476
  61. package/dist/mapbox/mapbox.js.map +0 -1
  62. package/dist/types/common.d.ts +0 -78
  63. package/dist/types/common.js +0 -2
  64. package/dist/types/common.js.map +0 -1
  65. package/dist/types/events-bkoi-gl.d.ts +0 -49
  66. package/dist/types/events-bkoi-gl.js +0 -2
  67. package/dist/types/events-bkoi-gl.js.map +0 -1
  68. package/dist/types/events-mapbox.d.ts +0 -49
  69. package/dist/types/events-mapbox.js +0 -2
  70. package/dist/types/events-mapbox.js.map +0 -1
  71. package/dist/types/events.d.ts +0 -39
  72. package/dist/types/events.js +0 -2
  73. package/dist/types/events.js.map +0 -1
  74. package/dist/types/index.d.ts +0 -70
  75. package/dist/types/index.js +0 -5
  76. package/dist/types/index.js.map +0 -1
  77. package/dist/types/lib.d.ts +0 -224
  78. package/dist/types/lib.js +0 -2
  79. package/dist/types/lib.js.map +0 -1
  80. package/dist/types/public.d.ts +0 -2
  81. package/dist/types/public.js +0 -2
  82. package/dist/types/public.js.map +0 -1
  83. package/dist/types/style-spec-bkoi-gl.d.ts +0 -9
  84. package/dist/types/style-spec-bkoi-gl.js +0 -2
  85. package/dist/types/style-spec-bkoi-gl.js.map +0 -1
  86. package/dist/types/style-spec-mapbox.d.ts +0 -7
  87. package/dist/types/style-spec-mapbox.js +0 -2
  88. package/dist/types/style-spec-mapbox.js.map +0 -1
  89. package/dist/utils/apply-react-style.d.ts +0 -2
  90. package/dist/utils/apply-react-style.js +0 -16
  91. package/dist/utils/apply-react-style.js.map +0 -1
  92. package/dist/utils/assert.d.ts +0 -1
  93. package/dist/utils/assert.js +0 -6
  94. package/dist/utils/assert.js.map +0 -1
  95. package/dist/utils/deep-equal.d.ts +0 -15
  96. package/dist/utils/deep-equal.js +0 -46
  97. package/dist/utils/deep-equal.js.map +0 -1
  98. package/dist/utils/set-globals.d.ts +0 -22
  99. package/dist/utils/set-globals.js +0 -19
  100. package/dist/utils/set-globals.js.map +0 -1
  101. package/dist/utils/style-utils.d.ts +0 -2
  102. package/dist/utils/style-utils.js +0 -42
  103. package/dist/utils/style-utils.js.map +0 -1
  104. package/dist/utils/transform.d.ts +0 -26
  105. package/dist/utils/transform.js +0 -56
  106. package/dist/utils/transform.js.map +0 -1
  107. package/dist/utils/use-isomorphic-layout-effect.d.ts +0 -3
  108. package/dist/utils/use-isomorphic-layout-effect.js +0 -4
  109. package/dist/utils/use-isomorphic-layout-effect.js.map +0 -1
  110. package/src/components/attribution-control.ts +0 -32
  111. package/src/components/fullscreen-control.tsx +0 -37
  112. package/src/components/geolocate-control.ts +0 -90
  113. package/src/components/layer.ts +0 -133
  114. package/src/components/map.tsx +0 -155
  115. package/src/components/marker.ts +0 -137
  116. package/src/components/navigation-control.ts +0 -29
  117. package/src/components/popup.ts +0 -116
  118. package/src/components/scale-control.ts +0 -46
  119. package/src/components/source.ts +0 -158
  120. package/src/components/use-control.ts +0 -64
  121. package/src/components/use-map.tsx +0 -69
  122. package/src/exports-bkoi-gl.ts +0 -156
  123. package/src/exports-mapbox.ts +0 -159
  124. package/src/index.ts +0 -2
  125. package/src/mapbox/create-ref.ts +0 -118
  126. package/src/mapbox/mapbox.ts +0 -742
  127. package/src/types/common.ts +0 -94
  128. package/src/types/events-bkoi-gl.ts +0 -78
  129. package/src/types/events-mapbox.ts +0 -76
  130. package/src/types/events.ts +0 -73
  131. package/src/types/index.ts +0 -93
  132. package/src/types/lib.ts +0 -279
  133. package/src/types/public.ts +0 -9
  134. package/src/types/style-spec-bkoi-gl.ts +0 -81
  135. package/src/types/style-spec-mapbox.ts +0 -80
  136. package/src/utils/apply-react-style.ts +0 -20
  137. package/src/utils/assert.ts +0 -5
  138. package/src/utils/deep-equal.ts +0 -61
  139. package/src/utils/set-globals.ts +0 -57
  140. package/src/utils/style-utils.ts +0 -59
  141. package/src/utils/transform.ts +0 -86
  142. package/src/utils/use-isomorphic-layout-effect.ts +0 -7
@@ -1,46 +0,0 @@
1
- export function arePointsEqual(a, b) {
2
- const ax = Array.isArray(a) ? a[0] : a ? a.x : 0;
3
- const ay = Array.isArray(a) ? a[1] : a ? a.y : 0;
4
- const bx = Array.isArray(b) ? b[0] : b ? b.x : 0;
5
- const by = Array.isArray(b) ? b[1] : b ? b.y : 0;
6
- return ax === bx && ay === by;
7
- }
8
- export function deepEqual(a, b) {
9
- if (a === b) {
10
- return true;
11
- }
12
- if (!a || !b) {
13
- return false;
14
- }
15
- if (Array.isArray(a)) {
16
- if (!Array.isArray(b) || a.length !== b.length) {
17
- return false;
18
- }
19
- for (let i = 0; i < a.length; i++) {
20
- if (!deepEqual(a[i], b[i])) {
21
- return false;
22
- }
23
- }
24
- return true;
25
- } else if (Array.isArray(b)) {
26
- return false;
27
- }
28
- if (typeof a === 'object' && typeof b === 'object') {
29
- const aKeys = Object.keys(a);
30
- const bKeys = Object.keys(b);
31
- if (aKeys.length !== bKeys.length) {
32
- return false;
33
- }
34
- for (const key of aKeys) {
35
- if (!b.hasOwnProperty(key)) {
36
- return false;
37
- }
38
- if (!deepEqual(a[key], b[key])) {
39
- return false;
40
- }
41
- }
42
- return true;
43
- }
44
- return false;
45
- }
46
- //# sourceMappingURL=deep-equal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deep-equal.js","names":["arePointsEqual","a","b","ax","Array","isArray","x","ay","y","bx","by","deepEqual","length","i","aKeys","Object","keys","bKeys","key","hasOwnProperty"],"sources":["../../src/utils/deep-equal.ts"],"sourcesContent":["import type {PointLike} from '../types';\n\n/**\n * Compare two points\n * @param a\n * @param b\n * @returns true if the points are equal\n */\nexport function arePointsEqual(a?: PointLike, b?: PointLike): boolean {\n const ax = Array.isArray(a) ? a[0] : a ? a.x : 0;\n const ay = Array.isArray(a) ? a[1] : a ? a.y : 0;\n const bx = Array.isArray(b) ? b[0] : b ? b.x : 0;\n const by = Array.isArray(b) ? b[1] : b ? b.y : 0;\n return ax === bx && ay === by;\n}\n\n/* eslint-disable complexity */\n/**\n * Compare any two objects\n * @param a\n * @param b\n * @returns true if the objects are deep equal\n */\nexport function deepEqual(a: any, b: any): boolean {\n if (a === b) {\n return true;\n }\n if (!a || !b) {\n return false;\n }\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) {\n return false;\n }\n }\n return true;\n } else if (Array.isArray(b)) {\n return false;\n }\n if (typeof a === 'object' && typeof b === 'object') {\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n for (const key of aKeys) {\n if (!b.hasOwnProperty(key)) {\n return false;\n }\n if (!deepEqual(a[key], b[key])) {\n return false;\n }\n }\n return true;\n }\n return false;\n}\n"],"mappings":"AAQA,OAAO,SAASA,cAAcA,CAACC,CAAa,EAAEC,CAAa,EAAW;EACpE,MAAMC,EAAE,GAAGC,KAAK,CAACC,OAAO,CAACJ,CAAC,CAAC,GAAGA,CAAC,CAAC,CAAC,CAAC,GAAGA,CAAC,GAAGA,CAAC,CAACK,CAAC,GAAG,CAAC;EAChD,MAAMC,EAAE,GAAGH,KAAK,CAACC,OAAO,CAACJ,CAAC,CAAC,GAAGA,CAAC,CAAC,CAAC,CAAC,GAAGA,CAAC,GAAGA,CAAC,CAACO,CAAC,GAAG,CAAC;EAChD,MAAMC,EAAE,GAAGL,KAAK,CAACC,OAAO,CAACH,CAAC,CAAC,GAAGA,CAAC,CAAC,CAAC,CAAC,GAAGA,CAAC,GAAGA,CAAC,CAACI,CAAC,GAAG,CAAC;EAChD,MAAMI,EAAE,GAAGN,KAAK,CAACC,OAAO,CAACH,CAAC,CAAC,GAAGA,CAAC,CAAC,CAAC,CAAC,GAAGA,CAAC,GAAGA,CAAC,CAACM,CAAC,GAAG,CAAC;EAChD,OAAOL,EAAE,KAAKM,EAAE,IAAIF,EAAE,KAAKG,EAAE;AAC/B;AASA,OAAO,SAASC,SAASA,CAACV,CAAM,EAAEC,CAAM,EAAW;EACjD,IAAID,CAAC,KAAKC,CAAC,EAAE;IACX,OAAO,IAAI;EACb;EACA,IAAI,CAACD,CAAC,IAAI,CAACC,CAAC,EAAE;IACZ,OAAO,KAAK;EACd;EACA,IAAIE,KAAK,CAACC,OAAO,CAACJ,CAAC,CAAC,EAAE;IACpB,IAAI,CAACG,KAAK,CAACC,OAAO,CAACH,CAAC,CAAC,IAAID,CAAC,CAACW,MAAM,KAAKV,CAAC,CAACU,MAAM,EAAE;MAC9C,OAAO,KAAK;IACd;IACA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGZ,CAAC,CAACW,MAAM,EAAEC,CAAC,EAAE,EAAE;MACjC,IAAI,CAACF,SAAS,CAACV,CAAC,CAACY,CAAC,CAAC,EAAEX,CAAC,CAACW,CAAC,CAAC,CAAC,EAAE;QAC1B,OAAO,KAAK;MACd;IACF;IACA,OAAO,IAAI;EACb,CAAC,MAAM,IAAIT,KAAK,CAACC,OAAO,CAACH,CAAC,CAAC,EAAE;IAC3B,OAAO,KAAK;EACd;EACA,IAAI,OAAOD,CAAC,KAAK,QAAQ,IAAI,OAAOC,CAAC,KAAK,QAAQ,EAAE;IAClD,MAAMY,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACf,CAAC,CAAC;IAC5B,MAAMgB,KAAK,GAAGF,MAAM,CAACC,IAAI,CAACd,CAAC,CAAC;IAC5B,IAAIY,KAAK,CAACF,MAAM,KAAKK,KAAK,CAACL,MAAM,EAAE;MACjC,OAAO,KAAK;IACd;IACA,KAAK,MAAMM,GAAG,IAAIJ,KAAK,EAAE;MACvB,IAAI,CAACZ,CAAC,CAACiB,cAAc,CAACD,GAAG,CAAC,EAAE;QAC1B,OAAO,KAAK;MACd;MACA,IAAI,CAACP,SAAS,CAACV,CAAC,CAACiB,GAAG,CAAC,EAAEhB,CAAC,CAACgB,GAAG,CAAC,CAAC,EAAE;QAC9B,OAAO,KAAK;MACd;IACF;IACA,OAAO,IAAI;EACb;EACA,OAAO,KAAK;AACd","ignoreList":[]}
@@ -1,22 +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
- export default function setGlobals(mapLib: any, props: GlobalSettings): void;
@@ -1,19 +0,0 @@
1
- const globalSettings = ['baseApiUrl', 'maxParallelImageRequests', 'workerClass', 'workerCount', 'workerUrl'];
2
- export default function setGlobals(mapLib, props) {
3
- for (const key of globalSettings) {
4
- if (key in props) {
5
- mapLib[key] = props[key];
6
- }
7
- }
8
- const {
9
- RTLTextPlugin = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js'
10
- } = props;
11
- if (RTLTextPlugin && mapLib.getRTLTextPluginStatus && mapLib.getRTLTextPluginStatus() === 'unavailable') {
12
- mapLib.setRTLTextPlugin(RTLTextPlugin, error => {
13
- if (error) {
14
- console.error(error);
15
- }
16
- }, true);
17
- }
18
- }
19
- //# sourceMappingURL=set-globals.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"set-globals.js","names":["globalSettings","setGlobals","mapLib","props","key","RTLTextPlugin","getRTLTextPluginStatus","setRTLTextPlugin","error","console"],"sources":["../../src/utils/set-globals.ts"],"sourcesContent":["export type GlobalSettings = {\n /** The map's default API URL for requesting tiles, styles, sprites, and glyphs. */\n baseApiUrl?: string;\n /** The maximum number of images (raster tiles, sprites, icons) to load in parallel.\n * @default 16\n */\n maxParallelImageRequests?: number;\n /** The map's RTL text plugin. Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left. */\n RTLTextPlugin?: string | false;\n /** 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.\nTakes precedence over `workerUrl`. */\n workerClass?: any;\n /** The number of web workers instantiated on a page with mapbox-gl maps.\n * @default 2\n */\n workerCount?: number;\n /** Provides an interface for loading mapbox-gl's WebWorker bundle from a self-hosted URL.\n * This is useful if your site needs to operate in a strict CSP (Content Security Policy) environment\n * wherein you are not allowed to load JavaScript code from a Blob URL, which is default behavior. */\n workerUrl?: string;\n};\n\nconst globalSettings = [\n 'baseApiUrl',\n 'maxParallelImageRequests',\n 'workerClass',\n 'workerCount',\n 'workerUrl'\n] as const;\n\nexport default function setGlobals(mapLib: any, props: GlobalSettings) {\n for (const key of globalSettings) {\n if (key in props) {\n mapLib[key] = props[key];\n }\n }\n\n const {\n RTLTextPlugin = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js'\n } = props;\n if (\n RTLTextPlugin &&\n mapLib.getRTLTextPluginStatus &&\n mapLib.getRTLTextPluginStatus() === 'unavailable'\n ) {\n mapLib.setRTLTextPlugin(\n RTLTextPlugin,\n (error?: Error) => {\n if (error) {\n // eslint-disable-next-line\n console.error(error);\n }\n },\n true\n );\n }\n}\n"],"mappings":"AAsBA,MAAMA,cAAc,GAAG,CACrB,YAAY,EACZ,0BAA0B,EAC1B,aAAa,EACb,aAAa,EACb,WAAW,CACH;AAEV,eAAe,SAASC,UAAUA,CAACC,MAAW,EAAEC,KAAqB,EAAE;EACrE,KAAK,MAAMC,GAAG,IAAIJ,cAAc,EAAE;IAChC,IAAII,GAAG,IAAID,KAAK,EAAE;MAChBD,MAAM,CAACE,GAAG,CAAC,GAAGD,KAAK,CAACC,GAAG,CAAC;IAC1B;EACF;EAEA,MAAM;IACJC,aAAa,GAAG;EAClB,CAAC,GAAGF,KAAK;EACT,IACEE,aAAa,IACbH,MAAM,CAACI,sBAAsB,IAC7BJ,MAAM,CAACI,sBAAsB,CAAC,CAAC,KAAK,aAAa,EACjD;IACAJ,MAAM,CAACK,gBAAgB,CACrBF,aAAa,EACZG,KAAa,IAAK;MACjB,IAAIA,KAAK,EAAE;QAETC,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC;MACtB;IACF,CAAC,EACD,IACF,CAAC;EACH;AACF","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- import { ImmutableLike, MapStyle } from '../types';
2
- export declare function normalizeStyle(style: string | MapStyle | ImmutableLike<MapStyle>): string | MapStyle;
@@ -1,42 +0,0 @@
1
- const refProps = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];
2
- export function normalizeStyle(style) {
3
- if (!style) {
4
- return null;
5
- }
6
- if (typeof style === 'string') {
7
- return style;
8
- }
9
- if ('toJS' in style) {
10
- style = style.toJS();
11
- }
12
- if (!style.layers) {
13
- return style;
14
- }
15
- const layerIndex = {};
16
- for (const layer of style.layers) {
17
- layerIndex[layer.id] = layer;
18
- }
19
- const layers = style.layers.map(layer => {
20
- let normalizedLayer = null;
21
- if ('interactive' in layer) {
22
- normalizedLayer = Object.assign({}, layer);
23
- delete normalizedLayer.interactive;
24
- }
25
- const layerRef = layerIndex[layer.ref];
26
- if (layerRef) {
27
- normalizedLayer = normalizedLayer || Object.assign({}, layer);
28
- delete normalizedLayer.ref;
29
- for (const propName of refProps) {
30
- if (propName in layerRef) {
31
- normalizedLayer[propName] = layerRef[propName];
32
- }
33
- }
34
- }
35
- return normalizedLayer || layer;
36
- });
37
- return {
38
- ...style,
39
- layers
40
- };
41
- }
42
- //# sourceMappingURL=style-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"style-utils.js","names":["refProps","normalizeStyle","style","toJS","layers","layerIndex","layer","id","map","normalizedLayer","Object","assign","interactive","layerRef","ref","propName"],"sources":["../../src/utils/style-utils.ts"],"sourcesContent":["import {ImmutableLike, MapStyle} from '../types';\n\nconst refProps = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];\n\n// Prepare a map style object for diffing\n// If immutable - convert to plain object\n// Work around some issues in older styles that would fail Mapbox's diffing\nexport function normalizeStyle(\n style: string | MapStyle | ImmutableLike<MapStyle>\n): string | MapStyle {\n if (!style) {\n return null;\n }\n if (typeof style === 'string') {\n return style;\n }\n if ('toJS' in style) {\n style = style.toJS();\n }\n if (!style.layers) {\n return style;\n }\n const layerIndex = {};\n\n for (const layer of style.layers) {\n layerIndex[layer.id] = layer;\n }\n\n const layers = style.layers.map(layer => {\n let normalizedLayer: typeof layer = null;\n\n if ('interactive' in layer) {\n normalizedLayer = Object.assign({}, layer);\n // Breaks style diffing :(\n // @ts-ignore legacy field not typed\n delete normalizedLayer.interactive;\n }\n\n // Style diffing doesn't work with refs so expand them out manually before diffing.\n // @ts-ignore legacy field not typed\n const layerRef = layerIndex[layer.ref];\n if (layerRef) {\n normalizedLayer = normalizedLayer || Object.assign({}, layer);\n // @ts-ignore\n delete normalizedLayer.ref;\n // https://github.com/mapbox/mapbox-gl-js/blob/master/src/style-spec/deref.js\n for (const propName of refProps) {\n if (propName in layerRef) {\n normalizedLayer[propName] = layerRef[propName];\n }\n }\n }\n\n return normalizedLayer || layer;\n });\n\n // Do not mutate the style object provided by the user\n return {...style, layers};\n}\n"],"mappings":"AAEA,MAAMA,QAAQ,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC;AAK7F,OAAO,SAASC,cAAcA,CAC5BC,KAAkD,EAC/B;EACnB,IAAI,CAACA,KAAK,EAAE;IACV,OAAO,IAAI;EACb;EACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC7B,OAAOA,KAAK;EACd;EACA,IAAI,MAAM,IAAIA,KAAK,EAAE;IACnBA,KAAK,GAAGA,KAAK,CAACC,IAAI,CAAC,CAAC;EACtB;EACA,IAAI,CAACD,KAAK,CAACE,MAAM,EAAE;IACjB,OAAOF,KAAK;EACd;EACA,MAAMG,UAAU,GAAG,CAAC,CAAC;EAErB,KAAK,MAAMC,KAAK,IAAIJ,KAAK,CAACE,MAAM,EAAE;IAChCC,UAAU,CAACC,KAAK,CAACC,EAAE,CAAC,GAAGD,KAAK;EAC9B;EAEA,MAAMF,MAAM,GAAGF,KAAK,CAACE,MAAM,CAACI,GAAG,CAACF,KAAK,IAAI;IACvC,IAAIG,eAA6B,GAAG,IAAI;IAExC,IAAI,aAAa,IAAIH,KAAK,EAAE;MAC1BG,eAAe,GAAGC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEL,KAAK,CAAC;MAG1C,OAAOG,eAAe,CAACG,WAAW;IACpC;IAIA,MAAMC,QAAQ,GAAGR,UAAU,CAACC,KAAK,CAACQ,GAAG,CAAC;IACtC,IAAID,QAAQ,EAAE;MACZJ,eAAe,GAAGA,eAAe,IAAIC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEL,KAAK,CAAC;MAE7D,OAAOG,eAAe,CAACK,GAAG;MAE1B,KAAK,MAAMC,QAAQ,IAAIf,QAAQ,EAAE;QAC/B,IAAIe,QAAQ,IAAIF,QAAQ,EAAE;UACxBJ,eAAe,CAACM,QAAQ,CAAC,GAAGF,QAAQ,CAACE,QAAQ,CAAC;QAChD;MACF;IACF;IAEA,OAAON,eAAe,IAAIH,KAAK;EACjC,CAAC,CAAC;EAGF,OAAO;IAAC,GAAGJ,KAAK;IAAEE;EAAM,CAAC;AAC3B","ignoreList":[]}
@@ -1,26 +0,0 @@
1
- import type { MapboxProps } from '../mapbox/mapbox';
2
- import type { Transform, ViewState } from '../types';
3
- /**
4
- * Make a copy of a transform
5
- * @param tr
6
- */
7
- export declare function cloneTransform(tr: Transform): Transform;
8
- /**
9
- * Copy projection from one transform to another. This only applies to mapbox-gl transforms
10
- * @param src the transform to copy projection settings from
11
- * @param dest to transform to copy projection settings to
12
- */
13
- export declare function syncProjection(src: Transform, dest: Transform): void;
14
- /**
15
- * Capture a transform's current state
16
- * @param transform
17
- * @returns descriptor of the view state
18
- */
19
- export declare function transformToViewState(tr: Transform): ViewState;
20
- /**
21
- * Mutate a transform to match the given view state
22
- * @param transform
23
- * @param viewState
24
- * @returns true if the transform has changed
25
- */
26
- export declare function applyViewStateToTransform(tr: Transform, props: MapboxProps): boolean;
@@ -1,56 +0,0 @@
1
- import { deepEqual } from "./deep-equal.js";
2
- export function cloneTransform(tr) {
3
- const newTransform = tr.clone();
4
- newTransform.pixelsToGLUnits = tr.pixelsToGLUnits;
5
- return newTransform;
6
- }
7
- export function syncProjection(src, dest) {
8
- if (!src.getProjection) {
9
- return;
10
- }
11
- const srcProjection = src.getProjection();
12
- const destProjection = dest.getProjection();
13
- if (!deepEqual(srcProjection, destProjection)) {
14
- dest.setProjection(srcProjection);
15
- }
16
- }
17
- export function transformToViewState(tr) {
18
- return {
19
- longitude: tr.center.lng,
20
- latitude: tr.center.lat,
21
- zoom: tr.zoom,
22
- pitch: tr.pitch,
23
- bearing: tr.bearing,
24
- padding: tr.padding
25
- };
26
- }
27
- export function applyViewStateToTransform(tr, props) {
28
- const v = props.viewState || props;
29
- let changed = false;
30
- if ('zoom' in v) {
31
- const zoom = tr.zoom;
32
- tr.zoom = v.zoom;
33
- changed = changed || zoom !== tr.zoom;
34
- }
35
- if ('bearing' in v) {
36
- const bearing = tr.bearing;
37
- tr.bearing = v.bearing;
38
- changed = changed || bearing !== tr.bearing;
39
- }
40
- if ('pitch' in v) {
41
- const pitch = tr.pitch;
42
- tr.pitch = v.pitch;
43
- changed = changed || pitch !== tr.pitch;
44
- }
45
- if (v.padding && !tr.isPaddingEqual(v.padding)) {
46
- changed = true;
47
- tr.padding = v.padding;
48
- }
49
- if ('longitude' in v && 'latitude' in v) {
50
- const center = tr.center;
51
- tr.center = new center.constructor(v.longitude, v.latitude);
52
- changed = changed || center !== tr.center;
53
- }
54
- return changed;
55
- }
56
- //# sourceMappingURL=transform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform.js","names":["deepEqual","cloneTransform","tr","newTransform","clone","pixelsToGLUnits","syncProjection","src","dest","getProjection","srcProjection","destProjection","setProjection","transformToViewState","longitude","center","lng","latitude","lat","zoom","pitch","bearing","padding","applyViewStateToTransform","props","v","viewState","changed","isPaddingEqual","constructor"],"sources":["../../src/utils/transform.ts"],"sourcesContent":["import type {MapboxProps} from '../mapbox/mapbox';\nimport type {Transform, ViewState} from '../types';\nimport {deepEqual} from './deep-equal';\n\n/**\n * Make a copy of a transform\n * @param tr\n */\nexport function cloneTransform(tr: Transform): Transform {\n const newTransform = tr.clone();\n // Work around mapbox bug - this value is not assigned in clone(), only in resize()\n newTransform.pixelsToGLUnits = tr.pixelsToGLUnits;\n return newTransform;\n}\n\n/**\n * Copy projection from one transform to another. This only applies to mapbox-gl transforms\n * @param src the transform to copy projection settings from\n * @param dest to transform to copy projection settings to\n */\nexport function syncProjection(src: Transform, dest: Transform): void {\n if (!src.getProjection) {\n return;\n }\n const srcProjection = src.getProjection();\n const destProjection = dest.getProjection();\n\n if (!deepEqual(srcProjection, destProjection)) {\n dest.setProjection(srcProjection);\n }\n}\n\n/**\n * Capture a transform's current state\n * @param transform\n * @returns descriptor of the view state\n */\nexport function transformToViewState(tr: Transform): ViewState {\n return {\n longitude: tr.center.lng,\n latitude: tr.center.lat,\n zoom: tr.zoom,\n pitch: tr.pitch,\n bearing: tr.bearing,\n padding: tr.padding\n };\n}\n\n/* eslint-disable complexity */\n/**\n * Mutate a transform to match the given view state\n * @param transform\n * @param viewState\n * @returns true if the transform has changed\n */\nexport function applyViewStateToTransform(tr: Transform, props: MapboxProps): boolean {\n const v: Partial<ViewState> = props.viewState || props;\n let changed = false;\n\n if ('zoom' in v) {\n const zoom = tr.zoom;\n tr.zoom = v.zoom;\n changed = changed || zoom !== tr.zoom;\n }\n if ('bearing' in v) {\n const bearing = tr.bearing;\n tr.bearing = v.bearing;\n changed = changed || bearing !== tr.bearing;\n }\n if ('pitch' in v) {\n const pitch = tr.pitch;\n tr.pitch = v.pitch;\n changed = changed || pitch !== tr.pitch;\n }\n if (v.padding && !tr.isPaddingEqual(v.padding)) {\n changed = true;\n tr.padding = v.padding;\n }\n if ('longitude' in v && 'latitude' in v) {\n const center = tr.center;\n // @ts-ignore\n tr.center = new center.constructor(v.longitude, v.latitude);\n changed = changed || center !== tr.center;\n }\n return changed;\n}\n"],"mappings":"SAEQA,SAAS;AAMjB,OAAO,SAASC,cAAcA,CAACC,EAAa,EAAa;EACvD,MAAMC,YAAY,GAAGD,EAAE,CAACE,KAAK,CAAC,CAAC;EAE/BD,YAAY,CAACE,eAAe,GAAGH,EAAE,CAACG,eAAe;EACjD,OAAOF,YAAY;AACrB;AAOA,OAAO,SAASG,cAAcA,CAACC,GAAc,EAAEC,IAAe,EAAQ;EACpE,IAAI,CAACD,GAAG,CAACE,aAAa,EAAE;IACtB;EACF;EACA,MAAMC,aAAa,GAAGH,GAAG,CAACE,aAAa,CAAC,CAAC;EACzC,MAAME,cAAc,GAAGH,IAAI,CAACC,aAAa,CAAC,CAAC;EAE3C,IAAI,CAACT,SAAS,CAACU,aAAa,EAAEC,cAAc,CAAC,EAAE;IAC7CH,IAAI,CAACI,aAAa,CAACF,aAAa,CAAC;EACnC;AACF;AAOA,OAAO,SAASG,oBAAoBA,CAACX,EAAa,EAAa;EAC7D,OAAO;IACLY,SAAS,EAAEZ,EAAE,CAACa,MAAM,CAACC,GAAG;IACxBC,QAAQ,EAAEf,EAAE,CAACa,MAAM,CAACG,GAAG;IACvBC,IAAI,EAAEjB,EAAE,CAACiB,IAAI;IACbC,KAAK,EAAElB,EAAE,CAACkB,KAAK;IACfC,OAAO,EAAEnB,EAAE,CAACmB,OAAO;IACnBC,OAAO,EAAEpB,EAAE,CAACoB;EACd,CAAC;AACH;AASA,OAAO,SAASC,yBAAyBA,CAACrB,EAAa,EAAEsB,KAAkB,EAAW;EACpF,MAAMC,CAAqB,GAAGD,KAAK,CAACE,SAAS,IAAIF,KAAK;EACtD,IAAIG,OAAO,GAAG,KAAK;EAEnB,IAAI,MAAM,IAAIF,CAAC,EAAE;IACf,MAAMN,IAAI,GAAGjB,EAAE,CAACiB,IAAI;IACpBjB,EAAE,CAACiB,IAAI,GAAGM,CAAC,CAACN,IAAI;IAChBQ,OAAO,GAAGA,OAAO,IAAIR,IAAI,KAAKjB,EAAE,CAACiB,IAAI;EACvC;EACA,IAAI,SAAS,IAAIM,CAAC,EAAE;IAClB,MAAMJ,OAAO,GAAGnB,EAAE,CAACmB,OAAO;IAC1BnB,EAAE,CAACmB,OAAO,GAAGI,CAAC,CAACJ,OAAO;IACtBM,OAAO,GAAGA,OAAO,IAAIN,OAAO,KAAKnB,EAAE,CAACmB,OAAO;EAC7C;EACA,IAAI,OAAO,IAAII,CAAC,EAAE;IAChB,MAAML,KAAK,GAAGlB,EAAE,CAACkB,KAAK;IACtBlB,EAAE,CAACkB,KAAK,GAAGK,CAAC,CAACL,KAAK;IAClBO,OAAO,GAAGA,OAAO,IAAIP,KAAK,KAAKlB,EAAE,CAACkB,KAAK;EACzC;EACA,IAAIK,CAAC,CAACH,OAAO,IAAI,CAACpB,EAAE,CAAC0B,cAAc,CAACH,CAAC,CAACH,OAAO,CAAC,EAAE;IAC9CK,OAAO,GAAG,IAAI;IACdzB,EAAE,CAACoB,OAAO,GAAGG,CAAC,CAACH,OAAO;EACxB;EACA,IAAI,WAAW,IAAIG,CAAC,IAAI,UAAU,IAAIA,CAAC,EAAE;IACvC,MAAMV,MAAM,GAAGb,EAAE,CAACa,MAAM;IAExBb,EAAE,CAACa,MAAM,GAAG,IAAIA,MAAM,CAACc,WAAW,CAACJ,CAAC,CAACX,SAAS,EAAEW,CAAC,CAACR,QAAQ,CAAC;IAC3DU,OAAO,GAAGA,OAAO,IAAIZ,MAAM,KAAKb,EAAE,CAACa,MAAM;EAC3C;EACA,OAAOY,OAAO;AAChB","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- import { useLayoutEffect } from 'react';
2
- declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
3
- export default useIsomorphicLayoutEffect;
@@ -1,4 +0,0 @@
1
- import { useEffect, useLayoutEffect } from 'react';
2
- const useIsomorphicLayoutEffect = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
3
- export default useIsomorphicLayoutEffect;
4
- //# sourceMappingURL=use-isomorphic-layout-effect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-isomorphic-layout-effect.js","names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","document"],"sources":["../../src/utils/use-isomorphic-layout-effect.ts"],"sourcesContent":["// From https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts\n// useLayoutEffect but does not trigger warning in server-side rendering\nimport {useEffect, useLayoutEffect} from 'react';\n\nconst useIsomorphicLayoutEffect = typeof document !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport default useIsomorphicLayoutEffect;\n"],"mappings":"AAEA,SAAQA,SAAS,EAAEC,eAAe,QAAO,OAAO;AAEhD,MAAMC,yBAAyB,GAAG,OAAOC,QAAQ,KAAK,WAAW,GAAGF,eAAe,GAAGD,SAAS;AAE/F,eAAeE,yBAAyB","ignoreList":[]}
@@ -1,32 +0,0 @@
1
- import * as React from 'react';
2
- import {useEffect, memo} from 'react';
3
- import {applyReactStyle} from '../utils/apply-react-style';
4
- import useControl from './use-control';
5
-
6
- import type {ControlPosition, AttributionControlInstance} from '../types';
7
-
8
- export type AttributionControlProps<OptionsT> = OptionsT & {
9
- /** Placement of the control relative to the map. */
10
- position?: ControlPosition;
11
- /** CSS style override, applied to the control's container */
12
- style?: React.CSSProperties;
13
- };
14
-
15
- function AttributionControl<AttributionControlOptions, ControlT extends AttributionControlInstance>(
16
- props: AttributionControlProps<AttributionControlOptions>
17
- ): null {
18
- const ctrl = useControl<ControlT>(
19
- ({mapLib}) => new mapLib.AttributionControl(props) as ControlT,
20
- {
21
- position: props.position
22
- }
23
- );
24
-
25
- useEffect(() => {
26
- applyReactStyle(ctrl._container, props.style);
27
- }, [props.style]);
28
-
29
- return null;
30
- }
31
-
32
- export default memo(AttributionControl);
@@ -1,37 +0,0 @@
1
- /* global document */
2
- import * as React from 'react';
3
- import {useEffect, memo} from 'react';
4
- import {applyReactStyle} from '../utils/apply-react-style';
5
- import useControl from './use-control';
6
-
7
- import type {ControlPosition, FullscreenControlInstance} from '../types';
8
-
9
- export type FullscreenControlProps<OptionsT> = Omit<OptionsT, 'container'> & {
10
- /** Id of the DOM element which should be made full screen. By default, the map container
11
- * element will be made full screen. */
12
- containerId?: string;
13
- /** Placement of the control relative to the map. */
14
- position?: ControlPosition;
15
- /** CSS style override, applied to the control's container */
16
- style?: React.CSSProperties;
17
- };
18
-
19
- function FullscreenControl<FullscreenControlOptions, ControlT extends FullscreenControlInstance>(
20
- props: FullscreenControlProps<FullscreenControlOptions>
21
- ): null {
22
- const ctrl = useControl<ControlT>(
23
- ({mapLib}) =>
24
- new mapLib.FullscreenControl({
25
- container: props.containerId && document.getElementById(props.containerId)
26
- }) as ControlT,
27
- {position: props.position}
28
- );
29
-
30
- useEffect(() => {
31
- applyReactStyle(ctrl._controlContainer, props.style);
32
- }, [props.style]);
33
-
34
- return null;
35
- }
36
-
37
- export default memo(FullscreenControl);
@@ -1,90 +0,0 @@
1
- import * as React from 'react';
2
- import {useImperativeHandle, useRef, useEffect, forwardRef, memo} from 'react';
3
- import {applyReactStyle} from '../utils/apply-react-style';
4
- import useControl from './use-control';
5
-
6
- import type {
7
- ControlPosition,
8
- GeolocateControlInstance,
9
- GeolocateEvent,
10
- GeolocateResultEvent,
11
- GeolocateErrorEvent
12
- } from '../types';
13
-
14
- export type GeolocateControlProps<
15
- OptionsT,
16
- ControlT extends GeolocateControlInstance
17
- > = OptionsT & {
18
- /** Placement of the control relative to the map. */
19
- position?: ControlPosition;
20
- /** CSS style override, applied to the control's container */
21
- style?: React.CSSProperties;
22
-
23
- /** Called on each Geolocation API position update that returned as success. */
24
- onGeolocate?: (e: GeolocateResultEvent<ControlT>) => void;
25
- /** Called on each Geolocation API position update that returned as an error. */
26
- onError?: (e: GeolocateErrorEvent<ControlT>) => void;
27
- /** Called on each Geolocation API position update that returned as success but user position
28
- * is out of map `maxBounds`. */
29
- onOutOfMaxBounds?: (e: GeolocateResultEvent<ControlT>) => void;
30
- /** Called when the GeolocateControl changes to the active lock state. */
31
- onTrackUserLocationStart?: (e: GeolocateEvent<ControlT>) => void;
32
- /** Called when the GeolocateControl changes to the background state. */
33
- onTrackUserLocationEnd?: (e: GeolocateEvent<ControlT>) => void;
34
- };
35
-
36
- function GeolocateControl<GeolocateControlOptions, ControlT extends GeolocateControlInstance>(
37
- props: GeolocateControlProps<GeolocateControlOptions, ControlT>,
38
- ref: React.Ref<ControlT>
39
- ) {
40
- const thisRef = useRef({props});
41
-
42
- const ctrl = useControl<ControlT>(
43
- ({mapLib}) => {
44
- const gc = new mapLib.GeolocateControl(props) as ControlT;
45
-
46
- // Hack: fix GeolocateControl reuse
47
- // When using React strict mode, the component is mounted twice.
48
- // GeolocateControl's UI creation is asynchronous. Removing and adding it back causes the UI to be initialized twice.
49
- // @ts-expect-error private method
50
- const setupUI = gc._setupUI;
51
- // @ts-expect-error private method
52
- gc._setupUI = args => {
53
- if (!gc._container.hasChildNodes()) {
54
- setupUI(args);
55
- }
56
- };
57
-
58
- gc.on('geolocate', e => {
59
- thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent<ControlT>);
60
- });
61
- gc.on('error', e => {
62
- thisRef.current.props.onError?.(e as GeolocateErrorEvent<ControlT>);
63
- });
64
- gc.on('outofmaxbounds', e => {
65
- thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent<ControlT>);
66
- });
67
- gc.on('trackuserlocationstart', e => {
68
- thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent<ControlT>);
69
- });
70
- gc.on('trackuserlocationend', e => {
71
- thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent<ControlT>);
72
- });
73
-
74
- return gc;
75
- },
76
- {position: props.position}
77
- );
78
-
79
- thisRef.current.props = props;
80
-
81
- useImperativeHandle(ref, () => ctrl, []);
82
-
83
- useEffect(() => {
84
- applyReactStyle(ctrl._container, props.style);
85
- }, [props.style]);
86
-
87
- return null;
88
- }
89
-
90
- export default memo(forwardRef(GeolocateControl));
@@ -1,133 +0,0 @@
1
- import {useContext, useEffect, useMemo, useState, useRef} from 'react';
2
- import {MapContext} from './map';
3
- import assert from '../utils/assert';
4
- import {deepEqual} from '../utils/deep-equal';
5
-
6
- import type {MapInstance, CustomLayerInterface, ILayer} from '../types';
7
-
8
- // Omiting property from a union type, see
9
- // https://github.com/microsoft/TypeScript/issues/39556#issuecomment-656925230
10
- type OptionalId<T> = T extends {id: string} ? Omit<T, 'id'> & {id?: string} : T;
11
- type OptionalSource<T> = T extends {source: string} ? Omit<T, 'source'> & {source?: string} : T;
12
-
13
- export type LayerProps<LayerT> = OptionalSource<OptionalId<LayerT>> & {
14
- /** If set, the layer will be inserted before the specified layer */
15
- beforeId?: string;
16
- };
17
-
18
- /* eslint-disable complexity, max-statements */
19
- function updateLayer<LayerT extends ILayer>(
20
- map: MapInstance,
21
- id: string,
22
- props: LayerProps<LayerT>,
23
- prevProps: LayerProps<LayerT>
24
- ) {
25
- assert(props.id === prevProps.id, 'layer id changed');
26
- assert(props.type === prevProps.type, 'layer type changed');
27
-
28
- if (props.type === 'custom' || prevProps.type === 'custom') {
29
- return;
30
- }
31
-
32
- const {layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId} = props;
33
-
34
- if (beforeId !== prevProps.beforeId) {
35
- map.moveLayer(id, beforeId);
36
- }
37
- if (layout !== prevProps.layout) {
38
- const prevLayout = prevProps.layout || {};
39
- for (const key in layout) {
40
- if (!deepEqual(layout[key], prevLayout[key])) {
41
- map.setLayoutProperty(id, key, layout[key]);
42
- }
43
- }
44
- for (const key in prevLayout) {
45
- if (!layout.hasOwnProperty(key)) {
46
- map.setLayoutProperty(id, key, undefined);
47
- }
48
- }
49
- }
50
- if (paint !== prevProps.paint) {
51
- const prevPaint = prevProps.paint || {};
52
- for (const key in paint) {
53
- if (!deepEqual(paint[key], prevPaint[key])) {
54
- map.setPaintProperty(id, key, paint[key]);
55
- }
56
- }
57
- for (const key in prevPaint) {
58
- if (!paint.hasOwnProperty(key)) {
59
- map.setPaintProperty(id, key, undefined);
60
- }
61
- }
62
- }
63
-
64
- if (!deepEqual(filter, prevProps.filter)) {
65
- map.setFilter(id, filter);
66
- }
67
- if (minzoom !== prevProps.minzoom || maxzoom !== prevProps.maxzoom) {
68
- map.setLayerZoomRange(id, minzoom, maxzoom);
69
- }
70
- }
71
-
72
- function createLayer<LayerT extends ILayer>(
73
- map: MapInstance,
74
- id: string,
75
- props: LayerProps<LayerT>
76
- ) {
77
- // @ts-ignore
78
- if (map.style && map.style._loaded && (!('source' in props) || map.getSource(props.source))) {
79
- const options: LayerProps<LayerT> = {...props, id};
80
- delete options.beforeId;
81
-
82
- // @ts-ignore
83
- map.addLayer(options, props.beforeId);
84
- }
85
- }
86
-
87
- /* eslint-enable complexity, max-statements */
88
-
89
- let layerCounter = 0;
90
-
91
- function Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInterface>) {
92
- const map = useContext(MapContext).map.getMap();
93
- const propsRef = useRef(props);
94
- const [, setStyleLoaded] = useState(0);
95
-
96
- const id = useMemo(() => props.id || `jsx-layer-${layerCounter++}`, []);
97
-
98
- useEffect(() => {
99
- if (map) {
100
- const forceUpdate = () => setStyleLoaded(version => version + 1);
101
- map.on('styledata', forceUpdate);
102
- forceUpdate();
103
-
104
- return () => {
105
- map.off('styledata', forceUpdate);
106
- // @ts-ignore
107
- if (map.style && map.style._loaded && map.getLayer(id)) {
108
- map.removeLayer(id);
109
- }
110
- };
111
- }
112
- return undefined;
113
- }, [map]);
114
-
115
- // @ts-ignore
116
- const layer = map && map.style && map.getLayer(id);
117
- if (layer) {
118
- try {
119
- updateLayer(map, id, props, propsRef.current);
120
- } catch (error) {
121
- console.warn(error); // eslint-disable-line
122
- }
123
- } else {
124
- createLayer(map, id, props);
125
- }
126
-
127
- // Store last rendered props
128
- propsRef.current = props;
129
-
130
- return null;
131
- }
132
-
133
- export default Layer;