forked from aws-samples/amazon-location-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
51 lines (42 loc) · 1.28 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
import Amplify from "aws-amplify";
import { Map, NavigationControl } from "maplibre-gl";
import { createMap } from "maplibre-gl-js-amplify";
import "maplibre-gl/dist/maplibre-gl.css";
import { StrictMode, useEffect, useRef, useState } from "react";
import ReactDOM from "react-dom";
import awsconfig from "./aws-exports";
import "./index.css";
// initialize Amplify
Amplify.configure(awsconfig);
const App = () => {
const mapRef = useRef<HTMLDivElement>(null);
const [map, setMap] = useState<Map>();
useEffect(() => {
async function initializeMap() {
if (mapRef.current != null) {
const map = await createMap({
container: mapRef.current,
center: [-123.1187, 49.2819],
zoom: 11,
});
setMap(map);
}
}
initializeMap();
}, [mapRef]);
useEffect(() => {
if (map != null) {
// configure the Map instance with controls, custom layers, behaviors, etc.
map.addControl(new NavigationControl(), "top-left");
}
}, [map]);
return <div ref={mapRef} style={{ width: "100%", height: "100vh" }} />;
};
ReactDOM.render(
<StrictMode>
<App />
</StrictMode>,
document.getElementById("root")
);