@longline/aqua-ui 1.0.339 → 1.0.340

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 (251) hide show
  1. package/containers/Anchor/Anchor.d.ts +5 -0
  2. package/containers/Anchor/Anchor.js +20 -8
  3. package/containers/Dock/Dock.d.ts +5 -0
  4. package/containers/Dock/Dock.js +1 -1
  5. package/containers/Dock/Dockable.d.ts +5 -0
  6. package/containers/Dock/Dockable.js +20 -12
  7. package/containers/DragBar/DragBar.d.ts +5 -0
  8. package/containers/DragBar/DragBar.js +16 -5
  9. package/containers/Form/Field.d.ts +0 -3
  10. package/containers/Form/Field.js +3 -6
  11. package/containers/Form/Form.js +5 -36
  12. package/containers/Form/Validation.d.ts +1 -1
  13. package/containers/Form/Validation.js +6 -6
  14. package/containers/Form/context/FormContext.d.ts +1 -2
  15. package/containers/Form/context/useForm.d.ts +1 -1
  16. package/containers/Form/elements/BoxWrapper.js +2 -0
  17. package/containers/GlassPane/GlassPane.d.ts +7 -2
  18. package/containers/GlassPane/GlassPane.js +3 -3
  19. package/containers/InfoBox/InfoBox.d.ts +5 -0
  20. package/containers/InfoBox/InfoBox.js +1 -1
  21. package/containers/List/List.d.ts +5 -0
  22. package/containers/List/List.js +1 -1
  23. package/containers/List/ListCell.d.ts +5 -0
  24. package/containers/List/ListCell.js +1 -1
  25. package/containers/List/ListRow.d.ts +7 -2
  26. package/containers/List/ListRow.js +1 -1
  27. package/containers/Message/Error.d.ts +2 -0
  28. package/containers/Message/Error.js +1 -1
  29. package/containers/Message/Message.d.ts +5 -0
  30. package/containers/Message/Message.js +1 -1
  31. package/containers/Message/NoData.d.ts +2 -0
  32. package/containers/Message/NoData.js +1 -1
  33. package/containers/Message/NoFilteredData.d.ts +2 -0
  34. package/containers/Message/NoFilteredData.js +1 -1
  35. package/containers/Openable/Openable.d.ts +5 -0
  36. package/containers/Openable/Openable.js +8 -8
  37. package/containers/PublicRoute/PublicRoute.d.ts +9 -1
  38. package/containers/PublicRoute/PublicRoute.js +3 -7
  39. package/containers/Tabs/Pane.d.ts +5 -0
  40. package/containers/Tabs/Pane.js +3 -3
  41. package/containers/Tabs/Tabs.d.ts +5 -0
  42. package/containers/Tabs/Tabs.js +3 -3
  43. package/controls/Chip/Chip.d.ts +15 -3
  44. package/controls/Chip/Chip.js +7 -6
  45. package/controls/CircularProgress/CircularProgress.d.ts +11 -0
  46. package/controls/CircularProgress/CircularProgress.js +19 -11
  47. package/controls/Dropzone/Dropzone.d.ts +11 -1
  48. package/controls/Dropzone/Dropzone.js +18 -7
  49. package/controls/Fab/Fab.d.ts +14 -6
  50. package/controls/Fab/Fab.js +7 -20
  51. package/controls/Ghost/Ghost.js +3 -3
  52. package/controls/Gradient/Gradient.d.ts +5 -0
  53. package/controls/Gradient/Gradient.js +7 -4
  54. package/controls/Histogram/Histogram.d.ts +8 -2
  55. package/controls/Histogram/Histogram.js +9 -9
  56. package/controls/Histogram/HistogramBar.d.ts +2 -2
  57. package/controls/Icon/Icon.d.ts +10 -4
  58. package/controls/Icon/Icon.js +23 -6
  59. package/controls/Key/Key.d.ts +5 -0
  60. package/controls/Key/Key.js +2 -5
  61. package/controls/LinearChart/LinearChart.d.ts +9 -0
  62. package/controls/LinearChart/LinearChart.js +11 -6
  63. package/controls/ListButton/ListButton.d.ts +46 -3
  64. package/controls/ListButton/ListButton.js +70 -9
  65. package/controls/ListView/ColumnsManager/ColumnDraggable.js +11 -5
  66. package/controls/ListView/ColumnsManager/SourceColumns.js +1 -1
  67. package/controls/ListView/IListViewProps.d.ts +9 -2
  68. package/controls/ListView/ListView.js +13 -12
  69. package/controls/ListView/defaults.d.ts +3 -0
  70. package/controls/ListView/defaults.js +6 -0
  71. package/controls/ListView/elements/Body.d.ts +1 -1
  72. package/controls/ListView/elements/Body.js +23 -12
  73. package/controls/ListView/elements/Ghost.js +3 -2
  74. package/controls/ListView/elements/Header.js +3 -2
  75. package/controls/ListView/elements/HeaderCell.js +3 -3
  76. package/controls/ListView/elements/Table.js +16 -10
  77. package/controls/Mouse/Mouse.d.ts +6 -4
  78. package/controls/Mouse/Mouse.js +15 -8
  79. package/controls/PrimaryButton/PrimaryButton.d.ts +9 -3
  80. package/controls/PrimaryButton/PrimaryButton.js +5 -5
  81. package/controls/Progress/Progress.d.ts +9 -0
  82. package/controls/Progress/Progress.js +12 -8
  83. package/controls/SecondaryButton/SecondaryButton.d.ts +8 -3
  84. package/controls/SecondaryButton/SecondaryButton.js +1 -1
  85. package/controls/SpeechRecognizer/EditorRegistry.js +1 -2
  86. package/controls/SpeechRecognizer/SpeechRecognizer.d.ts +9 -1
  87. package/controls/SpeechRecognizer/SpeechRecognizer.js +16 -9
  88. package/controls/TabBar/TabBar.d.ts +5 -0
  89. package/controls/TabBar/TabBar.js +14 -6
  90. package/controls/TabBar/Underliner.js +1 -1
  91. package/controls/TertiaryButton/TertiaryButton.d.ts +9 -3
  92. package/controls/TertiaryButton/TertiaryButton.js +5 -3
  93. package/controls/ToggleButton/ToggleButton.d.ts +8 -2
  94. package/controls/ToggleButton/ToggleButton.js +1 -1
  95. package/controls/View/View.d.ts +5 -0
  96. package/controls/View/View.js +1 -1
  97. package/formatters/CountryFormatter/CountryFormatter.d.ts +3 -2
  98. package/formatters/CountryFormatter/CountryUtil.d.ts +3 -3
  99. package/formatters/DateTimeFormatter/DateTimeFormatter.d.ts +11 -10
  100. package/formatters/DateTimeFormatter/elements/Custom.d.ts +1 -1
  101. package/formatters/DateTimeFormatter/elements/DistanceDate.d.ts +1 -1
  102. package/formatters/DateTimeFormatter/elements/LongDate.d.ts +1 -1
  103. package/formatters/DateTimeFormatter/elements/LongDateTime.d.ts +1 -1
  104. package/formatters/DateTimeFormatter/elements/LongTime.d.ts +1 -1
  105. package/formatters/DateTimeFormatter/elements/Month.d.ts +1 -1
  106. package/formatters/DateTimeFormatter/elements/ShortDate.d.ts +1 -1
  107. package/formatters/DateTimeFormatter/elements/ShortDateTime.d.ts +1 -1
  108. package/formatters/DateTimeFormatter/elements/ShortTime.d.ts +1 -1
  109. package/formatters/DivisionFormatter/DivisionFormatter.d.ts +2 -2
  110. package/formatters/DivisionFormatter/DivisionFormatter.js +1 -1
  111. package/formatters/DivisionFormatter/DivisionUtil.d.ts +1 -1
  112. package/formatters/DivisionFormatter/DivisionUtil.js +5 -3
  113. package/formatters/FilesizeFormatter/FilesizeFormatter.d.ts +3 -3
  114. package/formatters/GIS/CoordinateFormatter.d.ts +2 -2
  115. package/formatters/GIS/LatitudeFormatter.d.ts +2 -2
  116. package/formatters/GIS/LongitudeFormatter.d.ts +2 -2
  117. package/formatters/HumanFormatter/HumanFormatter.d.ts +3 -3
  118. package/formatters/NumberFormatter/NumberFormatter.d.ts +3 -3
  119. package/formatters/PhoneFormatter/PhoneFormatter.d.ts +3 -3
  120. package/formatters/StringFormatter/StringFormatter.d.ts +3 -3
  121. package/formatters/StringFormatter/StringFormatter.js +1 -4
  122. package/helper/DMS.d.ts +1 -1
  123. package/helper/DMS.js +2 -2
  124. package/hooks/useOutsideClose/useOutsideClose.js +20 -11
  125. package/hooks/useSpeechAIRecorder/useSpeechAIRecorder.js +10 -7
  126. package/index.js +1 -0
  127. package/inputs/DateInput/Body.d.ts +2 -2
  128. package/inputs/DateInput/Body.js +11 -7
  129. package/inputs/DateInput/Calendar.d.ts +1 -1
  130. package/inputs/DateInput/Calendar.js +3 -5
  131. package/inputs/DateInput/DateInput.d.ts +11 -3
  132. package/inputs/DateInput/DateInput.js +11 -3
  133. package/inputs/DateInput/Day.d.ts +1 -1
  134. package/inputs/DateInput/InfiniteList.js +6 -3
  135. package/inputs/DateInput/Navbar.js +3 -2
  136. package/inputs/DateInput/NumericInput.js +3 -0
  137. package/inputs/DateInput/Selector.d.ts +1 -1
  138. package/inputs/DateInput/Selector.js +9 -6
  139. package/inputs/Dropdown/Body.d.ts +2 -2
  140. package/inputs/Dropdown/Column.d.ts +1 -1
  141. package/inputs/Dropdown/Dropdown.d.ts +5 -0
  142. package/inputs/Dropdown/Dropdown.js +36 -63
  143. package/inputs/Dropdown/Pill.js +1 -1
  144. package/inputs/Dropdown/Selection.js +1 -1
  145. package/inputs/Editor/Editor.d.ts +5 -0
  146. package/inputs/Editor/Editor.js +16 -6
  147. package/inputs/Editor/buttons/SpeechAIButton.js +2 -0
  148. package/inputs/Editor/buttons/TextAIButton.d.ts +0 -13
  149. package/inputs/Editor/buttons/TextAIButton.js +30 -14
  150. package/inputs/Editor/buttons/TextAIMenu.js +1 -1
  151. package/inputs/Editor/menu/MenuBar.d.ts +1 -1
  152. package/inputs/Editor/menu/MenuBar.js +1 -1
  153. package/inputs/Editor/menu/MenuButton.js +1 -1
  154. package/inputs/Input/Clear.js +1 -1
  155. package/inputs/Input/Input.d.ts +5 -0
  156. package/inputs/Input/Input.js +8 -6
  157. package/inputs/Input/InputWrapper.d.ts +2 -0
  158. package/inputs/Input/InputWrapper.js +1 -1
  159. package/inputs/Input/Reveal.js +1 -1
  160. package/inputs/MonthRange/Body.d.ts +1 -1
  161. package/inputs/MonthRange/Calendar.d.ts +2 -2
  162. package/inputs/MonthRange/Calendar.js +6 -9
  163. package/inputs/MonthRange/MonthRange.d.ts +7 -1
  164. package/inputs/MonthRange/MonthRange.js +14 -6
  165. package/inputs/MonthRange/Selector.d.ts +1 -1
  166. package/inputs/MonthRange/Selector.js +12 -11
  167. package/inputs/PhoneInput/PhoneInput.d.ts +5 -0
  168. package/inputs/PhoneInput/PhoneInput.js +2 -2
  169. package/inputs/Selector/Selector.d.ts +5 -0
  170. package/inputs/Selector/Selector.js +4 -1
  171. package/inputs/Slider/Slider.d.ts +75 -22
  172. package/inputs/Slider/Slider.js +104 -22
  173. package/inputs/Textarea/Textarea.d.ts +5 -5
  174. package/inputs/Textarea/Textarea.js +3 -2
  175. package/map/Map/Map.d.ts +2 -2
  176. package/map/Map/Map.js +20 -14
  177. package/map/PositionsManager/PositionBox.js +7 -3
  178. package/map/PositionsManager/PositionsManager.js +33 -13
  179. package/map/controls/CompassButton/CompassButton.js +1 -1
  180. package/map/controls/FullscreenButton/FullscreenButton.js +1 -1
  181. package/map/controls/Geocoder/Geocoder.js +28 -14
  182. package/map/controls/Geocoder/GeocoderApi.js +2 -0
  183. package/map/controls/Geocoder/GeocoderSelector.js +1 -1
  184. package/map/controls/Graticule/Graticule.js +1 -5
  185. package/map/controls/MapLoader/MapLoader.js +1 -1
  186. package/map/controls/ScaleControl/ScaleControl.js +1 -1
  187. package/map/controls/ZoomInButton/ZoomInButton.js +1 -1
  188. package/map/controls/ZoomOutButton/ZoomOutButton.d.ts +1 -1
  189. package/map/controls/ZoomOutButton/ZoomOutButton.js +2 -2
  190. package/map/controls/base/MapButton/MapButton.d.ts +8 -2
  191. package/map/controls/base/MapButton/MapButton.js +11 -2
  192. package/map/controls/base/MapControl/MapControl.d.ts +5 -0
  193. package/map/controls/base/MapControl/MapControl.js +10 -7
  194. package/map/layers/ClusterLayer/ClusterLayer.d.ts +1 -1
  195. package/map/layers/ClusterLayer/ClusterLayer.js +7 -3
  196. package/map/layers/HtmlMarkerLayer/HtmlMarkerLayer.js +8 -4
  197. package/map/layers/IdwBlendLayer/IdwBlendLayer.js +9 -4
  198. package/map/layers/IdwLayer/IdwLayer.d.ts +2 -1
  199. package/map/layers/IdwLayer/IdwLayer.js +271 -215
  200. package/map/layers/InterpolationLayer/ContoursFragmentShader.d.ts +1 -1
  201. package/map/layers/InterpolationLayer/ContoursFragmentShader.js +1 -1
  202. package/map/layers/InterpolationLayer/InterpolationLayer.d.ts +4 -3
  203. package/map/layers/InterpolationLayer/InterpolationLayer.js +362 -275
  204. package/map/layers/ParticlesLayer/ParticlesLayer.d.ts +8 -7
  205. package/map/layers/ParticlesLayer/ParticlesLayer.js +528 -404
  206. package/map/markers/ClusterMarker/ClusterMarker.d.ts +6 -1
  207. package/map/markers/ClusterMarker/ClusterMarker.js +15 -6
  208. package/map/markers/RiskMarker/RiskMarker.d.ts +5 -1
  209. package/map/markers/RiskMarker/RiskMarker.js +4 -4
  210. package/modules/CountryDropdown/CountryDropdown.js +10 -1
  211. package/modules/Filter/Filter.d.ts +5 -0
  212. package/modules/Filter/Filter.js +10 -6
  213. package/modules/Globe/Globe.d.ts +5 -0
  214. package/modules/Globe/Globe.js +4 -4
  215. package/modules/MainMenu/Item.d.ts +9 -2
  216. package/modules/MainMenu/Item.js +8 -5
  217. package/modules/MainMenu/MainMenu.d.ts +5 -0
  218. package/modules/MainMenu/MainMenu.js +1 -1
  219. package/modules/ParticleGlobe/GL.d.ts +1 -1
  220. package/modules/ParticleGlobe/ParticleGlobe.d.ts +5 -0
  221. package/modules/ParticleGlobe/ParticleGlobe.js +69 -40
  222. package/modules/Public/Public.d.ts +5 -0
  223. package/modules/Public/Public.js +3 -3
  224. package/package.json +1 -1
  225. package/services/Auth/Auth.js +13 -7
  226. package/services/Auth/AuthContext.js +9 -1
  227. package/services/Dialog/Dialog.d.ts +7 -2
  228. package/services/Dialog/Dialog.js +7 -6
  229. package/services/Dialog/DialogWindow.d.ts +3 -1
  230. package/services/Dialog/DialogWindow.js +1 -1
  231. package/services/Dialog/XhrDialog.d.ts +1 -1
  232. package/services/Toast/Toast.js +5 -3
  233. package/services/Toast/ToastContainer.js +3 -1
  234. package/services/Toast/ToastContext.d.ts +1 -1
  235. package/services/Toast/ToastProvider.js +2 -0
  236. package/map/layers/HtmlMarkerLayer/HtmlMarkerLayer copy.d.ts +0 -35
  237. package/map/layers/HtmlMarkerLayer/HtmlMarkerLayer copy.js +0 -176
  238. package/modules/Root/Content.d.ts +0 -16
  239. package/modules/Root/Content.js +0 -25
  240. package/modules/Root/Overlay.d.ts +0 -23
  241. package/modules/Root/Overlay.js +0 -33
  242. package/modules/Root/Root.d.ts +0 -10
  243. package/modules/Root/Root.js +0 -46
  244. package/modules/Root/Shader.d.ts +0 -15
  245. package/modules/Root/Shader.js +0 -24
  246. package/modules/Root/Sidebar.d.ts +0 -13
  247. package/modules/Root/Sidebar.js +0 -24
  248. package/modules/Root/index.d.ts +0 -1
  249. package/modules/Root/index.js +0 -1
  250. package/modules/Root/stories/SampleContent.d.ts +0 -7
  251. package/modules/Root/stories/SampleContent.js +0 -44
