A React template for building interactive web maps with MapLibre GL JS.
- React 19 with TypeScript
- MapLibre GL JS for map rendering
- Vite for fast development and building
- Geoman for geometry drawing and editing
- GeoEditor for advanced geometry operations (cut, split, union, difference)
- Layer Control for layer visibility management
- Legend component for map legends
- GitHub Pages deployment workflow
- Node.js 20 or later
- npm
# Clone the repository
git clone https://github.com/opengeo/vite-maplibre-react.git
cd vite-maplibre-react
# Install dependencies
npm install# Start development server
npm run devOpen http://localhost:5173 in your browser.
# Build for production
npm run build
# Preview production build
npm run previewdocker build -t vite-maplibre-react .docker run -p 8080:80 vite-maplibre-reactOpen http://localhost:8080/vite-maplibre-react/ in your browser.
Create a docker-compose.yml file:
version: "3.8"
services:
app:
build: .
ports:
- "8080:80"Then run:
docker-compose upvite-maplibre-react/
├── src/
│ ├── components/
│ │ └── Map/
│ │ ├── Map.tsx # Main map component
│ │ ├── Map.css # Map styles
│ │ └── index.ts
│ ├── hooks/
│ │ ├── useMapLibre.ts # Custom hook for MapLibre
│ │ └── index.ts
│ ├── data/
│ │ └── countries.ts # Sample GeoJSON data
│ ├── config/
│ │ └── mapConfig.ts # Map configuration
│ ├── App.tsx
│ ├── App.css
│ ├── main.tsx
│ └── index.css
├── public/
├── index.html
├── package.json
├── vite.config.ts
├── tsconfig.json
├── Dockerfile
└── README.md
Edit src/config/mapConfig.ts:
export const BASE_MAP_STYLE = "https://your-style-url/style.json";Modify the setupLayers function in src/hooks/useMapLibre.ts to add your own data sources and layers.
Adjust GEO_EDITOR_CONFIG in src/config/mapConfig.ts to enable/disable drawing and editing tools.
The repository includes a GitHub Actions workflow for automatic deployment to GitHub Pages. Push to the main branch to trigger deployment.
npm run buildUpload the contents of the dist/ folder to your web server.