react-three-map 0.2.1 → 0.3.1

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.
Files changed (117) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +18 -15
  3. package/dist/cjs/main.js +1 -0
  4. package/dist/es/main.mjs +5 -0
  5. package/dist/es/main.mjs.map +1 -0
  6. package/dist/es/main2.mjs +38 -0
  7. package/dist/es/main2.mjs.map +1 -0
  8. package/dist/{maplibre/es/main.js3.mjs → es/main3.mjs} +1 -1
  9. package/dist/es/main3.mjs.map +1 -0
  10. package/dist/es/main4.mjs +19 -0
  11. package/dist/es/main4.mjs.map +1 -0
  12. package/dist/{maplibre/es/main.js5.mjs → es/main5.mjs} +3 -3
  13. package/dist/es/main5.mjs.map +1 -0
  14. package/dist/{maplibre/es/main.js6.mjs → es/main6.mjs} +2 -2
  15. package/dist/es/main6.mjs.map +1 -0
  16. package/dist/{maplibre/es/main.js7.mjs → es/main7.mjs} +1 -1
  17. package/dist/es/main7.mjs.map +1 -0
  18. package/dist/{maplibre/es/main.js8.mjs → es/main8.mjs} +1 -1
  19. package/dist/es/main8.mjs.map +1 -0
  20. package/dist/maplibre/cjs/main.js +1 -0
  21. package/dist/maplibre/es/main.mjs +5 -0
  22. package/dist/maplibre/es/main.mjs.map +1 -0
  23. package/dist/maplibre/es/main2.mjs +38 -0
  24. package/dist/maplibre/es/main2.mjs.map +1 -0
  25. package/dist/{es/main.js3.mjs → maplibre/es/main3.mjs} +1 -1
  26. package/dist/maplibre/es/main3.mjs.map +1 -0
  27. package/dist/maplibre/es/main4.mjs +19 -0
  28. package/dist/maplibre/es/main4.mjs.map +1 -0
  29. package/dist/{es/main.js8.mjs → maplibre/es/main5.mjs} +3 -3
  30. package/dist/maplibre/es/main5.mjs.map +1 -0
  31. package/dist/{es/main.js9.mjs → maplibre/es/main6.mjs} +2 -2
  32. package/dist/maplibre/es/main6.mjs.map +1 -0
  33. package/dist/{es/main.js10.mjs → maplibre/es/main7.mjs} +1 -1
  34. package/dist/maplibre/es/main7.mjs.map +1 -0
  35. package/dist/{es/main.js11.mjs → maplibre/es/main8.mjs} +1 -1
  36. package/dist/maplibre/es/main8.mjs.map +1 -0
  37. package/example-mapbox/package.json +29 -0
  38. package/example-mapbox/sandbox.config.json +3 -0
  39. package/example-mapbox/src/canvas.basic.stories.tsx +84 -0
  40. package/example-mapbox/src/comparison.stories.tsx +37 -0
  41. package/example-mapbox/src/html-on-top.stories.tsx +24 -0
  42. package/example-mapbox/src/my-scene.tsx +89 -0
  43. package/example-mapbox/src/render-on-demand.stories.tsx +32 -0
  44. package/example-mapbox/src/story-map.tsx +61 -0
  45. package/example-mapbox/src/vite-env.d.ts +1 -0
  46. package/example-mapbox/tsconfig.json +27 -0
  47. package/example-mapbox/tsconfig.node.json +10 -0
  48. package/example-mapbox/yarn.lock +4154 -0
  49. package/example-maplibre/package.json +29 -0
  50. package/example-maplibre/sandbox.config.json +3 -0
  51. package/example-maplibre/src/canvas.basic.stories.tsx +61 -0
  52. package/example-maplibre/src/comparison.stories.tsx +35 -0
  53. package/example-maplibre/src/html-on-top.stories.tsx +24 -0
  54. package/example-maplibre/src/my-scene.tsx +89 -0
  55. package/example-maplibre/src/render-on-demand.stories.tsx +32 -0
  56. package/example-maplibre/src/story-map.tsx +38 -0
  57. package/example-maplibre/src/vite-env.d.ts +1 -0
  58. package/example-maplibre/tsconfig.json +25 -0
  59. package/example-maplibre/tsconfig.node.json +10 -0
  60. package/example-maplibre/yarn.lock +4181 -0
  61. package/maplibre/package.json +2 -2
  62. package/package.json +22 -7
  63. package/src/{canvas/core → core}/generic-map.ts +15 -2
  64. package/src/{canvas/core → core}/state-ref.ts +2 -2
  65. package/src/{canvas/core/internal-canvas.tsx → core/use-canvas.tsx} +6 -18
  66. package/src/{canvas/core → core}/use-on-add.ts +3 -3
  67. package/src/{canvas/canvas-mapbox.tsx → mapbox/canvas.tsx} +15 -9
  68. package/src/mapbox/index.ts +1 -0
  69. package/src/{canvas/canvas-maplibre.tsx → maplibre/canvas.tsx} +13 -7
  70. package/src/maplibre/index.ts +1 -0
  71. package/src/stories/comparison.stories.tsx +27 -30
  72. package/src/stories/html-on-top.stories.tsx +11 -16
  73. package/src/stories/mapbox/story-mapbox.tsx +58 -0
  74. package/src/stories/mapbox-example.stories.tsx +84 -0
  75. package/src/stories/maplibre/story-maplibre.tsx +32 -0
  76. package/src/stories/{canvas.basic.stories.tsx → maplibre-example.stories.tsx} +28 -30
  77. package/src/stories/my-scene.tsx +3 -12
  78. package/src/stories/render-on-demand.stories.tsx +23 -37
  79. package/src/stories/story-map.tsx +23 -28
  80. package/tsconfig.json +5 -0
  81. package/dist/cjs/main.js.js +0 -1318
  82. package/dist/es/main.js.mjs +0 -5
  83. package/dist/es/main.js.mjs.map +0 -1
  84. package/dist/es/main.js10.mjs.map +0 -1
  85. package/dist/es/main.js11.mjs.map +0 -1
  86. package/dist/es/main.js2.mjs +0 -34
  87. package/dist/es/main.js2.mjs.map +0 -1
  88. package/dist/es/main.js3.mjs.map +0 -1
  89. package/dist/es/main.js4.mjs +0 -31
  90. package/dist/es/main.js4.mjs.map +0 -1
  91. package/dist/es/main.js5.mjs +0 -23537
  92. package/dist/es/main.js5.mjs.map +0 -1
  93. package/dist/es/main.js6.mjs +0 -5
  94. package/dist/es/main.js6.mjs.map +0 -1
  95. package/dist/es/main.js7.mjs +0 -5
  96. package/dist/es/main.js7.mjs.map +0 -1
  97. package/dist/es/main.js8.mjs.map +0 -1
  98. package/dist/es/main.js9.mjs.map +0 -1
  99. package/dist/maplibre/cjs/main.js.js +0 -1
  100. package/dist/maplibre/es/main.js.mjs +0 -5
  101. package/dist/maplibre/es/main.js.mjs.map +0 -1
  102. package/dist/maplibre/es/main.js2.mjs +0 -34
  103. package/dist/maplibre/es/main.js2.mjs.map +0 -1
  104. package/dist/maplibre/es/main.js3.mjs.map +0 -1
  105. package/dist/maplibre/es/main.js4.mjs +0 -31
  106. package/dist/maplibre/es/main.js4.mjs.map +0 -1
  107. package/dist/maplibre/es/main.js5.mjs.map +0 -1
  108. package/dist/maplibre/es/main.js6.mjs.map +0 -1
  109. package/dist/maplibre/es/main.js7.mjs.map +0 -1
  110. package/dist/maplibre/es/main.js8.mjs.map +0 -1
  111. package/src/main-mapbox.ts +0 -1
  112. package/src/main-maplibre.ts +0 -1
  113. /package/src/{canvas/core → core}/coords-to-matrix.ts +0 -0
  114. /package/src/{canvas/core → core}/create-events.ts +0 -0
  115. /package/src/{canvas/core → core}/generic-map.test.ts +0 -0
  116. /package/src/{canvas/core → core}/use-function.ts +0 -0
  117. /package/src/{canvas/core → core}/use-render.ts +0 -0