@@ -38,224 +38,280 @@ import { RgbColor } from '../../../helper/RgbColor';
38
38
  import { PresetGradients } from '../../../controls/Gradient';
39
39
  import { CopyVertexShader } from './CopyVertexShader';
40
40
  import { CopyFragmentShader } from './CopyFragmentShader';
41
+ // Default prop values, referenced both by the IdwLayerBase fallbacks and the
42
+ // IdwLayer wrapper below.
43
+ var DEFAULT_MIN_ZOOM = 0;
44
+ var DEFAULT_MAX_ZOOM = 99;
45
+ var DEFAULT_MAX_DISTANCE = 0.0002;
46
+ var DEFAULT_FADE_FRACTION = 0.15;
47
+ var DEFAULT_RESOLUTION = 256;
48
+ //
49
+ // Convert a hex color (e.g. #ff0022) to an [r,g,b,a] array,
50
+ // where r,g,b,a are in the 0.0-1.0 range.
51
+ //
52
+ var colorToRGBA = function (color) {
53
+ var rgb = RgbColor.FromString(color);
54
+ return [rgb.red / 255.0, rgb.green / 255.0, rgb.blue / 255.0, rgb.alpha];
55
+ };
56
+ //
57
+ // Clamp the fade fraction to its documented 0..1 range. Guards against
58
+ // empty/negative/NaN/out-of-range values reaching the shader.
59
+ //
60
+ var clampFadeFraction = function (value) {
61
+ var n = Number(value);
62
+ if (!Number.isFinite(n))
63
+ return DEFAULT_FADE_FRACTION;
64
+ return Math.max(0, Math.min(1, n));
65
+ };
66
+ var floatToRGBABytesLE = function (value) {
67
+ var buf = new ArrayBuffer(4);
68
+ var dv = new DataView(buf);
69
+ dv.setFloat32(0, value, true); // little-endian
70
+ return [dv.getUint8(0), dv.getUint8(1), dv.getUint8(2), dv.getUint8(3)];
71
+ };
41
72
  var IdwLayerBase = function (props) {
42
73
  var map = useMap();
43
- var idwProgram = React.useRef(null);
44
- var vertexBuffer = React.useRef(null);
45
- var dataTexture = React.useRef(null);
46
- var dataTextureWidth = React.useRef(null);
47
- var dataTextureHeight = React.useRef(null);
48
- var offscreenTexture = React.useRef(null);
49
- var fbo = React.useRef(null);
50
- var copyProgram = React.useRef(null);
51
- var copyBuffer = React.useRef(null);
52
- var _a = React.useState(0), time = _a[0], setTime = _a[1];
53
- var data = props.data.slice(0, 50);
54
- // When properties change, make sure that layer is redrawn.
55
- // Do this by varying its `key` with the current time.
56
- React.useEffect(function () {
57
- setTime(Date.now());
58
- }, [props.data, props.gradientStops]);
59
- //
60
- // Convert a hex color (e.g. #ff0022) to an [r,g,b,a] array,
61
- // where r,g,b,a are in the 0.0-1.0 range.
62
- //
63
- var colorToRGBA = function (color) {
64
- var rgb = RgbColor.FromString(color);
65
- return [rgb.red / 255.0, rgb.green / 255.0, rgb.blue / 255.0, rgb.alpha];
66
- };
67
- var floatToRGBABytesLE = function (value) {
68
- var buf = new ArrayBuffer(4);
69
- var dv = new DataView(buf);
70
- dv.setFloat32(0, value, true); // little-endian
71
- return [
72
- dv.getUint8(0),
73
- dv.getUint8(1),
74
- dv.getUint8(2),
75
- dv.getUint8(3),
76
- ];
77
- };
78
- var makeTexture = function (gl) {
79
- var minVal = Math.min.apply(Math, data.map(function (p) { return p.value; }));
80
- var maxVal = Math.max.apply(Math, data.map(function (p) { return p.value; }));
81
- var normalized = data.map(function (m) {
82
- var coord = MercatorCoordinate.fromLngLat({ lng: m.longitude, lat: m.latitude });
83
- return { x: coord.x, y: coord.y, value: (m.value - minVal) / (maxVal - minVal) };
84
- });
85
- var texSize = 1024;
86
- dataTextureWidth.current = texSize;
87
- dataTextureHeight.current = texSize;
88
- var pixels = new Uint8Array(texSize * texSize * 4);
89
- normalized.forEach(function (p, i) {
90
- var values = [p.x, p.y, p.value];
91
- for (var j = 0; j < 3; j++) {
92
- var _a = floatToRGBABytesLE(values[j]), r = _a[0], g = _a[1], b = _a[2], a = _a[3];
93
- var pixelIndex = i * 3 + j;
94
- var offset = pixelIndex * 4;
95
- if (offset + 3 < pixels.length) {
96
- pixels[offset + 0] = r;
97
- pixels[offset + 1] = g;
98
- pixels[offset + 2] = b;
99
- pixels[offset + 3] = a;
74
+ // The custom-layer callbacks are captured by Mapbox at add-time, so render
75
+ // reads live prop values through this ref rather than a stale closure.
76
+ var propsRef = React.useRef(props);
77
+ propsRef.current = props;
78
+ // Build a fresh custom layer — with its own private WebGL resource holder —
79
+ // whenever an input that requires re-initialising GL state changes (data,
80
+ // resolution). Each generation owns its resources and frees only those in its
81
+ // own onRemove, so the overlapping add/remove during a react-map-gl remount
82
+ // never clobbers the live generation.
83
+ var layer = React.useMemo(function () {
84
+ // Unique id per generation so the old and new layers coexist cleanly during
85
+ // the remount (old removeLayer + new addLayer both run).
86
+ var id = 'idw-' + Math.random().toString(36).slice(2);
87
+ // Private per-generation GL resources.
88
+ var idwProgram = null;
89
+ var vertexBuffer = null;
90
+ var dataTexture = null;
91
+ var dataTextureWidth = 0;
92
+ var dataTextureHeight = 0;
93
+ var offscreenTexture = null;
94
+ var fbo = null;
95
+ var copyProgram = null;
96
+ var copyBuffer = null;
97
+ var removed = false;
98
+ // The fragment shader loops over at most 1024 stations, so cap input here to
99
+ // match that hard ceiling rather than silently dropping data at an arbitrary
100
+ // lower limit.
101
+ var data = props.data.slice(0, 1024);
102
+ var makeTexture = function (gl) {
103
+ var minVal = Math.min.apply(Math, data.map(function (p) { return p.value; }));
104
+ var maxVal = Math.max.apply(Math, data.map(function (p) { return p.value; }));
105
+ // Avoid a 0/0 = NaN normalization when all values are equal (or there is
106
+ // only a single data point), which would otherwise poison the data texture.
107
+ var range = (maxVal - minVal) || 1;
108
+ var normalized = data.map(function (m) {
109
+ var coord = MercatorCoordinate.fromLngLat({ lng: m.longitude, lat: m.latitude });
110
+ return { x: coord.x, y: coord.y, value: (m.value - minVal) / range };
111
+ });
112
+ var texSize = 1024;
113
+ dataTextureWidth = texSize;
114
+ dataTextureHeight = texSize;
115
+ var pixels = new Uint8Array(texSize * texSize * 4);
116
+ normalized.forEach(function (p, i) {
117
+ var values = [p.x, p.y, p.value];
118
+ for (var j = 0; j < 3; j++) {
119
+ var _a = floatToRGBABytesLE(values[j]), r = _a[0], g = _a[1], b = _a[2], a = _a[3];
120
+ var pixelIndex = i * 3 + j;
121
+ var offset = pixelIndex * 4;
122
+ if (offset + 3 < pixels.length) {
123
+ pixels[offset + 0] = r;
124
+ pixels[offset + 1] = g;
125
+ pixels[offset + 2] = b;
126
+ pixels[offset + 3] = a;
127
+ }
100
128
  }
129
+ });
130
+ // Create / bind / upload texture
131
+ dataTexture = gl.createTexture();
132
+ gl.bindTexture(gl.TEXTURE_2D, dataTexture);
133
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, texSize, texSize, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
134
+ // Use nearest sampling — we want exact pixel values
135
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
136
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
137
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
138
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
139
+ };
140
+ var onAdd = function (mbMap, gl) {
141
+ // IDW PROGRAM
142
+ var _a;
143
+ var vertexShader = gl.createShader(gl.VERTEX_SHADER);
144
+ gl.shaderSource(vertexShader, IdwVertexShader);
145
+ gl.compileShader(vertexShader);
146
+ var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
147
+ gl.shaderSource(fragmentShader, IdwFragmentShader);
148
+ gl.compileShader(fragmentShader);
149
+ idwProgram = gl.createProgram();
150
+ gl.attachShader(idwProgram, vertexShader);
151
+ gl.attachShader(idwProgram, fragmentShader);
152
+ gl.linkProgram(idwProgram);
153
+ // Shaders are linked into the program now; flag them for deletion.
154
+ gl.deleteShader(vertexShader);
155
+ gl.deleteShader(fragmentShader);
156
+ // Create vertex buffer from vertices:
157
+ vertexBuffer = gl.createBuffer();
158
+ gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
159
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]), gl.STATIC_DRAW);
160
+ // Make an OpenGL texture that contains station data (x,y,value). The
161
+ // texture dimensions are saved and will be passed into a shader uniform.
162
+ // Note that lat/lng is converted to Mercator x,y, in the [0..1] range.
163
+ makeTexture(gl);
164
+ // create texture to render into
165
+ var resolution = (_a = propsRef.current.resolution) !== null && _a !== void 0 ? _a : DEFAULT_RESOLUTION;
166
+ offscreenTexture = gl.createTexture();
167
+ gl.bindTexture(gl.TEXTURE_2D, offscreenTexture);
168
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, resolution, resolution, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
169
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); // linear for smoother upsampling
170
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
171
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
172
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
173
+ // create framebuffer and attach texture
174
+ fbo = gl.createFramebuffer();
175
+ gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
176
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, offscreenTexture, 0);
177
+ // check completeness (best-effort)
178
+ var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
179
+ if (status !== gl.FRAMEBUFFER_COMPLETE) {
180
+ console.warn('Framebuffer not complete: ', status);
101
181
  }
102
- });
103
- // Create / bind / upload texture
104
- dataTexture.current = gl.createTexture();
105
- gl.bindTexture(gl.TEXTURE_2D, dataTexture.current);
106
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, texSize, texSize, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
107
- // Use nearest sampling — we want exact pixel values
108
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
109
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
110
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
111
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
112
- };
113
- var onAddLayer = function (map, gl) {
114
- // IDW PROGRAM
115
- // create a vertex shader
116
- var vertexShader = gl.createShader(gl.VERTEX_SHADER);
117
- gl.shaderSource(vertexShader, IdwVertexShader);
118
- gl.compileShader(vertexShader);
119
- // create a fragment shader
120
- var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
121
- gl.shaderSource(fragmentShader, IdwFragmentShader);
122
- gl.compileShader(fragmentShader);
123
- // link the two shaders into a WebGL program
124
- idwProgram.current = gl.createProgram();
125
- gl.attachShader(idwProgram.current, vertexShader);
126
- gl.attachShader(idwProgram.current, fragmentShader);
127
- gl.linkProgram(idwProgram.current);
128
- // Create vertex buffer from vertices:
129
- vertexBuffer.current = gl.createBuffer();
130
- gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.current);
131
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
132
- 0.0, 0.0,
133
- 1.0, 0.0,
134
- 0.0, 1.0,
135
- 1.0, 1.0
136
- ]), gl.STATIC_DRAW);
137
- // Make an OpenGL texture that contains station data (x,y,value).
138
- // The texture dimensions are saved and will be passed into a shader
139
- // uniform. Note that lat/lng is converted to Mercator x,y, which has
140
- // a range of [0..1].
141
- makeTexture(gl);
142
- // create texture to render into
143
- offscreenTexture.current = gl.createTexture();
144
- gl.bindTexture(gl.TEXTURE_2D, offscreenTexture.current);
145
- // allocate empty texture
146
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, props.resolution, props.resolution, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
147
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); // linear for smoother upsampling; you can use NEAREST if you want blocky
148
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
149
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
150
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
151
- // create framebuffer and attach texture
152
- fbo.current = gl.createFramebuffer();
153
- gl.bindFramebuffer(gl.FRAMEBUFFER, fbo.current);
154
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, offscreenTexture.current, 0);
155
- // check completeness (best-effort)
156
- var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
157
- if (status !== gl.FRAMEBUFFER_COMPLETE) {
158
- // Not fatal here — log to console
159
- // eslint-disable-next-line no-console
160
- console.warn('Framebuffer not complete: ', status);
161
- }
162
- // unbind
163
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
164
- // COPY PROGRAM
165
- // create a vertex shader
166
- var copyVertexShader = gl.createShader(gl.VERTEX_SHADER);
167
- gl.shaderSource(copyVertexShader, CopyVertexShader);
168
- gl.compileShader(copyVertexShader);
169
- // create a fragment shader
170
- var copyFragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
171
- gl.shaderSource(copyFragmentShader, CopyFragmentShader);
172
- gl.compileShader(copyFragmentShader);
173
- // link the two shaders into a WebGL program
174
- copyProgram.current = gl.createProgram();
175
- gl.attachShader(copyProgram.current, copyVertexShader);
176
- gl.attachShader(copyProgram.current, copyFragmentShader);
177
- gl.linkProgram(copyProgram.current);
178
- // Create vertex buffer from vertices:
179
- copyBuffer.current = gl.createBuffer();
180
- gl.bindBuffer(gl.ARRAY_BUFFER, copyBuffer.current);
181
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
182
- 0.0, 0.0,
183
- 1.0, 0.0,
184
- 0.0, 1.0,
185
- 1.0, 1.0
186
- ]), gl.STATIC_DRAW);
187
- };
188
- var onRender = function (gl, matrix, zoom, width, height) {
189
- // Render is called many times while the map is panned/zoomed.
190
- // You cannot have access to the map though.
191
- if (zoom < props.minZoom)
192
- return;
193
- if (zoom > props.maxZoom)
194
- return;
195
- //
196
- // FIRST PASS
197
- //
198
- gl.bindFramebuffer(gl.FRAMEBUFFER, fbo.current);
199
- var vp = gl.getParameter(gl.VIEWPORT);
200
- gl.viewport(0, 0, props.resolution, props.resolution);
201
- gl.clearColor(0, 0, 0, 0);
202
- gl.clear(gl.COLOR_BUFFER_BIT);
203
- // Render is called many times while the map is panned/zoomed.
204
- // You cannot have access to the map though.
205
- gl.useProgram(idwProgram.current);
206
- // Pass a matrix uniform in:
207
- gl.uniformMatrix4fv(gl.getUniformLocation(idwProgram.current, 'u_matrix'), false, matrix);
208
- // Pass in number of stations:
209
- gl.uniform1i(gl.getUniformLocation(idwProgram.current, "u_numStations"), data.length);
210
- // put the data texture on texture unit 0
211
- gl.activeTexture(gl.TEXTURE0);
212
- gl.bindTexture(gl.TEXTURE_2D, dataTexture.current);
213
- // Pass data texture in (use texture unit 0):
214
- gl.uniform1i(gl.getUniformLocation(idwProgram.current, "u_dataTexture"), 0);
215
- // Pass texture size in:
216
- // Tell the shader the size of the position texture
217
- gl.uniform2f(gl.getUniformLocation(idwProgram.current, "u_dataTextureSize"), dataTextureWidth.current, dataTextureHeight.current);
218
- // Stops - fill up to 12 stops by using values > 1 for filler stops.
219
- // e.g. [0.0, 0.5, 1.0, 2.0....] means that only the first 3 stops are used.
220
- var stops = __spreadArray([], props.gradientStops.map(function (s) { return s.pos; }), true);
221
- while (stops.length < 12)
222
- stops.push(2.0);
223
- gl.uniform1fv(gl.getUniformLocation(idwProgram.current, 'u_gradientStops'), new Float32Array(stops));
224
- var colors = props.gradientStops.map(function (s) { return colorToRGBA(s.color); }).flat();
225
- gl.uniform4fv(gl.getUniformLocation(idwProgram.current, 'u_gradientColors'), new Float32Array(colors));
226
- // Max distance from all stations at which a pixel is drawn:
227
- gl.uniform1f(gl.getUniformLocation(idwProgram.current, "u_maxDistance"), props.maxDistance);
228
- // Fraction of this max distance where fading begins:
229
- gl.uniform1f(gl.getUniformLocation(idwProgram.current, "u_fadeFraction"), props.fadeFraction);
230
- var aPos = gl.getAttribLocation(idwProgram.current, 'a_pos');
231
- gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer.current);
232
- gl.enableVertexAttribArray(aPos);
233
- gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
234
- gl.enable(gl.BLEND);
235
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
236
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
237
- //
238
- // SECOND PASS
239
- //
240
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
241
- // Restore mapbox viewport:
242
- gl.viewport(vp[0], vp[1], vp[2], vp[3]);
243
- gl.useProgram(copyProgram.current);
244
- // Pass a matrix uniform in:
245
- gl.uniformMatrix4fv(gl.getUniformLocation(copyProgram.current, 'u_matrix'), false, matrix);
246
- // bind offscreen texture into unit 0 for copy pass
247
- gl.activeTexture(gl.TEXTURE0);
248
- gl.bindTexture(gl.TEXTURE_2D, offscreenTexture.current);
249
- gl.uniform1i(gl.getUniformLocation(copyProgram.current, 'u_src'), 0);
250
- var aPos2 = gl.getAttribLocation(copyProgram.current, 'a_pos');
251
- gl.bindBuffer(gl.ARRAY_BUFFER, copyBuffer.current);
252
- gl.enableVertexAttribArray(aPos2);
253
- gl.vertexAttribPointer(aPos2, 2, gl.FLOAT, false, 0, 0);
254
- gl.enable(gl.BLEND);
255
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
256
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
257
- };
258
- return (React.createElement(Layer, { id: null, type: "custom", beforeId: "overlay", key: time, onAdd: onAddLayer, render: function (gl, matrix) { return onRender(gl, matrix, map.current.getZoom(), map.current.getContainer().clientWidth, map.current.getContainer().clientHeight); } }));
182
+ // unbind
183
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
184
+ // COPY PROGRAM
185
+ var copyVertexShader = gl.createShader(gl.VERTEX_SHADER);
186
+ gl.shaderSource(copyVertexShader, CopyVertexShader);
187
+ gl.compileShader(copyVertexShader);
188
+ var copyFragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
189
+ gl.shaderSource(copyFragmentShader, CopyFragmentShader);
190
+ gl.compileShader(copyFragmentShader);
191
+ copyProgram = gl.createProgram();
192
+ gl.attachShader(copyProgram, copyVertexShader);
193
+ gl.attachShader(copyProgram, copyFragmentShader);
194
+ gl.linkProgram(copyProgram);
195
+ // Shaders are linked into the program now; flag them for deletion.
196
+ gl.deleteShader(copyVertexShader);
197
+ gl.deleteShader(copyFragmentShader);
198
+ // Create vertex buffer from vertices:
199
+ copyBuffer = gl.createBuffer();
200
+ gl.bindBuffer(gl.ARRAY_BUFFER, copyBuffer);
201
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]), gl.STATIC_DRAW);
202
+ // The map is idle after a prop-driven remount, so force a repaint to draw
203
+ // the freshly-added layer (there is no animation loop to do it otherwise).
204
+ mbMap.triggerRepaint();
205
+ };
206
+ var render = function (gl, matrix) {
207
+ var _a, _b, _c, _d, _e, _f;
208
+ // Render is called many times while the map is panned/zoomed.
209
+ if (removed)
210
+ return; // Resources freed; ignore any trailing frame.
211
+ var m = map.current;
212
+ if (!m)
213
+ return;
214
+ var p = propsRef.current;
215
+ var zoom = m.getZoom();
216
+ if (zoom < ((_a = p.minZoom) !== null && _a !== void 0 ? _a : DEFAULT_MIN_ZOOM))
217
+ return;
218
+ if (zoom > ((_b = p.maxZoom) !== null && _b !== void 0 ? _b : DEFAULT_MAX_ZOOM))
219
+ return;
220
+ //
221
+ // FIRST PASS
222
+ //
223
+ gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
224
+ var vp = gl.getParameter(gl.VIEWPORT);
225
+ var resolution = (_c = p.resolution) !== null && _c !== void 0 ? _c : DEFAULT_RESOLUTION;
226
+ gl.viewport(0, 0, resolution, resolution);
227
+ gl.clearColor(0, 0, 0, 0);
228
+ gl.clear(gl.COLOR_BUFFER_BIT);
229
+ gl.useProgram(idwProgram);
230
+ // Pass a matrix uniform in:
231
+ gl.uniformMatrix4fv(gl.getUniformLocation(idwProgram, 'u_matrix'), false, matrix);
232
+ // Pass in number of stations:
233
+ gl.uniform1i(gl.getUniformLocation(idwProgram, 'u_numStations'), data.length);
234
+ // put the data texture on texture unit 0
235
+ gl.activeTexture(gl.TEXTURE0);
236
+ gl.bindTexture(gl.TEXTURE_2D, dataTexture);
237
+ // Pass data texture in (use texture unit 0):
238
+ gl.uniform1i(gl.getUniformLocation(idwProgram, 'u_dataTexture'), 0);
239
+ // Tell the shader the size of the position texture:
240
+ gl.uniform2f(gl.getUniformLocation(idwProgram, 'u_dataTextureSize'), dataTextureWidth, dataTextureHeight);
241
+ // Stops - fill up to 12 stops by using values > 1 for filler stops.
242
+ // e.g. [0.0, 0.5, 1.0, 2.0....] means that only the first 3 stops are used.
243
+ var stops = __spreadArray([], ((_d = p.gradientStops) !== null && _d !== void 0 ? _d : []).map(function (s) { return s.pos; }), true);
244
+ while (stops.length < 12)
245
+ stops.push(2.0);
246
+ gl.uniform1fv(gl.getUniformLocation(idwProgram, 'u_gradientStops'), new Float32Array(stops));
247
+ var colors = ((_e = p.gradientStops) !== null && _e !== void 0 ? _e : []).map(function (s) { return colorToRGBA(s.color); }).flat();
248
+ gl.uniform4fv(gl.getUniformLocation(idwProgram, 'u_gradientColors'), new Float32Array(colors));
249
+ // Max distance from all stations at which a pixel is drawn:
250
+ gl.uniform1f(gl.getUniformLocation(idwProgram, 'u_maxDistance'), (_f = p.maxDistance) !== null && _f !== void 0 ? _f : DEFAULT_MAX_DISTANCE);
251
+ // Fraction of this max distance where fading begins:
252
+ gl.uniform1f(gl.getUniformLocation(idwProgram, 'u_fadeFraction'), clampFadeFraction(p.fadeFraction));
253
+ var aPos = gl.getAttribLocation(idwProgram, 'a_pos');
254
+ gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
255
+ gl.enableVertexAttribArray(aPos);
256
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
257
+ gl.enable(gl.BLEND);
258
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
259
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
260
+ // Attribute-array enable state is global in WebGL1; disable what we
261
+ // enabled so a later draw can't reference a stale (freed) buffer left
262
+ // bound to a still-enabled index.
263
+ gl.disableVertexAttribArray(aPos);
264
+ //
265
+ // SECOND PASS
266
+ //
267
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
268
+ // Restore mapbox viewport:
269
+ gl.viewport(vp[0], vp[1], vp[2], vp[3]);
270
+ gl.useProgram(copyProgram);
271
+ // Pass a matrix uniform in:
272
+ gl.uniformMatrix4fv(gl.getUniformLocation(copyProgram, 'u_matrix'), false, matrix);
273
+ // bind offscreen texture into unit 0 for copy pass
274
+ gl.activeTexture(gl.TEXTURE0);
275
+ gl.bindTexture(gl.TEXTURE_2D, offscreenTexture);
276
+ gl.uniform1i(gl.getUniformLocation(copyProgram, 'u_src'), 0);
277
+ var aPos2 = gl.getAttribLocation(copyProgram, 'a_pos');
278
+ gl.bindBuffer(gl.ARRAY_BUFFER, copyBuffer);
279
+ gl.enableVertexAttribArray(aPos2);
280
+ gl.vertexAttribPointer(aPos2, 2, gl.FLOAT, false, 0, 0);
281
+ gl.enable(gl.BLEND);
282
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
283
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
284
+ gl.disableVertexAttribArray(aPos2);
285
+ };
286
+ // Free all WebGL resources when this generation's layer is removed (Mapbox
287
+ // calls this on removeLayer). gl.deleteX(null) is a safe no-op.
288
+ var onRemove = function (_mbMap, gl) {
289
+ removed = true;
290
+ gl.deleteProgram(idwProgram);
291
+ gl.deleteProgram(copyProgram);
292
+ gl.deleteBuffer(vertexBuffer);
293
+ gl.deleteBuffer(copyBuffer);
294
+ gl.deleteTexture(dataTexture);
295
+ gl.deleteTexture(offscreenTexture);
296
+ gl.deleteFramebuffer(fbo);
297
+ idwProgram = null;
298
+ copyProgram = null;
299
+ vertexBuffer = null;
300
+ copyBuffer = null;
301
+ dataTexture = null;
302
+ offscreenTexture = null;
303
+ fbo = null;
304
+ };
305
+ return { id: id, onAdd: onAdd, render: render, onRemove: onRemove };
306
+ // eslint-disable-next-line react-hooks/exhaustive-deps
307
+ }, [props.data, props.resolution]);
308
+ // Render-only prop changes don't rebuild GL state (render reads them live via
309
+ // propsRef), but the idle map needs a nudge to repaint with the new values.
310
+ React.useEffect(function () {
311
+ var _a;
312
+ (_a = map.current) === null || _a === void 0 ? void 0 : _a.triggerRepaint();
313
+ }, [map, props.gradientStops, props.minZoom, props.maxZoom, props.maxDistance, props.fadeFraction]);
314
+ return (React.createElement(Layer, { id: layer.id, key: layer.id, type: "custom", beforeId: "overlay", onAdd: layer.onAdd, onRemove: layer.onRemove, render: layer.render }));
259
315
  };
