Skip to content
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

layer disclaimer #1121

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading