@@ -4,45 +4,49 @@ import { FC, useRef, useState } from "react";
4
4
import Map from 'react-map-gl/maplibre' ;
5
5
import { Mesh } from "three" ;
6
6
import { Canvas } from "react-three-map/maplibre" ;
7
+ import { Leva } from "leva" ;
7
8
8
- export default { title : 'Canvas' }
9
+ export default { title : 'Canvas' }
9
10
10
11
export function Maplibre ( ) {
11
- return < div style = { { height : '100vh' } } >
12
- < Map
13
- antialias
14
- initialViewState = { {
15
- latitude : 51 ,
16
- longitude : 0 ,
17
- zoom : 13 ,
18
- pitch : 60 ,
19
- } }
20
- mapStyle = "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
21
- >
22
- < Canvas latitude = { 51 } longitude = { 0 } >
23
- < hemisphereLight
24
- args = { [ "#ffffff" , "#60666C" ] }
25
- position = { [ 1 , 4.5 , 3 ] }
26
- intensity = { Math . PI }
27
- />
28
- < object3D scale = { 500 } >
29
- < Box position = { [ - 1.2 , 1 , 0 ] } />
30
- < Box position = { [ 1.2 , 1 , 0 ] } />
31
- </ object3D >
32
- </ Canvas >
33
- </ Map >
34
- </ div >
12
+ return < >
13
+ < Leva theme = { { sizes : { rootWidth : '340px' , controlWidth : '150px' } } } />
14
+ < div style = { { height : '100vh' } } >
15
+ < Map
16
+ antialias
17
+ initialViewState = { {
18
+ latitude : 51 ,
19
+ longitude : 0 ,
20
+ zoom : 13 ,
21
+ pitch : 60 ,
22
+ } }
23
+ mapStyle = "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
24
+ >
25
+ < Canvas latitude = { 51 } longitude = { 0 } >
26
+ < hemisphereLight
27
+ args = { [ "#ffffff" , "#60666C" ] }
28
+ position = { [ 1 , 4.5 , 3 ] }
29
+ intensity = { Math . PI }
30
+ />
31
+ < object3D scale = { 500 } >
32
+ < Box position = { [ - 1.2 , 1 , 0 ] } />
33
+ < Box position = { [ 1.2 , 1 , 0 ] } />
34
+ </ object3D >
35
+ </ Canvas >
36
+ </ Map >
37
+ </ div >
38
+ </ >
35
39
}
36
40
37
- const Box : FC < { position : Vector3 } > = ( props ) => {
41
+ const Box : FC < { position : Vector3 } > = ( props ) => {
38
42
// This reference gives us direct access to the THREE.Mesh object
39
43
const ref = useRef < Mesh > ( null )
40
44
// Hold state for hovered and clicked events
41
45
const [ hovered , hover ] = useState ( false )
42
46
const [ clicked , click ] = useState ( false )
43
47
// Subscribe this component to the render-loop, rotate the mesh every frame
44
48
useFrame ( ( _state , delta ) => {
45
- if ( ! ref . current ) return ;
49
+ if ( ! ref . current ) return ;
46
50
ref . current . rotation . x += delta ;
47
51
ref . current . rotation . z -= delta ;
48
52
} )
0 commit comments