260
316
  /**
261
317
  * An `IdwLayer` takes a data array of points of the form
@@ -278,7 +334,7 @@ var IdwLayerBase = function (props) {
278
334
  * as long as it is a power of 2 (32, 64, 128, 256...).
279
335
  */
280
336
  var IdwLayer = function (_a) {
281
- var _b = _a.gradientStops, gradientStops = _b === void 0 ? PresetGradients.Blue : _b, _c = _a.minZoom, minZoom = _c === void 0 ? 0 : _c, _d = _a.maxZoom, maxZoom = _d === void 0 ? 99 : _d, _e = _a.maxDistance, maxDistance = _e === void 0 ? 0.0002 : _e, _f = _a.fadeFraction, fadeFraction = _f === void 0 ? 0.15 : _f, _g = _a.resolution, resolution = _g === void 0 ? 256 : _g, props = __rest(_a, ["gradientStops", "minZoom", "maxZoom", "maxDistance", "fadeFraction", "resolution"]);
337
+ var _b = _a.gradientStops, gradientStops = _b === void 0 ? PresetGradients.Blue : _b, _c = _a.minZoom, minZoom = _c === void 0 ? DEFAULT_MIN_ZOOM : _c, _d = _a.maxZoom, maxZoom = _d === void 0 ? DEFAULT_MAX_ZOOM : _d, _e = _a.maxDistance, maxDistance = _e === void 0 ? DEFAULT_MAX_DISTANCE : _e, _f = _a.fadeFraction, fadeFraction = _f === void 0 ? DEFAULT_FADE_FRACTION : _f, _g = _a.resolution, resolution = _g === void 0 ? DEFAULT_RESOLUTION : _g, props = __rest(_a, ["gradientStops", "minZoom", "maxZoom", "maxDistance", "fadeFraction", "resolution"]);
282
338
  return React.createElement(IdwLayerBase, __assign({ gradientStops: gradientStops, minZoom: minZoom, maxZoom: maxZoom, maxDistance: maxDistance, fadeFraction: fadeFraction, resolution: resolution }, props));
283
339
  };