@@ -1,13 +1,11 @@
1
1
  import { Box, Plane, useHelper } from "@react-three/drei";
2
2
  import { MeshProps, useFrame, useThree } from '@react-three/fiber';
3
- import { useControls } from "leva";
4
- import 'maplibre-gl/dist/maplibre-gl.css';
5
3
  import { useCallback, useRef, useState } from 'react';
6
4
  import { CameraHelper, MathUtils, Mesh, OrthographicCamera } from "three";
7
5
 
8
- export function MyScene() {
6
+ export function MyScene({ showCamHelper }: { showCamHelper?: boolean }) {
9
7
  return <>
10
- <Lights />
8
+ <Lights showCamHelper={showCamHelper} />
11
9
  <Floor />
12
10
  <MyBox position={[-8 * 3, 8 * 1.5, 0]} />
13
11
  <MyBox position={[8 * 3, 8 * 1.5, 0]} />
@@ -53,15 +51,9 @@ function MyBox(props: MeshProps) {
53
51
  </Box>
54
52
  );
55
53
  }
56
- function Lights() {
54
+ function Lights({ showCamHelper }: { showCamHelper?: boolean }) {
57
55
  const cam = useRef<OrthographicCamera>(null);
58
56
  const noCam = useRef<OrthographicCamera>(null);
59
- const { showCamHelper } = useControls({
60
- showCamHelper: {
61
- value: false,
62
- label: 'show camera helper'
63
- }
64
- });
65
57
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
58
  useHelper((showCamHelper ? cam : noCam) as any, CameraHelper)
67
59
  const camSize = 100;
@@ -77,7 +69,6 @@ function Lights() {
77
69
  ref={cam}
78
70
  attach="shadow-camera"
79
71
  args={[-camSize, camSize, -camSize, camSize, 0.1, 100]}
80
- rotation={[0, 90 * MathUtils.DEG2RAD, 0]}
81
72
  />
82
73
  </directionalLight>
83
74
  <pointLight position={[-10, 0, -20]} color="white" intensity={1} />
@@ -1,47 +1,33 @@
1
- import { ThemeState, useLadleContext } from "@ladle/react";
2
1
  import { Box, Stats } from "@react-three/drei";
3
- import 'maplibre-gl/dist/maplibre-gl.css';
4
- import { useState } from "react";
5
- import Map from 'react-map-gl';
2
+ import { useRef, useState } from "react";
6
3
  import { MathUtils } from "three";
7
- import { Canvas } from "../canvas/canvas-maplibre";
8
- import MapLibre from "maplibre-gl";
4
+ import { StoryMap } from "./story-map";
9
5
 
10
6
  export function Default() {
11
7
 
12
- const theme = useLadleContext().globalState.theme;
13
-
14
- const mapStyle = theme === ThemeState.Dark
15
- ? "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
16
- : "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json";
17
-
18
8
  const [hovered, hover] = useState(false);
19
9
 
20
- return <div style={{ height: '100vh', position: 'relative' }}>
21
- <Map
22
- mapLib={MapLibre}
23
- antialias
24
- initialViewState={{
25
- latitude: 51,
26
- longitude: 0,
27
- zoom: 13,
28
- pitch: 60,
29
- }}
30
- mapStyle={mapStyle}
31
- >
32
- <Canvas latitude={51} longitude={0} frameloop="demand">
33
- <Box
34
- args={[500, 500, 500]}
35
- position={[0, 250, 0]}
36
- rotation={[0, 45 * MathUtils.DEG2RAD, 0]}
37
- onPointerOver={() => hover(true)}
38
- onPointerOut={() => hover(false)}
39
- material-color={hovered ? 'purple' : 'orange'}
40
- />
41
- <Stats />
42
- </Canvas>
43
- </Map>
44
- <div style={{ position: 'absolute', top: 0, right: 0, left: 80, background: '#ffffffc2', padding: 5 }}>
10
+ const ref = useRef<HTMLDivElement>(null)
11
+
12
+ return <div ref={ref} style={{ height: '100vh', position: 'relative' }}>
13
+ <style>{`.stats{position:absolute !important}`}</style>
14
+ <StoryMap
15
+ latitude={51}
16
+ longitude={0}
17
+ zoom={13}
18
+ pitch={60}
19
+ canvas={{ frameloop: 'demand' }}>
20
+ <Box
21
+ args={[500, 500, 500]}
22
+ position={[0, 250, 0]}
23
+ rotation={[0, 45 * MathUtils.DEG2RAD, 0]}
24
+ onPointerOver={() => hover(true)}
25
+ onPointerOut={() => hover(false)}
26
+ material-color={hovered ? 'purple' : 'orange'}
27
+ />
28
+ <Stats className="stats" parent={ref} />
29
+ </StoryMap>
30
+ <div style={{ position: 'absolute', bottom: 0, right: 0, left: 0, background: '#ffffffc2', padding: '15px 20px 40px' }}>
45
31
  Hover over the box, it will only render once to change colour, or when you move the camera. Look at the stats to confirm.
46
32
  </div>
47
33
  </div>
@@ -1,40 +1,35 @@
1
- import 'maplibre-gl/dist/maplibre-gl.css';
2
- import { FC, PropsWithChildren } from "react"
3
- import MapLibre from "maplibre-gl";
4
- import Map from 'react-map-gl';
5
- import { useLadleContext, ThemeState } from '@ladle/react';
1
+ import { useControls } from 'leva';
2
+ import { FC, PropsWithChildren } from "react";
3
+ import { StoryMapbox } from './mapbox/story-mapbox';
4
+ import { StoryMaplibre } from './maplibre/story-maplibre';
5
+ import { CanvasProps } from '../maplibre/canvas';
6
+
7
+ export enum MapProvider {
8
+ maplibre = "maplibre",
9
+ mapbox = "mapbox",
10
+ }
6
11
 
7
12
  export interface StoryMapProps extends PropsWithChildren {
8
- latitude?: number,
9
- longitude?: number,
13
+ latitude: number,
14
+ longitude: number,
10
15
  zoom?: number,
11
16
  pitch?: number,
17
+ canvas?: Partial<CanvasProps>,
12
18
  }
13
19
 
14
20
  /** `<Map>` styled for stories */
15
- export const StoryMap: FC<StoryMapProps> = ({
16
- children
17
- }) => {
18
-
19
- const theme = useLadleContext().globalState.theme;
21
+ export const StoryMap: FC<StoryMapProps> = (props) => {
20
22
 
21
- const mapStyle = theme === ThemeState.Dark
22
- ? "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json"
23
- : "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json";
23
+ const { mapProvider } = useControls({
24
+ mapProvider: {
25
+ value: MapProvider.maplibre,
26
+ options: MapProvider,
27
+ label: 'map provider'
28
+ },
29
+ });
24
30
 
25
31
  return <div style={{ height: '100vh', position: 'relative' }}>
26
- <Map
27
- mapLib={MapLibre}
28
- antialias
29
- initialViewState={{
30
- latitude: 51,
31
- longitude: 0,
32
- zoom: 13,
33
- pitch: 60,
34
- }}
35
- mapStyle={mapStyle}
36
- >
37
- {children}
38
- </Map>
32
+ {mapProvider === MapProvider.maplibre && <StoryMaplibre {...props} />}
33
+ {mapProvider === MapProvider.mapbox && <StoryMapbox {...props} />}
39
34
  </div>
40
35
  }
package/tsconfig.json CHANGED
@@ -14,6 +14,11 @@
14
14
  "noEmit": true,
15
15
  "jsx": "react-jsx",
16
16
 
17
+ "paths": {
18
+ "react-three-map": ["./src/mapbox/index.ts"],
19
+ "react-three-map/maplibre": ["./src/maplibre/index.ts"],
20
+ },
21
+
17
22
  /* Linting */
18
23
  "strict": true,
19
24
  "noUnusedLocals": true,