|
| 1 | +import React from 'react'; |
| 2 | +import {createRoot} from 'react-dom/client'; |
| 3 | + |
| 4 | +import { |
| 5 | + APIProvider, |
| 6 | + Map3D, |
| 7 | + useMapsLibrary |
| 8 | +} from '@vis.gl/react-google-maps'; |
| 9 | +import ControlPanel from './control-panel'; |
| 10 | + |
| 11 | +import './app.css'; |
| 12 | + |
| 13 | +const API_KEY = |
| 14 | + globalThis.GOOGLE_MAPS_API_KEY ?? (process.env.GOOGLE_MAPS_API_KEY as string); |
| 15 | + |
| 16 | +// Tell TypeScript to allow the custom <gmp-route-3d> element |
| 17 | +declare global { |
| 18 | + namespace JSX { |
| 19 | + interface IntrinsicElements { |
| 20 | + 'gmp-route-3d': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & { |
| 21 | + 'autofits-camera'?: boolean; |
| 22 | + 'departure-time'?: string; |
| 23 | + destination?: any; |
| 24 | + origin?: any; |
| 25 | + 'routing-preference'?: string; |
| 26 | + 'travel-mode'?: string; |
| 27 | + }; |
| 28 | + } |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +const Map3DRouteExample = () => { |
| 33 | + // Make sure routes and maps3d libraries are loaded to register the custom elements |
| 34 | + useMapsLibrary('routes'); |
| 35 | + useMapsLibrary('maps3d'); |
| 36 | + |
| 37 | + return ( |
| 38 | + <> |
| 39 | + <Map3D |
| 40 | + defaultCenter={{lat: 43.67, lng: -79.40, altitude: 100}} |
| 41 | + defaultRange={12000} |
| 42 | + defaultHeading={0} |
| 43 | + defaultTilt={60} |
| 44 | + defaultRoll={0} |
| 45 | + defaultLabelsDisabled |
| 46 | + style={{width: '100vw', height: '100vh'}}> |
| 47 | + <gmp-route-3d |
| 48 | + origin={{lat: 43.65, lng: -79.38}} |
| 49 | + destination={{lat: 43.69, lng: -79.42}} |
| 50 | + travel-mode="DRIVING" |
| 51 | + /> |
| 52 | + </Map3D> |
| 53 | + </> |
| 54 | + ); |
| 55 | +}; |
| 56 | + |
| 57 | +const App = () => { |
| 58 | + return ( |
| 59 | + <APIProvider apiKey={API_KEY} version="alpha"> |
| 60 | + <Map3DRouteExample /> |
| 61 | + <ControlPanel /> |
| 62 | + </APIProvider> |
| 63 | + ); |
| 64 | +}; |
| 65 | +export default App; |
| 66 | + |
| 67 | +export function renderToDom(container: HTMLElement) { |
| 68 | + const root = createRoot(container); |
| 69 | + |
| 70 | + root.render( |
| 71 | + <React.StrictMode> |
| 72 | + <App /> |
| 73 | + </React.StrictMode> |
| 74 | + ); |
| 75 | +} |
0 commit comments