284
340
  IdwLayer.displayName = 'IdwLayer';
@@ -1,2 +1,2 @@
1
- declare const ContoursFragmentShader = " \n #ifdef GL_ES\n precision mediump float;\n #endif\n\n // Screen resolution is needed to convert gl_FragCoord to texture coordinate.\n uniform vec2 u_resolution;\n uniform sampler2D dataTexture;\n uniform int levels;\n uniform vec4 u_contourColor;\n uniform float u_contourThickness;\n uniform float u_gradientStops[12];\n uniform vec4 u_gradientColors[12];\n\n //\n // Given a value, find its corresponding color in the gradient stops.\n //\n vec4 getGradientColor(float position) {\n // Find left and right stop:\n float left = -1.0;\n float right = 99.0;\n vec4 leftColor;\n vec4 rightColor;\n\n for(int i = 0; i < 12; i++) {\n if (u_gradientStops[i] <= position) {\n left = u_gradientStops[i]; \n leftColor = u_gradientColors[i];\n } else break;\n }\n\n for(int i = 12 - 1; i >= 0; i--) {\n if (u_gradientStops[i] >= position) {\n right = u_gradientStops[i]; \n rightColor = u_gradientColors[i];\n } else break;\n }\n\n // Distance between stops:\n float width = right - left;\n // Distance from left stop:\n float dist = position - left;\n // Right stop weight:\n float weight;\n if(dist == 0.0) {\n weight = dist;\n } else {\n weight = dist / width;\n }\n\n float r = leftColor.x + (rightColor.x - leftColor.x) * weight;\n float g = leftColor.y + (rightColor.y - leftColor.y) * weight;\n float b = leftColor.z + (rightColor.z - leftColor.z) * weight;\n float a = leftColor.w + (rightColor.w - leftColor.w) * weight;\n return vec4(r, g, b, a); \n } \n\n //\n // Returns texture color at pixelCoord.\n //\n vec4 texelFetch(sampler2D tex, vec2 pixelCoord) {\n return texture2D(tex, pixelCoord / u_resolution);\n }\n\n //\n // Returns texture pixel shade, in a number of levels:\n int getShade(sampler2D tex, vec2 pixelCoord, float levels) {\n vec4 color = texelFetch(tex, pixelCoord);\n // If the color is transparent, return -1, so that there's always a contour line.\n if(color.w == 0.0) return -1;\n // Return greyscale shade in levels:\n return int(color.x * levels);\n }\n\n bool hasDifferentShade() {\n float numLevels = float(levels);\n float offset = max(1.0, u_contourThickness);\n\n // Get shades of input color and surrounding pixels:\n int shade = getShade(dataTexture, gl_FragCoord.xy, numLevels);\n int up = getShade(dataTexture, vec2(gl_FragCoord.x, gl_FragCoord.y - offset), numLevels);\n int down = getShade(dataTexture, vec2(gl_FragCoord.x, gl_FragCoord.y + offset), numLevels);\n int left = getShade(dataTexture, vec2(gl_FragCoord.x - offset, gl_FragCoord.y), numLevels);\n int right = getShade(dataTexture, vec2(gl_FragCoord.x + offset, gl_FragCoord.y), numLevels);\n return (up != shade || down != shade || left != shade || right != shade);\n }\n\n void main() {\n // Get input color:\n vec4 color = texelFetch(dataTexture, gl_FragCoord.xy);\n\n // If input is transparent, draw nothing.\n if(color.w == 0.0) return;\n\n // If the shade of the current pixel is different from any of its surrounding\n // pixels by at least a shade, then draw contour line color.\n if(levels != 0 && hasDifferentShade()) {\n gl_FragColor = u_contourColor;\n } \n // Otherwise draw the input color.\n else {\n gl_FragColor = getGradientColor(color.x);\n }\n }\n";
1
+ declare const ContoursFragmentShader = " \n #ifdef GL_ES\n precision mediump float;\n #endif\n\n // Screen resolution is needed to convert gl_FragCoord to texture coordinate.\n uniform vec2 u_resolution;\n uniform sampler2D dataTexture;\n uniform int levels;\n uniform vec4 u_contourColor;\n uniform float u_contourThickness;\n uniform float u_gradientStops[12];\n uniform vec4 u_gradientColors[12];\n\n //\n // Given a value, find its corresponding color in the gradient stops.\n //\n vec4 getGradientColor(float position) {\n // Find left and right stop:\n float left = -1.0;\n float right = 99.0;\n vec4 leftColor;\n vec4 rightColor;\n\n for(int i = 0; i < 12; i++) {\n if (u_gradientStops[i] <= position) {\n left = u_gradientStops[i]; \n leftColor = u_gradientColors[i];\n } else break;\n }\n\n for(int i = 12 - 1; i >= 0; i--) {\n if (u_gradientStops[i] >= position) {\n right = u_gradientStops[i]; \n rightColor = u_gradientColors[i];\n } else break;\n }\n\n // Distance between stops:\n float width = right - left;\n // Distance from left stop:\n float dist = position - left;\n // Right stop weight:\n float weight;\n if(dist == 0.0) {\n weight = dist;\n } else {\n weight = dist / width;\n }\n\n float r = leftColor.x + (rightColor.x - leftColor.x) * weight;\n float g = leftColor.y + (rightColor.y - leftColor.y) * weight;\n float b = leftColor.z + (rightColor.z - leftColor.z) * weight;\n float a = leftColor.w + (rightColor.w - leftColor.w) * weight;\n return vec4(r, g, b, a); \n } \n\n //\n // Returns texture color at pixelCoord.\n //\n vec4 texelFetch(sampler2D tex, vec2 pixelCoord) {\n return texture2D(tex, pixelCoord / u_resolution);\n }\n\n //\n // Returns texture pixel shade, in a number of levels:\n int getShade(sampler2D tex, vec2 pixelCoord, float levels) {\n vec4 color = texelFetch(tex, pixelCoord);\n // If the color is transparent, return -1, so that there's always a contour line.\n if(color.w == 0.0) return -1;\n // Return greyscale shade in levels:\n return int(color.x * levels);\n }\n\n bool hasDifferentShade() {\n float numLevels = float(levels);\n float offset = max(1.0, u_contourThickness);\n\n // Get shades of input color and surrounding pixels:\n int shade = getShade(dataTexture, gl_FragCoord.xy, numLevels);\n int up = getShade(dataTexture, vec2(gl_FragCoord.x, gl_FragCoord.y - offset), numLevels);\n int down = getShade(dataTexture, vec2(gl_FragCoord.x, gl_FragCoord.y + offset), numLevels);\n int left = getShade(dataTexture, vec2(gl_FragCoord.x - offset, gl_FragCoord.y), numLevels);\n int right = getShade(dataTexture, vec2(gl_FragCoord.x + offset, gl_FragCoord.y), numLevels);\n return (up != shade || down != shade || left != shade || right != shade);\n }\n\n void main() {\n // Get input color:\n vec4 color = texelFetch(dataTexture, gl_FragCoord.xy);\n\n // If input is transparent, draw nothing.\n if(color.w == 0.0) return;\n\n // If the shade of the current pixel is different from any of its surrounding\n // pixels by at least a shade, then draw contour line color. A thickness of\n // 0 disables contour lines entirely.\n if(levels != 0 && u_contourThickness > 0.0 && hasDifferentShade()) {\n gl_FragColor = u_contourColor;\n }\n // Otherwise draw the input color.\n else {\n gl_FragColor = getGradientColor(color.x);\n }\n }\n";
2
2
  export { ContoursFragmentShader };
