Elegant Mapbox GL JS integration with Nuxt
----------------------------------------------------------------
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![License][license-src]][license-href]
>
- ✨ Release Notes
- 🏀 Online playground
- 🏗 Easily add Mapbox to your Nuxt app with Vue components
- 🌎 useMapbox Composable for easy access
- 👷 defineMapboxMarker & defineMapboxPopup for making custom components
- 🎛️ defineMapboxControl for creating your own controls
- 📖 Persistent map instances across routes
1. Add nuxt-mapbox & mapbox-gl dependencies to your project
``bash`
npx nuxi@latest module add nuxt-mapbox
npm install --save-dev mapbox-gl
2. Add nuxt-mapbox to the modules section of nuxt.config.ts
`js`
export default defineNuxtConfig({
modules: [
'nuxt-mapbox'
]
})
3. Add your Mapbox API key to the mapbox section of nuxt.config.ts
`js`
export default defineNuxtConfig({
modules: [
'nuxt-mapbox'
],
mapbox: {
accessToken: '{API_KEY}'
}
})
Map instances are created with components. You can provide all the options through component props
Example:
`html`
style="position: absolute; top: 0; bottom: 0; left: 250px; width: 500px;"
:options="{
style: 'mapbox://styles/mapbox/light-v11', // style URL
center: [-68.137343, 45.137451], // starting position
zoom: 5 // starting zoom
}"
/>
You can add Layers, Sources & Controls by nesting their respective components inside the Map
Examples:
`html`
>
:source="{
type: 'geojson',
data: '/test.geojson'
}"
/>
source: '{ID}',
id: 'geojson-layer',
type: 'fill'
}"
/>
`bashInstall dependencies
npm install
[npm-version-src]: https://img.shields.io/npm/v/nuxt-mapbox/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/nuxt-mapbox
[npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-mapbox.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-downloads-href]: https://npmjs.com/package/nuxt-mapbox
[license-src]: https://img.shields.io/npm/l/nuxt-mapbox.svg?style=flat&colorA=18181B&colorB=28CF8D
[license-href]: https://npmjs.com/package/nuxt-mapbox