-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into chore/ruff-upgrade
- Loading branch information
Showing
66 changed files
with
29,327 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MAPLIBRE_STYLE_URL=https://api.example.com/style.json?key=mykey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { Marker } from 'maplibre-gl' | ||
|
||
import { Map, MapComponent } from './Map' | ||
|
||
const meta: Meta<typeof Map> = { | ||
title: 'Components/Map', | ||
component: Map, | ||
tags: ['autodocs'], | ||
} | ||
type Story = StoryObj<typeof Map> | ||
|
||
const coordinates: [number, number] = [0.119167, 52.205276] | ||
|
||
export const Unavailable: Story = {} | ||
|
||
export const Basic: Story = { | ||
render: (args) => ( | ||
<MapComponent | ||
mapLibreStyleUrl="" // TODO: set this value for the publish storybook and visual regression tests | ||
{...args} | ||
/> | ||
), | ||
args: { | ||
center: coordinates, | ||
markers: [new Marker({ color: 'var(--primary)' }).setLngLat(coordinates)], | ||
className: 'h-60', | ||
}, | ||
} | ||
|
||
export default meta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useEffect, useRef } from 'react' | ||
import { Map as RawMap, Marker } from 'maplibre-gl' | ||
import useResizeObserver from 'use-resize-observer' | ||
|
||
import 'maplibre-gl/dist/maplibre-gl.css' | ||
|
||
/** Latitude and longtitude in degrees (+lat is east, -lat is west, +lon is south, -lon is north). */ | ||
export interface MapProps { | ||
/** Coordinates to center the map on by default. */ | ||
center: [number, number] | ||
/** Markers to show. */ | ||
markers?: Marker[] | ||
/** Map container class names. */ | ||
className?: string | ||
/** The map's MapLibre style. This must be a JSON object conforming to the schema described in the MapLibre Style Specification, or a URL to such JSON. */ | ||
mapLibreStyleUrl: string | ||
} | ||
|
||
export function Map({ className, ...rest }: Omit<MapProps, 'mapLibreStyleUrl'>): JSX.Element { | ||
if (!window.JS_MAPLIBRE_STYLE_URL) { | ||
return ( | ||
<div className={`w-full h-full flex flex-col items-center justify-center text-muted p-3 ${className}`}> | ||
<h1>Map unavailable</h1> | ||
<p> | ||
The <code>MAPLIBRE_STYLE_URL</code> setting is not defined. Please configure this setting with a | ||
valid MapLibre Style URL to display maps. | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
return <MapComponent mapLibreStyleUrl={window.JS_MAPLIBRE_STYLE_URL} className={className} {...rest} /> | ||
} | ||
|
||
export function MapComponent({ center, markers, className, mapLibreStyleUrl }: MapProps): JSX.Element { | ||
const mapContainer = useRef<HTMLDivElement>(null) | ||
const map = useRef<RawMap | null>(null) | ||
|
||
useEffect(() => { | ||
map.current = new RawMap({ | ||
container: mapContainer.current as HTMLElement, | ||
style: mapLibreStyleUrl, | ||
center, | ||
zoom: 4, | ||
maxZoom: 10, | ||
}) | ||
if (markers) { | ||
for (const marker of markers) { | ||
marker.addTo(map.current) | ||
} | ||
} | ||
}, []) | ||
|
||
useResizeObserver({ | ||
ref: mapContainer, | ||
onResize: () => { | ||
if (map.current) { | ||
map.current.resize() | ||
} | ||
}, | ||
}) | ||
|
||
return <div ref={mapContainer} className={className} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.