@performant-software/geospatial 1.1.3-beta.8 → 1.1.4-beta.10

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@performant-software/geospatial",
3
- "version": "1.1.3-beta.8",
3
+ "version": "1.1.4-beta.10",
4
4
  "description": "TODO: ADD",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",
@@ -1,80 +0,0 @@
1
- // @flow
2
-
3
- import {
4
- Children,
5
- cloneElement,
6
- useEffect,
7
- useState
8
- } from 'react';
9
- import { createPortal } from 'react-dom';
10
- import { MapboxMap, useControl } from 'react-map-gl';
11
- import { IControl } from 'maplibre-gl';
12
- import _ from 'underscore';
13
-
14
- /**
15
- * Layer control implementation.
16
- */
17
- class LayerControl implements IControl {
18
- _map: MapboxMap = null;
19
- _container: HTMLElement;
20
- _redraw: () => void;
21
-
22
- constructor(redraw: () => void) {
23
- this._redraw = redraw;
24
- }
25
-
26
- onAdd(map) {
27
- this._map = map;
28
- map.on('move', this._redraw);
29
-
30
- this._container = document.createElement('div');
31
- this._container.className = 'maplibregl-ctrl-group maplibregl-ctrl';
32
- this._redraw();
33
- return this._container;
34
- }
35
-
36
- onRemove() {
37
- this._container.remove();
38
- this._map.off('move', this._redraw);
39
- this._map = null;
40
- }
41
-
42
- getMap() {
43
- return this._map;
44
- }
45
-
46
- getElement() {
47
- return this._container;
48
- }
49
- }
50
-
51
- /**
52
- * Layer container.
53
- *
54
- * @param props
55
- *
56
- * @returns {React$Portal}
57
- */
58
- const LayerMenuContainer = (props) => {
59
- const [, setVersion] = useState(0);
60
-
61
- const ctrl = useControl(() => {
62
- const forceUpdate = () => setVersion((v) => v + 1);
63
- return new LayerControl(forceUpdate);
64
- }, { position: props.position });
65
-
66
- const map = ctrl.getMap();
67
-
68
- const children = Children.map(_.compact(props.children), (child) => cloneElement(child, { map }));
69
-
70
- useEffect(() => {
71
- if (props.mapRef) {
72
- // eslint-disable-next-line no-param-reassign
73
- props.mapRef.current = map;
74
- }
75
- }, [map, props.mapRef]);
76
-
77
- return map && createPortal(children, ctrl.getElement());
78
- };
79
-
80
- export default LayerMenuContainer;