<Mapbox>

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

Usage

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.

Basic example

MapComponent.vue
<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>

<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>

Type Definition

type 
MapboxProps
= {
/** * The class to apply to the cluster marker. */
clusterMarkerClass
?: string;
/** * The class to apply to the cluster cluster marker. */
clusterClusterMarkerClass
?: string;
};

API Reference

Props

PropDefaultType
clusterMarkerClass
string

The class to apply to the cluster marker.

clusterClusterMarkerClass
string

The class to apply to the cluster cluster marker.

Events

See the MapboxMap events for the available events.

Slots

SlotPayload
cluster-marker

Custom template for individual markers

cluster-cluster-marker

Custom template for cluster markers

Exposed

ExposedType
focusFeatures()(features: MapboxFeatures) => void

Focus the map on specific features

Changelog

v0.2.3

on

#ebea626c

-

improvement: added full typescript support