@reearth/core 0.0.7-alpha.12 → 0.0.7-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reearth/core",
3
- "version": "0.0.7-alpha.12",
3
+ "version": "0.0.7-alpha.13",
4
4
  "author": "Re:Earth contributors <community@reearth.io>",
5
5
  "license": "Apache-2.0",
6
6
  "description": "A library that abstracts a map engine as one common API.",
@@ -36,7 +36,7 @@ import {
36
36
  CameraEventType,
37
37
  KeyboardEventModifier,
38
38
  } from "cesium";
39
- import { useCallback, MutableRefObject } from "react";
39
+ import { MutableRefObject, useMemo } from "react";
40
40
 
41
41
  import type { Camera, Clock } from "..";
42
42
  import { ClassificationType } from "../../mantle";
@@ -48,7 +48,7 @@ import type {
48
48
  OverideKeyboardEventModifier,
49
49
  ScreenSpaceCameraControllerOptions,
50
50
  } from "../../types";
51
- import { tweenInterval, useCanvas, useImage, LatLngHeight } from "../../utils";
51
+ import { tweenInterval, useImage, LatLngHeight } from "../../utils";
52
52
 
53
53
  import { DEFAULT_SCREEN_SPACE_CAMERA_ASSIGNMENTS } from "./constants";
54
54
 
@@ -56,8 +56,7 @@ export const layerIdField = `__reearth_layer_id`;
56
56
 
57
57
  const defaultImageSize = 50;
58
58
 
59
- export const drawIcon = (
60
- c: HTMLCanvasElement,
59
+ const drawIcon = (
61
60
  image: HTMLImageElement | undefined,
62
61
  w: number,
63
62
  h: number,
@@ -68,6 +67,7 @@ export const drawIcon = (
68
67
  shadowOffsetX = 0,
69
68
  shadowOffsetY = 0,
70
69
  ) => {
70
+ const c = document.createElement("canvas");
71
71
  const ctx = c.getContext("2d");
72
72
  if (!image || !ctx) return;
73
73
 
@@ -104,6 +104,7 @@ export const drawIcon = (
104
104
  }
105
105
 
106
106
  ctx.restore();
107
+ return c.toDataURL();
107
108
  };
108
109
 
109
110
  export const useIcon = ({
@@ -138,13 +139,11 @@ export const useIcon = ({
138
139
  ? Math.floor(img.height * imageSize)
139
140
  : Math.floor((w / img.width) * img.height);
140
141
 
141
- const draw = useCallback(
142
- (can: HTMLCanvasElement) =>
143
- drawIcon(can, img, w, h, crop, shadow, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY),
142
+ const canvas = useMemo(
143
+ () => drawIcon(img, w, h, crop, shadow, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY),
144
144
  [crop, h, img, shadow, shadowBlur, shadowColor, shadowOffsetX, shadowOffsetY, w],
145
145
  );
146
- const canvas = useCanvas(draw);
147
- return [canvas, w, h];
146
+ return [canvas ?? "", w, h];
148
147
  };
149
148
 
150
149
  export const ho = (o: "left" | "center" | "right" | undefined): HorizontalOrigin | undefined =>
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, useMemo, useRef } from "react";
1
+ import { useState, useEffect, useRef } from "react";
2
2
 
3
3
  export const useImage = (src?: string): HTMLImageElement | undefined => {
4
4
  const imgRef = useRef<HTMLImageElement>();
@@ -23,13 +23,3 @@ export const useImage = (src?: string): HTMLImageElement | undefined => {
23
23
 
24
24
  return img;
25
25
  };
26
-
27
- export const useCanvas = (cb: (canvas: HTMLCanvasElement) => void): string => {
28
- const can = useMemo(() => document.createElement("canvas"), []);
29
- const [data, setData] = useState<string>("");
30
- useEffect(() => {
31
- cb(can);
32
- setData(can.toDataURL());
33
- }, [can, cb]);
34
- return data;
35
- };