react-three-map 0.1.1 → 0.1.2

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": "react-three-map",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Use react-three-fiber inside MapLibre and Mapbox",
5
5
  "main": "dist/cjs/main.js",
6
6
  "module": "dist/es/main.js",
@@ -22,7 +22,9 @@
22
22
  "preview": "vite preview",
23
23
  "ts": "tsc -w",
24
24
  "stories": "yarn ladle serve",
25
- "build:stories": "yarn ladle build"
25
+ "build:stories": "yarn ladle build",
26
+ "release": "npm run publish",
27
+ "prerelease": "yarn build"
26
28
  },
27
29
  "dependencies": {},
28
30
  "devDependencies": {
@@ -1,9 +1,9 @@
1
1
  import { RenderProps, createRoot } from "@react-three/fiber";
2
+ import { useState } from "react";
2
3
  import { MapInstance } from "react-map-gl";
3
4
  import { createEvents } from "./create-events";
4
5
  import { StateRef } from "./state-ref";
5
6
  import { useFunction } from "./use-function";
6
- import { useState } from "react";
7
7
 
8
8
  export function useOnAdd (ref: StateRef, renderProps: RenderProps<HTMLCanvasElement>) {
9
9
 
@@ -52,14 +52,25 @@ export function useOnAdd (ref: StateRef, renderProps: RenderProps<HTMLCanvasElem
52
52
  root,
53
53
  }
54
54
 
55
+ map.on('resize', onResize)
56
+
55
57
  setTimeout(()=>setMounted(true));
56
58
 
57
59
  })
58
60
 
59
- const onRemove = useFunction(()=>{
61
+ const onResize = useFunction(()=>{
62
+ if(!ref.current?.state) return;
63
+ const state = ref.current.state;
64
+ const map = ref.current.map;
65
+ const canvas = map.getCanvas();
66
+ state.setSize(canvas.width, canvas.height);
67
+ })
68
+
69
+ const onRemove = useFunction((map: MapInstance)=>{
60
70
  setTimeout(()=>{
61
71
  if(!ref.current) return;
62
72
  ref.current.root.unmount();
73
+ map.off(onRemove);
63
74
  })
64
75
  })
65
76