# react-three-map
**Repository Path**: zyy_gis98/react-three-map
## Basic Information
- **Project Name**: react-three-map
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: cool-extrution
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-09-03
- **Last Updated**: 2024-09-03
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# React Three Map
[](https://github.com/RodrigoHamuy/react-three-map)
[](https://npmjs.com/package/react-three-map)
[](https://bundlephobia.com/result?p=react-three-map)
[](https://github.com/RodrigoHamuy/react-three-map/actions?query=workflow%3Arelease)
[](https://rodrigohamuy.github.io/react-three-map/?story=canvas--a-maplibre-example)
[](https://github.com/sponsors/RodrigoHamuy?frequency=one-time&sponsor=RodrigoHamuy)
`react-three-map` is a bridge to use [`react-three-fiber`](https://github.com/pmndrs/react-three-fiber) inside [`react-map-gl`](https://github.com/visgl/react-map-gl).
Until now you had:
| imperative | declarative (react) |
| --------------- | ----------------- |
| Maplibre/Mapbox | react-map-gl |
| THREE.js | react-three-fiber |
Now with `react-three-map`, you can use them together :fist_right::star::fist_left:.
```sh
npm install react-three-map
```
## :book: Examples
Check out our examples [here](https://rodrigohamuy.github.io/react-three-map) (powered by [Ladle](https://ladle.dev/)).
## :mag: What does it look like?
Let's build the same react-three-fiber basic example, but now it can be inside a map. (live demo). |
|
1. Import `Canvas` from `react-three-map` instead of `@react-three/fiber`.
2. Give it a latitude and longitude so it knows where to position the scene in the map.
3. Everything else should work just as usual.
```jsx
import "maplibre-gl/dist/maplibre-gl.css"
import { createRoot } from 'react-dom/client'
import React, { useRef, useState } from 'react'
import { useFrame } from "@react-three/fiber"
import { useRef, useState } from "react"
import Map from "react-map-gl/maplibre"
import { Canvas } from "react-three-map/maplibre"
// import { Canvas } from "react-three-map" // if you are using MapBox
function BasicExample() {
return
}
```
## :thinking: Why we build this?
Look [how complex](https://maplibre.org/maplibre-gl-js-docs/example/add-3d-model/) is to add just one ThreeJS object to a map.
Look [how complex](https://docs.pmnd.rs/react-three-fiber/api/canvas#createroot) is to create your custom root for R3F.
You can now replace all that complexity and hundreds of lines of code with the `