@@ -1,2 +1,2 @@
1
- var ContoursFragmentShader = /*glsl*/ " \n #ifdef GL_ES\n precision mediump float;\n #endif\n\n // Screen resolution is needed to convert gl_FragCoord to texture coordinate.\n uniform vec2 u_resolution;\n uniform sampler2D dataTexture;\n uniform int levels;\n uniform vec4 u_contourColor;\n uniform float u_contourThickness;\n uniform float u_gradientStops[12];\n uniform vec4 u_gradientColors[12];\n\n //\n // Given a value, find its corresponding color in the gradient stops.\n //\n vec4 getGradientColor(float position) {\n // Find left and right stop:\n float left = -1.0;\n float right = 99.0;\n vec4 leftColor;\n vec4 rightColor;\n\n for(int i = 0; i < 12; i++) {\n if (u_gradientStops[i] <= position) {\n left = u_gradientStops[i]; \n leftColor = u_gradientColors[i];\n } else break;\n }\n\n for(int i = 12 - 1; i >= 0; i--) {\n if (u_gradientStops[i] >= position) {\n right = u_gradientStops[i]; \n rightColor = u_gradientColors[i];\n } else break;\n }\n\n // Distance between stops:\n float width = right - left;\n // Distance from left stop:\n float dist = position - left;\n // Right stop weight:\n float weight;\n if(dist == 0.0) {\n weight = dist;\n } else {\n weight = dist / width;\n }\n\n float r = leftColor.x + (rightColor.x - leftColor.x) * weight;\n float g = leftColor.y + (rightColor.y - leftColor.y) * weight;\n float b = leftColor.z + (rightColor.z - leftColor.z) * weight;\n float a = leftColor.w + (rightColor.w - leftColor.w) * weight;\n return vec4(r, g, b, a); \n } \n\n //\n // Returns texture color at pixelCoord.\n //\n vec4 texelFetch(sampler2D tex, vec2 pixelCoord) {\n return texture2D(tex, pixelCoord / u_resolution);\n }\n\n //\n // Returns texture pixel shade, in a number of levels:\n int getShade(sampler2D tex, vec2 pixelCoord, float levels) {\n vec4 color = texelFetch(tex, pixelCoord);\n // If the color is transparent, return -1, so that there's always a contour line.\n if(color.w == 0.0) return -1;\n // Return greyscale shade in levels:\n return int(color.x * levels);\n }\n\n bool hasDifferentShade() {\n float numLevels = float(levels);\n float offset = max(1.0, u_contourThickness);\n\n // Get shades of input color and surrounding pixels:\n int shade = getShade(dataTexture, gl_FragCoord.xy, numLevels);\n int up = getShade(dataTexture, vec2(gl_FragCoord.x, gl_FragCoord.y - offset), numLevels);\n int down = getShade(dataTexture, vec2(gl_FragCoord.x, gl_FragCoord.y + offset), numLevels);\n int left = getShade(dataTexture, vec2(gl_FragCoord.x - offset, gl_FragCoord.y), numLevels);\n int right = getShade(dataTexture, vec2(gl_FragCoord.x + offset, gl_FragCoord.y), numLevels);\n return (up != shade || down != shade || left != shade || right != shade);\n }\n\n void main() {\n // Get input color:\n vec4 color = texelFetch(dataTexture, gl_FragCoord.xy);\n\n // If input is transparent, draw nothing.\n if(color.w == 0.0) return;\n\n // If the shade of the current pixel is different from any of its surrounding\n // pixels by at least a shade, then draw contour line color.\n if(levels != 0 && hasDifferentShade()) {\n gl_FragColor = u_contourColor;\n } \n // Otherwise draw the input color.\n else {\n gl_FragColor = getGradientColor(color.x);\n }\n }\n";
1
+ var ContoursFragmentShader = /*glsl*/ " \n #ifdef GL_ES\n precision mediump float;\n #endif\n\n // Screen resolution is needed to convert gl_FragCoord to texture coordinate.\n uniform vec2 u_resolution;\n uniform sampler2D dataTexture;\n uniform int levels;\n uniform vec4 u_contourColor;\n uniform float u_contourThickness;\n uniform float u_gradientStops[12];\n uniform vec4 u_gradientColors[12];\n\n //\n // Given a value, find its corresponding color in the gradient stops.\n //\n vec4 getGradientColor(float position) {\n // Find left and right stop:\n float left = -1.0;\n float right = 99.0;\n vec4 leftColor;\n vec4 rightColor;\n\n for(int i = 0; i < 12; i++) {\n if (u_gradientStops[i] <= position) {\n left = u_gradientStops[i]; \n leftColor = u_gradientColors[i];\n } else break;\n }\n\n for(int i = 12 - 1; i >= 0; i--) {\n if (u_gradientStops[i] >= position) {\n right = u_gradientStops[i]; \n rightColor = u_gradientColors[i];\n } else break;\n }\n\n // Distance between stops:\n float width = right - left;\n // Distance from left stop:\n float dist = position - left;\n // Right stop weight:\n float weight;\n if(dist == 0.0) {\n weight = dist;\n } else {\n weight = dist / width;\n }\n\n float r = leftColor.x + (rightColor.x - leftColor.x) * weight;\n float g = leftColor.y + (rightColor.y - leftColor.y) * weight;\n float b = leftColor.z + (rightColor.z - leftColor.z) * weight;\n float a = leftColor.w + (rightColor.w - leftColor.w) * weight;\n return vec4(r, g, b, a); \n } \n\n //\n // Returns texture color at pixelCoord.\n //\n vec4 texelFetch(sampler2D tex, vec2 pixelCoord) {\n return texture2D(tex, pixelCoord / u_resolution);\n }\n\n //\n // Returns texture pixel shade, in a number of levels:\n int getShade(sampler2D tex, vec2 pixelCoord, float levels) {\n vec4 color = texelFetch(tex, pixelCoord);\n // If the color is transparent, return -1, so that there's always a contour line.\n if(color.w == 0.0) return -1;\n // Return greyscale shade in levels:\n return int(color.x * levels);\n }\n\n bool hasDifferentShade() {\n float numLevels = float(levels);\n float offset = max(1.0, u_contourThickness);\n\n // Get shades of input color and surrounding pixels:\n int shade = getShade(dataTexture, gl_FragCoord.xy, numLevels);\n int up = getShade(dataTexture, vec2(gl_FragCoord.x, gl_FragCoord.y - offset), numLevels);\n int down = getShade(dataTexture, vec2(gl_FragCoord.x, gl_FragCoord.y + offset), numLevels);\n int left = getShade(dataTexture, vec2(gl_FragCoord.x - offset, gl_FragCoord.y), numLevels);\n int right = getShade(dataTexture, vec2(gl_FragCoord.x + offset, gl_FragCoord.y), numLevels);\n return (up != shade || down != shade || left != shade || right != shade);\n }\n\n void main() {\n // Get input color:\n vec4 color = texelFetch(dataTexture, gl_FragCoord.xy);\n\n // If input is transparent, draw nothing.\n if(color.w == 0.0) return;\n\n // If the shade of the current pixel is different from any of its surrounding\n // pixels by at least a shade, then draw contour line color. A thickness of\n // 0 disables contour lines entirely.\n if(levels != 0 && u_contourThickness > 0.0 && hasDifferentShade()) {\n gl_FragColor = u_contourColor;\n }\n // Otherwise draw the input color.\n else {\n gl_FragColor = getGradientColor(color.x);\n }\n }\n";
2
2
  export { ContoursFragmentShader };
@@ -15,8 +15,8 @@ interface IInterpolationLayerProps {
15
15
  */
16
16
  gradientStops?: IGradientStop[];
17
17
  /**
18
- * Number of contour lines. This is a power of 2, between 2 and 256.
19
- * If 0, then no contour lines are drawn.
18
+ * Number of contour lines, clamped to the integer range 0..99 (higher
19
+ * counts slow rendering). If 0, then no contour lines are drawn.
20
20
  * @default 0
21
21
  */
22
22
  levels?: number;
@@ -26,7 +26,8 @@ interface IInterpolationLayerProps {
26
26
  */
27
27
  contourColor?: string;
28
28
  /**
29
- * Thickness of contour lines in pixels.
29
+ * Thickness of contour lines in pixels, clamped to the range 0..9.
30
+ * A thickness of 0 draws no contour lines.
30
31
  * @default 1
31
32
  */
32
33
  contourThickness?: number;