Skip to main content
Docs homeExamplesGitHub
Layers

MapLibre Layers

Native MapLibre GL layers and custom derived layers

See Peer Dependencies for the complete list of required packages for each component.

MapLibre Layers

Native MapLibre GL layer components for common use cases.

Base Layers

These components wrap MapLibre's native layer types:

ComponentDescription
VLayerMaplibreGeojsonGeoJSON data visualization
VLayerMaplibreVectorVector tile layers
VLayerMaplibreRasterRaster tile layers
VLayerMaplibreImageGeoreferenced images
VLayerMaplibreVideoGeoreferenced video
VLayerMaplibreCanvasCustom canvas rendering
VLayerMaplibrePmtilePMTiles archives

VLayerMaplibreGeojson

Adds a GeoJSON source and one MapLibre layer that draws it. The source and the layer are added when the style is ready and data is set, and they are removed on unmount. data can be a FeatureCollection, a Feature, a geometry, or a URL string that MapLibre fetches itself. An empty FeatureCollection is valid and clears the layer, so a cleared selection needs no extra call.

Props

PropTypeDefaultDescription
sourceIdstring'maplibre-gl-geojson-source'Source ID. Layers with the same sourceId share one source: the first one adds it, and it is removed when the last one unmounts.
layerIdstring'maplibre-gl-geojson-layer'Layer ID. Must be unique on the map.
sourceGeoJSONSourceSpecificationrequiredSource specification. source.data accepts an object or a URL string; a change updates the source data in place, including a change to an empty FeatureCollection.
layerLayerSpecificationrequiredLayer specification. Its id and source are set from layerId and sourceId. paint and layout changes are applied to the live layer.
beforestring''ID of a layer to insert this layer before. If that layer is not on the map yet, the layer is added on top and moved under it once it appears. Empty adds it on top.

Events

EventPayloadDescription
on-click{ features, coordinates }A feature of this layer was clicked.

Order

Layers are added in the order they mount, which is template order. A later layer draws on top, so put a casing before its line. Use before to place a layer under one that is already on the map, for example under the basemap labels.

Example: one source, several layers

<script setup lang="ts">
import { ref } from 'vue';
import { VMap, VLayerMaplibreGeojson } from '@geoql/v-maplibre';
import type { GeoJSONSourceSpecification, LayerSpecification } from 'maplibre-gl';

const roads = ref<GeoJSONSourceSpecification>({
  type: 'geojson',
  data: { type: 'FeatureCollection', features: [] }, // load your data
});

const casing: LayerSpecification = {
  id: 'roads-casing',
  type: 'line',
  source: 'roads',
  paint: { 'line-color': '#1f2937', 'line-width': 6 },
};

const line: LayerSpecification = {
  id: 'roads-line',
  type: 'line',
  source: 'roads',
  paint: { 'line-color': '#f8fafc', 'line-width': 3 },
};
</script>

<template>
  <VMap :options="mapOptions">
    <!-- Drawn first, so it is under the line. -->
    <VLayerMaplibreGeojson
      source-id="roads"
      layer-id="roads-casing"
      :source="roads"
      :layer="casing"
      before="place-labels"
    />
    <VLayerMaplibreGeojson
      source-id="roads"
      layer-id="roads-line"
      :source="roads"
      :layer="line"
      before="place-labels"
      @on-click="({ features }) => console.log(features)"
    />
  </VMap>
</template>

place-labels must be a layer in your basemap style. Leave before out to add the layers on top.

Custom Layers

Higher-level components that compose multiple MapLibre layers:

VLayerMaplibreCluster

Clustered point visualization with automatic grouping.

Props

PropTypeDefaultDescription
sourceIdstring'cluster-source'GeoJSON source ID
baseLayerIdstring'cluster'Base ID for generated layers
sourceGeoJSONSourceSpecification-GeoJSON source configuration
visibilitybooleantrueLayer visibility
clusterPaintobjectSee belowCluster circle styling
unclusteredPaintobjectSee belowIndividual point styling
textPaintobjectSee belowCluster count text styling

Events

EventPayloadDescription
cluster-click{ features, coordinates }Cluster circle clicked
point-click{ features, coordinates }Individual point clicked

Example

<script setup lang="ts">
import { VMap, VLayerMaplibreCluster } from '@geoql/v-maplibre';

const earthquakes = ref({
  type: 'FeatureCollection',
  features: [], // Load your point data
});
</script>

