generated from taylorbryant/gatsby-starter-tailwind
-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add functionality for switching layer styles * apply satellite and make color switch to white if satellite is picked * implement key outsourcing, renaming map style names * change from HoverCard to PopOver component * change layout to vertical and add some breakpoints
- Loading branch information
1 parent
1112346
commit c995c64
Showing
5 changed files
with
113 additions
and
6 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
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,63 @@ | ||
import * as Popover from '@radix-ui/react-popover' | ||
import { MAP_STYLES, type MapStyles } from './MapSelector' | ||
import { useState } from 'react' | ||
|
||
interface Props { | ||
emit: (key: keyof MapStyles) => void | ||
} | ||
|
||
const MapLayersSelector: React.FC<Props> = ({ emit }) => { | ||
const [mapImgUrl, setMapImgUrl] = useState<string>(MAP_STYLES.standard.imgUrl) | ||
const [mapName, setMapName] = useState<string>('standard') | ||
|
||
const emitMap = (key: string): void => { | ||
const styleKey = key as keyof MapStyles | ||
const imgUrl = MAP_STYLES[styleKey].imgUrl | ||
|
||
setMapName(key) | ||
setMapImgUrl(imgUrl) | ||
emit(styleKey) | ||
} | ||
return ( | ||
<> | ||
<Popover.Root> | ||
<Popover.Trigger asChild> | ||
<button className='absolute bottom-20 left-3 bg-white rounded p-1.5 shadow'> | ||
<span> | ||
<img | ||
className='w-12 h-12 md:w-16 md:h-16 rounded border-[1px] border-slate-300' | ||
src={mapImgUrl} | ||
alt='Currently selected maptiler layer' | ||
/> | ||
<span className={`break-word text-[0.65rem] absolute bottom-2 left-1/2 -translate-x-1/2 ${mapName === 'satellite' ? 'text-white' : ''}`}>{mapName}</span> | ||
</span> | ||
</button> | ||
</Popover.Trigger> | ||
<Popover.Portal> | ||
<Popover.Content className=' pt-1.5 bg-white rounded grid grid-cols-1' side='top' sideOffset={20}> | ||
<button className='cursor-pointer col-span-1'> | ||
{Object.keys(MAP_STYLES).map((key) => { | ||
const mapKey = key as keyof typeof MAP_STYLES | ||
const { imgUrl } = MAP_STYLES[mapKey] | ||
return ( | ||
<div className='px-1.5' key={key} onClick={() => emitMap(key)}> | ||
<span className='grid grid-cols-1 justify-items-center'> | ||
<img | ||
className='w-12 h-12 md:w-16 md:h-16 rounded col-span-1 shadow border-[1px] border-slate-300' | ||
src={imgUrl} | ||
alt='Currently selected maptiler layer' | ||
/> | ||
<span className='col-span-1 text-[0.65rem] '>{key}</span> | ||
</span> | ||
</div> | ||
) | ||
})} | ||
</button> | ||
<Popover.Arrow className='fill-[white]' /> | ||
</Popover.Content> | ||
</Popover.Portal> | ||
</Popover.Root> | ||
</> | ||
) | ||
} | ||
export default MapLayersSelector |
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 |
---|---|---|
@@ -1,4 +1,37 @@ | ||
export const MAP_STYLES = { | ||
outdoor: 'https://api.maptiler.com/maps/outdoor-v2/style.json?key=ejjLkz58mUNz9TgNs0Ed', | ||
dataviz: 'https://api.maptiler.com/maps/dataviz/style.json?key=ejjLkz58mUNz9TgNs0Ed' | ||
const MAPTILER_KEY = process.env.NEXT_PUBLIC_MAPTILER_API_KEY !== undefined ? process.env.NEXT_PUBLIC_MAPTILER_API_KEY : 'key' | ||
export const MAP_STYLES: MapStyles = { | ||
outdoor: { | ||
style: `https://api.maptiler.com/maps/outdoor-v2/style.json?key=${MAPTILER_KEY}`, | ||
imgUrl: 'https://docs.maptiler.com/sdk-js/api/map-styles/img/style-outdoor-v2.jpeg' | ||
}, | ||
minimal: { | ||
style: `https://api.maptiler.com/maps/dataviz/style.json?key=${MAPTILER_KEY}`, | ||
imgUrl: 'https://docs.maptiler.com/sdk-js/api/map-styles/img/style-bright-v2-pastel.jpeg' | ||
}, | ||
standard: { | ||
style: `https://api.maptiler.com/maps/basic/style.json?key=${MAPTILER_KEY}`, | ||
imgUrl: 'https://docs.maptiler.com/sdk-js/api/map-styles/img/style-basic-v2.jpeg' | ||
}, | ||
satellite: { | ||
style: `https://api.maptiler.com/maps/satellite/style.json?key=${MAPTILER_KEY}`, | ||
imgUrl: 'https://docs.maptiler.com/sdk-js/api/map-styles/img/style-satellite.jpeg' | ||
} | ||
} | ||
export interface MapStyles { | ||
outdoor: { | ||
style: string | ||
imgUrl: string | ||
} | ||
minimal: { | ||
style: string | ||
imgUrl: string | ||
} | ||
standard: { | ||
style: string | ||
imgUrl: string | ||
} | ||
satellite: { | ||
style: string | ||
imgUrl: string | ||
} | ||
} |