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
@@ -1,30 +1,27 @@
1
- import { createPortal } from 'react-dom';
2
- import { useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo } from 'react';
1
+ import { createPortal } from "react-dom";
2
+ import { useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo } from "react";
3
3
  import { applyReactStyle } from "../utils/apply-react-style.js";
4
4
  import { MapContext } from "./map.js";
5
5
  import { deepEqual } from "../utils/deep-equal.js";
6
- function getClassList(className) {
7
- return new Set(className ? className.trim().split(/\s+/) : []);
8
- }
9
- function Popup(props, ref) {
6
+ import { compareClassNames } from "../utils/compare-class-names.js";
7
+ export const Popup = memo(forwardRef((props, ref) => {
10
8
  const {
11
9
  map,
12
10
  mapLib
13
11
  } = useContext(MapContext);
14
12
  const container = useMemo(() => {
15
- return document.createElement('div');
13
+ return document.createElement("div");
16
14
  }, []);
17
15
  const thisRef = useRef({
18
16
  props
19
17
  });
20
- thisRef.current.props = props;
21
18
  const popup = useMemo(() => {
22
19
  const options = {
23
20
  ...props
24
21
  };
25
22
  const pp = new mapLib.Popup(options);
26
23
  pp.setLngLat([props.longitude, props.latitude]);
27
- pp.once('open', e => {
24
+ pp.once("open", e => {
28
25
  thisRef.current.props.onOpen?.(e);
29
26
  });
30
27
  return pp;
@@ -33,10 +30,10 @@ function Popup(props, ref) {
33
30
  const onClose = e => {
34
31
  thisRef.current.props.onClose?.(e);
35
32
  };
36
- popup.on('close', onClose);
33
+ popup.on("close", onClose);
37
34
  popup.setDOMContent(container).addTo(map.getMap());
38
35
  return () => {
39
- popup.off('close', onClose);
36
+ popup.off("close", onClose);
40
37
  if (popup.isOpen()) {
41
38
  popup.remove();
42
39
  }
@@ -47,33 +44,25 @@ function Popup(props, ref) {
47
44
  }, [props.style]);
48
45
  useImperativeHandle(ref, () => popup, []);
49
46
  if (popup.isOpen()) {
47
+ const oldProps = thisRef.current.props;
50
48
  if (popup.getLngLat().lng !== props.longitude || popup.getLngLat().lat !== props.latitude) {
51
49
  popup.setLngLat([props.longitude, props.latitude]);
52
50
  }
53
- if (props.offset && !deepEqual(popup.options.offset, props.offset)) {
51
+ if (props.offset && !deepEqual(oldProps.offset, props.offset)) {
54
52
  popup.setOffset(props.offset);
55
53
  }
56
- if (popup.options.anchor !== props.anchor || popup.options.maxWidth !== props.maxWidth) {
54
+ if (oldProps.anchor !== props.anchor || oldProps.maxWidth !== props.maxWidth) {
57
55
  popup.options.anchor = props.anchor;
58
56
  popup.setMaxWidth(props.maxWidth);
59
57
  }
60
- if (popup.options.className !== props.className) {
61
- const prevClassList = getClassList(popup.options.className);
62
- const nextClassList = getClassList(props.className);
63
- for (const c of prevClassList) {
64
- if (!nextClassList.has(c)) {
65
- popup.removeClassName(c);
66
- }
58
+ const classNameDiff = compareClassNames(oldProps.className, props.className);
59
+ if (classNameDiff) {
60
+ for (const c of classNameDiff) {
61
+ popup.toggleClassName(c);
67
62
  }
68
- for (const c of nextClassList) {
69
- if (!prevClassList.has(c)) {
70
- popup.addClassName(c);
71
- }
72
- }
73
- popup.options.className = props.className;
74
63
  }
64
+ thisRef.current.props = props;
75
65
  }
76
66
  return createPortal(props.children, container);
77
- }
78
- export default memo(forwardRef(Popup));
67
+ }));
79
68
  //# sourceMappingURL=popup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"popup.js","names":["createPortal","useImperativeHandle","useEffect","useMemo","useRef","useContext","forwardRef","memo","applyReactStyle","MapContext","deepEqual","getClassList","className","Set","trim","split","Popup","props","ref","map","mapLib","container","document","createElement","thisRef","current","popup","options","pp","setLngLat","longitude","latitude","once","e","onOpen","onClose","on","setDOMContent","addTo","getMap","off","isOpen","remove","getElement","style","getLngLat","lng","lat","offset","setOffset","anchor","maxWidth","setMaxWidth","prevClassList","nextClassList","c","has","removeClassName","addClassName","children"],"sources":["../../src/components/popup.ts"],"sourcesContent":["/* global document */\nimport * as React from 'react';\nimport {createPortal} from 'react-dom';\nimport {useImperativeHandle, useEffect, useMemo, useRef, useContext, forwardRef, memo} from 'react';\nimport {applyReactStyle} from '../utils/apply-react-style';\n\nimport type {PopupEvent, PopupInstance} from '../types';\n\nimport {MapContext} from './map';\nimport {deepEqual} from '../utils/deep-equal';\n\nexport type PopupProps<OptionsT, PopupT extends PopupInstance> = OptionsT & {\n /** Longitude of the anchor location */\n longitude: number;\n /** Latitude of the anchor location */\n latitude: number;\n\n // These types will be further constraint by OptionsT\n anchor?: string;\n offset?: any;\n className?: string;\n maxWidth?: string;\n\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n\n onOpen?: (e: PopupEvent<PopupT>) => void;\n onClose?: (e: PopupEvent<PopupT>) => void;\n children?: React.ReactNode;\n};\n\n// Adapted from https://github.com/mapbox/mapbox-gl-js/blob/v1.13.0/src/ui/popup.js\nfunction getClassList(className: string) {\n return new Set(className ? className.trim().split(/\\s+/) : []);\n}\n\n/* eslint-disable complexity,max-statements */\nfunction Popup<PopupOptions, PopupT extends PopupInstance>(\n props: PopupProps<PopupOptions, PopupT>,\n ref: React.Ref<PopupT>\n) {\n const {map, mapLib} = useContext(MapContext);\n const container = useMemo(() => {\n return document.createElement('div');\n }, []);\n const thisRef = useRef({props});\n thisRef.current.props = props;\n\n const popup: PopupT = useMemo(() => {\n const options = {...props};\n const pp = new mapLib.Popup(options) as PopupT;\n pp.setLngLat([props.longitude, props.latitude]);\n pp.once('open', e => {\n thisRef.current.props.onOpen?.(e as PopupEvent<PopupT>);\n });\n return pp;\n }, []);\n\n useEffect(() => {\n const onClose = e => {\n thisRef.current.props.onClose?.(e as PopupEvent<PopupT>);\n };\n popup.on('close', onClose);\n popup.setDOMContent(container).addTo(map.getMap());\n\n return () => {\n // https://github.com/visgl/react-map-gl/issues/1825\n // onClose should not be fired if the popup is removed by unmounting\n // When using React strict mode, the component is mounted twice.\n // Firing the onClose callback here would be a false signal to remove the component.\n popup.off('close', onClose);\n if (popup.isOpen()) {\n popup.remove();\n }\n };\n }, []);\n\n useEffect(() => {\n applyReactStyle(popup.getElement(), props.style);\n }, [props.style]);\n\n useImperativeHandle(ref, () => popup, []);\n\n if (popup.isOpen()) {\n if (popup.getLngLat().lng !== props.longitude || popup.getLngLat().lat !== props.latitude) {\n popup.setLngLat([props.longitude, props.latitude]);\n }\n if (props.offset && !deepEqual(popup.options.offset, props.offset)) {\n popup.setOffset(props.offset);\n }\n if (popup.options.anchor !== props.anchor || popup.options.maxWidth !== props.maxWidth) {\n popup.options.anchor = props.anchor;\n popup.setMaxWidth(props.maxWidth);\n }\n if (popup.options.className !== props.className) {\n const prevClassList = getClassList(popup.options.className);\n const nextClassList = getClassList(props.className);\n\n for (const c of prevClassList) {\n if (!nextClassList.has(c)) {\n popup.removeClassName(c);\n }\n }\n for (const c of nextClassList) {\n if (!prevClassList.has(c)) {\n popup.addClassName(c);\n }\n }\n popup.options.className = props.className;\n }\n }\n\n return createPortal(props.children, container);\n}\n\nexport default memo(forwardRef(Popup));\n"],"mappings":"AAEA,SAAQA,YAAY,QAAO,WAAW;AACtC,SAAQC,mBAAmB,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,UAAU,EAAEC,UAAU,EAAEC,IAAI,QAAO,OAAO;AAAC,SAC5FC,eAAe;AAAA,SAIfC,UAAU;AAAA,SACVC,SAAS;AAuBjB,SAASC,YAAYA,CAACC,SAAiB,EAAE;EACvC,OAAO,IAAIC,GAAG,CAACD,SAAS,GAAGA,SAAS,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChE;AAGA,SAASC,KAAKA,CACZC,KAAuC,EACvCC,GAAsB,EACtB;EACA,MAAM;IAACC,GAAG;IAAEC;EAAM,CAAC,GAAGf,UAAU,CAACI,UAAU,CAAC;EAC5C,MAAMY,SAAS,GAAGlB,OAAO,CAAC,MAAM;IAC9B,OAAOmB,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EACtC,CAAC,EAAE,EAAE,CAAC;EACN,MAAMC,OAA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,eAAe,CAACF,CAAC,CAAC;QAC1B;MACF;MACA,KAAK,MAAMA,CAAC,IAAID,aAAa,EAAE;QAC7B,IAAI,CAACD,aAAa,CAACG,GAAG,CAACD,CAAC,CAAC,EAAE;UACzB7B,KAAK,CAACgC,YAAY,CAACH,CAAC,CAAC;QACvB;MACF;MACA7B,KAAK,CAACC,OAAO,CAACf,SAAS,GAAGK,KAAK,CAACL,SAAS;IAC3C;EACF;EAEA,OAAOZ,YAAY,CAACiB,KAAK,CAAC0C,QAAQ,EAAEtC,SAAS,CAAC;AAChD;AAEA,eAAed,IAAI,CAACD,UAAU,CAACU,KAAK,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"popup.js","names":["createPortal","useImperativeHandle","useEffect","useMemo","useRef","useContext","forwardRef","memo","applyReactStyle","MapContext","deepEqual","compareClassNames","Popup","props","ref","map","mapLib","container","document","createElement","thisRef","popup","options","pp","setLngLat","longitude","latitude","once","e","current","onOpen","onClose","on","setDOMContent","addTo","getMap","off","isOpen","remove","getElement","style","oldProps","getLngLat","lng","lat","offset","setOffset","anchor","maxWidth","setMaxWidth","classNameDiff","className","c","toggleClassName","children"],"sources":["../../src/components/popup.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-floating-promises */\n/* global document */\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n useImperativeHandle,\n useEffect,\n useMemo,\n useRef,\n useContext,\n forwardRef,\n memo,\n} from \"react\";\nimport { applyReactStyle } from \"../utils/apply-react-style\";\n\nimport type { Popup as PopupInstance, PopupOptions } from \"../types/lib\";\nimport type { PopupEvent } from \"../types/events\";\n\nimport { MapContext } from \"./map\";\nimport { deepEqual } from \"../utils/deep-equal\";\nimport { compareClassNames } from \"../utils/compare-class-names\";\n\nexport type PopupProps = PopupOptions & {\n /** Longitude of the anchor location */\n longitude: number;\n /** Latitude of the anchor location */\n latitude: number;\n\n /** CSS style override, applied to the control's container */\n style?: React.CSSProperties;\n\n onOpen?: (e: PopupEvent) => void;\n onClose?: (e: PopupEvent) => void;\n children?: React.ReactNode;\n};\n\n/* eslint-disable complexity,max-statements */\nexport const Popup: React.FC<PopupProps> = memo(\n forwardRef((props: PopupProps, ref: React.Ref<PopupInstance>) => {\n const { map, mapLib } = useContext(MapContext);\n const container = useMemo(() => {\n return document.createElement(\"div\");\n }, []);\n const thisRef = useRef({ props });\n\n const popup: PopupInstance = useMemo(() => {\n const options = { ...props };\n const pp = new mapLib.Popup(options);\n pp.setLngLat([props.longitude, props.latitude]);\n pp.once(\"open\", (e) => {\n thisRef.current.props.onOpen?.(e as PopupEvent);\n });\n return pp;\n }, []);\n\n useEffect(() => {\n const onClose = (e) => {\n thisRef.current.props.onClose?.(e as PopupEvent);\n };\n popup.on(\"close\", onClose);\n popup.setDOMContent(container).addTo(map.getMap());\n\n return () => {\n // https://github.com/visgl/react-map-gl/issues/1825\n // onClose should not be fired if the popup is removed by unmounting\n // When using React strict mode, the component is mounted twice.\n // Firing the onClose callback here would be a false signal to remove the component.\n popup.off(\"close\", onClose);\n if (popup.isOpen()) {\n popup.remove();\n }\n };\n }, []);\n\n useEffect(() => {\n applyReactStyle(popup.getElement(), props.style);\n }, [props.style]);\n\n useImperativeHandle(ref, () => popup, []);\n\n if (popup.isOpen()) {\n const oldProps = thisRef.current.props;\n if (\n popup.getLngLat().lng !== props.longitude ||\n popup.getLngLat().lat !== props.latitude\n ) {\n popup.setLngLat([props.longitude, props.latitude]);\n }\n if (props.offset && !deepEqual(oldProps.offset, props.offset)) {\n popup.setOffset(props.offset);\n }\n if (\n oldProps.anchor !== props.anchor ||\n oldProps.maxWidth !== props.maxWidth\n ) {\n popup.options.anchor = props.anchor;\n popup.setMaxWidth(props.maxWidth);\n }\n const classNameDiff = compareClassNames(\n oldProps.className,\n props.className,\n );\n if (classNameDiff) {\n for (const c of classNameDiff) {\n popup.toggleClassName(c);\n }\n }\n thisRef.current.props = props;\n }\n\n return createPortal(props.children, container);\n }),\n);\n"],"mappings":"AAGA,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,EACpC;MACA3B,KAAK,CAACC,OAAO,CAACyB,MAAM,GAAGlC,KAAK,CAACkC,MAAM;MACnC1B,KAAK,CAAC4B,WAAW,CAACpC,KAAK,CAACmC,QAAQ,CAAC;IACnC;IACA,MAAME,aAAa,GAAGvC,iBAAiB,CACrC8B,QAAQ,CAACU,SAAS,EAClBtC,KAAK,CAACsC,SACR,CAAC;IACD,IAAID,aAAa,EAAE;MACjB,KAAK,MAAME,CAAC,IAAIF,aAAa,EAAE;QAC7B7B,KAAK,CAACgC,eAAe,CAACD,CAAC,CAAC;MAC1B;IACF;IACAhC,OAAO,CAACS,OAAO,CAAChB,KAAK,GAAGA,KAAK;EAC/B;EAEA,OAAOb,YAAY,CAACa,KAAK,CAACyC,QAAQ,EAAErC,SAAS,CAAC;AAChD,CAAC,CACH,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
2
- import type { ControlPosition, ScaleControlInstance } from '../types';
3
- export type ScaleControlProps<OptionsT> = OptionsT & {
1
+ import * as React from "react";
2
+ import type { ControlPosition, ScaleControlOptions } from "../types/lib";
3
+ export type ScaleControlProps = ScaleControlOptions & {
4
4
  unit?: string;
5
5
  maxWidth?: number;
6
6
  /** Placement of the control relative to the map. */
@@ -8,6 +8,4 @@ export type ScaleControlProps<OptionsT> = OptionsT & {
8
8
  /** CSS style override, applied to the control's container */
9
9
  style?: React.CSSProperties;
10
10
  };
11
- declare function ScaleControl<ScaleControlOptions, ControlT extends ScaleControlInstance>(props: ScaleControlProps<ScaleControlOptions>): null;
12
- declare const _default: React.MemoExoticComponent<typeof ScaleControl>;
13
- export default _default;
11
+ export declare const ScaleControl: React.FC<ScaleControlProps>;
@@ -1,7 +1,7 @@
1
- import { useEffect, useRef, memo } from 'react';
1
+ import { useEffect, useRef, memo } from "react";
2
2
  import { applyReactStyle } from "../utils/apply-react-style.js";
3
- import useControl from "./use-control.js";
4
- function ScaleControl(props) {
3
+ import { useControl } from "./use-control.js";
4
+ function _ScaleControl(props) {
5
5
  const ctrl = useControl(_ref => {
6
6
  let {
7
7
  mapLib
@@ -27,5 +27,5 @@ function ScaleControl(props) {
27
27
  }, [style]);
28
28
  return null;
29
29
  }
30
- export default memo(ScaleControl);
30
+ export const ScaleControl = memo(_ScaleControl);
31
31
  //# sourceMappingURL=scale-control.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scale-control.js","names":["useEffect","useRef","memo","applyReactStyle","useControl","ScaleControl","props","ctrl","_ref","mapLib","position","propsRef","prevProps","current","style","maxWidth","undefined","options","unit","setUnit","_container"],"sources":["../../src/components/scale-control.ts"],"sourcesContent":["import * as React from 'react';\nimport {useEffect, useRef, memo} from 'react';\nimport {applyReactStyle} from '../utils/apply-react-style';\nimport useControl from './use-control';\n\nimport type {ControlPosition, ScaleControlInstance} from '../types';\n\nexport type ScaleControlProps<OptionsT> = OptionsT & {\n // These props will be further constraint by OptionsT\n unit?: string;\n maxWidth?: number;\n\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 ScaleControl<ScaleControlOptions, ControlT extends ScaleControlInstance>(\n props: ScaleControlProps<ScaleControlOptions>\n): null {\n const ctrl = useControl<ControlT>(({mapLib}) => new mapLib.ScaleControl(props) as ControlT, {\n position: props.position\n });\n const propsRef = useRef<ScaleControlProps<ScaleControlOptions>>(props);\n\n const prevProps = propsRef.current;\n propsRef.current = props;\n\n const {style} = props;\n\n if (props.maxWidth !== undefined && props.maxWidth !== prevProps.maxWidth) {\n ctrl.options.maxWidth = props.maxWidth;\n }\n if (props.unit !== undefined && props.unit !== prevProps.unit) {\n ctrl.setUnit(props.unit);\n }\n\n useEffect(() => {\n applyReactStyle(ctrl._container, style);\n }, [style]);\n\n return null;\n}\n\nexport default memo(ScaleControl);\n"],"mappings":"AACA,SAAQA,SAAS,EAAEC,MAAM,EAAEC,IAAI,QAAO,OAAO;AAAC,SACtCC,eAAe;AAAA,OAChBC,UAAU;AAejB,SAASC,YAAYA,CACnBC,KAA6C,EACvC;EACN,MAAMC,IAAI,GAAGH,UAAU,CAAWI,IAAA;IAAA,IAAC;MAACC;IAAM,CAAC,GAAAD,IAAA;IAAA,OAAK,IAAIC,MAAM,CAACJ,YAAY,CAACC,KAAK,CAAC;EAAA,CAAY,EAAE;IAC1FI,QAAQ,EAAEJ,KAAK,CAACI;EAClB,CAAC,CAAC;EACF,MAAMC,QAAQ,GAAGV,MAAM,CAAyCK,KAAK,CAAC;EAEtE,MAAMM,SAAS,GAAGD,QAAQ,CAACE,OAAO;EAClCF,QAAQ,CAACE,OAAO,GAAGP,KAAK;EAExB,MAAM;IAACQ;EAAK,CAAC,GAAGR,KAAK;EAErB,IAAIA,KAAK,CAACS,QAAQ,KAAKC,SAAS,IAAIV,KAAK,CAACS,QAAQ,KAAKH,SAAS,CAACG,QAAQ,EAAE;IACzER,IAAI,CAACU,OAAO,CAACF,QAAQ,GAAGT,KAAK,CAACS,QAAQ;EACxC;EACA,IAAIT,KAAK,CAACY,IAAI,KAAKF,SAAS,IAAIV,KAAK,CAACY,IAAI,KAAKN,SAAS,CAACM,IAAI,EAAE;IAC7DX,IAAI,CAACY,OAAO,CAACb,KAAK,CAACY,IAAI,CAAC;EAC1B;EAEAlB,SAAS,CAAC,MAAM;IACdG,eAAe,CAACI,IAAI,CAACa,UAAU,EAAEN,KAAK,CAAC;EACzC,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX,OAAO,IAAI;AACb;AAEA,eAAeZ,IAAI,CAACG,YAAY,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"scale-control.js","names":["useEffect","useRef","memo","applyReactStyle","useControl","_ScaleControl","props","ctrl","_ref","mapLib","ScaleControl","position","propsRef","prevProps","current","style","maxWidth","undefined","options","unit","setUnit","_container"],"sources":["../../src/components/scale-control.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useEffect, useRef, memo } from \"react\";\nimport { applyReactStyle } from \"../utils/apply-react-style\";\nimport { useControl } from \"./use-control\";\n\nimport type { ControlPosition, ScaleControlOptions } from \"../types/lib\";\n\nexport type ScaleControlProps = ScaleControlOptions & {\n // These props will be further constraint by OptionsT\n unit?: string;\n maxWidth?: number;\n\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 _ScaleControl(props: ScaleControlProps) {\n const ctrl = useControl(({ mapLib }) => new mapLib.ScaleControl(props), {\n position: props.position,\n });\n const propsRef = useRef<ScaleControlProps>(props);\n\n const prevProps = propsRef.current;\n propsRef.current = props;\n\n const { style } = props;\n\n if (props.maxWidth !== undefined && props.maxWidth !== prevProps.maxWidth) {\n ctrl.options.maxWidth = props.maxWidth;\n }\n if (props.unit !== undefined && props.unit !== prevProps.unit) {\n ctrl.setUnit(props.unit);\n }\n\n useEffect(() => {\n applyReactStyle(ctrl._container, style);\n }, [style]);\n\n return null;\n}\n\nexport const ScaleControl: React.FC<ScaleControlProps> = memo(_ScaleControl);\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,MAAM,EAAEC,IAAI,QAAQ,OAAO;AAAC,SACvCC,eAAe;AAAA,SACfC,UAAU;AAenB,SAASC,aAAaA,CAACC,KAAwB,EAAE;EAC/C,MAAMC,IAAI,GAAGH,UAAU,CAACI,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OAAK,IAAIC,MAAM,CAACC,YAAY,CAACJ,KAAK,CAAC;EAAA,GAAE;IACtEK,QAAQ,EAAEL,KAAK,CAACK;EAClB,CAAC,CAAC;EACF,MAAMC,QAAQ,GAAGX,MAAM,CAAoBK,KAAK,CAAC;EAEjD,MAAMO,SAAS,GAAGD,QAAQ,CAACE,OAAO;EAClCF,QAAQ,CAACE,OAAO,GAAGR,KAAK;EAExB,MAAM;IAAES;EAAM,CAAC,GAAGT,KAAK;EAEvB,IAAIA,KAAK,CAACU,QAAQ,KAAKC,SAAS,IAAIX,KAAK,CAACU,QAAQ,KAAKH,SAAS,CAACG,QAAQ,EAAE;IACzET,IAAI,CAACW,OAAO,CAACF,QAAQ,GAAGV,KAAK,CAACU,QAAQ;EACxC;EACA,IAAIV,KAAK,CAACa,IAAI,KAAKF,SAAS,IAAIX,KAAK,CAACa,IAAI,KAAKN,SAAS,CAACM,IAAI,EAAE;IAC7DZ,IAAI,CAACa,OAAO,CAACd,KAAK,CAACa,IAAI,CAAC;EAC1B;EAEAnB,SAAS,CAAC,MAAM;IACdG,eAAe,CAACI,IAAI,CAACc,UAAU,EAAEN,KAAK,CAAC;EACzC,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX,OAAO,IAAI;AACb;AAEA,OAAO,MAAML,YAAyC,GAAGR,IAAI,CAACG,aAAa,CAAC","ignoreList":[]}
@@ -1,7 +1,6 @@
1
- import type { ISource, CustomSource } from '../types';
2
- export type SourceProps<SourceT> = (SourceT | CustomSource) & {
1
+ import type { SourceSpecification } from "../types/style-spec";
2
+ export type SourceProps = SourceSpecification & {
3
3
  id?: string;
4
4
  children?: any;
5
5
  };
6
- declare function Source<SourceT extends ISource>(props: SourceProps<SourceT>): any;
7
- export default Source;
6
+ export declare function Source(props: SourceProps): any;
@@ -1,6 +1,5 @@
1
- import * as React from 'react';
2
- import { useContext, useEffect, useMemo, useState, useRef } from 'react';
3
- import { cloneElement } from 'react';
1
+ import * as React from "react";
2
+ import { useContext, useEffect, useMemo, useState, useRef, cloneElement } from "react";
4
3
  import { MapContext } from "./map.js";
5
4
  import assert from "../utils/assert.js";
6
5
  import { deepEqual } from "../utils/deep-equal.js";
@@ -18,12 +17,12 @@ function createSource(map, id, props) {
18
17
  return null;
19
18
  }
20
19
  function updateSource(source, props, prevProps) {
21
- assert(props.id === prevProps.id, 'source id changed');
22
- assert(props.type === prevProps.type, 'source type changed');
23
- let changedKey = '';
20
+ assert(props.id === prevProps.id, "source id changed");
21
+ assert(props.type === prevProps.type, "source type changed");
22
+ let changedKey = "";
24
23
  let changedKeyCount = 0;
25
24
  for (const key in props) {
26
- if (key !== 'children' && key !== 'id' && !deepEqual(prevProps[key], props[key])) {
25
+ if (key !== "children" && key !== "id" && !deepEqual(prevProps[key], props[key])) {
27
26
  changedKey = key;
28
27
  changedKeyCount++;
29
28
  }
@@ -32,30 +31,30 @@ function updateSource(source, props, prevProps) {
32
31
  return;
33
32
  }
34
33
  const type = props.type;
35
- if (type === 'geojson') {
34
+ if (type === "geojson") {
36
35
  source.setData(props.data);
37
- } else if (type === 'image') {
36
+ } else if (type === "image") {
38
37
  source.updateImage({
39
38
  url: props.url,
40
39
  coordinates: props.coordinates
41
40
  });
42
- } else if ('setCoordinates' in source && changedKeyCount === 1 && changedKey === 'coordinates') {
43
- source.setCoordinates(props.coordinates);
44
- } else if ('setUrl' in source) {
41
+ } else {
45
42
  switch (changedKey) {
46
- case 'url':
47
- source.setUrl(props.url);
43
+ case "coordinates":
44
+ source.setCoordinates?.(props.coordinates);
45
+ break;
46
+ case "url":
47
+ source.setUrl?.(props.url);
48
48
  break;
49
- case 'tiles':
50
- source.setTiles(props.tiles);
49
+ case "tiles":
50
+ source.setTiles?.(props.tiles);
51
51
  break;
52
52
  default:
53
+ console.warn(`Unable to update <Source> prop: ${changedKey}`);
53
54
  }
54
- } else {
55
- console.warn(`Unable to update <Source> prop: ${changedKey}`);
56
55
  }
57
56
  }
58
- function Source(props) {
57
+ export function Source(props) {
59
58
  const map = useContext(MapContext).map.getMap();
60
59
  const propsRef = useRef(props);
61
60
  const [, setStyleLoaded] = useState(0);
@@ -63,10 +62,10 @@ function Source(props) {
63
62
  useEffect(() => {
64
63
  if (map) {
65
64
  const forceUpdate = () => setTimeout(() => setStyleLoaded(version => version + 1), 0);
66
- map.on('styledata', forceUpdate);
65
+ map.on("styledata", forceUpdate);
67
66
  forceUpdate();
68
67
  return () => {
69
- map.off('styledata', forceUpdate);
68
+ map.off("styledata", forceUpdate);
70
69
  if (map.style && map.style._loaded && map.getSource(id)) {
71
70
  const allLayers = map.getStyle()?.layers;
72
71
  if (allLayers) {
@@ -93,5 +92,4 @@ function Source(props) {
93
92
  source: id
94
93
  })) || null;
95
94
  }
96
- export default Source;
97
95
  //# sourceMappingURL=source.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"source.js","names":["React","useContext","useEffect","useMemo","useState","useRef","cloneElement","MapContext","assert","deepEqual","sourceCounter","createSource","map","id","props","style","_loaded","options","children","addSource","getSource","updateSource","source","prevProps","type","changedKey","changedKeyCount","key","setData","data","updateImage","url","coordinates","setCoordinates","setUrl","setTiles","tiles","console","warn","Source","getMap","propsRef","setStyleLoaded","forceUpdate","setTimeout","version","on","off","allLayers","getStyle","layers","layer","removeLayer","removeSource","undefined","current","Children","child"],"sources":["../../src/components/source.ts"],"sourcesContent":["import * as React from 'react';\nimport {useContext, useEffect, useMemo, useState, useRef} from 'react';\nimport {cloneElement} from 'react';\nimport {MapContext} from './map';\nimport assert from '../utils/assert';\nimport {deepEqual} from '../utils/deep-equal';\n\nimport type {\n MapInstance,\n ISource,\n CustomSource,\n GeoJSONSourceImplementation,\n ImageSourceImplemtation,\n AnySourceImplementation\n} from '../types';\nimport type {GeoJSONSourceRaw, ImageSourceRaw, VectorSourceRaw} from '../types/style-spec-bkoi-gl';\n\nexport type SourceProps<SourceT> = (SourceT | CustomSource) & {\n id?: string;\n children?: any;\n};\n\nlet sourceCounter = 0;\n\nfunction createSource<SourceT extends ISource>(\n map: MapInstance,\n id: string,\n props: SourceProps<SourceT>\n) {\n // @ts-ignore\n if (map.style && map.style._loaded) {\n const options = {...props};\n delete options.id;\n delete options.children;\n // @ts-ignore\n map.addSource(id, options);\n return map.getSource(id);\n }\n return null;\n}\n\n/* eslint-disable complexity */\nfunction updateSource<SourceT extends ISource>(\n source: AnySourceImplementation,\n props: SourceProps<SourceT>,\n prevProps: SourceProps<SourceT>\n) {\n assert(props.id === prevProps.id, 'source id changed');\n assert(props.type === prevProps.type, 'source type changed');\n\n let changedKey = '';\n let changedKeyCount = 0;\n\n for (const key in props) {\n if (key !== 'children' && key !== 'id' && !deepEqual(prevProps[key], props[key])) {\n changedKey = key;\n changedKeyCount++;\n }\n }\n\n if (!changedKeyCount) {\n return;\n }\n\n const type = props.type;\n\n if (type === 'geojson') {\n (source as GeoJSONSourceImplementation).setData(\n (props as unknown as GeoJSONSourceRaw).data as any\n );\n } else if (type === 'image') {\n (source as ImageSourceImplemtation).updateImage({\n url: (props as unknown as ImageSourceRaw).url,\n coordinates: (props as unknown as ImageSourceRaw).coordinates\n });\n } else if ('setCoordinates' in source && changedKeyCount === 1 && changedKey === 'coordinates') {\n source.setCoordinates((props as ImageSourceRaw).coordinates);\n } else if ('setUrl' in source) {\n // Added in 1.12.0:\n // vectorTileSource.setTiles\n // vectorTileSource.setUrl\n switch (changedKey) {\n case 'url':\n source.setUrl((props as VectorSourceRaw).url);\n break;\n case 'tiles':\n source.setTiles((props as VectorSourceRaw).tiles);\n break;\n default:\n }\n } else {\n // eslint-disable-next-line\n console.warn(`Unable to update <Source> prop: ${changedKey}`);\n }\n}\n/* eslint-enable complexity */\n\nfunction Source<SourceT extends ISource>(props: SourceProps<SourceT>) {\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-source-${sourceCounter++}`, []);\n\n useEffect(() => {\n if (map) {\n /* global setTimeout */\n const forceUpdate = () => setTimeout(() => setStyleLoaded(version => version + 1), 0);\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.getSource(id)) {\n // Parent effects are destroyed before child ones, see\n // https://github.com/facebook/react/issues/16728\n // Source can only be removed after all child layers are removed\n const allLayers = map.getStyle()?.layers;\n if (allLayers) {\n for (const layer of allLayers) {\n // @ts-ignore (2339) source does not exist on all layer types\n if (layer.source === id) {\n map.removeLayer(layer.id);\n }\n }\n }\n map.removeSource(id);\n }\n };\n }\n return undefined;\n }, [map]);\n\n // @ts-ignore\n let source = map && map.style && map.getSource(id);\n if (source) {\n updateSource(source, props, propsRef.current);\n } else {\n source = createSource(map, id, props);\n }\n propsRef.current = props;\n\n return (\n (source &&\n React.Children.map(\n props.children,\n child =>\n child &&\n cloneElement(child, {\n source: id\n })\n )) ||\n null\n );\n}\n\nexport default Source;\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAQC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,MAAM,QAAO,OAAO;AACtE,SAAQC,YAAY,QAAO,OAAO;AAAC,SAC3BC,UAAU;AAAA,OACXC,MAAM;AAAA,SACLC,SAAS;AAiBjB,IAAIC,aAAa,GAAG,CAAC;AAErB,SAASC,YAAYA,CACnBC,GAAgB,EAChBC,EAAU,EACVC,KAA2B,EAC3B;EAEA,IAAIF,GAAG,CAACG,KAAK,IAAIH,GAAG,CAACG,KAAK,CAACC,OAAO,EAAE;IAClC,MAAMC,OAAO,GAAG;MAAC,GAAGH;IAAK,CAAC;IAC1B,OAAOG,OAAO,CAACJ,EAAE;IACjB,OAAOI,OAAO,CAACC,QAAQ;IAEvBN,GAAG,CAACO,SAAS,CAACN,EAAE,EAAEI,OAAO,CAAC;IAC1B,OAAOL,GAAG,CAACQ,SAAS,CAACP,EAAE,CAAC;EAC1B;EACA,OAAO,IAAI;AACb;AAGA,SAASQ,YAAYA,CACnBC,MAA+B,EAC/BR,KAA2B,EAC3BS,SAA+B,EAC/B;EACAf,MAAM,CAACM,KAAK,CAACD,EAAE,KAAKU,SAAS,CAACV,EAAE,EAAE,mBAAmB,CAAC;EACtDL,MAAM,CAACM,KAAK,CAACU,IAAI,KAAKD,SAAS,CAACC,IAAI,EAAE,qBAAqB,CAAC;EAE5D,IAAIC,UAAU,GAAG,EAAE;EACnB,IAAIC,eAAe,GAAG,CAAC;EAEvB,KAAK,MAAMC,GAAG,IAAIb,KAAK,EAAE;IACvB,IAAIa,GAAG,KAAK,UAAU,IA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AO,CAAC;EAC/C,CAAC,MAAM;IACLjC,MAAM,GAAGX,YAAY,CAACC,GAAG,EAAEC,EAAE,EAAEC,KAAK,CAAC;EACvC;EACA2B,QAAQ,CAACc,OAAO,GAAGzC,KAAK;EAExB,OACGQ,MAAM,IACLtB,KAAK,CAACwD,QAAQ,CAAC5C,GAAG,CAChBE,KAAK,CAACI,QAAQ,EACduC,KAAK,IACHA,KAAK,IACLnD,YAAY,CAACmD,KAAK,EAAE;IAClBnC,MAAM,EAAET;EACV,CAAC,CACL,CAAC,IACH,IAAI;AAER;AAEA,eAAe0B,MAAM","ignoreList":[]}
1
+ {"version":3,"file":"source.js","names":["React","useContext","useEffect","useMemo","useState","useRef","cloneElement","MapContext","assert","deepEqual","sourceCounter","createSource","map","id","props","style","_loaded","options","children","addSource","getSource","updateSource","source","prevProps","type","changedKey","changedKeyCount","key","setData","data","updateImage","url","coordinates","setCoordinates","setUrl","setTiles","tiles","console","warn","Source","getMap","propsRef","setStyleLoaded","forceUpdate","setTimeout","version","on","off","allLayers","getStyle","layers","layer","removeLayer","removeSource","undefined","current","Children","child"],"sources":["../../src/components/source.ts"],"sourcesContent":["import * as React from \"react\";\nimport {\n useContext,\n useEffect,\n useMemo,\n useState,\n useRef,\n cloneElement,\n} from \"react\";\nimport { MapContext } from \"./map\";\nimport assert from \"../utils/assert\";\nimport { deepEqual } from \"../utils/deep-equal\";\n\nimport type {\n GeoJSONSourceImplementation,\n ImageSourceImplementation,\n AnySourceImplementation,\n} from \"../types/internal\";\nimport type { SourceSpecification } from \"../types/style-spec\";\nimport type { Map as MapInstance } from \"../types/lib\";\n\nexport type SourceProps = SourceSpecification & {\n id?: string;\n children?: any;\n};\n\nlet sourceCounter = 0;\n\nfunction createSource(map: MapInstance, id: string, props: SourceProps) {\n // @ts-ignore\n if (map.style && map.style._loaded) {\n const options = { ...props };\n delete options.id;\n delete options.children;\n // @ts-ignore\n map.addSource(id, options);\n return map.getSource(id);\n }\n return null;\n}\n\n/* eslint-disable complexity */\nfunction updateSource(\n source: AnySourceImplementation,\n props: SourceProps,\n prevProps: SourceProps,\n) {\n assert(props.id === prevProps.id, \"source id changed\");\n assert(props.type === prevProps.type, \"source type changed\");\n\n let changedKey = \"\";\n let changedKeyCount = 0;\n\n for (const key in props) {\n if (\n key !== \"children\" &&\n key !== \"id\" &&\n !deepEqual(prevProps[key], props[key])\n ) {\n changedKey = key;\n changedKeyCount++;\n }\n }\n\n if (!changedKeyCount) {\n return;\n }\n\n const type = props.type;\n\n if (type === \"geojson\") {\n (source as GeoJSONSourceImplementation).setData(props.data);\n } else if (type === \"image\") {\n (source as ImageSourceImplementation).updateImage({\n url: props.url,\n coordinates: props.coordinates,\n });\n } else {\n switch (changedKey) {\n case \"coordinates\":\n // @ts-ignore\n source.setCoordinates?.(props.coordinates);\n break;\n case \"url\":\n // @ts-ignore\n source.setUrl?.(props.url);\n break;\n case \"tiles\":\n // @ts-ignore\n source.setTiles?.(props.tiles);\n break;\n default:\n // eslint-disable-next-line\n console.warn(`Unable to update <Source> prop: ${changedKey}`);\n }\n }\n}\n/* eslint-enable complexity */\n\nexport function Source(props: SourceProps) {\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-source-${sourceCounter++}`, []);\n\n useEffect(() => {\n if (map) {\n /* global setTimeout */\n const forceUpdate = () =>\n setTimeout(() => setStyleLoaded((version) => version + 1), 0);\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.getSource(id)) {\n // Parent effects are destroyed before child ones, see\n // https://github.com/facebook/react/issues/16728\n // Source can only be removed after all child layers are removed\n const allLayers = map.getStyle()?.layers;\n if (allLayers) {\n for (const layer of allLayers) {\n // @ts-ignore (2339) source does not exist on all layer types\n if (layer.source === id) {\n map.removeLayer(layer.id);\n }\n }\n }\n map.removeSource(id);\n }\n };\n }\n return undefined;\n }, [map]);\n\n // @ts-ignore\n let source = map && map.style && map.getSource(id);\n if (source) {\n updateSource(source, props, propsRef.current);\n } else {\n source = createSource(map, id, props);\n }\n propsRef.current = props;\n\n return (\n (source &&\n React.Children.map(\n props.children,\n (child) =>\n child &&\n cloneElement(child, {\n source: id,\n }),\n )) ||\n null\n );\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SACEC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,YAAY,QACP,OAAO;AAAC,SACNC,UAAU;AAAA,OACZC,MAAM;AAAA,SACJC,SAAS;AAelB,IAAIC,aAAa,GAAG,CAAC;AAErB,SAASC,YAAYA,CAACC,GAAgB,EAAEC,EAAU,EAAEC,KAAkB,EAAE;EAEtE,IAAIF,GAAG,CAACG,KAAK,IAAIH,GAAG,CAACG,KAAK,CAACC,OAAO,EAAE;IAClC,MAAMC,OAAO,GAAG;MAAE,GAAGH;IAAM,CAAC;IAC5B,OAAOG,OAAO,CAACJ,EAAE;IACjB,OAAOI,OAAO,CAACC,QAAQ;IAEvBN,GAAG,CAACO,SAAS,CAACN,EAAE,EAAEI,OAAO,CAAC;IAC1B,OAAOL,GAAG,CAACQ,SAAS,CAACP,EAAE,CAAC;EAC1B;EACA,OAAO,IAAI;AACb;AAGA,SAASQ,YAAYA,CACnBC,MAA+B,EAC/BR,KAAkB,EAClBS,SAAsB,EACtB;EACAf,MAAM,CAACM,KAAK,CAACD,EAAE,KAAKU,SAAS,CAACV,EAAE,EAAE,mBAAmB,CAAC;EACtDL,MAAM,CAACM,KAAK,CAACU,IAAI,KAAKD,SAAS,CAACC,IAAI,EAAE,qBAAqB,CAAC;EAE5D,IAAIC,UAAU,GAAG,EAAE;EACnB,IAAIC,eAAe,GAAG,CAAC;EAEvB,KAAK,MAAMC,GAAG,IAAIb,KAAK,EAAE;IACvB,IACEa,GAAG,KAAK,UAAU,IAClBA,GAAG,KAA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GQ,MAAM,IACLtB,KAAK,CAACwD,QAAQ,CAAC5C,GAAG,CAChBE,KAAK,CAACI,QAAQ,EACbuC,KAAK,IACJA,KAAK,IACLnD,YAAY,CAACmD,KAAK,EAAE;IAClBnC,MAAM,EAAET;EACV,CAAC,CACL,CAAC,IACH,IAAI;AAER","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import * as React from "react";
2
+ import type { ControlPosition } from "../types/lib";
3
+ import type { TerrainSpecification } from "../types/style-spec";
4
+ export type TerrainControlProps = TerrainSpecification & {
5
+ /** Placement of the control relative to the map. */
6
+ position?: ControlPosition;
7
+ /** CSS style override, applied to the control's container */
8
+ style?: React.CSSProperties;
9
+ };
10
+ export declare const TerrainControl: React.FC<TerrainControlProps>;
@@ -0,0 +1,19 @@
1
+ import { useEffect, memo } from "react";
2
+ import { applyReactStyle } from "../utils/apply-react-style.js";
3
+ import { useControl } from "./use-control.js";
4
+ function _TerrainControl(props) {
5
+ const ctrl = useControl(_ref => {
6
+ let {
7
+ mapLib
8
+ } = _ref;
9
+ return new mapLib.TerrainControl(props);
10
+ }, {
11
+ position: props.position
12
+ });
13
+ useEffect(() => {
14
+ applyReactStyle(ctrl._container, props.style);
15
+ }, [props.style]);
16
+ return null;
17
+ }
18
+ export const TerrainControl = memo(_TerrainControl);
19
+ //# sourceMappingURL=terrain-control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terrain-control.js","names":["useEffect","memo","applyReactStyle","useControl","_TerrainControl","props","ctrl","_ref","mapLib","TerrainControl","position","_container","style"],"sources":["../../src/components/terrain-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 } from \"../types/lib\";\nimport type { TerrainSpecification } from \"../types/style-spec\";\n\nexport type TerrainControlProps = TerrainSpecification & {\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 _TerrainControl(props: TerrainControlProps) {\n const ctrl = useControl(({ mapLib }) => new mapLib.TerrainControl(props), {\n position: props.position,\n });\n\n useEffect(() => {\n applyReactStyle(ctrl._container, props.style);\n }, [props.style]);\n\n return null;\n}\n\nexport const TerrainControl: React.FC<TerrainControlProps> =\n memo(_TerrainControl);\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,IAAI,QAAQ,OAAO;AAAC,SAC/BC,eAAe;AAAA,SACfC,UAAU;AAYnB,SAASC,eAAeA,CAACC,KAA0B,EAAE;EACnD,MAAMC,IAAI,GAAGH,UAAU,CAACI,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OAAK,IAAIC,MAAM,CAACC,cAAc,CAACJ,KAAK,CAAC;EAAA,GAAE;IACxEK,QAAQ,EAAEL,KAAK,CAACK;EAClB,CAAC,CAAC;EAEFV,SAAS,CAAC,MAAM;IACdE,eAAe,CAACI,IAAI,CAACK,UAAU,EAAEN,KAAK,CAACO,KAAK,CAAC;EAC/C,CAAC,EAAE,CAACP,KAAK,CAACO,KAAK,CAAC,CAAC;EAEjB,OAAO,IAAI;AACb;AAEA,OAAO,MAAMH,cAA6C,GACxDR,IAAI,CAACG,eAAe,CAAC","ignoreList":[]}
@@ -1,9 +1,9 @@
1
- import type { IControl, ControlPosition } from '../types';
2
- import type { MapContextValue } from './map';
1
+ import type { IControl, ControlPosition } from "../types/lib";
2
+ import type { MapContextValue } from "./map";
3
3
  type ControlOptions = {
4
4
  position?: ControlPosition;
5
5
  };
6
- declare function useControl<T extends IControl>(onCreate: (context: MapContextValue) => T, opts?: ControlOptions): T;
7
- declare function useControl<T extends IControl>(onCreate: (context: MapContextValue) => T, onRemove: (context: MapContextValue) => void, opts?: ControlOptions): T;
8
- declare function useControl<T extends IControl>(onCreate: (context: MapContextValue) => T, onAdd: (context: MapContextValue) => void, onRemove: (context: MapContextValue) => void, opts?: ControlOptions): T;
9
- export default useControl;
6
+ export declare function useControl<T extends IControl>(onCreate: (context: MapContextValue) => T, opts?: ControlOptions): T;
7
+ export declare function useControl<T extends IControl>(onCreate: (context: MapContextValue) => T, onRemove: (context: MapContextValue) => void, opts?: ControlOptions): T;
8
+ export declare function useControl<T extends IControl>(onCreate: (context: MapContextValue) => T, onAdd: (context: MapContextValue) => void, onRemove: (context: MapContextValue) => void, opts?: ControlOptions): T;
9
+ export {};
@@ -1,12 +1,12 @@
1
- import { useContext, useMemo, useEffect } from 'react';
1
+ import { useContext, useMemo, useEffect } from "react";
2
2
  import { MapContext } from "./map.js";
3
- function useControl(onCreate, arg1, arg2, arg3) {
3
+ export function useControl(onCreate, arg1, arg2, arg3) {
4
4
  const context = useContext(MapContext);
5
5
  const ctrl = useMemo(() => onCreate(context), []);
6
6
  useEffect(() => {
7
7
  const opts = arg3 || arg2 || arg1;
8
- const onAdd = typeof arg1 === 'function' && typeof arg2 === 'function' ? arg1 : null;
9
- const onRemove = typeof arg2 === 'function' ? arg2 : typeof arg1 === 'function' ? arg1 : null;
8
+ const onAdd = typeof arg1 === "function" && typeof arg2 === "function" ? arg1 : null;
9
+ const onRemove = typeof arg2 === "function" ? arg2 : typeof arg1 === "function" ? arg1 : null;
10
10
  const {
11
11
  map
12
12
  } = context;
@@ -27,5 +27,4 @@ function useControl(onCreate, arg1, arg2, arg3) {
27
27
  }, []);
28
28
  return ctrl;
29
29
  }
30
- export default useControl;
31
30
  //# sourceMappingURL=use-control.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-control.js","names":["useContext","useMemo","useEffect","MapContext","useControl","onCreate","arg1","arg2","arg3","context","ctrl","opts","onAdd","onRemove","map","hasControl","addControl","position","removeControl"],"sources":["../../src/components/use-control.ts"],"sourcesContent":["import {useContext, useMemo, useEffect} from 'react';\nimport type {IControl, ControlPosition} from '../types';\nimport {MapContext} from './map';\nimport type {MapContextValue} from './map';\n\ntype ControlOptions = {\n position?: ControlPosition;\n};\n\nfunction useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n opts?: ControlOptions\n): T;\n\nfunction useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n onRemove: (context: MapContextValue) => void,\n opts?: ControlOptions\n): T;\n\nfunction useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n onAdd: (context: MapContextValue) => void,\n onRemove: (context: MapContextValue) => void,\n opts?: ControlOptions\n): T;\n\nfunction useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n arg1?: ((context: MapContextValue) => void) | ControlOptions,\n arg2?: ((context: MapContextValue) => void) | ControlOptions,\n arg3?: ControlOptions\n): T {\n const context = useContext(MapContext);\n const ctrl = useMemo(() => onCreate(context), []);\n\n useEffect(() => {\n const opts = (arg3 || arg2 || arg1) as ControlOptions;\n const onAdd = typeof arg1 === 'function' && typeof arg2 === 'function' ? arg1 : null;\n const onRemove = typeof arg2 === 'function' ? arg2 : typeof arg1 === 'function' ? arg1 : null;\n\n const {map} = context;\n if (!map.hasControl(ctrl)) {\n map.addControl(ctrl, opts?.position);\n if (onAdd) {\n onAdd(context);\n }\n }\n\n return () => {\n if (onRemove) {\n onRemove(context);\n }\n // Map might have been removed (parent effects are destroyed before child ones)\n if (map.hasControl(ctrl)) {\n map.removeControl(ctrl);\n }\n };\n }, []);\n\n return ctrl;\n}\n\nexport default useControl;\n"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,OAAO,EAAEC,SAAS,QAAO,OAAO;AAAC,SAE7CC,UAAU;AAyBlB,SAASC,UAAUA,CACjBC,QAAyC,EACzCC,IAA4D,EAC5DC,IAA4D,EAC5DC,IAAqB,EAClB;EACH,MAAMC,OAAO,GAAGT,UAAU,CAACG,UAAU,CAAC;EACtC,MAAMO,IAAI,GAAGT,OAAO,CAAC,MAAMI,QAAQ,CAACI,OAAO,CAAC,EAAE,EAAE,CAAC;EAEjDP,SAAS,CAAC,MAAM;IACd,MAAMS,IAAI,GAAIH,IAAI,IAAID,IAAI,IAAID,IAAuB;IACrD,MAAMM,KAAK,GAAG,OAAON,IAAI,KAAK,UAAU,IAAI,OAAOC,IAAI,KAAK,UAAU,GAAGD,IAAI,GAAG,IAAI;IACpF,MAAMO,QAAQ,GAAG,OAAON,IAAI,KAAK,UAAU,GAAGA,IAAI,GAAG,OAAOD,IAAI,KAAK,UAAU,GAAGA,IAAI,GAAG,IAAI;IAE7F,MAAM;MAACQ;IAAG,CAAC,GAAGL,OAAO;IACrB,IAAI,CAACK,GAAG,CAACC,UAAU,CAACL,IAAI,CAAC,EAAE;MACzBI,GAAG,CAACE,UAAU,CAACN,IAAI,EAAEC,IAAI,EAAEM,QAAQ,CAAC;MACpC,IAAIL,KAAK,EAAE;QACTA,KAAK,CAACH,OAAO,CAAC;MAChB;IACF;IAEA,OAAO,MAAM;MACX,IAAII,QAAQ,EAAE;QACZA,QAAQ,CAACJ,OAAO,CAAC;MACnB;MAEA,IAAIK,GAAG,CAACC,UAAU,CAACL,IAAI,CAAC,EAAE;QACxBI,GAAG,CAACI,aAAa,CAACR,IAAI,CAAC;MACzB;IACF,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOA,IAAI;AACb;AAEA,eAAeN,UAAU","ignoreList":[]}
1
+ {"version":3,"file":"use-control.js","names":["useContext","useMemo","useEffect","MapContext","useControl","onCreate","arg1","arg2","arg3","context","ctrl","opts","onAdd","onRemove","map","hasControl","addControl","position","removeControl"],"sources":["../../src/components/use-control.ts"],"sourcesContent":["import { useContext, useMemo, useEffect } from \"react\";\nimport type { IControl, ControlPosition } from \"../types/lib\";\nimport { MapContext } from \"./map\";\nimport type { MapContextValue } from \"./map\";\n\ntype ControlOptions = {\n position?: ControlPosition;\n};\n\nexport function useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n opts?: ControlOptions,\n): T;\n\nexport function useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n onRemove: (context: MapContextValue) => void,\n opts?: ControlOptions,\n): T;\n\nexport function useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n onAdd: (context: MapContextValue) => void,\n onRemove: (context: MapContextValue) => void,\n opts?: ControlOptions,\n): T;\n\nexport function useControl<T extends IControl>(\n onCreate: (context: MapContextValue) => T,\n arg1?: ((context: MapContextValue) => void) | ControlOptions,\n arg2?: ((context: MapContextValue) => void) | ControlOptions,\n arg3?: ControlOptions,\n): T {\n const context = useContext(MapContext);\n const ctrl = useMemo(() => onCreate(context), []);\n\n useEffect(() => {\n const opts = (arg3 || arg2 || arg1) as ControlOptions;\n const onAdd =\n typeof arg1 === \"function\" && typeof arg2 === \"function\" ? arg1 : null;\n const onRemove =\n typeof arg2 === \"function\"\n ? arg2\n : typeof arg1 === \"function\"\n ? arg1\n : null;\n\n const { map } = context;\n if (!map.hasControl(ctrl)) {\n map.addControl(ctrl, opts?.position);\n if (onAdd) {\n onAdd(context);\n }\n }\n\n return () => {\n if (onRemove) {\n onRemove(context);\n }\n // Map might have been removed (parent effects are destroyed before child ones)\n if (map.hasControl(ctrl)) {\n map.removeControl(ctrl);\n }\n };\n }, []);\n\n return ctrl;\n}\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,OAAO,EAAEC,SAAS,QAAQ,OAAO;AAAC,SAE9CC,UAAU;AAyBnB,OAAO,SAASC,UAAUA,CACxBC,QAAyC,EACzCC,IAA4D,EAC5DC,IAA4D,EAC5DC,IAAqB,EAClB;EACH,MAAMC,OAAO,GAAGT,UAAU,CAACG,UAAU,CAAC;EACtC,MAAMO,IAAI,GAAGT,OAAO,CAAC,MAAMI,QAAQ,CAACI,OAAO,CAAC,EAAE,EAAE,CAAC;EAEjDP,SAAS,CAAC,MAAM;IACd,MAAMS,IAAI,GAAIH,IAAI,IAAID,IAAI,IAAID,IAAuB;IACrD,MAAMM,KAAK,GACT,OAAON,IAAI,KAAK,UAAU,IAAI,OAAOC,IAAI,KAAK,UAAU,GAAGD,IAAI,GAAG,IAAI;IACxE,MAAMO,QAAQ,GACZ,OAAON,IAAI,KAAK,UAAU,GACtBA,IAAI,GACJ,OAAOD,IAAI,KAAK,UAAU,GAC1BA,IAAI,GACJ,IAAI;IAEV,MAAM;MAAEQ;IAAI,CAAC,GAAGL,OAAO;IACvB,IAAI,CAACK,GAAG,CAACC,UAAU,CAACL,IAAI,CAAC,EAAE;MACzBI,GAAG,CAACE,UAAU,CAACN,IAAI,EAAEC,IAAI,EAAEM,QAAQ,CAAC;MACpC,IAAIL,KAAK,EAAE;QACTA,KAAK,CAACH,OAAO,CAAC;MAChB;IACF;IAEA,OAAO,MAAM;MACX,IAAII,QAAQ,EAAE;QACZA,QAAQ,CAACJ,OAAO,CAAC;MACnB;MAEA,IAAIK,GAAG,CAACC,UAAU,CAACL,IAAI,CAAC,EAAE;QACxBI,GAAG,CAACI,aAAa,CAACR,IAAI,CAAC;MACzB;IACF,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOA,IAAI;AACb","ignoreList":[]}
@@ -1,20 +1,19 @@
1
- import * as React from 'react';
2
- import { MapRef } from '../mapbox/create-ref';
3
- import { MapInstance } from '../types';
1
+ import * as React from "react";
2
+ import { MapRef } from "../maplibre/create-ref";
4
3
  type MountedMapsContextValue = {
5
4
  maps: {
6
- [id: string]: MapRef<MapInstance>;
5
+ [id: string]: MapRef;
7
6
  };
8
- onMapMount: (map: MapRef<MapInstance>, id: string) => void;
7
+ onMapMount: (map: MapRef, id: string) => void;
9
8
  onMapUnmount: (id: string) => void;
10
9
  };
11
10
  export declare const MountedMapsContext: React.Context<MountedMapsContextValue>;
12
11
  export declare const MapProvider: React.FC<{
13
12
  children?: React.ReactNode;
14
13
  }>;
15
- export type MapCollection<MapT extends MapInstance> = {
16
- [id: string]: MapRef<MapT> | undefined;
17
- current?: MapRef<MapT>;
14
+ export type MapCollection = {
15
+ [id: string]: MapRef | undefined;
16
+ current?: MapRef;
18
17
  };
19
- export declare function useMap<MapT extends MapInstance>(): MapCollection<MapT>;
18
+ export declare function useMap(): MapCollection;
20
19
  export {};
@@ -1,13 +1,13 @@
1
- import * as React from 'react';
2
- import { useState, useCallback, useMemo, useContext } from 'react';
1
+ import * as React from "react";
2
+ import { useState, useCallback, useMemo, useContext } from "react";
3
3
  import { MapContext } from "./map.js";
4
4
  export const MountedMapsContext = React.createContext(null);
5
5
  export const MapProvider = props => {
6
6
  const [maps, setMaps] = useState({});
7
7
  const onMapMount = useCallback(function (map) {
8
- let id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
8
+ let id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "default";
9
9
  setMaps(currMaps => {
10
- if (id === 'current') {
10
+ if (id === "current") {
11
11
  throw new Error("'current' cannot be used as map id");
12
12
  }
13
13
  if (currMaps[id]) {
@@ -20,7 +20,7 @@ export const MapProvider = props => {
20
20
  });
21
21
  }, []);
22
22
  const onMapUnmount = useCallback(function () {
23
- let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
23
+ let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
24
24
  setMaps(currMaps => {
25
25
  if (currMaps[id]) {
26
26
  const nextMaps = {
@@ -1 +1 @@
1
- {"version":3,"file":"use-map.js","names":["React","useState","useCallback","useMemo","useContext","MapContext","MountedMapsContext","createContext","MapProvider","props","maps","setMaps","onMapMount","map","id","arguments","length","undefined","currMaps","Error","onMapUnmount","nextMaps","createElement","Provider","value","children","useMap","currentMap","mapsWithCurrent","current"],"sources":["../../src/components/use-map.tsx"],"sourcesContent":["import * as React from 'react';\nimport {useState, useCallback, useMemo, useContext} from 'react';\n\nimport {MapRef} from '../mapbox/create-ref';\nimport {MapContext} from './map';\nimport {MapInstance} from '../types';\n\ntype MountedMapsContextValue = {\n maps: {[id: string]: MapRef<MapInstance>};\n onMapMount: (map: MapRef<MapInstance>, id: string) => void;\n onMapUnmount: (id: string) => void;\n};\n\nexport const MountedMapsContext = React.createContext<MountedMapsContextValue>(null);\n\nexport const MapProvider: React.FC<{children?: React.ReactNode}> = props => {\n const [maps, setMaps] = useState<{[id: string]: MapRef<MapInstance>}>({});\n\n const onMapMount = useCallback((map: MapRef<MapInstance>, id: string = 'default') => {\n setMaps(currMaps => {\n if (id === 'current') {\n throw new Error(\"'current' cannot be used as map id\");\n }\n if (currMaps[id]) {\n throw new Error(`Multiple maps with the same id: ${id}`);\n }\n return {...currMaps, [id]: map};\n });\n }, []);\n\n const onMapUnmount = useCallback((id: string = 'default') => {\n setMaps(currMaps => {\n if (currMaps[id]) {\n const nextMaps = {...currMaps};\n delete nextMaps[id];\n return nextMaps;\n }\n return currMaps;\n });\n }, []);\n\n return (\n <MountedMapsContext.Provider\n value={{\n maps,\n onMapMount,\n onMapUnmount\n }}\n >\n {props.children}\n </MountedMapsContext.Provider>\n );\n};\n\nexport type MapCollection<MapT extends MapInstance> = {\n [id: string]: MapRef<MapT> | undefined;\n current?: MapRef<MapT>;\n};\n\nexport function useMap<MapT extends MapInstance>(): MapCollection<MapT> {\n const maps = useContext(MountedMapsContext)?.maps;\n const currentMap = useContext(MapContext);\n\n const mapsWithCurrent = useMemo(() => {\n return {...maps, current: currentMap?.map};\n }, [maps, currentMap]);\n\n return mapsWithCurrent as MapCollection<MapT>;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAQC,QAAQ,EAAEC,WAAW,EAAEC,OAAO,EAAEC,UAAU,QAAO,OAAO;AAAC,SAGzDC,UAAU;AASlB,OAAO,MAAMC,kBAAkB,GAAGN,KAAK,CAACO,aAAa,CAA0B,IAAI,CAAC;AAEpF,OAAO,MAAMC,WAAmD,GAAGC,KAAK,IAAI;EAC1E,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGV,QAAQ,CAAsC,CAAC,CAAC,CAAC;EAEzE,MAAMW,UAAU,GAAGV,WAAW,CAAC,UAACW,GAAwB,EAA6B;IAAA,IAA3BC,EAAU,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,SA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AC,EAAE,CAACH,IAAI,EAAEiB,UAAU,CAAC,CAAC;EAEtB,OAAOC,eAAe;AACxB","ignoreList":[]}
1
+ {"version":3,"file":"use-map.js","names":["React","useState","useCallback","useMemo","useContext","MapContext","MountedMapsContext","createContext","MapProvider","props","maps","setMaps","onMapMount","map","id","arguments","length","undefined","currMaps","Error","onMapUnmount","nextMaps","createElement","Provider","value","children","useMap","currentMap","mapsWithCurrent","current"],"sources":["../../src/components/use-map.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { useState, useCallback, useMemo, useContext } from \"react\";\n\nimport { MapRef } from \"../maplibre/create-ref\";\nimport { MapContext } from \"./map\";\n\ntype MountedMapsContextValue = {\n maps: { [id: string]: MapRef };\n onMapMount: (map: MapRef, id: string) => void;\n onMapUnmount: (id: string) => void;\n};\n\nexport const MountedMapsContext =\n React.createContext<MountedMapsContextValue>(null);\n\nexport const MapProvider: React.FC<{ children?: React.ReactNode }> = (\n props,\n) => {\n const [maps, setMaps] = useState<{ [id: string]: MapRef }>({});\n\n const onMapMount = useCallback((map: MapRef, id: string = \"default\") => {\n setMaps((currMaps) => {\n if (id === \"current\") {\n throw new Error(\"'current' cannot be used as map id\");\n }\n if (currMaps[id]) {\n throw new Error(`Multiple maps with the same id: ${id}`);\n }\n return { ...currMaps, [id]: map };\n });\n }, []);\n\n const onMapUnmount = useCallback((id: string = \"default\") => {\n setMaps((currMaps) => {\n if (currMaps[id]) {\n const nextMaps = { ...currMaps };\n delete nextMaps[id];\n return nextMaps;\n }\n return currMaps;\n });\n }, []);\n\n return (\n <MountedMapsContext.Provider\n value={{\n maps,\n onMapMount,\n onMapUnmount,\n }}\n >\n {props.children}\n </MountedMapsContext.Provider>\n );\n};\n\nexport type MapCollection = {\n [id: string]: MapRef | undefined;\n current?: MapRef;\n};\n\nexport function useMap(): MapCollection {\n const maps = useContext(MountedMapsContext)?.maps;\n const currentMap = useContext(MapContext);\n\n const mapsWithCurrent = useMemo(() => {\n return { ...maps, current: currentMap?.map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QAAQ;MACjB;MACA,OAAOH,QAAQ;IACjB,CAAC,CAAC;EACJ,CAAC,EAAE,EAAE,CAAC;EAEN,OACElB,KAAA,CAAAsB,aAAA,CAAChB,kBAAkB,CAACiB,QAAQ;IAC1BC,KAAK,EAAE;MACLd,IAAI;MACJE,UAAU;MACVQ;IACF;EAAE,GAEDX,KAAK,CAACgB,QACoB,CAAC;AAElC,CAAC;AAOD,OAAO,SAASC,MAAMA,CAAA,EAAkB;EACtC,MAAMhB,IAAI,GAAGN,UAAU,CAACE,kBAAkB,CAAC,EAAEI,IAAI;EACjD,MAAMiB,UAAU,GAAGvB,UAAU,CAACC,UAAU,CAAC;EAEzC,MAAMuB,eAAe,GAAGzB,OAAO,CAAC,MAAM;IACpC,OAAO;MAAE,GAAGO,IAAI;MAAEmB,OAAO,EAAEF,UAAU,EAAEd;IAAI,CAAC;EAC9C,CAAC,EAAE,CAACH,IAAI,EAAEiB,UAAU,CAAC,CAAC;EAEtB,OAAOC,eAAe;AACxB","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ import { Map } from "./components/map";
2
+ export { Map };
3
+ export default Map;
4
+ export { Marker } from "./components/marker";
5
+ export { Popup } from "./components/popup";
6
+ export { AttributionControl } from "./components/attribution-control";
7
+ export { FullscreenControl } from "./components/fullscreen-control";
8
+ export { GeolocateControl } from "./components/geolocate-control";
9
+ export { NavigationControl } from "./components/navigation-control";
10
+ export { ScaleControl } from "./components/scale-control";
11
+ export { TerrainControl } from "./components/terrain-control";
12
+ export { LogoControl } from "./components/logo-control";
13
+ export { Source } from "./components/source";
14
+ export { Layer } from "./components/layer";
15
+ export { useControl } from "./components/use-control";
16
+ export { MapProvider, useMap } from "./components/use-map";
17
+ export type { MapProps } from "./components/map";
18
+ export type { MapRef } from "./maplibre/create-ref";
19
+ export type { MarkerProps } from "./components/marker";
20
+ export type { PopupProps } from "./components/popup";
21
+ export type { AttributionControlProps } from "./components/attribution-control";
22
+ export type { FullscreenControlProps } from "./components/fullscreen-control";
23
+ export type { GeolocateControlProps } from "./components/geolocate-control";
24
+ export type { NavigationControlProps } from "./components/navigation-control";
25
+ export type { ScaleControlProps } from "./components/scale-control";
26
+ export type { TerrainControlProps } from "./components/terrain-control";
27
+ export type { LogoControlProps } from "./components/logo-control";
28
+ export type { SourceProps } from "./components/source";
29
+ export type { LayerProps } from "./components/layer";
30
+ export * from "./types/common";
31
+ export * from "./types/events";
32
+ export * from "./types/lib";
33
+ export * from "./types/style-spec";
@@ -0,0 +1,21 @@
1
+ import { Map } from "./components/map.js";
2
+ export { Map };
3
+ export default Map;
4
+ export { Marker } from "./components/marker.js";
5
+ export { Popup } from "./components/popup.js";
6
+ export { AttributionControl } from "./components/attribution-control.js";
7
+ export { FullscreenControl } from "./components/fullscreen-control.js";
8
+ export { GeolocateControl } from "./components/geolocate-control.js";
9
+ export { NavigationControl } from "./components/navigation-control.js";
10
+ export { ScaleControl } from "./components/scale-control.js";
11
+ export { TerrainControl } from "./components/terrain-control.js";
12
+ export { LogoControl } from "./components/logo-control.js";
13
+ export { Source } from "./components/source.js";
14
+ export { Layer } from "./components/layer.js";
15
+ export { useControl } from "./components/use-control.js";
16
+ export { MapProvider, useMap } from "./components/use-map.js";
17
+ export * from "./types/common.js";
18
+ export * from "./types/events.js";
19
+ export * from "./types/lib.js";
20
+ export * from "./types/style-spec.js";
21
+ //# sourceMappingURL=exports-maplibre-gl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports-maplibre-gl.js","names":["Map","Marker","Popup","AttributionControl","FullscreenControl","GeolocateControl","NavigationControl","ScaleControl","TerrainControl","LogoControl","Source","Layer","useControl","MapProvider","useMap"],"sources":["../src/exports-maplibre-gl.ts"],"sourcesContent":["import { Map } from \"./components/map\";\nexport { Map };\nexport default Map;\n\nexport { Marker } from \"./components/marker\";\nexport { Popup } from \"./components/popup\";\nexport { AttributionControl } from \"./components/attribution-control\";\nexport { FullscreenControl } from \"./components/fullscreen-control\";\nexport { GeolocateControl } from \"./components/geolocate-control\";\nexport { NavigationControl } from \"./components/navigation-control\";\nexport { ScaleControl } from \"./components/scale-control\";\nexport { TerrainControl } from \"./components/terrain-control\";\nexport { LogoControl } from \"./components/logo-control\";\nexport { Source } from \"./components/source\";\nexport { Layer } from \"./components/layer\";\nexport { useControl } from \"./components/use-control\";\nexport { MapProvider, useMap } from \"./components/use-map\";\n\nexport type { MapProps } from \"./components/map\";\nexport type { MapRef } from \"./maplibre/create-ref\";\nexport type { MarkerProps } from \"./components/marker\";\nexport type { PopupProps } from \"./components/popup\";\nexport type { AttributionControlProps } from \"./components/attribution-control\";\nexport type { FullscreenControlProps } from \"./components/fullscreen-control\";\nexport type { GeolocateControlProps } from \"./components/geolocate-control\";\nexport type { NavigationControlProps } from \"./components/navigation-control\";\nexport type { ScaleControlProps } from \"./components/scale-control\";\nexport type { TerrainControlProps } from \"./components/terrain-control\";\nexport type { LogoControlProps } from \"./components/logo-control\";\nexport type { SourceProps } from \"./components/source\";\nexport type { LayerProps } from \"./components/layer\";\n\n// Types\nexport * from \"./types/common\";\nexport * from \"./types/events\";\nexport * from \"./types/lib\";\nexport * from \"./types/style-spec\";\n"],"mappings":"SAASA,GAAG;AACZ,SAASA,GAAG;AACZ,eAAeA,GAAG;AAAC,SAEVC,MAAM;AAAA,SACNC,KAAK;AAAA,SACLC,kBAAkB;AAAA,SAClBC,iBAAiB;AAAA,SACjBC,gBAAgB;AAAA,SAChBC,iBAAiB;AAAA,SACjBC,YAAY;AAAA,SACZC,cAAc;AAAA,SACdC,WAAW;AAAA,SACXC,MAAM;AAAA,SACNC,KAAK;AAAA,SACLC,UAAU;AAAA,SACVC,WAAW,EAAEC,MAAM;AAAA;AAAA;AAAA;AAAA","ignoreList":[]}