generated from taylorbryant/gatsby-starter-tailwind
-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show crag info on hover (#1081)
- Loading branch information
Showing
5 changed files
with
194 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,44 @@ | ||
import { Marker } from 'react-map-gl' | ||
import { Point } from '@turf/helpers' | ||
import { Marker, Source, Layer, LineLayer } from 'react-map-gl' | ||
import { Point, Polygon } from '@turf/helpers' | ||
import { MapPin } from '@phosphor-icons/react/dist/ssr' | ||
|
||
export const AreaActiveMarker: React.FC<{ point: Point }> = ({ point }) => { | ||
const { coordinates } = point | ||
/** | ||
* Highlight selected feature on the map | ||
*/ | ||
export const SelectedFeature: React.FC<{ geometry: Point | Polygon }> = ({ geometry }) => { | ||
switch (geometry.type) { | ||
case 'Point': | ||
return <SelectedPoint geometry={geometry} /> | ||
case 'Polygon': | ||
return <SelectedPolygon geometry={geometry} /> | ||
default: return null | ||
} | ||
} | ||
|
||
const SelectedPoint: React.FC<{ geometry: Point }> = ({ geometry }) => { | ||
const { coordinates } = geometry | ||
return ( | ||
<Marker longitude={coordinates[0]} latitude={coordinates[1]} style={{ zIndex: 2000 }}> | ||
<Marker longitude={coordinates[0]} latitude={coordinates[1]}> | ||
<MapPin size={36} weight='fill' className='text-accent' /> | ||
</Marker> | ||
) | ||
} | ||
|
||
export const SelectedPolygon: React.FC<{ geometry: Polygon }> = ({ geometry }) => { | ||
return ( | ||
<Source id='selected-polygon' type='geojson' data={geometry}> | ||
<Layer {...selectedBoundary} /> | ||
</Source> | ||
) | ||
} | ||
|
||
const selectedBoundary: LineLayer = { | ||
id: 'polygon2', | ||
type: 'line', | ||
paint: { | ||
'line-opacity': ['step', ['zoom'], 0.85, 10, 0.5], | ||
'line-width': ['step', ['zoom'], 2, 10, 10], | ||
'line-color': '#004F6E', // See 'area-cue' in tailwind.config.js | ||
'line-blur': 4 | ||
} | ||
} |
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,53 @@ | ||
import * as Popover from '@radix-ui/react-popover' | ||
import { HoverInfo, MapAreaFeatureProperties } from './AreaMap' | ||
import { getAreaPageFriendlyUrl } from '@/js/utils' | ||
import { Card } from '../core/Card' | ||
import { EntityIcon } from '@/app/editArea/[slug]/general/components/AreaItem' | ||
import { SelectedPolygon } from './AreaActiveMarker' | ||
/** | ||
* Area info panel | ||
*/ | ||
export const AreaInfoHover: React.FC<HoverInfo> = ({ data, geometry, mapInstance }) => { | ||
const parent = data?.parent == null ? null : JSON.parse(data.parent) | ||
const parentName = parent?.name ?? 'Unknown' | ||
const parentId = parent?.id ?? null | ||
|
||
let screenXY | ||
if (geometry.type === 'Point') { | ||
screenXY = mapInstance.project(geometry.coordinates) | ||
} else { | ||
return <SelectedPolygon geometry={geometry} /> | ||
} | ||
return ( | ||
<Popover.Root defaultOpen> | ||
<Popover.Anchor style={{ position: 'absolute', left: screenXY.x, top: screenXY.y }} /> | ||
<Popover.Content align='center' side='top' alignOffset={12}> | ||
{data != null && <Content {...data} parentName={parentName} parentId={parentId} />} | ||
<Popover.Arrow /> | ||
</Popover.Content> | ||
</Popover.Root> | ||
) | ||
} | ||
|
||
export const Content: React.FC<MapAreaFeatureProperties & { parentName: string, parentId: string | null }> = ({ id, name, parentName, parentId }) => { | ||
const url = parentId == null | ||
? parentName | ||
: ( | ||
<a | ||
href={getAreaPageFriendlyUrl(parentId, name)} | ||
className='inline-flex items-center gap-1.5' | ||
> | ||
<EntityIcon type='area' size={16} /><span className='text-secondary font-medium hover:underline '>{parentName}</span> | ||
</a> | ||
) | ||
return ( | ||
<Card> | ||
<div className='flex flex-col gap-y-1 text-xs'> | ||
<div>{url}</div> | ||
<div className='ml-2'> | ||
<span className='text-secondary'>∟</span><a href={getAreaPageFriendlyUrl(id, name)} className='text-sm font-medium hover:underline'>{name}</a> | ||
</div> | ||
</div> | ||
</Card> | ||
) | ||
} |
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
977f11f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
open-tacos – ./
open-tacos-openbeta-dev.vercel.app
open-tacos-git-develop-openbeta-dev.vercel.app
openbeta.io
www.openbeta.io
openclimbmap.com
tacos.openbeta.io