map.web.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { APIProvider, Map, Marker } from '@vis.gl/react-google-maps';
  2. import { appSetting } from 'app/lib/util';
  3. import { View } from 'app/design/view';
  4. import { BlockWrapper } from 'app/components/block-wrapper';
  5. export default function ElementMap({ data, blockWrapperProps }) {
  6. const apiKey = appSetting('config', 'api_keys', 'google_maps');
  7. // Without a location or a configured API key the map would render a broken,
  8. // watermarked tile and emit ApiProjectMapError, so skip rendering instead.
  9. if (!data.location?.lat || !apiKey)
  10. return null;
  11. const center = { lat: data.location.lat, lng: data.location.lng };
  12. return (
  13. <BlockWrapper {...blockWrapperProps}>
  14. <View className='w-full aspect-square'>
  15. <View className='rounded-lg overflow-hidden w-full aspect-square' style={{ minHeight: 200 }}>
  16. <APIProvider apiKey={apiKey}>
  17. <Map
  18. defaultCenter={center}
  19. defaultZoom={14}
  20. mapTypeControl={true}
  21. fullscreenControl={true}
  22. >
  23. <Marker position={center} />
  24. </Map>
  25. </APIProvider>
  26. </View>
  27. </View>
  28. </BlockWrapper>
  29. );
  30. }