@longline/aqua-ui 1.0.51 → 1.0.53

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.
@@ -17,35 +17,16 @@ interface IProps {
17
17
  * correctly.
18
18
  */
19
19
  idField: string;
20
+ /**
21
+ * Minimum zoom level at which to show markers.
22
+ * @default 0
23
+ */
24
+ minZoom?: number;
25
+ /**
26
+ * Maximum zoom level at which to show markers.
27
+ * @default 99
28
+ */
29
+ maxZoom?: number;
20
30
  }
21
- /**
22
- * The `HtmlMarkerLayer` manages HTML markers on a map. HTML markers are far slower
23
- * than OpenGL layers, but much more flexible: with SVG, any shape of marker can
24
- * be designed, and the markers can easily be made responsive to hover.
25
- *
26
- * The `HtmlMarkerLayer` keeps an internal cache, creating and rendering markers only
27
- * when they are visible in the map viewport. This is a suitable solution for clusters
28
- * (where by definition there are never very many icons in the viewport), or when
29
- * there are simply not _that_ many markers: up to a few hundred in the viewport is the
30
- * upper limit.
31
- *
32
- * The `HtmlMarkerLayer` must be placed inside a GeoJSON `Source`. In that source,
33
- * each feature must have a unique ID (passed to this layer as the `idField`), which
34
- * is used to tell features apart. When features are refreshed, it is imported that
35
- * they all get new IDs so that old markers get removed correctly.
36
- *
37
- * The `HtmlMarkerLayer` component takes a _function child_. This function accepts
38
- * a `props` object, which will be the properties from each GeoJSON feature for which
39
- * a marker is rendered.
40
- *
41
- * ```tsx
42
- * // featureCollection has a property "id" with unique values
43
- * <Source id="mysource" type="geojson" data={featureCollection}>
44
- * <HtmlMarkerLayer sourceId="mysource" idField="id">
45
- * {(markerProps) => <MyMarkerComponent color="gold" radius={45} {...markerProps}/>
46
- * </HtmlMarkerLayer>
47
- * </Source>
48
- * ```
49
- */
50
- declare const HtmlMarkerLayer: (props: IProps) => React.JSX.Element;
31
+ declare const HtmlMarkerLayer: ({ minZoom, maxZoom, ...props }: IProps) => React.JSX.Element;
51
32
  export { HtmlMarkerLayer };
@@ -9,6 +9,17 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
12
23
  import * as React from 'react';
13
24
  import * as ReactDOM from 'react-dom/client';
14
25
  import { Layer, useMap } from 'react-map-gl';
@@ -42,13 +53,15 @@ import { Marker } from 'mapbox-gl';
42
53
  * </Source>
