aws-northstar
Version:
NorthStar Design System
74 lines (70 loc) • 3.84 kB
JavaScript
/** *******************************************************************************************************************
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. *
******************************************************************************************************************** */
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React, { useCallback, useMemo } from 'react';
import MapGL, { Marker, NavigationControl } from 'react-map-gl';
import RoomIcon from '@material-ui/icons/Room';
import { makeStyles } from '@material-ui/core/styles';
const useStyles = makeStyles((theme) => ({
navStyle: {
position: 'absolute',
top: 10,
left: 0,
padding: '10px',
},
muiIconOverride: {
color: theme.palette.info.dark,
height: '24px',
transform: `translate(${-36 / 2}px,${-24}px)`,
},
}));
var MAP_STYLE;
(function (MAP_STYLE) {
MAP_STYLE["satellite"] = "mapbox://styles/mapbox/satellite-v9";
MAP_STYLE["default"] = "mapbox://styles/mapbox/streets-v11";
})(MAP_STYLE || (MAP_STYLE = {}));
/**
* Map renders interactive maps from vector tiles and NorthStar styles using WebGL.
*/
const Map = (_a) => {
var { token, mapStyle = 'default', viewportWidth = 600, viewportHeight = 600, viewportLatitude, viewportLongitude, viewportZoom = 5, pins } = _a, props = __rest(_a, ["token", "mapStyle", "viewportWidth", "viewportHeight", "viewportLatitude", "viewportLongitude", "viewportZoom", "pins"]);
const viewportInitialConfig = useMemo(() => ({
width: viewportWidth,
height: viewportHeight,
latitude: viewportLatitude,
longitude: viewportLongitude,
zoom: viewportZoom,
bearing: 0,
pitch: 0,
}), [viewportWidth, viewportHeight, viewportLatitude, viewportLongitude, viewportZoom]);
const classes = useStyles({});
const [viewport, setViewport] = React.useState(viewportInitialConfig);
const marker = useCallback(({ latitude, longitude }) => (React.createElement(Marker, { key: `${latitude}-${longitude}`, latitude: latitude, longitude: longitude },
React.createElement(RoomIcon, { fontSize: "large", color: "secondary", classes: { colorSecondary: classes.muiIconOverride } }))), [classes]);
return (React.createElement("div", { "data-testid": props['data-testid'] },
React.createElement(MapGL, Object.assign({ mapStyle: MAP_STYLE[mapStyle], mapboxApiAccessToken: token }, viewport, { onViewportChange: (nextViewport) => setViewport(nextViewport) }),
pins.map((city) => marker(Object.assign({}, city))),
React.createElement("div", { className: classes.navStyle },
React.createElement(NavigationControl, null)))));
};
export default Map;