<template>
  <VMap :options="mapOptions">
    <VLayerMaplibreCluster
      source-id="earthquakes"
      base-layer-id="quakes"
      :source="{ type: 'geojson', data: earthquakes }"
      @cluster-click="handleClusterClick"
      @point-click="handlePointClick"
    />
  </VMap>
</template>

VLayerMaplibreRoute

Route/path visualization for navigation and delivery tracking.

Props

PropTypeDefaultDescription
idstringAuto-generatedUnique route identifier
coordinates[number, number][]-Array of lng, lat coordinates
colorstring'#4285F4'Line color
widthnumber4Line width in pixels
opacitynumber1Line opacity (0-1)
lineCap'butt' | 'round' | 'square''round'Line cap style
lineJoin'bevel' | 'round' | 'miter''round'Line join style
visiblebooleantrueRoute visibility
interactivebooleantrueEnable hover/click
dashArraynumber[]-Dash pattern for dashed lines
blurnumber0Line blur in pixels

Events

EventPayloadDescription
click{ coordinates }Route line clicked
mouseenter-Mouse enters route
mouseleave-Mouse leaves route

Example

<script setup lang="ts">
import { VMap, VLayerMaplibreRoute } from '@geoql/v-maplibre';

const routeCoordinates = ref([
  [-122.4194, 37.7749],
  [-122.4089, 37.7855],
  [-122.3984, 37.7925],
]);
</script>

<template>
  <VMap :options="mapOptions">
    <VLayerMaplibreRoute
      id="my-route"
      :coordinates="routeCoordinates"
      color="#10b981"
      :width="5"
      @click="handleRouteClick"
    />
  </VMap>
</template>

VLayerMaplibreIsochrone

Isochrone/isodistance polygon visualization for travel time analysis.

Isochrones show areas reachable within a specific time or distance from a point. They're commonly used for delivery coverage, commute analysis, and accessibility mapping.

Props

PropTypeDefaultDescription
idstringAuto-generatedUnique layer identifier
dataIsochroneData | null-GeoJSON FeatureCollection from routing API
fillOpacitynumber0.4Polygon fill opacity (0-1)
lineWidthnumber2Outline width in pixels
lineOpacitynumber0.8Outline opacity (0-1)
visiblebooleantrueLayer visibility
interactivebooleantrueEnable hover/click
reverseOrderbooleantrueReverse feature order for proper stacking

Events

EventPayloadDescription
click{ feature, coordinates }Polygon clicked
mouseenterfeatureMouse enters polygon
mouseleave-Mouse leaves polygon

Data Format

The component accepts GeoJSON from routing APIs like Valhalla or OSRM. It automatically handles color format conversion (Valhalla returns colors without # prefix).

interface IsochroneData {
  type: 'FeatureCollection';
  features: Array<{
    type: 'Feature';
    properties: {
      color: string;      // e.g., '2563eb' or '#2563eb'
      contour?: number;   // Time in minutes or distance
      metric?: string;    // 'time' or 'distance'
    };
    geometry: Polygon | MultiPolygon;
  }>;
}

Example with Valhalla API

<script setup lang="ts">
import { VMap, VMarker, VLayerMaplibreIsochrone } from '@geoql/v-maplibre';

const originPoint = ref<[number, number]>([-73.985, 40.758]);
const isochroneData = ref(null);

async function fetchIsochrone() {
  const params = {
    locations: [{ lat: originPoint.value[1], lon: originPoint.value[0] }],
    costing: 'auto',
    contours: [
      { time: 5, color: '2563eb' },
      { time: 10, color: '7c3aed' },
      { time: 15, color: 'db2777' },
    ],
    polygons: true,
  };

  const response = await fetch(`/api/isochrone?json=${encodeURIComponent(JSON.stringify(params))}`);
  isochroneData.value = await response.json();
}

function handleMarkerDrag(event) {
  const lngLat = event.target.getLngLat();
  originPoint.value = [lngLat.lng, lngLat.lat];
  fetchIsochrone();
}
</script>

<template>
  <VMap :options="mapOptions" @loaded="fetchIsochrone">
    <VLayerMaplibreIsochrone
      id="travel-zones"
      :data="isochroneData"
      :fill-opacity="0.5"
      @click="handleZoneClick"
    />
    <VMarker
      :coordinates="originPoint"
      :options="{ draggable: true }"
      @dragend="handleMarkerDrag"
    />
  </VMap>
</template>

Use Cases

  • Real Estate: Show commute times to office locations
  • Logistics: Determine delivery coverage areas
  • Urban Planning: Analyze accessibility of public services
  • Emergency Services: Visualize response time coverage