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
package/package.json CHANGED
@@ -1,76 +1,124 @@
1
1
  {
2
2
  "name": "react-bkoi-gl",
3
- "version": "1.0.7",
4
- "description": "React components for Barikoi GL JS",
3
+ "version": "2.0.1",
4
+ "engines": {
5
+ "node": ">=18.18.0"
6
+ },
7
+ "description": "A React library for Barikoi Maps with interactive components, markers, popups, and controls.",
5
8
  "type": "module",
6
9
  "types": "dist/index.d.ts",
7
10
  "main": "dist/index.cjs",
8
11
  "module": "dist/index.js",
9
- "author": "barikoi",
10
- "readme": "README.md",
11
- "license": "MIT",
12
- "homepage": "https://docs.barikoi.com/docs/maps-api",
13
12
  "exports": {
14
13
  ".": {
15
- "types": "./dist/index.d.ts",
16
- "require": "./dist/index.cjs",
17
- "import": "./dist/index.js"
18
- },
19
- "./bkoi-gl": {
20
- "types": "./dist/exports-bkoi-gl.d.ts",
21
- "require": "./dist/exports-bkoi-gl.cjs",
22
- "import": "./dist/exports-bkoi-gl.js"
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.cts",
20
+ "default": "./dist/index.cjs"
21
+ }
23
22
  },
24
23
  "./styles": {
24
+ "types": "./dist/styles/index.d.ts",
25
25
  "import": "./dist/styles/react-bkoi-gl.css",
26
26
  "default": "./dist/styles/react-bkoi-gl.css"
27
27
  }
28
28
  },
29
+ "author": "barikoi",
30
+ "readme": "README.md",
31
+ "license": "MIT",
32
+ "homepage": "https://docs.barikoi.com/docs/maps-api",
29
33
  "files": [
30
- "src",
31
34
  "dist",
32
- "bkoi-gl",
35
+ "LICENSE",
33
36
  "README.md"
34
37
  ],
35
38
  "scripts": {
36
- "typecheck": "tsc -p tsconfig.build.json --noEmit",
37
- "build": "ocular-clean && ocular-build && node scripts/modify-css.js",
38
- "lint": "ocular-lint",
39
- "cover": "ocular-test cover",
40
- "test": "yarn typecheck && ocular-test",
41
- "test-fast": "yarn typecheck && ocular-test node",
42
- "metrics": "ocular-metrics"
39
+ "typecheck": "tsc --noEmit",
40
+ "clean": "rm -rf dist",
41
+ "build": "tsup && node scripts/modify-css.js",
42
+ "lint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
43
+ "test": "npm run typecheck && jest",
44
+ "coverage": "jest --coverage --passWithNoTests",
45
+ "prepare": "husky"
43
46
  },
44
47
  "dependencies": {
45
- "@maplibre/maplibre-gl-style-spec": "^19.2.1",
46
- "@rollup/plugin-typescript": "^11.1.6",
47
- "bkoi-gl": ">=2.0.0",
48
- "mapbox-gl": "^1.13.0"
48
+ "@maplibre/maplibre-gl-style-spec": "^24.4.1",
49
+ "maplibre-gl": "^5.15.0"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "react": ">=16.3.0",
52
53
  "react-dom": ">=16.3.0"
53
54
  },
54
55
  "devDependencies": {
55
- "@commitlint/cli": "^19.4.1",
56
- "@commitlint/config-conventional": "^19.4.1",
57
- "@types/mapbox-gl": "^3.4.0",
58
- "@types/react": "^16.0.0",
59
- "bkoi-gl": ">=2.0.0",
60
- "ocular-dev-tools": "2.0.0-alpha.15",
56
+ "@commitlint/cli": "^20.3.0",
57
+ "@commitlint/config-conventional": "^20.3.0",
58
+ "@testing-library/jest-dom": "^6.9.1",
59
+ "@testing-library/react": "^14.3.1",
60
+ "@types/jest": "^29.5.14",
61
+ "@types/node": "^22.13.3",
62
+ "@types/react": "^18.3.27",
63
+ "@typescript-eslint/eslint-plugin": "^8.52.0",
64
+ "@typescript-eslint/parser": "^8.52.0",
65
+ "babel-jest": "^29.7.0",
66
+ "eslint": "^8.57.1",
67
+ "eslint-plugin-import": "^2.32.0",
68
+ "husky": "^9.1.7",
69
+ "identity-obj-proxy": "^3.0.0",
70
+ "jest": "^29.7.0",
71
+ "jest-environment-jsdom": "^29.7.0",
72
+ "puppeteer": "^24.34.0",
61
73
  "react": "^18.0.0",
62
74
  "react-dom": "^18.0.0",
63
- "typescript": "^4.0.0"
75
+ "react-test-renderer": "^18.0.0",
76
+ "tape-promise": "^4.0.0",
77
+ "ts-jest": "^29.4.6",
78
+ "tsup": "^8.5.1",
79
+ "typescript": "^5.9.3"
80
+ },
81
+ "publishConfig": {
82
+ "access": "public"
64
83
  },
65
84
  "keywords": [
66
85
  "barikoi",
86
+ "bkoi",
67
87
  "bkoi-gl",
68
88
  "react",
69
89
  "react-bkoi-gl",
70
- "react bkoi"
90
+ "react bkoi",
91
+ "react-bkoi",
92
+ "barikoi maps",
93
+ "barikoi-gl",
94
+ "maplibre",
95
+ "maplibre-gl",
96
+ "react-map",
97
+ "react-maplibre",
98
+ "maps",
99
+ "mapping",
100
+ "bangladesh",
101
+ "bangladesh maps",
102
+ "interactive maps",
103
+ "map components",
104
+ "markers",
105
+ "popups",
106
+ "navigation",
107
+ "geolocation",
108
+ "map controls"
71
109
  ],