43
54
  * ```
44
55
  */
45
- var HtmlMarkerLayer = function (props) {
56
+ var HtmlMarkerLayerBase = function (props) {
46
57
  var map = useMap().current;
47
58
  // Can't call props.children directly from map render event handler.
48
59
  // Make a ref copy:
49
60
  var children = React.useRef(props.children);
50
61
  var markers = React.useRef({});
51
62
  var markersOnScreen = React.useRef({});
63
+ var minZoom = React.useRef(props.minZoom);
64
+ var maxZoom = React.useRef(props.maxZoom);
52
65
  // Add render event to map, and remove it when this component
53
66
  // is unmounted. Whenever the map renders, we must refresh
54
67
  // all markers.
@@ -60,6 +73,8 @@ var HtmlMarkerLayer = function (props) {
60
73
  // Also clear map and repaint it, because child component props may
61
74
  // have changed.
62
75
  React.useEffect(function () {
76
+ minZoom.current = props.minZoom;
77
+ maxZoom.current = props.maxZoom;
63
78
  children.current = props.children;
64
79
  for (var id in markersOnScreen.current) {
65
80
  markersOnScreen.current[id].remove();
@@ -67,7 +82,7 @@ var HtmlMarkerLayer = function (props) {
67
82
  markers.current = {};
68
83
  markersOnScreen.current = {};
69
84
  map.triggerRepaint();
70
- }, [props.children]);
85
+ }, [props.children, props.minZoom, props.maxZoom]);
71
86
  // When component is unmounted, remove all its markers from the map.
72
87
  React.useEffect(function () {
73
88
  return function () {
@@ -105,11 +120,11 @@ var HtmlMarkerLayer = function (props) {
105
120
  // Retrieve all features that are currently rendered on a visible map tile,
106
121
  // thus excluding everything that's off-screen, for speed. The use of
107
122
  // querySourceFeatures requires that at least one Layer exists, which is
108
- // why we have layer that renders only invisible circles.
123
+ // why we have a layer that renders only invisible circles.
109
124
  // querySourceFeatures often results duplicates due to buffering.
110
125
  // Remove these duplicates by looking at each feature's unique ID.
111
126
  var seen = {};
112
- var features = map.querySourceFeatures(props.sourceId).filter(function (f) {
127
+ var features = (map.getZoom() < minZoom.current || map.getZoom() > maxZoom.current) ? [] : map.querySourceFeatures(props.sourceId).filter(function (f) {
113
128
  var id = f.properties[props.idField];
114
129
  return seen.hasOwnProperty(id) ? false : (seen[id] = true);
115
130
  });
@@ -148,4 +163,8 @@ var HtmlMarkerLayer = function (props) {
148
163
  // though it's empty.
149
164
  return (React.createElement(Layer, { source: props.sourceId, type: "circle", paint: { "circle-radius": 0 } }));
150
165
  };
166
+ var HtmlMarkerLayer = function (_a) {
167
+ var _b = _a.minZoom, minZoom = _b === void 0 ? 0 : _b, _c = _a.maxZoom, maxZoom = _c === void 0 ? 99 : _c, props = __rest(_a, ["minZoom", "maxZoom"]);
168
+ return React.createElement(HtmlMarkerLayerBase, __assign({ minZoom: minZoom, maxZoom: maxZoom }, props));
169
+ };
151
170
  export { HtmlMarkerLayer };
@@ -25,11 +25,21 @@ interface IProps {
25
25
  * @default #35ABE2
26
26
  */
27
27
  contourColor?: string;
28
+ /**
29
+ * Minimum zoom level at which to render layer.
30
+ * @default 0
31
+ */
32
+ minZoom?: number;
33
+ /**
34
+ * Maximum zoom level at which to render layer.
35
+ * @default 99
36
+ */
37
+ maxZoom?: number;
28
38
  }
29
39
  /**
30
40
  * An `InterpolationLayer` takes a data array of the form `{ latitude, longitude, value }`. It performs triangulation
31
41
  * and draws the data in an OpenGL layer. Optionally, a number of contour `levels` can be set to draw contour lines.
32
42
  * Gradient colors are configurable using `gradientStops`.
33
43
  */
34
- declare const InterpolationLayer: ({ levels, contourColor, gradientStops, ...props }: IProps) => React.JSX.Element;
44
+ declare const InterpolationLayer: ({ levels, contourColor, gradientStops, minZoom, maxZoom, ...props }: IProps) => React.JSX.Element;
35
45
  export { InterpolationLayer };
@@ -218,9 +218,13 @@ var InterpolationLayerBase = function (props) {
218
218
  gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
219
219
  gl.drawArrays(gl.TRIANGLES, 0, 6);
220
220
  };
221
- var onRender = function (gl, matrix, width, height) {
221
+ var onRender = function (gl, matrix, zoom, width, height) {
222
222
  // Render is called many times while the map is panned/zoomed.
223
223
  // You cannot have access to the map though.
224
+ if (zoom < props.minZoom)
225
+ return;
226
+ if (zoom > props.maxZoom)
227
+ return;
224
228
  // Bind & clear framebuffer, then render levels into it:
225
229
  // It is crucial to set the viewport size to match the resolution of the
226
230
  // texture we're rendering into.
@@ -239,7 +243,7 @@ var InterpolationLayerBase = function (props) {
239
243
  // @ts-ignore
240
244
  , {
241
245
  // @ts-ignore
242
- type: "custom", beforeId: "overlay", key: time, onAdd: onAddLayer, render: function (gl, matrix) { return onRender(gl, matrix, map.current.getContainer().clientWidth, map.current.getContainer().clientHeight); } }));
246
+ 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); } }));
243
247
  };
244
248
  /**
245
249
  * An `InterpolationLayer` takes a data array of the form `{ latitude, longitude, value }`. It performs triangulation
@@ -250,7 +254,7 @@ var InterpolationLayer = function (_a) {
250
254
  var _b = _a.levels, levels = _b === void 0 ? 0 : _b, _c = _a.contourColor, contourColor = _c === void 0 ? '#35ABE2' : _c, _d = _a.gradientStops, gradientStops = _d === void 0 ? [
251
255
  { pos: 0.0, color: '#0000ffff' },
252
256
  { pos: 1.0, color: '#000000ff' }
253
- ] : _d, props = __rest(_a, ["levels", "contourColor", "gradientStops"]);
254
- return React.createElement(InterpolationLayerBase, __assign({ levels: levels, contourColor: contourColor, gradientStops: gradientStops }, props));
257
+ ] : _d, _e = _a.minZoom, minZoom = _e === void 0 ? 0 : _e, _f = _a.maxZoom, maxZoom = _f === void 0 ? 99 : _f, props = __rest(_a, ["levels", "contourColor", "gradientStops", "minZoom", "maxZoom"]);
258
+ return React.createElement(InterpolationLayerBase, __assign({ levels: levels, contourColor: contourColor, gradientStops: gradientStops, minZoom: minZoom, maxZoom: maxZoom }, props));
255
259
  };
256
260
  export { InterpolationLayer };
@@ -36,6 +36,16 @@ interface IProps {
36
36
  * @default 1.0
37
37
  */
38
38
  pointSize?: number;
39
+ /**
40
+ * Minimum zoom level at which to render layer.
41
+ * @default 0
42
+ */
43
+ minZoom?: number;
44
+ /**
45
+ * Maximum zoom level at which to render layer.
46
+ * @default 99
47
+ */
48
+ maxZoom?: number;
39
49
  }
40
- declare const ParticlesLayer: ({ particles, density, delay, gradientStops, ...props }: IProps) => React.JSX.Element;
50
+ declare const ParticlesLayer: ({ particles, density, delay, gradientStops, minZoom, maxZoom, ...props }: IProps) => React.JSX.Element;
41
51
  export { ParticlesLayer };
@@ -303,7 +303,11 @@ var ParticlesLayerBase = function (props) {
303
303
  gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
304
304
  gl.drawArrays(gl.POINTS, 0, props.density * props.density * props.particles);
305
305
  };
306
- var onRender = function (gl, matrix, width, height) {
306
+ var onRender = function (gl, matrix, zoom, width, height) {
307
+ if (zoom < props.minZoom)
308
+ return;
309
+ if (zoom > props.maxZoom)
310
+ return;
307
311
  gl.useProgram(uvProgram.current);
308
312
  // Render U-texture:
309
313
  gl.bindFramebuffer(gl.FRAMEBUFFER, fboU.current);
@@ -328,7 +332,7 @@ var ParticlesLayerBase = function (props) {
328
332
  // @ts-ignore
329
333
  , {
330
334
  // @ts-ignore
331
- type: "custom", beforeId: "overlay", key: time, onAdd: onAddLayer, render: function (gl, matrix) { return onRender(gl, matrix, map.current.getContainer().clientWidth, map.current.getContainer().clientHeight); } }));
335
+ 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); } }));
332
336
  };
333
337
  var ParticlesLayer = function (_a) {
334
338
  var _b = _a.particles, particles = _b === void 0 ? 80 : _b, _c = _a.density, density = _c === void 0 ? 40 : _c, _d = _a.delay, delay = _d === void 0 ? 0 : _d, _e = _a.gradientStops, gradientStops = _e === void 0 ? [
@@ -336,7 +340,7 @@ var ParticlesLayer = function (_a) {
336
340
  { pos: 0.25, color: '#5c5cffff' },
337
341
  { pos: 0.5, color: '#5c5cff00' },
338
342
  { pos: 1.0, color: '#5c5cff00' }, // transparent blue
339
- ] : _e, props = __rest(_a, ["particles", "density", "delay", "gradientStops"]);
340
- return React.createElement(ParticlesLayerBase, __assign({ particles: particles, density: density, gradientStops: gradientStops, delay: delay }, props));
343
+ ] : _e, _f = _a.minZoom, minZoom = _f === void 0 ? 0 : _f, _g = _a.maxZoom, maxZoom = _g === void 0 ? 99 : _g, props = __rest(_a, ["particles", "density", "delay", "gradientStops", "minZoom", "maxZoom"]);
344
+ return React.createElement(ParticlesLayerBase, __assign({ particles: particles, density: density, gradientStops: gradientStops, delay: delay, minZoom: minZoom, maxZoom: maxZoom }, props));
341
345
  };
342
346
  export { ParticlesLayer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longline/aqua-ui",
3
- "version": "1.0.51",
3
+ "version": "1.0.53",
4
4
  "description": "AquaUI",
5
5
  "author": "Alexander van Oostenrijk / Longline Environment",
6
6
  "license": "Commercial",