@aws-amplify/ui-react-geo 1.0.2 → 2.0.1
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.
|
@@ -1 +1,72 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { useRef, useEffect } from 'react';
|
|
2
|
+
import maplibregl from 'maplibre-gl';
|
|
3
|
+
import { createAmplifyGeocoder } from 'maplibre-gl-js-amplify';
|
|
4
|
+
import { useMap, useControl } from 'react-map-gl';
|
|
5
|
+
import { useSetUserAgent } from '@aws-amplify/ui-react-core';
|
|
6
|
+
import { VERSION } from '../../version.mjs';
|
|
7
|
+
|
|
8
|
+
const LOCATION_SEARCH_OPTIONS = {
|
|
9
|
+
maplibregl,
|
|
10
|
+
marker: { color: '#3FB1CE' },
|
|
11
|
+
popup: true,
|
|
12
|
+
showResultMarkers: { color: '#3FB1CE' },
|
|
13
|
+
showResultsWhileTyping: true,
|
|
14
|
+
};
|
|
15
|
+
const LOCATION_SEARCH_CONTAINER = 'geocoder-container';
|
|
16
|
+
const LocationSearchControl = ({ position = 'top-right', ...props }) => {
|
|
17
|
+
useControl(() => createAmplifyGeocoder(props), {
|
|
18
|
+
position,
|
|
19
|
+
});
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
const LocationSearchStandalone = (props) => {
|
|
23
|
+
const hasMounted = useRef(false);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!hasMounted.current) {
|
|
26
|
+
createAmplifyGeocoder(props).addTo(`#${LOCATION_SEARCH_CONTAINER}`);
|
|
27
|
+
hasMounted.current = true;
|
|
28
|
+
}
|
|
29
|
+
}, [props]);
|
|
30
|
+
return React.createElement("div", { id: LOCATION_SEARCH_CONTAINER });
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The `<LocationSearch>` component provides location search.
|
|
34
|
+
*
|
|
35
|
+
* [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/geo#location-search)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Used as a map control:
|
|
39
|
+
* function App() {
|
|
40
|
+
* return (
|
|
41
|
+
* <MapView>
|
|
42
|
+
* <LocationSearch />
|
|
43
|
+
* </MapView>
|
|
44
|
+
* );
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Used as a standalone component:
|
|
49
|
+
* function App() {
|
|
50
|
+
* return <LocationSearch />;
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
const LocationSearch = (props) => {
|
|
54
|
+
const { current: map } = useMap();
|
|
55
|
+
useSetUserAgent({
|
|
56
|
+
componentName: 'LocationSearch',
|
|
57
|
+
packageName: 'react-geo',
|
|
58
|
+
version: VERSION,
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* This logic determines whether the LocationSearch exists as part of a Map component or if it is a standalone component.
|
|
62
|
+
* The `useControl` hook inside `LocationSearchControl` from `react-map-gl` makes it easy to add a control to a map,
|
|
63
|
+
* but throws an error if that map doesn't exist. If the map doesn't exist, the LocationSearch is mounted to a container
|
|
64
|
+
* upon rendering inside the `LocationSearchStandalone`.
|
|
65
|
+
*/
|
|
66
|
+
if (map) {
|
|
67
|
+
return React.createElement(LocationSearchControl, { ...LOCATION_SEARCH_OPTIONS, ...props });
|
|
68
|
+
}
|
|
69
|
+
return React.createElement(LocationSearchStandalone, { ...LOCATION_SEARCH_OPTIONS, ...props });
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { LocationSearch };
|
|
@@ -1 +1,62 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Amplify } from 'aws-amplify';
|
|
2
|
+
import { fetchAuthSession } from 'aws-amplify/auth';
|
|
3
|
+
import React, { forwardRef, useMemo, useState, useEffect } from 'react';
|
|
4
|
+
import maplibregl from 'maplibre-gl';
|
|
5
|
+
import { AmplifyMapLibreRequest } from 'maplibre-gl-js-amplify';
|
|
6
|
+
import ReactMapGL from 'react-map-gl';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The `MapView` component uses [react-map-gl](https://visgl.github.io/react-map-gl/) and
|
|
10
|
+
* [maplibre-gl-js](https://visgl.github.io/react-map-gl/) to provide an interactive map using
|
|
11
|
+
* [Amplify Geo APIs](https://docs.amplify.aws/lib/geo/getting-started/q/platform/js/) powered by
|
|
12
|
+
* [Amazon Location Service](https://aws.amazon.com/location/). Since `MapView` is a wrapper of the
|
|
13
|
+
* [react-map-gl default Map](https://visgl.github.io/react-map-gl/docs/api-reference/map/), it accepts the same
|
|
14
|
+
* properties except `transformRequest` which is set by Amplify.
|
|
15
|
+
*
|
|
16
|
+
* [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/geo#mapview)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Basic usage of MapView:
|
|
20
|
+
* function App() {
|
|
21
|
+
* return <MapView />
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
const MapView = forwardRef(({ mapLib, mapStyle, style, ...props }, ref) => {
|
|
25
|
+
const geoConfig = useMemo(() => {
|
|
26
|
+
return (Amplify.getConfig().Geo?.LocationService ??
|
|
27
|
+
{});
|
|
28
|
+
}, []);
|
|
29
|
+
const [transformRequest, setTransformRequest] = useState();
|
|
30
|
+
const styleProps = useMemo(() => ({
|
|
31
|
+
height: '100vh',
|
|
32
|
+
position: 'relative',
|
|
33
|
+
width: '100vw',
|
|
34
|
+
...style,
|
|
35
|
+
}), [style]);
|
|
36
|
+
/**
|
|
37
|
+
* The transformRequest is a callback used by react-map-gl before it makes a request for an external URL. It signs
|
|
38
|
+
* the request with AWS Sigv4 Auth, provided valid credentials, and is how we integrate react-map-gl with Amplify Geo
|
|
39
|
+
* and Amazon Location Service. Once the transformRequest is created, we render the map.
|
|
40
|
+
*/
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
(async () => {
|
|
43
|
+
const { credentials } = await fetchAuthSession();
|
|
44
|
+
if (credentials && geoConfig) {
|
|
45
|
+
const { region } = geoConfig;
|
|
46
|
+
const { transformRequest: amplifyTransformRequest } = new AmplifyMapLibreRequest(credentials, region);
|
|
47
|
+
setTransformRequest(() => amplifyTransformRequest);
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
}, [geoConfig]);
|
|
51
|
+
/**
|
|
52
|
+
* The mapLib property is used by react-map-gl@v7 to override the underlying map library. The default library is
|
|
53
|
+
* mapbox-gl-js, which uses its own copyrighted license. We override the map library with the BSD-licensed
|
|
54
|
+
* maplibre-gl-js.
|
|
55
|
+
*
|
|
56
|
+
* The default mapStyle we use is just the map ID provided by aws-exports.
|
|
57
|
+
*/
|
|
58
|
+
return transformRequest ? (React.createElement(ReactMapGL, { ...props, mapLib: mapLib ?? maplibregl, mapStyle: mapStyle ?? geoConfig?.maps?.default, ref: ref, style: styleProps, transformRequest: transformRequest, fog: props.fog, terrain: props.terrain })) : null;
|
|
59
|
+
});
|
|
60
|
+
MapView.displayName = 'MapView';
|
|
61
|
+
|
|
62
|
+
export { MapView };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export{MapView}from
|
|
1
|
+
export { MapView } from './components/MapView/MapView.mjs';
|
|
2
|
+
export { LocationSearch } from './components/LocationSearch/LocationSearch.mjs';
|
package/dist/index.js
CHANGED
|
@@ -1 +1,140 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var awsAmplify = require('aws-amplify');
|
|
6
|
+
var auth = require('aws-amplify/auth');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var maplibregl = require('maplibre-gl');
|
|
9
|
+
var maplibreGlJsAmplify = require('maplibre-gl-js-amplify');
|
|
10
|
+
var ReactMapGL = require('react-map-gl');
|
|
11
|
+
var uiReactCore = require('@aws-amplify/ui-react-core');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
16
|
+
var maplibregl__default = /*#__PURE__*/_interopDefaultLegacy(maplibregl);
|
|
17
|
+
var ReactMapGL__default = /*#__PURE__*/_interopDefaultLegacy(ReactMapGL);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The `MapView` component uses [react-map-gl](https://visgl.github.io/react-map-gl/) and
|
|
21
|
+
* [maplibre-gl-js](https://visgl.github.io/react-map-gl/) to provide an interactive map using
|
|
22
|
+
* [Amplify Geo APIs](https://docs.amplify.aws/lib/geo/getting-started/q/platform/js/) powered by
|
|
23
|
+
* [Amazon Location Service](https://aws.amazon.com/location/). Since `MapView` is a wrapper of the
|
|
24
|
+
* [react-map-gl default Map](https://visgl.github.io/react-map-gl/docs/api-reference/map/), it accepts the same
|
|
25
|
+
* properties except `transformRequest` which is set by Amplify.
|
|
26
|
+
*
|
|
27
|
+
* [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/geo#mapview)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Basic usage of MapView:
|
|
31
|
+
* function App() {
|
|
32
|
+
* return <MapView />
|
|
33
|
+
* }
|
|
34
|
+
*/
|
|
35
|
+
const MapView = React.forwardRef(({ mapLib, mapStyle, style, ...props }, ref) => {
|
|
36
|
+
const geoConfig = React.useMemo(() => {
|
|
37
|
+
return (awsAmplify.Amplify.getConfig().Geo?.LocationService ??
|
|
38
|
+
{});
|
|
39
|
+
}, []);
|
|
40
|
+
const [transformRequest, setTransformRequest] = React.useState();
|
|
41
|
+
const styleProps = React.useMemo(() => ({
|
|
42
|
+
height: '100vh',
|
|
43
|
+
position: 'relative',
|
|
44
|
+
width: '100vw',
|
|
45
|
+
...style,
|
|
46
|
+
}), [style]);
|
|
47
|
+
/**
|
|
48
|
+
* The transformRequest is a callback used by react-map-gl before it makes a request for an external URL. It signs
|
|
49
|
+
* the request with AWS Sigv4 Auth, provided valid credentials, and is how we integrate react-map-gl with Amplify Geo
|
|
50
|
+
* and Amazon Location Service. Once the transformRequest is created, we render the map.
|
|
51
|
+
*/
|
|
52
|
+
React.useEffect(() => {
|
|
53
|
+
(async () => {
|
|
54
|
+
const { credentials } = await auth.fetchAuthSession();
|
|
55
|
+
if (credentials && geoConfig) {
|
|
56
|
+
const { region } = geoConfig;
|
|
57
|
+
const { transformRequest: amplifyTransformRequest } = new maplibreGlJsAmplify.AmplifyMapLibreRequest(credentials, region);
|
|
58
|
+
setTransformRequest(() => amplifyTransformRequest);
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
}, [geoConfig]);
|
|
62
|
+
/**
|
|
63
|
+
* The mapLib property is used by react-map-gl@v7 to override the underlying map library. The default library is
|
|
64
|
+
* mapbox-gl-js, which uses its own copyrighted license. We override the map library with the BSD-licensed
|
|
65
|
+
* maplibre-gl-js.
|
|
66
|
+
*
|
|
67
|
+
* The default mapStyle we use is just the map ID provided by aws-exports.
|
|
68
|
+
*/
|
|
69
|
+
return transformRequest ? (React__default["default"].createElement(ReactMapGL__default["default"], { ...props, mapLib: mapLib ?? maplibregl__default["default"], mapStyle: mapStyle ?? geoConfig?.maps?.default, ref: ref, style: styleProps, transformRequest: transformRequest, fog: props.fog, terrain: props.terrain })) : null;
|
|
70
|
+
});
|
|
71
|
+
MapView.displayName = 'MapView';
|
|
72
|
+
|
|
73
|
+
const VERSION = '2.0.1';
|
|
74
|
+
|
|
75
|
+
const LOCATION_SEARCH_OPTIONS = {
|
|
76
|
+
maplibregl: maplibregl__default["default"],
|
|
77
|
+
marker: { color: '#3FB1CE' },
|
|
78
|
+
popup: true,
|
|
79
|
+
showResultMarkers: { color: '#3FB1CE' },
|
|
80
|
+
showResultsWhileTyping: true,
|
|
81
|
+
};
|
|
82
|
+
const LOCATION_SEARCH_CONTAINER = 'geocoder-container';
|
|
83
|
+
const LocationSearchControl = ({ position = 'top-right', ...props }) => {
|
|
84
|
+
ReactMapGL.useControl(() => maplibreGlJsAmplify.createAmplifyGeocoder(props), {
|
|
85
|
+
position,
|
|
86
|
+
});
|
|
87
|
+
return null;
|
|
88
|
+
};
|
|
89
|
+
const LocationSearchStandalone = (props) => {
|
|
90
|
+
const hasMounted = React.useRef(false);
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
if (!hasMounted.current) {
|
|
93
|
+
maplibreGlJsAmplify.createAmplifyGeocoder(props).addTo(`#${LOCATION_SEARCH_CONTAINER}`);
|
|
94
|
+
hasMounted.current = true;
|
|
95
|
+
}
|
|
96
|
+
}, [props]);
|
|
97
|
+
return React__default["default"].createElement("div", { id: LOCATION_SEARCH_CONTAINER });
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The `<LocationSearch>` component provides location search.
|
|
101
|
+
*
|
|
102
|
+
* [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/geo#location-search)
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // Used as a map control:
|
|
106
|
+
* function App() {
|
|
107
|
+
* return (
|
|
108
|
+
* <MapView>
|
|
109
|
+
* <LocationSearch />
|
|
110
|
+
* </MapView>
|
|
111
|
+
* );
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* // Used as a standalone component:
|
|
116
|
+
* function App() {
|
|
117
|
+
* return <LocationSearch />;
|
|
118
|
+
* }
|
|
119
|
+
*/
|
|
120
|
+
const LocationSearch = (props) => {
|
|
121
|
+
const { current: map } = ReactMapGL.useMap();
|
|
122
|
+
uiReactCore.useSetUserAgent({
|
|
123
|
+
componentName: 'LocationSearch',
|
|
124
|
+
packageName: 'react-geo',
|
|
125
|
+
version: VERSION,
|
|
126
|
+
});
|
|
127
|
+
/**
|
|
128
|
+
* This logic determines whether the LocationSearch exists as part of a Map component or if it is a standalone component.
|
|
129
|
+
* The `useControl` hook inside `LocationSearchControl` from `react-map-gl` makes it easy to add a control to a map,
|
|
130
|
+
* but throws an error if that map doesn't exist. If the map doesn't exist, the LocationSearch is mounted to a container
|
|
131
|
+
* upon rendering inside the `LocationSearchStandalone`.
|
|
132
|
+
*/
|
|
133
|
+
if (map) {
|
|
134
|
+
return React__default["default"].createElement(LocationSearchControl, { ...LOCATION_SEARCH_OPTIONS, ...props });
|
|
135
|
+
}
|
|
136
|
+
return React__default["default"].createElement(LocationSearchStandalone, { ...LOCATION_SEARCH_OPTIONS, ...props });
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
exports.LocationSearch = LocationSearch;
|
|
140
|
+
exports.MapView = MapView;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "2.0.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-geo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/esm/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -35,45 +35,25 @@
|
|
|
35
35
|
"prebuild": "rimraf dist",
|
|
36
36
|
"size": "yarn size-limit",
|
|
37
37
|
"test": "jest",
|
|
38
|
-
"test:ci": "yarn test && yarn check:esm",
|
|
39
38
|
"test:watch": "yarn test --watch",
|
|
40
39
|
"typecheck": "tsc --noEmit"
|
|
41
40
|
},
|
|
42
41
|
"dependencies": {
|
|
42
|
+
"@aws-amplify/ui-react-core": "3.0.1",
|
|
43
43
|
"mapbox-gl": "1.13.1",
|
|
44
44
|
"maplibre-gl": "2.1.9",
|
|
45
|
-
"maplibre-gl-js-amplify": "^
|
|
45
|
+
"maplibre-gl-js-amplify": "^4.0.0",
|
|
46
46
|
"react-map-gl": "7.0.23",
|
|
47
|
-
"tslib": "2.
|
|
47
|
+
"tslib": "^2.5.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"aws-amplify": "^
|
|
51
|
-
"
|
|
52
|
-
"react
|
|
50
|
+
"@aws-amplify/geo": "^3.0.2",
|
|
51
|
+
"aws-amplify": "^6.0.2",
|
|
52
|
+
"react": "^16.14.0 || ^17.0 || ^18.0",
|
|
53
|
+
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@
|
|
56
|
-
"@rollup/plugin-typescript": "^8.3.1",
|
|
57
|
-
"@size-limit/preset-big-lib": "^8.2.6",
|
|
58
|
-
"@testing-library/jest-dom": "^5.14.1",
|
|
59
|
-
"@testing-library/react": "^12.0.0",
|
|
60
|
-
"@testing-library/react-hooks": "^7.0.1",
|
|
61
|
-
"@testing-library/user-event": "^13.2.1",
|
|
62
|
-
"@types/jest": "^26.0.23",
|
|
63
|
-
"@types/mapbox__mapbox-gl-draw": "^1.3.3",
|
|
64
|
-
"@types/react": "^17.0.2",
|
|
65
|
-
"@types/testing-library__jest-dom": "^5.14.1",
|
|
66
|
-
"eslint": "^8.44.0",
|
|
67
|
-
"jest": "^27.0.4",
|
|
68
|
-
"react": "^17.0.2",
|
|
69
|
-
"react-dom": "^17.0.2",
|
|
70
|
-
"rimraf": "^3.0.2",
|
|
71
|
-
"rollup": "^2.70.0",
|
|
72
|
-
"rollup-plugin-node-externals": "^4.1.1",
|
|
73
|
-
"rollup-plugin-styles": "^4.0.0",
|
|
74
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
75
|
-
"size-limit": "^8.2.6",
|
|
76
|
-
"ts-jest": "^27.0.3"
|
|
56
|
+
"@types/mapbox__mapbox-gl-draw": "^1.3.3"
|
|
77
57
|
},
|
|
78
58
|
"sideEffects": [
|
|
79
59
|
"dist/**/*.css"
|