Mapbox

Gitlab
A Vue component that provides a complete Mapbox GL JS integration with clustering support.
Added since: v0.1.0
Last changed:

Overview

The Mapbox component is a high-level wrapper that combines MapboxMap and MapboxSupercluster components to provide a complete Mapbox GL JS integration with built-in clustering support. It handles the initialization of the map and manages the clustering of markers automatically.

Usage

<template>
  <Mapbox
    :features="features"
    :initialize-with="mapOptions"
    @loaded="onMapLoaded"
  >
    <!-- Custom marker template -->
    <template #marker="{ id, feature }">
      <MapboxMarker
        :id="id"
        :feature="feature"
        class="custom-marker"
      >
        {{ feature.properties.name }}
      </MapboxMarker>
    </template>

    <!-- Custom cluster marker template -->
    <template #cluster="{ id, feature }">
      <MapboxClusterMarker
        :id="id"
        :feature="feature"
        class="custom-cluster"
      >
        {{ feature.properties.point_count }}
      </MapboxClusterMarker>
    </template>
  </Mapbox>
</template>

<script setup lang="ts">
const features = ref([
  {
    type: 'Feature',
    geometry: {
      type: 'Point',
      coordinates: [-74.5, 40]
    },
    properties: {
      name: 'Location 1'
    }
  }
]);

const mapOptions = {
  zoom: 12,
  center: [-74.5, 40]
};

const onMapLoaded = (map) => {
  console.log('Map loaded:', map);
};
</script>

API Reference

Props

PropDefaultType
clusterMarkerClass
string
CSS class to apply to individual markers
clusterClusterMarkerClass
string
CSS class to apply to cluster markers

Emits

EmitPayload
loaded
(map: Map) => void
Emitted when the map is fully loaded

Slots

SlotPayload
marker
{ id: string, feature: Feature }
Custom template for individual markers
cluster
{ id: string, feature: Feature }
Custom template for cluster markers
loader
{}
Custom loading state template

Exposed

ExposedType
focusFeatures()
(features: MapboxFeatures) => void
Focus the map on specific features

Features

  • Automatic marker clustering
  • Custom marker templates
  • Custom cluster templates

Changelog