A Svelte component library for Mapbox GL JS, providing easy-to-use components for building interactive maps.
npm install mapbox-svelte
Add your mapbox key to env
PUBLIC_MAPBOX_KEY=your_key
<script>
import * as Mapbox from 'mapbox-svelte';
let mapComponent: Mapbox.Container
</script>
<div class="map-container">
<Mapbox.Container bind:this={mapComponent}>
<Mapbox.Polygon source="source" {coordinates}></Mapbox.Polygon>
<Mapbox.Layer
layerConfig={{
id: 'hehe',
source: 'source',
type: 'fill',
paint: { 'fill-color': '#0080ff', 'fill-opacity': 0.5 }
}}
></Mapbox.Layer>
</Mapbox.Container>
</div>
<style>
.map-container {
width: 100%;
height: 500px;
}
</style>
Container
- Main map containerGroup
- Group multiple map elementsLayer
- Mapbox layer wrapperMark
- Simple map markerPoint
- Point geometryPolygon
- Polygon geometryPopup
- Map popupTooltip
- Hover tooltipMIT