Vue 3 Plugin for MapLibre GL JS

5.6.1 · active · verified Tue Apr 21

Vue-MapLibre-GL is a small, actively maintained Vue 3 plugin that provides components and utilities for integrating MapLibre GL JS into Vue applications. The current stable version is 5.6.1, with minor releases occurring frequently, indicating active development and responsiveness to bug fixes and feature enhancements. Key differentiators include full TypeScript support, a comprehensive set of Vue components for managing maps, controls, sources, markers, and layers, and a built-in 'Simple Draw Control' that allows users to draw polygons, circles, and static circles. It also features support for multiple map instances via the `useMap` composition API hook, customizable style switching, language toggling, and automatic map restart on `CONTEXT_LOST_WEBGL` events, which is particularly useful for mobile device stability.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic MapLibre GL map within a Vue 3 application, including a navigation control. It shows the necessary imports for CSS and Vue components, and initializes the map with a default style and view.

import { createApp } from 'vue';
import { MglMap, MglNavigationControl } from 'vue-maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
import 'vue-maplibre-gl/dist/vue-maplibre-gl.css';
// import 'vue-maplibre-gl/dist/vue-maplibre-gl-draw.css'; // Uncomment if using MglDrawControl

const app = createApp({
  components: {
    MglMap,
    MglNavigationControl,
  },
  data() {
    return {
      mapStyle: 'https://demotiles.maplibre.org/style.json', // Or any other MapLibre GL compatible style URL
      center: [-74.0060, 40.7128], // New York City coordinates
      zoom: 10,
    };
  },
  template: `
    <div style="width: 100%; height: 500px;">
      <mgl-map
        :map-style="mapStyle"
        :center="center"
        :zoom="zoom"
      >
        <mgl-navigation-control position="top-right" />
      </mgl-map>
    </div>
  `,
});

app.mount('#app');

view raw JSON →