Skip to content

Commit

Permalink
layer disclaimer
Browse files Browse the repository at this point in the history
  • Loading branch information
mluena committed May 6, 2024
1 parent 09ed776 commit 06edc9f
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 243 deletions.
12 changes: 9 additions & 3 deletions src/components/map/drawing-tool/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type DrawControlProps = ConstructorParameters<typeof MapboxDraw>[0] & {
customPolygon?: GeoJSON.FeatureCollection;
onSetCustomPolygon?: (customPolygon) => void;
styles?: typeof DRAWING_STYLES;
onError?: (message: string, error: Error) => void;
};

const DEFAULT_PROPS: Partial<DrawControlProps> = {
Expand Down Expand Up @@ -49,7 +50,7 @@ export const DrawControl = (props: DrawControlProps) => {
}
);

const { onSetCustomPolygon, customPolygon } = props;
const { onSetCustomPolygon, customPolygon, onError } = props;

useEffect(() => {
if (!customPolygon) {
Expand All @@ -61,13 +62,18 @@ export const DrawControl = (props: DrawControlProps) => {
if (!drawRef) return null;

if (customPolygon) {
drawRef.add(customPolygon);
try {
drawRef.add(customPolygon);
} catch (error) {
console.error('Error adding custom polygon:', error);
onError?.('Error adding custom polygon:', error);
}

if (onSetCustomPolygon) {
onSetCustomPolygon(customPolygon);
}
}
}, [onSetCustomPolygon, customPolygon, drawRef]);
}, [onSetCustomPolygon, customPolygon, drawRef, onError]);

return null;
};
Expand Down
Loading

0 comments on commit 06edc9f

Please sign in to comment.