72
110
  "repository": {
73
111
  "type": "git",
74
- "url": "https://github.com/barikoi/react-bkoi-gl.git"
112
+ "url": "git+https://github.com/barikoi/react-bkoi-gl.git"
113
+ },
114
+ "bugs": {
115
+ "url": "https://github.com/barikoi/react-bkoi-gl/issues"
116
+ },
117
+ "overrides": {
118
+ "@testing-library/react-hooks": {
119
+ "react": "$react",
120
+ "react-dom": "$react-dom",
121
+ "react-test-renderer": "$react-test-renderer"
122
+ }
75
123
  }
76
124
  }
@@ -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
- }
@@ -1,11 +0,0 @@
1
- import * as React from 'react';
2
- import type { ControlPosition, AttributionControlInstance } from '../types';
3
- export type AttributionControlProps<OptionsT> = OptionsT & {
4
- /** Placement of the control relative to the map. */
5
- position?: ControlPosition;
6
- /** CSS style override, applied to the control's container */
7
- style?: React.CSSProperties;
8
- };
9
- declare function AttributionControl<AttributionControlOptions, ControlT extends AttributionControlInstance>(props: AttributionControlProps<AttributionControlOptions>): null;
10
- declare const _default: React.MemoExoticComponent<typeof AttributionControl>;
11
- export default _default;
@@ -1,19 +0,0 @@
1
- import { useEffect, memo } from 'react';
2
- import { applyReactStyle } from "../utils/apply-react-style.js";
3
- import useControl from "./use-control.js";
4
- function AttributionControl(props) {
5
- const ctrl = useControl(_ref => {
6
- let {
7
- mapLib
8
- } = _ref;
9
- return new mapLib.AttributionControl(props);
10
- }, {
11
- position: props.position
12
- });
13
- useEffect(() => {
14
- applyReactStyle(ctrl._container, props.style);
15
- }, [props.style]);
16
- return null;
17
- }
18
- export default memo(AttributionControl);
19
- //# sourceMappingURL=attribution-control.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"attribution-control.js","names":["useEffect","memo","applyReactStyle","useControl","AttributionControl","props","ctrl","_ref","mapLib","position","_container","style"],"sources":["../../src/components/attribution-control.ts"],"sourcesContent":["import * as React from 'react';\nimport {useEffect, memo} from 'react';\nimport {applyReactStyle} from '../utils/apply-react-style';\nimport useControl from './use-control';\n\nimport type {ControlPosition, AttributionControlInstance} from '../types';\n\nexport type AttributionControlProps<OptionsT> = OptionsT & {\n /** Placement of the control relative to the map. */\n position?: ControlPosition;\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n};\n\nfunction AttributionControl<AttributionControlOptions, ControlT extends AttributionControlInstance>(\n props: AttributionControlProps<AttributionControlOptions>\n): null {\n const ctrl = useControl<ControlT>(\n ({mapLib}) => new mapLib.AttributionControl(props) as ControlT,\n {\n position: props.position\n }\n );\n\n useEffect(() => {\n applyReactStyle(ctrl._container, props.style);\n }, [props.style]);\n\n return null;\n}\n\nexport default memo(AttributionControl);\n"],"mappings":"AACA,SAAQA,SAAS,EAAEC,IAAI,QAAO,OAAO;AAAC,SAC9BC,eAAe;AAAA,OAChBC,UAAU;AAWjB,SAASC,kBAAkBA,CACzBC,KAAyD,EACnD;EACN,MAAMC,IAAI,GAAGH,UAAU,CACrBI,IAAA;IAAA,IAAC;MAACC;IAAM,CAAC,GAAAD,IAAA;IAAA,OAAK,IAAIC,MAAM,CAACJ,kBAAkB,CAACC,KAAK,CAAC;EAAA,CAAY,EAC9D;IACEI,QAAQ,EAAEJ,KAAK,CAACI;EAClB,CACF,CAAC;EAEDT,SAAS,CAAC,MAAM;IACdE,eAAe,CAACI,IAAI,CAACI,UAAU,EAAEL,KAAK,CAACM,KAAK,CAAC;EAC/C,CAAC,EAAE,CAACN,KAAK,CAACM,KAAK,CAAC,CAAC;EAEjB,OAAO,IAAI;AACb;AAEA,eAAeV,IAAI,CAACG,kBAAkB,CAAC","ignoreList":[]}
@@ -1,14 +0,0 @@
1
- import * as React from 'react';
2
- import type { ControlPosition, FullscreenControlInstance } from '../types';
3
- export type FullscreenControlProps<OptionsT> = Omit<OptionsT, 'container'> & {
4
- /** Id of the DOM element which should be made full screen. By default, the map container
5
- * element will be made full screen. */
6
- containerId?: string;
7
- /** Placement of the control relative to the map. */
8
- position?: ControlPosition;
9
- /** CSS style override, applied to the control's container */
10
- style?: React.CSSProperties;
11
- };
12
- declare function FullscreenControl<FullscreenControlOptions, ControlT extends FullscreenControlInstance>(props: FullscreenControlProps<FullscreenControlOptions>): null;
13
- declare const _default: React.MemoExoticComponent<typeof FullscreenControl>;
14
- export default _default;
@@ -1,21 +0,0 @@
1
- import { useEffect, memo } from 'react';
2
- import { applyReactStyle } from "../utils/apply-react-style.js";
3
- import useControl from "./use-control.js";
4
- function FullscreenControl(props) {
5
- const ctrl = useControl(_ref => {
6
- let {
7
- mapLib
8
- } = _ref;
9
- return new mapLib.FullscreenControl({
10
- container: props.containerId && document.getElementById(props.containerId)
11
- });
12
- }, {
13
- position: props.position
14
- });
15
- useEffect(() => {
16
- applyReactStyle(ctrl._controlContainer, props.style);
17
- }, [props.style]);
18
- return null;
19
- }
20
- export default memo(FullscreenControl);
21
- //# sourceMappingURL=fullscreen-control.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fullscreen-control.js","names":["useEffect","memo","applyReactStyle","useControl","FullscreenControl","props","ctrl","_ref","mapLib","container","containerId","document","getElementById","position","_controlContainer","style"],"sources":["../../src/components/fullscreen-control.tsx"],"sourcesContent":["/* global document */\nimport * as React from 'react';\nimport {useEffect, memo} from 'react';\nimport {applyReactStyle} from '../utils/apply-react-style';\nimport useControl from './use-control';\n\nimport type {ControlPosition, FullscreenControlInstance} from '../types';\n\nexport type FullscreenControlProps<OptionsT> = Omit<OptionsT, 'container'> & {\n /** Id of the DOM element which should be made full screen. By default, the map container\n * element will be made full screen. */\n containerId?: string;\n /** Placement of the control relative to the map. */\n position?: ControlPosition;\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n};\n\nfunction FullscreenControl<FullscreenControlOptions, ControlT extends FullscreenControlInstance>(\n props: FullscreenControlProps<FullscreenControlOptions>\n): null {\n const ctrl = useControl<ControlT>(\n ({mapLib}) =>\n new mapLib.FullscreenControl({\n container: props.containerId && document.getElementById(props.containerId)\n }) as ControlT,\n {position: props.position}\n );\n\n useEffect(() => {\n applyReactStyle(ctrl._controlContainer, props.style);\n }, [props.style]);\n\n return null;\n}\n\nexport default memo(FullscreenControl);\n"],"mappings":"AAEA,SAAQA,SAAS,EAAEC,IAAI,QAAO,OAAO;AAAC,SAC9BC,eAAe;AAAA,OAChBC,UAAU;AAcjB,SAASC,iBAAiBA,CACxBC,KAAuD,EACjD;EACN,MAAMC,IAAI,GAAGH,UAAU,CACrBI,IAAA;IAAA,IAAC;MAACC;IAAM,CAAC,GAAAD,IAAA;IAAA,OACP,IAAIC,MAAM,CAACJ,iBAAiB,CAAC;MAC3BK,SAAS,EAAEJ,KAAK,CAACK,WAAW,IAAIC,QAAQ,CAACC,cAAc,CAACP,KAAK,CAACK,WAAW;IAC3E,CAAC,CAAC;EAAA,CAAY,EAChB;IAACG,QAAQ,EAAER,KAAK,CAACQ;EAAQ,CAC3B,CAAC;EAEDb,SAAS,CAAC,MAAM;IACdE,eAAe,CAACI,IAAI,CAACQ,iBAAiB,EAAET,KAAK,CAACU,KAAK,CAAC;EACtD,CAAC,EAAE,CAACV,KAAK,CAACU,KAAK,CAAC,CAAC;EAEjB,OAAO,IAAI;AACb;AAEA,eAAed,IAAI,CAACG,iBAAiB,CAAC","ignoreList":[]}
@@ -1,37 +0,0 @@
1
- import * as React from 'react';
2
- import type { ControlPosition, GeolocateControlInstance, GeolocateEvent, GeolocateResultEvent, GeolocateErrorEvent } from '../types';
3
- export type GeolocateControlProps<OptionsT, ControlT extends GeolocateControlInstance> = OptionsT & {
4
- /** Placement of the control relative to the map. */
5
- position?: ControlPosition;
6
- /** CSS style override, applied to the control's container */
7
- style?: React.CSSProperties;
8
- /** Called on each Geolocation API position update that returned as success. */
9
- onGeolocate?: (e: GeolocateResultEvent<ControlT>) => void;
10
- /** Called on each Geolocation API position update that returned as an error. */
11
- onError?: (e: GeolocateErrorEvent<ControlT>) => void;
12
- /** Called on each Geolocation API position update that returned as success but user position
13
- * is out of map `maxBounds`. */
14
- onOutOfMaxBounds?: (e: GeolocateResultEvent<ControlT>) => void;
15
- /** Called when the GeolocateControl changes to the active lock state. */
16
- onTrackUserLocationStart?: (e: GeolocateEvent<ControlT>) => void;
17
- /** Called when the GeolocateControl changes to the background state. */
18
- onTrackUserLocationEnd?: (e: GeolocateEvent<ControlT>) => void;
19
- };
20
- declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<{
21
- /** Placement of the control relative to the map. */
22
- position?: ControlPosition;
23
- /** CSS style override, applied to the control's container */
24
- style?: React.CSSProperties;
25
- /** Called on each Geolocation API position update that returned as success. */
26
- onGeolocate?: (e: GeolocateResultEvent<GeolocateControlInstance>) => void;
27
- /** Called on each Geolocation API position update that returned as an error. */
28
- onError?: (e: GeolocateErrorEvent<GeolocateControlInstance>) => void;
29
- /** Called on each Geolocation API position update that returned as success but user position
30
- * is out of map `maxBounds`. */
31
- onOutOfMaxBounds?: (e: GeolocateResultEvent<GeolocateControlInstance>) => void;
32
- /** Called when the GeolocateControl changes to the active lock state. */
33
- onTrackUserLocationStart?: (e: GeolocateEvent<GeolocateControlInstance>) => void;
34
- /** Called when the GeolocateControl changes to the background state. */
35
- onTrackUserLocationEnd?: (e: GeolocateEvent<GeolocateControlInstance>) => void;
36
- } & React.RefAttributes<GeolocateControlInstance>>>;
37
- export default _default;
@@ -1,46 +0,0 @@
1
- import { useImperativeHandle, useRef, useEffect, forwardRef, memo } from 'react';
2
- import { applyReactStyle } from "../utils/apply-react-style.js";
3
- import useControl from "./use-control.js";
4
- function GeolocateControl(props, ref) {
5
- const thisRef = useRef({
6
- props
7
- });
8
- const ctrl = useControl(_ref => {
9
- let {
10
- mapLib
11
- } = _ref;
12
- const gc = new mapLib.GeolocateControl(props);
13
- const setupUI = gc._setupUI;
14
- gc._setupUI = args => {
15
- if (!gc._container.hasChildNodes()) {
16
- setupUI(args);
17
- }
18
- };
19
- gc.on('geolocate', e => {
20
- thisRef.current.props.onGeolocate?.(e);
21
- });
22
- gc.on('error', e => {
23
- thisRef.current.props.onError?.(e);
24
- });
25
- gc.on('outofmaxbounds', e => {
26
- thisRef.current.props.onOutOfMaxBounds?.(e);
27
- });
28
- gc.on('trackuserlocationstart', e => {
29
- thisRef.current.props.onTrackUserLocationStart?.(e);
30
- });
31
- gc.on('trackuserlocationend', e => {
32
- thisRef.current.props.onTrackUserLocationEnd?.(e);
33
- });
34
- return gc;
35
- }, {
36
- position: props.position
37
- });
38
- thisRef.current.props = props;
39
- useImperativeHandle(ref, () => ctrl, []);
40
- useEffect(() => {
41
- applyReactStyle(ctrl._container, props.style);
42
- }, [props.style]);
43
- return null;
44
- }
45
- export default memo(forwardRef(GeolocateControl));
46
- //# sourceMappingURL=geolocate-control.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"geolocate-control.js","names":["useImperativeHandle","useRef","useEffect","forwardRef","memo","applyReactStyle","useControl","GeolocateControl","props","ref","thisRef","ctrl","_ref","mapLib","gc","setupUI","_setupUI","args","_container","hasChildNodes","on","e","current","onGeolocate","onError","onOutOfMaxBounds","onTrackUserLocationStart","onTrackUserLocationEnd","position","style"],"sources":["../../src/components/geolocate-control.ts"],"sourcesContent":["import * as React from 'react';\nimport {useImperativeHandle, useRef, useEffect, forwardRef, memo} from 'react';\nimport {applyReactStyle} from '../utils/apply-react-style';\nimport useControl from './use-control';\n\nimport type {\n ControlPosition,\n GeolocateControlInstance,\n GeolocateEvent,\n GeolocateResultEvent,\n GeolocateErrorEvent\n} from '../types';\n\nexport type GeolocateControlProps<\n OptionsT,\n ControlT extends GeolocateControlInstance\n> = OptionsT & {\n /** Placement of the control relative to the map. */\n position?: ControlPosition;\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n\n /** Called on each Geolocation API position update that returned as success. */\n onGeolocate?: (e: GeolocateResultEvent<ControlT>) => void;\n /** Called on each Geolocation API position update that returned as an error. */\n onError?: (e: GeolocateErrorEvent<ControlT>) => void;\n /** Called on each Geolocation API position update that returned as success but user position\n * is out of map `maxBounds`. */\n onOutOfMaxBounds?: (e: GeolocateResultEvent<ControlT>) => void;\n /** Called when the GeolocateControl changes to the active lock state. */\n onTrackUserLocationStart?: (e: GeolocateEvent<ControlT>) => void;\n /** Called when the GeolocateControl changes to the background state. */\n onTrackUserLocationEnd?: (e: GeolocateEvent<ControlT>) => void;\n};\n\nfunction GeolocateControl<GeolocateControlOptions, ControlT extends GeolocateControlInstance>(\n props: GeolocateControlProps<GeolocateControlOptions, ControlT>,\n ref: React.Ref<ControlT>\n) {\n const thisRef = useRef({props});\n\n const ctrl = useControl<ControlT>(\n ({mapLib}) => {\n const gc = new mapLib.GeolocateControl(props) as ControlT;\n\n // Hack: fix GeolocateControl reuse\n // When using React strict mode, the component is mounted twice.\n // GeolocateControl's UI creation is asynchronous. Removing and adding it back causes the UI to be initialized twice.\n // @ts-expect-error private method\n const setupUI = gc._setupUI;\n // @ts-expect-error private method\n gc._setupUI = args => {\n if (!gc._container.hasChildNodes()) {\n setupUI(args);\n }\n };\n\n gc.on('geolocate', e => {\n thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent<ControlT>);\n });\n gc.on('error', e => {\n thisRef.current.props.onError?.(e as GeolocateErrorEvent<ControlT>);\n });\n gc.on('outofmaxbounds', e => {\n thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent<ControlT>);\n });\n gc.on('trackuserlocationstart', e => {\n thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent<ControlT>);\n });\n gc.on('trackuserlocationend', e => {\n thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent<ControlT>);\n });\n\n return gc;\n },\n {position: props.position}\n );\n\n thisRef.current.props = props;\n\n useImperativeHandle(ref, () => ctrl, []);\n\n useEffect(() => {\n applyReactStyle(ctrl._container, props.style);\n }, [props.style]);\n\n return null;\n}\n\nexport default memo(forwardRef(GeolocateControl));\n"],"mappings":"AACA,SAAQA,mBAAmB,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,EAAEC,IAAI,QAAO,OAAO;AAAC,SACvEC,eAAe;AAAA,OAChBC,UAAU;AAgCjB,SAASC,gBAAgBA,CACvBC,KAA+D,EAC/DC,GAAwB,EACxB;EACA,MAAMC,OAAO,GAAGT,MAAM,CAAC;IAACO;EAAK,CAAC,CAAC;EAE/B,MAAMG,IAAI,GAAGL,UAAU,CACrBM,IAAA,IAAc;IAAA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,MAAME,IAAI,EAAE,EAAE,CAAC;EAExCT,SAAS,CAAC,MAAM;IACdG,eAAe,CAACM,IAAI,CAACO,UAAU,EAAEV,KAAK,CAACqB,KAAK,CAAC;EAC/C,CAAC,EAAE,CAACrB,KAAK,CAACqB,KAAK,CAAC,CAAC;EAEjB,OAAO,IAAI;AACb;AAEA,eAAezB,IAAI,CAACD,UAAU,CAACI,gBAAgB,CAAC,CAAC","ignoreList":[]}
@@ -1,17 +0,0 @@
1
- import type { CustomLayerInterface, ILayer } from '../types';
2
- type OptionalId<T> = T extends {
3
- id: string;
4
- } ? Omit<T, 'id'> & {
5
- id?: string;
6
- } : T;
7
- type OptionalSource<T> = T extends {
8
- source: string;
9
- } ? Omit<T, 'source'> & {
10
- source?: string;
11
- } : T;
12
- export type LayerProps<LayerT> = OptionalSource<OptionalId<LayerT>> & {
13
- /** If set, the layer will be inserted before the specified layer */
14
- beforeId?: string;
15
- };
16
- declare function Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInterface>): any;
17
- export default Layer;
@@ -1,99 +0,0 @@
1
- import { useContext, useEffect, useMemo, useState, useRef } from 'react';
2
- import { MapContext } from "./map.js";
3
- import assert from "../utils/assert.js";
4
- import { deepEqual } from "../utils/deep-equal.js";
5
- function updateLayer(map, id, props, prevProps) {
6
- assert(props.id === prevProps.id, 'layer id changed');
7
- assert(props.type === prevProps.type, 'layer type changed');
8
- if (props.type === 'custom' || prevProps.type === 'custom') {
9
- return;
10
- }
11
- const {
12
- layout = {},
13
- paint = {},
14
- filter,
15
- minzoom,
16
- maxzoom,
17
- beforeId
18
- } = props;
19
- if (beforeId !== prevProps.beforeId) {
20
- map.moveLayer(id, beforeId);
21
- }
22
- if (layout !== prevProps.layout) {
23
- const prevLayout = prevProps.layout || {};
24
- for (const key in layout) {
25
- if (!deepEqual(layout[key], prevLayout[key])) {
26
- map.setLayoutProperty(id, key, layout[key]);
27
- }
28
- }
29
- for (const key in prevLayout) {
30
- if (!layout.hasOwnProperty(key)) {
31
- map.setLayoutProperty(id, key, undefined);
32
- }
33
- }
34
- }
35
- if (paint !== prevProps.paint) {
36
- const prevPaint = prevProps.paint || {};
37
- for (const key in paint) {
38
- if (!deepEqual(paint[key], prevPaint[key])) {
39
- map.setPaintProperty(id, key, paint[key]);
40
- }
41
- }
42
- for (const key in prevPaint) {
43
- if (!paint.hasOwnProperty(key)) {
44
- map.setPaintProperty(id, key, undefined);
45
- }
46
- }
47
- }
48
- if (!deepEqual(filter, prevProps.filter)) {
49
- map.setFilter(id, filter);
50
- }
51
- if (minzoom !== prevProps.minzoom || maxzoom !== prevProps.maxzoom) {
52
- map.setLayerZoomRange(id, minzoom, maxzoom);
53
- }
54
- }
55
- function createLayer(map, id, props) {
56
- if (map.style && map.style._loaded && (!('source' in props) || map.getSource(props.source))) {
57
- const options = {
58
- ...props,
59
- id
60
- };
61
- delete options.beforeId;
62
- map.addLayer(options, props.beforeId);
63
- }
64
- }
65
- let layerCounter = 0;
66
- function Layer(props) {
67
- const map = useContext(MapContext).map.getMap();
68
- const propsRef = useRef(props);
69
- const [, setStyleLoaded] = useState(0);
70
- const id = useMemo(() => props.id || `jsx-layer-${layerCounter++}`, []);
71
- useEffect(() => {
72
- if (map) {
73
- const forceUpdate = () => setStyleLoaded(version => version + 1);
74
- map.on('styledata', forceUpdate);
75
- forceUpdate();
76
- return () => {
77
- map.off('styledata', forceUpdate);
78
- if (map.style && map.style._loaded && map.getLayer(id)) {
79
- map.removeLayer(id);
80
- }
81
- };
82
- }
83
- return undefined;
84
- }, [map]);
85
- const layer = map && map.style && map.getLayer(id);
86
- if (layer) {
87
- try {
88
- updateLayer(map, id, props, propsRef.current);
89
- } catch (error) {
90
- console.warn(error);
91
- }
92
- } else {
93
- createLayer(map, id, props);
94
- }
95
- propsRef.current = props;
96
- return null;
97
- }
98
- export default Layer;
99
- //# sourceMappingURL=layer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layer.js","names":["useContext","useEffect","useMemo","useState","useRef","MapContext","assert","deepEqual","updateLayer","map","id","props","prevProps","type","layout","paint","filter","minzoom","maxzoom","beforeId","moveLayer","prevLayout","key","setLayoutProperty","hasOwnProperty","undefined","prevPaint","setPaintProperty","setFilter","setLayerZoomRange","createLayer","style","_loaded","getSource","source","options","addLayer","layerCounter","Layer","getMap","propsRef","setStyleLoaded","forceUpdate","version","on","off","getLayer","removeLayer","layer","current","error","console","warn"],"sources":["../../src/components/layer.ts"],"sourcesContent":["import {useContext, useEffect, useMemo, useState, useRef} from 'react';\nimport {MapContext} from './map';\nimport assert from '../utils/assert';\nimport {deepEqual} from '../utils/deep-equal';\n\nimport type {MapInstance, CustomLayerInterface, ILayer} from '../types';\n\n// Omiting property from a union type, see\n// https://github.com/microsoft/TypeScript/issues/39556#issuecomment-656925230\ntype OptionalId<T> = T extends {id: string} ? Omit<T, 'id'> & {id?: string} : T;\ntype OptionalSource<T> = T extends {source: string} ? Omit<T, 'source'> & {source?: string} : T;\n\nexport type LayerProps<LayerT> = OptionalSource<OptionalId<LayerT>> & {\n /** If set, the layer will be inserted before the specified layer */\n beforeId?: string;\n};\n\n/* eslint-disable complexity, max-statements */\nfunction updateLayer<LayerT extends ILayer>(\n map: MapInstance,\n id: string,\n props: LayerProps<LayerT>,\n prevProps: LayerProps<LayerT>\n) {\n assert(props.id === prevProps.id, 'layer id changed');\n assert(props.type === prevProps.type, 'layer type changed');\n\n if (props.type === 'custom' || prevProps.type === 'custom') {\n return;\n }\n\n const {layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId} = props;\n\n if (beforeId !== prevProps.beforeId) {\n map.moveLayer(id, beforeId);\n }\n if (layout !== prevProps.layout) {\n const prevLayout = prevProps.layout || {};\n for (const key in layout) {\n if (!deepEqual(layout[key], prevLayout[key])) {\n map.setLayoutProperty(id, key, layout[key]);\n }\n }\n for (const key in prevLayout) {\n if (!layout.hasOwnProperty(key)) {\n map.setLayoutProperty(id, key, undefined);\n }\n }\n }\n if (paint !== prevProps.paint) {\n const prevPaint = prevProps.paint || {};\n for (const key in paint) {\n if (!deepEqual(paint[key], prevPaint[key])) {\n map.setPaintProperty(id, key, paint[key]);\n }\n }\n for (const key in prevPaint) {\n if (!paint.hasOwnProperty(key)) {\n map.setPaintProperty(id, key, undefined);\n }\n }\n }\n\n if (!deepEqual(filter, prevProps.filter)) {\n map.setFilter(id, filter);\n }\n if (minzoom !== prevProps.minzoom || maxzoom !== prevProps.maxzoom) {\n map.setLayerZoomRange(id, minzoom, maxzoom);\n }\n}\n\nfunction createLayer<LayerT extends ILayer>(\n map: MapInstance,\n id: string,\n props: LayerProps<LayerT>\n) {\n // @ts-ignore\n if (map.style && map.style._loaded && (!('source' in props) || map.getSource(props.source))) {\n const options: LayerProps<LayerT> = {...props, id};\n delete options.beforeId;\n\n // @ts-ignore\n map.addLayer(options, props.beforeId);\n }\n}\n\n/* eslint-enable complexity, max-statements */\n\nlet layerCounter = 0;\n\nfunction Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInterface>) {\n const map = useContext(MapContext).map.getMap();\n const propsRef = useRef(props);\n const [, setStyleLoaded] = useState(0);\n\n const id = useMemo(() => props.id || `jsx-layer-${layerCounter++}`, []);\n\n useEffect(() => {\n if (map) {\n const forceUpdate = () => setStyleLoaded(version => version + 1);\n map.on('styledata', forceUpdate);\n forceUpdate();\n\n return () => {\n map.off('styledata', forceUpdate);\n // @ts-ignore\n if (map.style && map.style._loaded && map.getLayer(id)) {\n map.removeLayer(id);\n }\n };\n }\n return undefined;\n }, [map]);\n\n // @ts-ignore\n const layer = map && map.style && map.getLayer(id);\n if (layer) {\n try {\n updateLayer(map, id, props, propsRef.current);\n } catch (error) {\n console.warn(error); // eslint-disable-line\n }\n } else {\n createLayer(map, id, props);\n }\n\n // Store last rendered props\n propsRef.current = props;\n\n return null;\n}\n\nexport default Layer;\n"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,MAAM,QAAO,OAAO;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,EAAE6B,QAAQ,CAACS,OAAO,CAAC;IAC/C,CAAC,CAAC,OAAOC,KAAK,EAAE;MACdC,OAAO,CAACC,IAAI,CAACF,KAAK,CAAC;IACrB;EACF,CAAC,MAAM;IACLpB,WAAW,CAACrB,GAAG,EAAEC,EAAE,EAAEC,KAAK,CAAC;EAC7B;EAGA6B,QAAQ,CAACS,OAAO,GAAGtC,KAAK;EAExB,OAAO,IAAI;AACb;AAEA,eAAe2B,KAAK","ignoreList":[]}
@@ -1,23 +0,0 @@
1
- import * as React from 'react';
2
- import { MapboxProps } from '../mapbox/mapbox';
3
- import { MapRef } from '../mapbox/create-ref';
4
- import type { CSSProperties } from 'react';
5
- import { GlobalSettings } from '../utils/set-globals';
6
- import type { MapLib, MapInstance, MapStyle, Callbacks } from '../types';
7
- export type MapContextValue<MapT extends MapInstance = MapInstance> = {
8
- mapLib: MapLib<MapT>;
9
- map: MapRef<MapT>;
10
- };
11
- export declare const MapContext: React.Context<MapContextValue<MapInstance>>;
12
- type MapInitOptions<MapOptions> = Omit<MapOptions, 'style' | 'container' | 'bounds' | 'fitBoundsOptions' | 'center'>;
13
- export type MapProps<MapOptions, StyleT extends MapStyle, CallbacksT extends Callbacks, MapT extends MapInstance> = MapInitOptions<MapOptions> & MapboxProps<StyleT, CallbacksT> & GlobalSettings & {
14
- mapLib?: MapLib<MapT> | Promise<MapLib<MapT>>;
15
- reuseMaps?: boolean;
16
- /** Map container id */
17
- id?: string;
18
- /** Map container CSS style */
19
- style?: CSSProperties;
20
- children?: any;
21
- };
22
- export default function Map<MapOptions, StyleT extends MapStyle, CallbacksT extends Callbacks, MapT extends MapInstance>(props: MapProps<MapOptions, StyleT, CallbacksT, MapT>, ref: React.Ref<MapRef<MapT>>, defaultLib: MapLib<MapT> | Promise<MapLib<MapT>>): React.JSX.Element;
23
- export {};
@@ -1,102 +0,0 @@
1
- import * as React from 'react';
2
- import { useState, useRef, useEffect, useContext, useMemo, useImperativeHandle } from 'react';
3
- import { MountedMapsContext } from "./use-map.js";
4
- import Mapbox from "../mapbox/mapbox.js";
5
- import createRef from "../mapbox/create-ref.js";
6
- import useIsomorphicLayoutEffect from "../utils/use-isomorphic-layout-effect.js";
7
- import setGlobals from "../utils/set-globals.js";
8
- export const MapContext = React.createContext(null);
9
- export default function Map(props, ref, defaultLib) {
10
- const mountedMapsContext = useContext(MountedMapsContext);
11
- const [mapInstance, setMapInstance] = useState(null);
12
- const containerRef = useRef();
13
- const {
14
- current: contextValue
15
- } = useRef({
16
- mapLib: null,
17
- map: null
18
- });
19
- useEffect(() => {
20
- const mapLib = props.mapLib;
21
- let isMounted = true;
22
- let mapbox;
23
- Promise.resolve(mapLib || defaultLib).then(module => {
24
- if (!isMounted) {
25
- return;
26
- }
27
- if (!module) {
28
- throw new Error('Invalid mapLib');
29
- }
30
- const mapboxgl = 'Map' in module ? module : module.default;
31
- if (!mapboxgl.Map) {
32
- throw new Error('Invalid mapLib');
33
- }
34
- setGlobals(mapboxgl, props);
35
- if (!mapboxgl.supported || mapboxgl.supported(props)) {
36
- if (props.reuseMaps) {
37
- mapbox = Mapbox.reuse(props, containerRef.current);
38
- }
39
- if (!mapbox) {
40
- mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);
41
- }
42
- contextValue.map = createRef(mapbox);
43
- contextValue.mapLib = mapboxgl;
44
- setMapInstance(mapbox);
45
- mountedMapsContext?.onMapMount(contextValue.map, props.id);
46
- } else {
47
- throw new Error('Map is not supported by this browser');
48
- }
49
- }).catch(error => {
50
- const {
51
- onError
52
- } = props;
53
- if (onError) {
54
- onError({
55
- type: 'error',
56
- target: null,
57
- originalEvent: null,
58
- error
59
- });
60
- } else {
61
- console.error(error);
62
- }
63
- });
64
- return () => {
65
- isMounted = false;
66
- if (mapbox) {
67
- mountedMapsContext?.onMapUnmount(props.id);
68
- if (props.reuseMaps) {
69
- mapbox.recycle();
70
- } else {
71
- mapbox.destroy();
72
- }
73
- }
74
- };
75
- }, []);
76
- useIsomorphicLayoutEffect(() => {
77
- if (mapInstance) {
78
- mapInstance.setProps(props);
79
- }
80
- });
81
- useImperativeHandle(ref, () => contextValue.map, [mapInstance]);
82
- const style = useMemo(() => ({
83
- position: 'relative',
84
- width: '100%',
85
- height: '100%',
86
- ...props.style
87
- }), [props.style]);
88
- const CHILD_CONTAINER_STYLE = {
89
- height: '100%'
90
- };
91
- return React.createElement("div", {
92
- id: props.id,
93
- ref: containerRef,
94
- style: style
95
- }, mapInstance && React.createElement(MapContext.Provider, {
96
- value: contextValue
97
- }, React.createElement("div", {
98
- "mapboxgl-children": "",
99
- style: CHILD_CONTAINER_STYLE
100
- }, props.children)));
101
- }
102
- //# sourceMappingURL=map.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"map.js","names":["React","useState","useRef","useEffect","useContext","useMemo","useImperativeHandle","MountedMapsContext","Mapbox","createRef","useIsomorphicLayoutEffect","setGlobals","MapContext","createContext","Map","props","ref","defaultLib","mountedMapsContext","mapInstance","setMapInstance","containerRef","current","contextValue","mapLib","map","isMounted","mapbox","Promise","resolve","then","module","Error","mapboxgl","default","supported","reuseMaps","reuse","onMapMount","id","catch","error","onError","type","target","originalEvent","console","onMapUnmount","recycle","destroy","setProps","style","position","width","height","CHILD_CONTAINER_STYLE","createElement","Provider","value","children"],"sources":["../../src/components/map.tsx"],"sourcesContent":["import * as React from 'react';\nimport {useState, useRef, useEffect, useContext, useMemo, useImperativeHandle} from 'react';\n\nimport {MountedMapsContext} from './use-map';\nimport Mapbox, {MapboxProps} from '../mapbox/mapbox';\nimport createRef, {MapRef} from '../mapbox/create-ref';\n\nimport type {CSSProperties} from 'react';\nimport useIsomorphicLayoutEffect from '../utils/use-isomorphic-layout-effect';\nimport setGlobals, {GlobalSettings} from '../utils/set-globals';\nimport type {MapLib, MapInstance, MapStyle, Callbacks} from '../types';\n\nexport type MapContextValue<MapT extends MapInstance = MapInstance> = {\n mapLib: MapLib<MapT>;\n map: MapRef<MapT>;\n};\n\nexport const MapContext = React.createContext<MapContextValue>(null);\n\ntype MapInitOptions<MapOptions> = Omit<\n MapOptions,\n 'style' | 'container' | 'bounds' | 'fitBoundsOptions' | 'center'\n>;\n\nexport type MapProps<\n MapOptions,\n StyleT extends MapStyle,\n CallbacksT extends Callbacks,\n MapT extends MapInstance\n> = MapInitOptions<MapOptions> &\n MapboxProps<StyleT, CallbacksT> &\n GlobalSettings & {\n mapLib?: MapLib<MapT> | Promise<MapLib<MapT>>;\n reuseMaps?: boolean;\n /** Map container id */\n id?: string;\n /** Map container CSS style */\n style?: CSSProperties;\n children?: any;\n };\n\nexport default function Map<\n MapOptions,\n StyleT extends MapStyle,\n CallbacksT extends Callbacks,\n MapT extends MapInstance\n>(\n props: MapProps<MapOptions, StyleT, CallbacksT, MapT>,\n ref: React.Ref<MapRef<MapT>>,\n defaultLib: MapLib<MapT> | Promise<MapLib<MapT>>\n) {\n const mountedMapsContext = useContext(MountedMapsContext);\n const [mapInstance, setMapInstance] = useState<Mapbox<StyleT, CallbacksT, MapT>>(null);\n const containerRef = useRef();\n\n const {current: contextValue} = useRef<MapContextValue<MapT>>({mapLib: null, map: null});\n\n useEffect(() => {\n const mapLib = props.mapLib;\n let isMounted = true;\n let mapbox: Mapbox<StyleT, CallbacksT, MapT>;\n\n Promise.resolve(mapLib || defaultLib)\n .then((module: MapLib<MapT> | {default: MapLib<MapT>}) => {\n if (!isMounted) {\n return;\n }\n if (!module) {\n throw new Error('Invalid mapLib');\n }\n const mapboxgl = 'Map' in module ? module : module.default;\n if (!mapboxgl.Map) {\n throw new Error('Invalid mapLib');\n }\n\n // workerUrl & workerClass may change the result of supported()\n // https://github.com/visgl/react-map-gl/discussions/2027\n setGlobals(mapboxgl, props);\n if (!mapboxgl.supported || mapboxgl.supported(props)) {\n if (props.reuseMaps) {\n mapbox = Mapbox.reuse(props, containerRef.current);\n }\n if (!mapbox) {\n mapbox = new Mapbox(mapboxgl.Map, props, containerRef.current);\n }\n contextValue.map = createRef(mapbox);\n contextValue.mapLib = mapboxgl;\n\n setMapInstance(mapbox);\n mountedMapsContext?.onMapMount(contextValue.map, props.id);\n } else {\n throw new Error('Map is not supported by this browser');\n }\n })\n .catch(error => {\n const {onError} = props;\n if (onError) {\n onError({\n type: 'error',\n target: null,\n originalEvent: null,\n error\n });\n } else {\n console.error(error); // eslint-disable-line\n }\n });\n\n return () => {\n isMounted = false;\n if (mapbox) {\n mountedMapsContext?.onMapUnmount(props.id);\n if (props.reuseMaps) {\n mapbox.recycle();\n } else {\n mapbox.destroy();\n }\n }\n };\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n if (mapInstance) {\n mapInstance.setProps(props);\n }\n });\n\n useImperativeHandle(ref, () => contextValue.map, [mapInstance]);\n\n const style: CSSProperties = useMemo(\n () => ({\n position: 'relative',\n width: '100%',\n height: '100%',\n ...props.style\n }),\n [props.style]\n );\n\n const CHILD_CONTAINER_STYLE = {\n height: '100%'\n };\n\n return (\n <div id={props.id} ref={containerRef} style={style}>\n {mapInstance && (\n <MapContext.Provider value={contextValue}>\n <div mapboxgl-children=\"\" style={CHILD_CONTAINER_STYLE}>\n {props.children}\n </div>\n </MapContext.Provider>\n )}\n </div>\n );\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAQC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,EAAEC,OAAO,EAAEC,mBAAmB,QAAO,OAAO;AAAC,SAEpFC,kBAAkB;AAAA,OACnBC,MAAM;AAAA,OACNC,SAAS;AAAA,OAGTC,yBAAyB;AAAA,OACzBC,UAAU;AAQjB,OAAO,MAAMC,UAAU,GAAGZ,KAAK,CAACa,aAAa,CAAkB,IAAI,CAAC;AAwBpE,eAAe,SAASC,GAAGA,CAMzBC,KAAqD,EACrDC,GAA4B,EAC5BC,UAAgD,EAChD;EACA,MAAMC,kBAAkB,GAAGd,UAAU,CAACG,kBAAkB,CAAC;EACzD,MAAM,CAACY,WAAW,EAAEC,cAAc,CAAC,GAAGnB,QAAQ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