Skip to content

Commit

Permalink
fix: option to enable or disable cutouts on merge
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jul 29, 2024
1 parent ffe0040 commit a3ca08e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/src/components/drawer/Drawing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function DrawingTab() {
<ListSubheader disableGutters>Drawing</ListSubheader>
<Toggle field="snappable" />
<Toggle field="continueDrawing" />
<Toggle field="keepCutoutsOnMerge" />
<UserTextInput field="radius" disabled={calculationMode === 'S2'} />
<MultiOptionList
field="setActiveMode"
Expand Down
2 changes: 2 additions & 0 deletions client/src/hooks/usePersist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface UsePersist {
snappable: boolean
continueDrawing: boolean
setActiveMode: 'hover' | 'click'
keepCutoutsOnMerge: boolean

// Client Settings
darkMode: boolean
Expand Down Expand Up @@ -95,6 +96,7 @@ export const usePersist = create(
darkMode: true,
tab: 0,
drawer: false,
keepCutoutsOnMerge: false,
location: [0, 0],
zoom: 18,
category: 'pokestop',
Expand Down
13 changes: 11 additions & 2 deletions client/src/hooks/useShapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
KojiKey,
} from '@assets/types'
import { useDbCache } from './useDbCache'
import { usePersist } from './usePersist'

const { setRecord } = useDbCache.getState()

Expand Down Expand Up @@ -280,6 +281,8 @@ export const useShapes = create<UseShapes>((set, get) => ({
MultiPolygon,
setters: { remove, add },
} = get()
const { keepCutoutsOnMerge } = usePersist.getState()

let newPoly: Feature<Polygon | MultiPolygon> = {
geometry: { type: 'MultiPolygon', coordinates: [] },
type: 'Feature',
Expand Down Expand Up @@ -329,8 +332,14 @@ export const useShapes = create<UseShapes>((set, get) => ({
}
}
})
if (newPoly.geometry.type === 'Polygon') {
newPoly.geometry.coordinates = [newPoly.geometry.coordinates[0]]
if (!keepCutoutsOnMerge) {
if (newPoly.geometry.type === 'Polygon') {
newPoly.geometry.coordinates = [newPoly.geometry.coordinates[0]]
} else if (newPoly.geometry.type === 'MultiPolygon') {
newPoly.geometry.coordinates = newPoly.geometry.coordinates.map(
(p) => [p[0]],
)
}
}
Object.entries(
all
Expand Down

0 comments on commit a3ca08e

Please sign in to comment.