Skip to content

Commit

Permalink
fix #95 fix stories
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoHamuy committed Apr 19, 2024
1 parent eb9e9b7 commit 5162646
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions stories/src/canvas/maplibre.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,49 @@ import { FC, useRef, useState } from "react";
import Map from 'react-map-gl/maplibre';
import { Mesh } from "three";
import { Canvas } from "react-three-map/maplibre";
import { Leva } from "leva";

export default {title: 'Canvas'}
export default { title: 'Canvas' }

export function Maplibre() {
return <div style={{ height: '100vh' }}>
<Map
antialias
initialViewState={{
latitude: 51,
longitude: 0,
zoom: 13,
pitch: 60,
}}
mapStyle="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
>
<Canvas latitude={51} longitude={0}>
<hemisphereLight
args={["#ffffff", "#60666C"]}
position={[1, 4.5, 3]}
intensity={Math.PI}
/>
<object3D scale={500}>
<Box position={[-1.2, 1, 0]} />
<Box position={[1.2, 1, 0]} />
</object3D>
</Canvas>
</Map>
</div>
return <>
<Leva theme={{ sizes: { rootWidth: '340px', controlWidth: '150px' } }} />
<div style={{ height: '100vh' }}>
<Map
antialias
initialViewState={{
latitude: 51,
longitude: 0,
zoom: 13,
pitch: 60,
}}
mapStyle="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
>
<Canvas latitude={51} longitude={0}>
<hemisphereLight
args={["#ffffff", "#60666C"]}
position={[1, 4.5, 3]}
intensity={Math.PI}
/>
<object3D scale={500}>
<Box position={[-1.2, 1, 0]} />
<Box position={[1.2, 1, 0]} />
</object3D>
</Canvas>
</Map>
</div>
</>
}

const Box : FC<{position: Vector3}> = (props) => {
const Box: FC<{ position: Vector3 }> = (props) => {
// This reference gives us direct access to the THREE.Mesh object
const ref = useRef<Mesh>(null)
// Hold state for hovered and clicked events
const [hovered, hover] = useState(false)
const [clicked, click] = useState(false)
// Subscribe this component to the render-loop, rotate the mesh every frame
useFrame((_state, delta) => {
if(!ref.current) return;
if (!ref.current) return;
ref.current.rotation.x += delta;
ref.current.rotation.z -= delta;
})
Expand Down

0 comments on commit 5162646

Please sign in to comment.