Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix: use data URL for marker images
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Dec 17, 2021
1 parent e41f670 commit 576ea46
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const Marker: React.FC<PrimitiveProps<Property>> = ({ layer }) => {
: undefined;
}, [extrude, location, height]);

const [canvas, img] = useIcon({
const [icon, img] = useIcon({
image,
imageSize,
crop,
Expand Down Expand Up @@ -178,7 +178,7 @@ const Marker: React.FC<PrimitiveProps<Property>> = ({ layer }) => {
/>
) : (
<BillboardGraphics
image={canvas}
image={icon}
color={cesiumImageColor}
horizontalOrigin={ho(horizontalOrigin)}
verticalOrigin={vo(verticalOrigin)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const useIcon = ({
shadowBlur?: number;
shadowOffsetX?: number;
shadowOffsetY?: number;
}): [HTMLCanvasElement, HTMLImageElement | undefined] => {
}): [string, HTMLImageElement | undefined] => {
const img = useImage(image);
const draw = useCallback(
can =>
Expand Down
15 changes: 6 additions & 9 deletions src/util/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ export const useImage = (src?: string): HTMLImageElement | undefined => {
return img;
};

export const useCanvas = (cb: (canvas: HTMLCanvasElement) => void) => {
const canvas1 = useMemo(() => document.createElement("canvas"), []);
const canvas2 = useMemo(() => document.createElement("canvas"), []);
const [canvas, setCanvas] = useState(canvas1);
export const useCanvas = (cb: (canvas: HTMLCanvasElement) => void): string => {
const can = useMemo(() => document.createElement("canvas"), []);
const [data, setData] = useState<string>("");
useEffect(() => {
const can = canvas === canvas2 ? canvas1 : canvas2;
cb(can);
setCanvas(can);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [canvas1, canvas2, cb]); // ignore canvas
return canvas;
setData(can.toDataURL());
}, [can, cb]);
return data;
};

0 comments on commit 576ea46

Please sign in to comment.