Skip to content

@maplibre-yaml/core/components

Web components for maplibre-yaml

This module exports the <ml-map> web component for rendering MapLibre maps from YAML or JSON configuration.

For most users, import the auto-registration module:

import '@maplibre-yaml/core/register';
import 'maplibre-gl/dist/maplibre-gl.css';

Then use the component in HTML:

<ml-map src="/configs/my-map.yaml" style="height: 400px;"></ml-map>

The <ml-map> component supports three ways to provide configuration:

<ml-map src="/configs/map.yaml"></ml-map>
<ml-map>
<script type="text/yaml">
type: map
id: inline
config:
center: [0, 0]
zoom: 2
mapStyle: "https://..."
layers: []
</script>
</ml-map>
<ml-map config='{"type":"map",...}'></ml-map>

If you need more control over registration:

import { MLMap, registerMLMap } from '@maplibre-yaml/core/components';
// Register with default name
registerMLMap();
// Or register with custom name
customElements.define('my-map', MLMap);