Skip to content

Commit

Permalink
Switch to non-ref object usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dzole0311 committed Oct 24, 2024
1 parent f5ff42c commit ae793f7
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions app/scripts/components/common/map/controls/aoi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import MapboxDraw from '@mapbox/mapbox-gl-draw';
import StaticMode from '@mapbox/mapbox-gl-draw-static-mode';
import { useTheme } from 'styled-components';
import { useAtomValue } from 'jotai';
import { useRef } from 'react';
import { useControl } from 'react-map-gl';
import type { MapRef } from 'react-map-gl';
import useAois from '../hooks/use-aois';
Expand Down Expand Up @@ -37,7 +36,6 @@ export default function DrawControl(props: DrawControlProps) {
const theme = useTheme();
const aoisFeatures = useAtomValue(aoisFeaturesAtom);
const { onUpdate, onDelete, onSelectionChange, onDrawModeChange } = useAois();
const mapRef = useRef<ExtendedMapRef | null>(null);

const drawControl = useControl<MapboxDraw>(
() => {
Expand All @@ -55,11 +53,9 @@ export default function DrawControl(props: DrawControlProps) {
return control;
},
({ map }) => {
mapRef.current = map as ExtendedMapRef;
const extendedMap = map as ExtendedMapRef;
// We're making the controls available on the map instance for later use throughout
// the app (e.g in the CustomAoIControl)
extendedMap._drawControl = drawControl;
(map as ExtendedMapRef)._drawControl = drawControl;
map.on('draw.create', onUpdate);
map.on('draw.update', onUpdate);
map.on('draw.delete', onDelete);
Expand All @@ -78,7 +74,6 @@ export default function DrawControl(props: DrawControlProps) {
map.off('draw.delete', onDelete);
map.off('draw.selectionchange', onSelectionChange);
map.off('draw.modechange', onDrawModeChange);
mapRef.current = null;
},
{
position: 'top-left'
Expand Down

0 comments on commit ae793f7

Please sign in to comment.