@longline/aqua-ui 1.0.348 → 1.0.349
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/map/Map/Map.d.ts +2 -3
- package/map/Map/Map.js +20 -5
- package/map/context/MapContext.d.ts +72 -0
- package/map/context/MapContext.js +31 -0
- package/map/context/index.d.ts +1 -0
- package/map/context/index.js +1 -0
- package/map/controls/CompassButton/CompassButton.js +2 -3
- package/map/controls/FullscreenButton/FullscreenButton.js +2 -2
- package/map/controls/ScaleControl/ScaleControl.js +1 -1
- package/map/controls/ZoomInButton/ZoomInButton.js +2 -3
- package/map/controls/ZoomOutButton/ZoomOutButton.js +2 -3
- package/map/controls/base/MapControl/MapControl.js +3 -1
- package/package.json +1 -1
package/map/Map/Map.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { MapMouseEvent, Map as OriginalMap } from 'mapbox-gl';
|
|
3
|
-
import { Map as GLMap,
|
|
3
|
+
import { Map as GLMap, ViewStateChangeEvent } from 'react-map-gl/mapbox';
|
|
4
4
|
import { ITestable } from '../../Types';
|
|
5
|
+
import { ViewStateContext, useViewState } from '../context';
|
|
5
6
|
interface IMapProps extends ITestable {
|
|
6
7
|
/** @ignore */
|
|
7
8
|
children?: React.ReactNode;
|
|
@@ -134,8 +135,6 @@ interface IMapProps extends ITestable {
|
|
|
134
135
|
*/
|
|
135
136
|
transformRequest?: React.ComponentProps<typeof GLMap>['transformRequest'];
|
|
136
137
|
}
|
|
137
|
-
declare const ViewStateContext: React.Context<ViewState | null>;
|
|
138
|
-
declare const useViewState: () => ViewState | null;
|
|
139
138
|
declare const Map: {
|
|
140
139
|
({ longitude, latitude, zoom, pitch, bearing, logoPosition, interactiveLayerIds, noRotate, preserveDrawingBuffer, minZoom, maxZoom, fadeDuration, doubleClickZoom, ...props }: IMapProps): React.JSX.Element;
|
|
141
140
|
displayName: string;
|
package/map/Map/Map.js
CHANGED
|
@@ -62,10 +62,22 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
62
62
|
};
|
|
63
63
|
import * as React from 'react';
|
|
64
64
|
import styled, { useTheme } from "styled-components";
|
|
65
|
-
import { Map as GLMap, Layer, Source } from 'react-map-gl/mapbox';
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
import { Map as GLMap, Layer, Source, useMap as useGLMap } from 'react-map-gl/mapbox';
|
|
66
|
+
import { MapInstanceContext, ViewStateContext, useViewState } from '../context';
|
|
67
|
+
/**
|
|
68
|
+
* Publishes the live map on this package's own context, so that controls can
|
|
69
|
+
* reach it through `useMap()` from `map/context` without importing
|
|
70
|
+
* react-map-gl — and therefore without dragging mapbox-gl into the bundle of
|
|
71
|
+
* any app that only wants a zoom button.
|
|
72
|
+
*
|
|
73
|
+
* Must render inside `GLMap`, since that is what puts react-map-gl's own
|
|
74
|
+
* context in scope for the hook below.
|
|
75
|
+
*/
|
|
76
|
+
var MapInstanceBridge = function (_a) {
|
|
77
|
+
var _b;
|
|
78
|
+
var children = _a.children;
|
|
79
|
+
var current = useGLMap().current;
|
|
80
|
+
return (React.createElement(MapInstanceContext.Provider, { value: (_b = current) !== null && _b !== void 0 ? _b : null }, children));
|
|
69
81
|
};
|
|
70
82
|
/**
|
|
71
83
|
* `Map` creates a react-mapbox-gl map instance. The map stretches to fill its
|
|
@@ -231,7 +243,8 @@ var MapBase = function (props) {
|
|
|
231
243
|
React.createElement(Source, { type: "raster", tiles: ["https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}@2x.webp?access_token=".concat(props.token)] },
|
|
232
244
|
React.createElement(Layer, { beforeId: "overlay", type: "raster" }))),
|
|
233
245
|
React.createElement(ViewStateContext.Provider, { value: __assign({}, viewState) },
|
|
234
|
-
React.createElement(
|
|
246
|
+
React.createElement(MapInstanceBridge, null,
|
|
247
|
+
React.createElement(Controls, null, props.children)))));
|
|
235
248
|
};
|
|
236
249
|
var Controls = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n pointer-events: none;\n & > * {\n pointer-events: all;\n }\n\n ", ";\n"], ["\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n pointer-events: none;\n & > * {\n pointer-events: all;\n }\n\n ", ";\n"])), function (p) { return p.theme.font.bodyMedium; });
|
|
237
250
|
var Map = function (_a) {
|
|
@@ -239,5 +252,7 @@ var Map = function (_a) {
|
|
|
239
252
|
return React.createElement(MapBase, __assign({ longitude: longitude, latitude: latitude, zoom: zoom, pitch: pitch, bearing: bearing, logoPosition: logoPosition, interactiveLayerIds: interactiveLayerIds, noRotate: noRotate, preserveDrawingBuffer: preserveDrawingBuffer, minZoom: minZoom, maxZoom: maxZoom, fadeDuration: fadeDuration, doubleClickZoom: doubleClickZoom }, props));
|
|
240
253
|
};
|
|
241
254
|
Map.displayName = 'Map';
|
|
255
|
+
// useViewState and ViewStateContext now live in map/context, which is free of
|
|
256
|
+
// react-map-gl. Re-exported here so existing imports keep working.
|
|
242
257
|
export { Map, useViewState, ViewStateContext };
|
|
243
258
|
var templateObject_1;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The map's current view state.
|
|
4
|
+
*
|
|
5
|
+
* Declared here rather than imported from react-map-gl, deliberately: anything
|
|
6
|
+
* that imports react-map-gl also pulls in the whole of mapbox-gl, and the point
|
|
7
|
+
* of this module is that a control can reach the map without paying that. The
|
|
8
|
+
* shape matches react-map-gl's `ViewState`, so the two stay assignable to each
|
|
9
|
+
* other and `Map` can feed its own state straight into the context.
|
|
10
|
+
*/
|
|
11
|
+
interface IViewState {
|
|
12
|
+
longitude: number;
|
|
13
|
+
latitude: number;
|
|
14
|
+
zoom: number;
|
|
15
|
+
pitch: number;
|
|
16
|
+
bearing: number;
|
|
17
|
+
/** Members are optional, matching react-map-gl's `PaddingOptions`. */
|
|
18
|
+
padding: {
|
|
19
|
+
top?: number;
|
|
20
|
+
bottom?: number;
|
|
21
|
+
left?: number;
|
|
22
|
+
right?: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The part of a map that the controls in this package actually use.
|
|
27
|
+
*
|
|
28
|
+
* Structural on purpose. A mapbox-gl `Map`, a maplibre-gl `Map` and
|
|
29
|
+
* react-map-gl's `MapRef` all satisfy it, so a host can hand over whichever it
|
|
30
|
+
* has and this package needs a dependency on none of them.
|
|
31
|
+
*/
|
|
32
|
+
interface IMapInstance {
|
|
33
|
+
zoomIn(): void;
|
|
34
|
+
zoomOut(): void;
|
|
35
|
+
getZoom(): number;
|
|
36
|
+
getMinZoom(): number;
|
|
37
|
+
getMaxZoom(): number;
|
|
38
|
+
rotateTo(bearing: number, options?: any): void;
|
|
39
|
+
resetNorthPitch(options?: any): void;
|
|
40
|
+
getContainer(): HTMLElement;
|
|
41
|
+
}
|
|
42
|
+
declare const ViewStateContext: React.Context<IViewState | null>;
|
|
43
|
+
declare const MapInstanceContext: React.Context<IMapInstance | null>;
|
|
44
|
+
/**
|
|
45
|
+
* The current view state of the surrounding map: centre, zoom, bearing, pitch
|
|
46
|
+
* and padding.
|
|
47
|
+
*
|
|
48
|
+
* `Map` provides this automatically to everything it hosts. A host driving its
|
|
49
|
+
* own map instance provides `ViewStateContext` itself.
|
|
50
|
+
*/
|
|
51
|
+
declare const useViewState: () => IViewState | null;
|
|
52
|
+
/**
|
|
53
|
+
* The surrounding map instance.
|
|
54
|
+
*
|
|
55
|
+
* `Map` provides this automatically to everything it hosts. A host driving its
|
|
56
|
+
* own map — a bare mapbox-gl or maplibre-gl instance, say — provides
|
|
57
|
+
* `MapInstanceContext` itself:
|
|
58
|
+
*
|
|
59
|
+
* ```tsx
|
|
60
|
+
* <MapInstanceContext.Provider value={map}>
|
|
61
|
+
* <ViewStateContext.Provider value={viewState}>
|
|
62
|
+
* <ZoomInButton x={20} y={20}/>
|
|
63
|
+
* </ViewStateContext.Provider>
|
|
64
|
+
* </MapInstanceContext.Provider>
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* Note this returns the map itself, where react-map-gl's like-named hook
|
|
68
|
+
* returns a collection to pick `current` out of.
|
|
69
|
+
*/
|
|
70
|
+
declare const useMap: () => IMapInstance | null;
|
|
71
|
+
export { ViewStateContext, MapInstanceContext, useViewState, useMap };
|
|
72
|
+
export type { IViewState, IMapInstance };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
var ViewStateContext = React.createContext(null);
|
|
3
|
+
var MapInstanceContext = React.createContext(null);
|
|
4
|
+
/**
|
|
5
|
+
* The current view state of the surrounding map: centre, zoom, bearing, pitch
|
|
6
|
+
* and padding.
|
|
7
|
+
*
|
|
8
|
+
* `Map` provides this automatically to everything it hosts. A host driving its
|
|
9
|
+
* own map instance provides `ViewStateContext` itself.
|
|
10
|
+
*/
|
|
11
|
+
var useViewState = function () { return React.useContext(ViewStateContext); };
|
|
12
|
+
/**
|
|
13
|
+
* The surrounding map instance.
|
|
14
|
+
*
|
|
15
|
+
* `Map` provides this automatically to everything it hosts. A host driving its
|
|
16
|
+
* own map — a bare mapbox-gl or maplibre-gl instance, say — provides
|
|
17
|
+
* `MapInstanceContext` itself:
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <MapInstanceContext.Provider value={map}>
|
|
21
|
+
* <ViewStateContext.Provider value={viewState}>
|
|
22
|
+
* <ZoomInButton x={20} y={20}/>
|
|
23
|
+
* </ViewStateContext.Provider>
|
|
24
|
+
* </MapInstanceContext.Provider>
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Note this returns the map itself, where react-map-gl's like-named hook
|
|
28
|
+
* returns a collection to pick `current` out of.
|
|
29
|
+
*/
|
|
30
|
+
var useMap = function () { return React.useContext(MapInstanceContext); };
|
|
31
|
+
export { ViewStateContext, MapInstanceContext, useViewState, useMap };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MapContext';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MapContext';
|
|
@@ -25,15 +25,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
25
25
|
return t;
|
|
26
26
|
};
|
|
27
27
|
import * as React from 'react';
|
|
28
|
-
import { useMap } from 'react-map-gl/mapbox';
|
|
29
28
|
import styled, { css } from 'styled-components';
|
|
30
29
|
import { MapButton } from '../base/MapButton';
|
|
31
|
-
import { useViewState } from '../../
|
|
30
|
+
import { useMap, useViewState } from '../../context';
|
|
32
31
|
import { Mouse } from '../../../controls/Mouse';
|
|
33
32
|
import { Key } from '../../../controls/Key';
|
|
34
33
|
var CompassButtonBase = function (props) {
|
|
35
34
|
var viewState = useViewState();
|
|
36
|
-
var map = useMap()
|
|
35
|
+
var map = useMap();
|
|
37
36
|
return (React.createElement(MapButton, __assign({ "data-testid": props['data-testid'] || "CompassButton", ariaLabel: "Reset bearing and pitch", onClick: function () { map.rotateTo(0); map.resetNorthPitch(); } }, props),
|
|
38
37
|
React.createElement("div", { style: { transform: "rotateX(".concat(props.visualizePitch ? viewState.pitch : 0, "deg)") } },
|
|
39
38
|
React.createElement("svg", { style: { transform: "rotateZ(".concat(-viewState.bearing, "deg)") }, xmlns: "http://www.w3.org/2000/svg", x: "0px", y: "0px", viewBox: "0 0 1000 1000" },
|
|
@@ -21,8 +21,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
23
|
import * as React from 'react';
|
|
24
|
-
import { useMap } from 'react-map-gl/mapbox';
|
|
25
24
|
import { MapButton } from '../base/MapButton';
|
|
25
|
+
import { useMap } from '../../context';
|
|
26
26
|
/**
|
|
27
27
|
* The `FullscreenButton` toggles the map full-screen when clicked.
|
|
28
28
|
*
|
|
@@ -35,7 +35,7 @@ import { MapButton } from '../base/MapButton';
|
|
|
35
35
|
*/
|
|
36
36
|
var FullscreenButton = function (_a) {
|
|
37
37
|
var _b = _a.hint, hint = _b === void 0 ? React.createElement(React.Fragment, null, "Toggle fullscreen map") : _b, _c = _a.mode, mode = _c === void 0 ? 'document' : _c, props = __rest(_a, ["hint", "mode"]);
|
|
38
|
-
var map = useMap()
|
|
38
|
+
var map = useMap();
|
|
39
39
|
// Does the browser offer full screen support?
|
|
40
40
|
var checkFullscreenSupport = function () {
|
|
41
41
|
return !!(window.document.fullscreenEnabled ||
|
|
@@ -26,7 +26,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
26
26
|
};
|
|
27
27
|
import * as React from 'react';
|
|
28
28
|
import styled from 'styled-components';
|
|
29
|
-
import { useViewState } from '../../
|
|
29
|
+
import { useViewState } from '../../context';
|
|
30
30
|
import { MapControl } from '../base/MapControl/MapControl';
|
|
31
31
|
var DEFAULT_WIDTH = 100;
|
|
32
32
|
// Number display steps, in meters:
|
|
@@ -21,9 +21,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
23
|
import * as React from 'react';
|
|
24
|
-
import { useMap } from 'react-map-gl/mapbox';
|
|
25
24
|
import { MapButton } from '../base/MapButton';
|
|
26
|
-
import { useViewState } from '../../
|
|
25
|
+
import { useMap, useViewState } from '../../context';
|
|
27
26
|
import { Mouse } from '../../../controls/Mouse';
|
|
28
27
|
import { Key } from '../../../controls/Key';
|
|
29
28
|
/**
|
|
@@ -48,7 +47,7 @@ var ZoomInButton = function (_a) {
|
|
|
48
47
|
React.createElement(Mouse, { size: 16, wheel: true }),
|
|
49
48
|
" Zoom in") : _b, props = __rest(_a, ["hint"]);
|
|
50
49
|
var viewState = useViewState();
|
|
51
|
-
var map = useMap()
|
|
50
|
+
var map = useMap();
|
|
52
51
|
return (React.createElement(MapButton, __assign({ "data-testid": props['data-testid'] || "ZoomInButton", ariaLabel: "Zoom in", disabled: viewState.zoom >= map.getMaxZoom(), onClick: function () { return map.zoomIn(); }, hint: hint }, props),
|
|
53
52
|
React.createElement("svg", { width: "100", height: "100", viewBox: "0 0 100 100", xmlns: "http://www.w3.org/2000/svg" },
|
|
54
53
|
React.createElement("path", { d: "M100,43.2v13.6c0,1.9-0.7,3.5-2,4.8c-1.3,1.3-2.9,2-4.8,2H63.6v29.5c0,1.9-0.7,3.5-2,4.8c-1.3,1.3-2.9,2-4.8,2H43.2c-1.9,0-3.5-0.7-4.8-2c-1.3-1.3-2-2.9-2-4.8V63.6H6.8c-1.9,0-3.5-0.7-4.8-2c-1.3-1.3-2-2.9-2-4.8V43.2c0-1.9,0.7-3.5,2-4.8c1.3-1.3,2.9-2,4.8-2h29.5V6.8c0-1.9,0.7-3.5,2-4.8c1.3-1.3,2.9-2,4.8-2h13.6c1.9,0,3.5,0.7,4.8,2c1.3,1.3,2,2.9,2,4.8v29.5h29.5c1.9,0,3.5,0.7,4.8,2C99.3,39.7,100,41.3,100,43.2z" }))));
|
|
@@ -21,9 +21,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
23
|
import * as React from 'react';
|
|
24
|
-
import { useMap } from 'react-map-gl/mapbox';
|
|
25
24
|
import { MapButton } from '../base/MapButton';
|
|
26
|
-
import { useViewState } from '../../
|
|
25
|
+
import { useMap, useViewState } from '../../context';
|
|
27
26
|
import { Mouse } from '../../../controls/Mouse';
|
|
28
27
|
import { Key } from '../../../controls/Key';
|
|
29
28
|
/**
|
|
@@ -48,7 +47,7 @@ var ZoomOutButton = function (_a) {
|
|
|
48
47
|
React.createElement(Mouse, { size: 16, wheel: true }),
|
|
49
48
|
" Zoom out") : _b, props = __rest(_a, ["hint"]);
|
|
50
49
|
var viewState = useViewState();
|
|
51
|
-
var map = useMap()
|
|
50
|
+
var map = useMap();
|
|
52
51
|
return (React.createElement(MapButton, __assign({ "data-testid": props['data-testid'] || "ZoomOutButton", ariaLabel: "Zoom out", disabled: viewState.zoom <= map.getMinZoom(), onClick: function () { return map.zoomOut(); }, hint: hint }, props),
|
|
53
52
|
React.createElement("svg", { width: "100", height: "100", viewBox: "0 0 100 100", xmlns: "http://www.w3.org/2000/svg" },
|
|
54
53
|
React.createElement("path", { d: "M93.2,36.4c1.9,0,3.5,0.7,4.8,2c1.3,1.3,2,2.9,2,4.8v13.6c0,1.9-0.7,3.5-2,4.8c-1.3,1.3-2.9,2-4.8,2H63.6H6.8c-1.9,0-3.5-0.7-4.8-2c-1.3-1.3-2-2.9-2-4.8V43.2c0-1.9,0.7-3.5,2-4.8c1.3-1.3,2.9-2,4.8-2" }))));
|
|
@@ -26,7 +26,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
26
26
|
};
|
|
27
27
|
import * as React from 'react';
|
|
28
28
|
import styled from 'styled-components';
|
|
29
|
-
|
|
29
|
+
// From map/context, not map/Map: importing the Map component here would pull
|
|
30
|
+
// react-map-gl, and with it mapbox-gl, into every app that uses a control.
|
|
31
|
+
import { useViewState } from '../../../context';
|
|
30
32
|
// Default prop values, referenced both by the MapControlBase fallbacks and the
|
|
31
33
|
// MapControl wrapper below.
|
|
32
34
|
var DEFAULT_X = 0;
|