-
-
Notifications
You must be signed in to change notification settings - Fork 26
Rectangular 'bbox' region picker #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
73f511e
8713cab
dde4103
b339bc1
5a0be21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { useState, useEffect } from 'react' | ||
|
Jakidxav marked this conversation as resolved.
Outdated
|
||
| import { useMap } from '../../../map-provider' | ||
| import RectangleRenderer from './rectangle-renderer' | ||
|
|
||
| import { HANDLE_RADIUS } from './rectangle-renderer' | ||
|
|
||
| const RectanglePicker = ({ | ||
| id, | ||
| backgroundColor, | ||
| center, | ||
| color, | ||
| fontFamily, | ||
| fontSize, | ||
| radius, | ||
| onIdle, | ||
| onDrag, | ||
| units, | ||
| maxRadius, | ||
| minRadius, | ||
| }) => { | ||
| const { map } = useMap() | ||
| const [renderer, setRenderer] = useState(null) | ||
|
|
||
| useEffect(() => { | ||
| const renderer = RectangleRenderer({ | ||
| id, | ||
| map, | ||
| onIdle, | ||
| onDrag, | ||
| initialCenter: center, | ||
| initialRadius: radius, | ||
| units, | ||
| maxRadius, | ||
| minRadius, | ||
| }) | ||
|
|
||
| setRenderer(renderer) | ||
|
|
||
| return function cleanup() { | ||
| // need to check load state for fast-refresh purposes | ||
| if (map.loaded()) renderer.remove() | ||
| } | ||
| }, []) | ||
|
|
||
| return ( | ||
| <svg | ||
| id={`rectangle-picker-${id}`} | ||
| style={{ | ||
| position: 'absolute', | ||
| top: 0, | ||
| left: 0, | ||
| width: '100%', | ||
| height: '100%', | ||
| }} | ||
| > | ||
| <defs> | ||
| <clipPath id={`rect-clip-${id}`}> | ||
| <path id={`rectangle-cutout-${id}`} /> | ||
| </clipPath> | ||
| </defs> | ||
|
|
||
| <path | ||
| id={`rectangle-${id}`} | ||
| stroke={color} | ||
| strokeWidth={1} | ||
| fill='transparent' | ||
| cursor='move' | ||
| /> | ||
|
|
||
| <rect | ||
| x='0' | ||
| y='0' | ||
| width='100%' | ||
| height='100%' | ||
| clipPath={`url(#rect-clip-${id})`} | ||
| fill={backgroundColor} | ||
| fillOpacity={0.5} | ||
|
Jakidxav marked this conversation as resolved.
Outdated
|
||
| /> | ||
|
|
||
| <circle | ||
| id={`handle-${id}`} | ||
| r={HANDLE_RADIUS} | ||
| fill={color} | ||
| cursor='ew-resize' | ||
| /> | ||
|
|
||
| <line | ||
| id={`radius-guideline-${id}`} | ||
| stroke={color} | ||
| strokeOpacity={0} | ||
| strokeWidth={1} | ||
| strokeDasharray='3,2' | ||
| /> | ||
|
|
||
| <g id={`radius-text-container-${id}`}> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we change to show side length here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is probably much more intuitive. Then a circular region picker could be created with: And a rectangular region picker with: or something similar? We could then check to make sure that radius props are only used when |
||
| <text | ||
| id={`radius-text-${id}`} | ||
| textAnchor='middle' | ||
| fontFamily={fontFamily} | ||
| fontSize={fontSize} | ||
| fill={color} | ||
| /> | ||
| </g> | ||
| </svg> | ||
| ) | ||
| } | ||
|
|
||
| export default RectanglePicker | ||
Uh oh!
There was an error while loading. Please reload this page.