1.5.9 • Published 9 days ago

nuxt-mapbox v1.5.9

Weekly downloads
-
License
MIT
Repository
-
Last release
9 days ago

Nuxt-Mapbox

Elegant Mapbox integration with Nuxt

npm version npm downloads License

Features

  • 🏗  Easily add Mapbox to your Nuxt app with Vue components
  • 🌎  useMapbox Composable for easy access
  • 👷  defineMapboxMarker & defineMapboxPopup for making custom components
  • 📖  Supports many map instances across routes

TODO

  • Popup
  • Marker
  • Add rest of global properties to config
  • Event Listeners
  • Unit tests
  • Custom Control Component?

Quick Setup

  1. Add nuxt-mapbox & mapbox-gl dependencies to your project
# Using pnpm
pnpm add -D nuxt-mapbox mapbox-gl

# Using yarn
yarn add --dev nuxt-mapbox mapbox-gl

# Using npm
npm install --save-dev nuxt-mapbox mapbox-gl
  1. Add nuxt-mapbox to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-mapbox'
  ]
})
  1. Add your Mapbox API key to the mapbox section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-mapbox'
  ],
  mapbox: {
    accessToken: '{API_KEY}'
  }
})

Usage

View the Mapbox GL JS Docs for reference.

Map instances are created with components. You can provide all the options through component props

Example:

    <MapboxMap
      map-id="{ID}"
      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 & Controls by nesting their components inside the Map

Examples:

    <MapboxMap>
      <MapboxSource 
        source-id="geojson"
        :source="{
          type: 'geojson',
          data: '/test.geojson'
        }"
      />
      <MapboxLayer
        source-id="geojson"
        :layer="{
          source: 'geojson',
          id: 'geojson-layer',
          type: 'fill'
        }"
      />
    </MapboxMap>
    <MapboxMap>
      <MapboxLayer
        source-id="{ID}"
        :source="{
          type: 'geojson',
          data: '/test.geojson'
        }"
        :layer="{
          source: '{ID}',
          id: 'geojson-layer',
          type: 'fill'
        }"
      />
      <MapboxFullscreenControl />
    </MapboxMap>

You can access the map instance with the useMapbox composable. You must provide the map id.

The map instance will not be available until the page is fully loaded, so you must access it through a callback

    useMapbox(mapId, (map) => {
      // Do whatever with map here
    })

You can access the map instance ref directly with _useMapboxInstance

NOTE: The map instance will be null until is initialized so you cannot access it directly on setup. Use a watcher as shown or useMapbox instead:

    const map = _useMapboxInstance(mapId)
    watch(map, () => {
      if (map.value)
        // Do whatever with map
    })

Custom Popups & Markers

While it is recommended to use the default popup & marker components, making your own is easy using defineMapboxMarker & defineMapboxPopup.

By passing a template ref you can put custom html directly into your component

Examples:

      const popup = defineMapboxPopup(popupId, options, templateRef)
      popup?.setLngLat(lnglat)

NOTE: Because of the way markers are implemented in Mapbox, if passing a template ref to defineMapboxPopup you have to define properties in a callback like so:

    const markerRef = defineMapboxMarker(markerId, options, templateRef, (marker) => {
        marker.setLngLat([110, 6])
    })

Development

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release
1.5.10-dev.3

9 days ago

1.6.0-dev.0

9 days ago

1.5.10-dev.2

11 days ago

1.5.10-dev.1

11 days ago

1.5.10-dev.0

11 days ago

1.5.9-dev.1

2 months ago

1.5.9

2 months ago

1.5.8-dev.0

3 months ago

1.5.8

3 months ago

1.5.7

4 months ago

1.5.6

4 months ago

1.5.1-dev.1

6 months ago

1.5.0-dev.0

7 months ago

1.5.3-dev.1

5 months ago

1.5.0-dev.1

7 months ago

1.5.0-dev.2

6 months ago

1.5.0-dev.3

6 months ago

1.5.5

5 months ago

1.5.0-dev.4

6 months ago

1.5.4

5 months ago

1.5.3

5 months ago

1.5.3-dev.0

5 months ago

1.5.2

6 months ago

1.5.1

6 months ago

1.5.0

6 months ago

1.4.5

7 months ago

1.4.5-1

7 months ago

1.5.4-dev.1

5 months ago

1.5.4-dev.0

5 months ago

1.5.2-dev.0

6 months ago

1.4.5-dev.0

7 months ago

1.4.0-dev.1

11 months ago

1.4.0-dev.2

10 months ago

1.4.0-dev.3

10 months ago

1.3.5-dev.1

11 months ago

1.4.0-dev.4

10 months ago

1.3.8-dev.7

11 months ago

1.3.8-dev.6

11 months ago

1.4.0-dev.0

11 months ago

1.4.0-dev.9

10 months ago

1.4.4

8 months ago

1.4.3

8 months ago

1.4.2

9 months ago

1.4.0-dev.5

10 months ago

1.4.1

9 months ago

1.4.0-dev.6

10 months ago

1.3.5-dev.0

11 months ago

1.4.0

10 months ago

1.4.0-dev.7

10 months ago

1.4.0-dev.8

10 months ago

1.3.8-dev.5

11 months ago

1.3.8-dev.4

11 months ago

1.3.8-dev.3

11 months ago

1.3.8-dev.2

11 months ago

1.3.8-dev.1

11 months ago

1.3.8-dev.0

11 months ago

1.3.7-dev.4

11 months ago

1.3.7-dev.3

11 months ago

1.3.7-dev.0

11 months ago

1.3.9

11 months ago

1.3.7-dev.2

11 months ago

1.3.8

11 months ago

1.3.7-dev.1

11 months ago

1.3.4-dev.1

12 months ago

1.4.0-dev.11

10 months ago

1.3.4-dev.2

12 months ago

1.4.0-dev.10

10 months ago

1.4.2-dev.0

9 months ago

1.3.7

11 months ago

1.3.6

11 months ago

1.3.5

11 months ago

1.3.4

12 months ago

1.3.3

12 months ago

1.3.3-dev.0

12 months ago

1.4.1-dev.0

9 months ago

1.3.6-dev.0

11 months ago

1.3.2

1 year ago

1.3.2-1

1 year ago

1.3.2-dev.1

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.3.0-dev.2

1 year ago

1.3.0-dev.1

1 year ago

1.3.0-dev.0

1 year ago

1.2.3

1 year ago

1.2.3-dev.0

1 year ago

1.2.2

1 year ago

1.2.2-dev.6

1 year ago

1.2.2-dev.4

1 year ago

1.2.2-dev.3

1 year ago

1.2.2-dev.2

1 year ago

1.2.2-dev.1

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.2.0-alpha.2

1 year ago

1.2.0-alpha.1

1 year ago

1.2.0-alpha.0

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago