### Install svelte-maplibre Source: https://github.com/dimfeld/svelte-maplibre/blob/master/README.md Command to install the library via npm. ```bash npm install svelte-maplibre ``` -------------------------------- ### Implement Complete Control Example Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/08-CONTROL-COMPONENTS.md A full example demonstrating standard controls, custom control groups, and terrain toggling. ```svelte ↑ ⊕ ``` -------------------------------- ### Implement BackgroundLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Usage example for rendering the map background. ```svelte ``` -------------------------------- ### Implement LineLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Usage example for rendering lines. ```svelte ``` -------------------------------- ### FullscreenControl Usage Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/08-CONTROL-COMPONENTS.md Example of implementing the FullscreenControl component. ```svelte ``` -------------------------------- ### Implement HeatmapLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Usage example for rendering a heatmap from points. ```svelte ``` -------------------------------- ### Implement SymbolLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Usage example for rendering text labels and icons. ```svelte ``` -------------------------------- ### TopoJSON Usage Example Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/05-SOURCE-COMPONENTS.md Example implementation of a TopoJSON component with a nested FillLayer. ```svelte ``` -------------------------------- ### ImageSource Usage Example Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/05-SOURCE-COMPONENTS.md Example implementation of an ImageSource component with a nested RasterLayer. ```svelte ``` -------------------------------- ### Implement CircleLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Usage example for rendering circles at feature points. ```svelte ``` -------------------------------- ### ControlButton Usage Example Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/08-CONTROL-COMPONENTS.md Demonstrates how to use ControlButton within a Control component. ```svelte map.easeTo({ bearing: 0 })} class="icon-rotate" > ⟲ ``` -------------------------------- ### Implement DeckGlAccessor examples Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/02-TYPES.md Demonstration of using DeckGlAccessor with both a function and a constant value. ```typescript const colorAccessor: DeckGlAccessor = feature => { return feature.properties?.color ?? [255, 0, 0]; }; // Or constant: const constantColor: DeckGlAccessor = [0, 255, 0]; ``` -------------------------------- ### Implement FillExtrusionLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Usage example for rendering 3D extruded polygons. ```svelte ``` -------------------------------- ### Implement FillLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Usage example for rendering filled polygons with an onclick handler. ```svelte { console.log('Clicked polygon:', info.features[0].properties); }} /> ``` -------------------------------- ### ScaleControl Usage Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/08-CONTROL-COMPONENTS.md Example of implementing the ScaleControl component with custom width and units. ```svelte ``` -------------------------------- ### Initialize MapLibre component in Svelte Source: https://github.com/dimfeld/svelte-maplibre/blob/master/README.md Example of setting up the MapLibre component within a Svelte file, including worker configuration in the module script. ```svelte ``` -------------------------------- ### Initialize basic MapLibre map Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/04-MAPLIBRE-COMPONENT.md Shows the standard setup for a MapLibre component, including worker URL configuration and CSS sizing. ```svelte ``` -------------------------------- ### Use MapEvents Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/08-CONTROL-COMPONENTS.md Example of subscribing to map events using the MapEvents component. ```svelte console.log('Map ready')} onclick={(e) => console.log('Click:', e.lngLat)} /> ``` -------------------------------- ### ControlGroup Usage Example Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/08-CONTROL-COMPONENTS.md Demonstrates grouping multiple ControlButton components within a ControlGroup. ```svelte map.zoomIn()}>+ map.zoomOut()}>− map.easeTo({ bearing: 0 })}>↑ ``` -------------------------------- ### VectorTileSource Usage Example Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/05-SOURCE-COMPONENTS.md Standard implementation of VectorTileSource with nested layer components. ```svelte ``` -------------------------------- ### Implement DeckGlLayer Component Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Example demonstrating the integration of a Deck.gl ScatterplotLayer into a Svelte MapLibre map. ```svelte d.coordinates} getRadius={(d) => d.radius} getFillColor={(d) => d.color} getLineColor={(d) => [0, 0, 0]} onclick={(info) => console.log('Clicked:', info.object)} /> ``` -------------------------------- ### PMTiles Protocol Usage Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/05-SOURCE-COMPONENTS.md Example of using the VectorTileSource component with a PMTiles URL. ```svelte ``` -------------------------------- ### Control Component Usage Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/08-CONTROL-COMPONENTS.md Examples of implementing custom controls using the Control component with different positioning and styling options. ```svelte
``` -------------------------------- ### Implement JoinedData Component Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Example showing how to use JoinedData to link tabular data to map features for data-driven styling. ```svelte ``` -------------------------------- ### Enable Hover State Management Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Example of using manageHoverState to track hovered features and update paint properties based on feature state. ```svelte ``` -------------------------------- ### Implement Terrain Component Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Example usage of the Terrain component nested within a RasterDEMTileSource. ```svelte ``` -------------------------------- ### AttributionControl Usage Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/08-CONTROL-COMPONENTS.md Example of implementing the AttributionControl component when the default attribution is disabled. ```svelte ``` -------------------------------- ### Implement ZoomRange Component Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Example usage of the ZoomRange component to constrain nested layers. ```svelte ``` -------------------------------- ### Configure Advanced GeoJSON Clustering Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/05-SOURCE-COMPONENTS.md Example of configuring cluster properties and aggregations within the GeoJSON component. ```svelte ``` -------------------------------- ### MarkerLayer Usage Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Example of rendering markers from GeoJSON features using the MarkerLayer component. ```svelte ``` -------------------------------- ### Handle layer click events in Svelte Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/02-TYPES.md Example usage of LayerClickInfo within a Svelte component to process click events on a CircleLayer. ```svelte ``` -------------------------------- ### zoomTransition(start, startValue, end, endValue) Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/03-UTILITIES.md Creates a linear interpolation expression that scales property values based on the map zoom level. ```APIDOC ## zoomTransition(start: number, startValue: number | ExpressionSpecification, end: number, endValue: number | ExpressionSpecification) ### Description Create a linear interpolation expression that changes with map zoom level. Useful for scaling properties smoothly as users zoom. ### Parameters - **start** (number) - Required - Start zoom level - **startValue** (number | ExpressionSpecification) - Required - Value at start zoom - **end** (number) - Required - End zoom level - **endValue** (number | ExpressionSpecification) - Required - Value at end zoom ### Returns MapLibre interpolation expression ### Example ```svelte ``` ``` -------------------------------- ### Library Entry Points Configuration Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/00-PROJECT-OVERVIEW.md Displays the package exports configuration for the library, including the main entry point and various submodules. ```text Main export: ./dist/index.js (+ types) Submodules: - ./context.svelte.js - Context management utilities - ./expressions.js - MapLibre expression helpers - ./filters.js - Filter and comparison utilities - ./source.js - Source management utilities - ./types.js - Type definitions and utilities - ./*.svelte - Individual Svelte components - ./*.css - Stylesheets for components ``` -------------------------------- ### Enable standard controls and hash Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/04-MAPLIBRE-COMPONENT.md Configures the map with built-in controls and URL hash synchronization. ```svelte ``` -------------------------------- ### updatedDeckGlContext() Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Initializes the Deck.gl layer context. ```APIDOC ## updatedDeckGlContext() ### Description Initialize Deck.gl layer context. ### Returns - **Object** - Contains `layer` (Box) and `layerEvent` (Box). ``` -------------------------------- ### Render Basic Map Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/09-QUICK-START-PATTERNS.md Initializes a map instance with a specified style, center, and zoom level. ```svelte ``` -------------------------------- ### updatedMarkerContext() Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Initializes marker and event contexts, setting the marker as a popup target. ```APIDOC ## updatedMarkerContext() ### Description Initialize marker and event contexts. Sets marker as popup target. ### Returns - **Object** - Contains `marker` (Box) and `layerEvent` (Box). ``` -------------------------------- ### updatedLayerContext(interactive) Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Initializes layer and event contexts, optionally setting up popup targeting if interactive is enabled. ```APIDOC ## updatedLayerContext(interactive) ### Description Initialize layer and event contexts. If `interactive` is true, also sets up popup targeting. ### Parameters - **interactive** (boolean) - Optional - Default: true - Whether this layer should handle mouse events. ### Returns - **Object** - Contains `layer` (Box) and `layerEvent` (Box). ``` -------------------------------- ### Get Viewport Hash in TypeScript Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/03-UTILITIES.md Generates a URL hash string representing the current map zoom, center, bearing, and pitch. ```typescript import { getViewportHash } from 'svelte-maplibre'; const hash = getViewportHash(map); // Result: "#12/37.7749/-122.4194" or "#12/37.7749/-122.4194/45/30" ``` -------------------------------- ### Initialize Source Context Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Initializes source and cluster contexts for use by source components. ```typescript function updatedSourceContext(): { source: Box; cluster: Box; } ``` ```typescript const { source, cluster } = updatedSourceContext(); source.value = 'my-source-id'; cluster.value = { radius: 50 }; ``` -------------------------------- ### Basic Marker Usage Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Minimal implementation of a marker at specified coordinates. ```svelte ``` -------------------------------- ### Handle Map Lifecycle Events Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/04-MAPLIBRE-COMPONENT.md Use onload to perform actions once the map is ready, or onerror to catch runtime issues. ```svelte { console.log('Map ready'); map.setFeatureState({ source: 'my-source', id: 1 }, { selected: true }); }} /> ``` ```svelte { console.error('Map error:', error); }} /> ``` -------------------------------- ### DefaultMarker Usage Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Basic implementation of a pre-styled blue pin marker. ```svelte ``` -------------------------------- ### Using isDeckGlMouseEvent type guard Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Demonstrates how to use the type guard to access Deck.gl specific properties like object. ```typescript if (isDeckGlMouseEvent(event)) { console.log('Deck.gl picking info:', event.object); } else { console.log('Map layer event'); } ``` -------------------------------- ### Documentation Content Checklist Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/README.md A list of standard elements included in each major documentation file for the project. ```text ✓ Function/component signatures with types ✓ Parameter tables (name, type, default, description) ✓ Return type documentation ✓ Usage examples (real code) ✓ Event documentation ✓ Lifecycle information ✓ Common patterns ✓ Cross-references ✓ Source file locations ``` -------------------------------- ### Create Responsive Map Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/09-QUICK-START-PATTERNS.md Wraps the MapLibre component in a container to control dimensions via CSS. ```svelte
``` -------------------------------- ### Implement Manual Popup Control Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Uses the bind:open directive to programmatically control the visibility of a popup. ```svelte

Content

``` -------------------------------- ### Initialize Marker Context Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Initializes marker and event contexts, setting the marker as a popup target. ```typescript function updatedMarkerContext(): { marker: Box; layerEvent: Box; } ``` ```typescript const { marker, layerEvent } = updatedMarkerContext(); // Now nested Popup components will attach to this marker ``` -------------------------------- ### Enable URL Hash Navigation Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/09-QUICK-START-PATTERNS.md Synchronizes the map view state with the URL hash to allow bookmarking of specific map positions. ```svelte { replaceState(url.href, $page.state); }} style="..." /> ``` -------------------------------- ### BackgroundLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Renders the map background. ```APIDOC ## BackgroundLayer ### Description Renders the map background (cannot be nested in a source, usually placed at the end). ### Import `import { BackgroundLayer } from 'svelte-maplibre';` ### Props - **paint** (BackgroundLayerSpecification['paint']) - Required - **id** (any) - Optional - **children** (Snippet) - Optional ### Example ```svelte ``` ``` -------------------------------- ### Display the Svelte-MapLibre component hierarchy Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/README.md Visual representation of the library's component structure, including sources, layers, features, and controls. ```text MapLibre Component ├─ MapLibre (root) ├─ Sources │ ├─ GeoJSON │ ├─ VectorTileSource │ ├─ RasterTileSource │ ├─ RasterDEMTileSource │ ├─ ImageSource │ └─ TopoJSON ├─ Layers │ ├─ Layer (generic) │ ├─ CircleLayer │ ├─ LineLayer │ ├─ FillLayer │ ├─ SymbolLayer │ ├─ BackgroundLayer │ ├─ RasterLayer │ ├─ HeatmapLayer │ ├─ HillshadeLayer │ └─ FillExtrusionLayer ├─ Features │ ├─ Marker / DefaultMarker │ ├─ MarkerLayer │ ├─ Popup │ ├─ DeckGlLayer │ ├─ Terrain │ ├─ ZoomRange │ └─ JoinedData └─ Controls ├─ Control / ControlGroup / ControlButton ├─ NavigationControl ├─ GeolocateControl ├─ FullscreenControl ├─ ScaleControl ├─ AttributionControl ├─ TerrainControl └─ MapEvents ``` -------------------------------- ### Implementing Interactive Layers with Events Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Enable interactivity and hover state management using the interactive and manageHoverState props, combined with event handlers. ```svelte ``` -------------------------------- ### Handle Mouse Events Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/04-MAPLIBRE-COMPONENT.md Capture mouse interactions on the map background using event handlers like onclick. ```svelte { console.log('Clicked at:', e.lngLat); }} /> ``` -------------------------------- ### Implement Source-Layer Hierarchy Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/00-PROJECT-OVERVIEW.md Nest layer components within a source component to automatically register and apply source IDs via context. ```svelte ``` -------------------------------- ### Implement Hover Popup Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Configures a popup to trigger automatically on hover over a layer. ```svelte

Hover info

``` -------------------------------- ### LineLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Renders lines. ```APIDOC ## LineLayer ### Description Renders lines. ### Import `import { LineLayer } from 'svelte-maplibre';` ### Props - **paint** (LineLayerSpecification['paint']) - Required - **layout** (LineLayerSpecification['layout']) - Optional ### Example ```svelte ``` ``` -------------------------------- ### Use TerrainControl Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/08-CONTROL-COMPONENTS.md Basic implementation of the TerrainControl component. ```svelte ``` -------------------------------- ### Implement GeoJSON Source with Clustering Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/05-SOURCE-COMPONENTS.md Basic usage of the GeoJSON component within a MapLibre map, demonstrating point clustering and layer styling. ```svelte ``` -------------------------------- ### boundsEqual(param: LngLatBoundsLike, mapBounds: LngLatBounds | undefined) Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/02-TYPES.md Compares two bounds for equality with floating-point tolerance. ```APIDOC ## boundsEqual(param: LngLatBoundsLike, mapBounds: LngLatBounds | undefined) ### Description Compare two bounds for equality with floating-point tolerance. ### Parameters - **param** (LngLatBoundsLike) - New bounds to compare - **mapBounds** (LngLatBounds | undefined) - Current map bounds ### Returns Object with `equal` flag and normalized bounds ### Example ```typescript import { boundsEqual } from 'svelte-maplibre'; import { LngLatBounds } from 'maplibre-gl'; const bounds = [[-74, 40], [-73, 41]]; const mapBounds = new LngLatBounds([-74, 40], [-73, 41]); const { equal } = boundsEqual(bounds, mapBounds); console.log(equal); // true ``` ``` -------------------------------- ### Configure MapLibre worker for Vite Source: https://github.com/dimfeld/svelte-maplibre/blob/master/README.md Import the worker URL and set it using maplibregl.setWorkerUrl before initializing the map. ```javascript import * as maplibregl from 'maplibre-gl'; import maplibreWorkerUrl from 'maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url'; maplibregl.setWorkerUrl(maplibreWorkerUrl); ``` -------------------------------- ### updatedSourceContext() Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Initializes source and cluster contexts for use by source components to make their ID and cluster options available to nested layers. ```APIDOC ## updatedSourceContext() ### Description Initializes source and cluster contexts. Used by source components (GeoJSON, VectorTileSource, etc.) to make their ID and cluster options available to nested layers. ### Returns - **Object** - Contains `source` (Box) and `cluster` (Box). ``` -------------------------------- ### Implement Popup with Marker Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/07-FEATURE-COMPONENTS.md Attaches a popup to a Marker component. ```svelte { /* open */ }}>

Marker popup

``` -------------------------------- ### Layer Interaction and Hover State Management Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/09-QUICK-START-PATTERNS.md Implements hover and selection states using feature-state and component bindings. ```svelte {#if hoveredFeature}

Hovering: {hoveredFeature.properties?.name}

{/if} ``` -------------------------------- ### Configure ClusterOptions Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/02-TYPES.md Configuration interface for GeoJSON source clustering. ```typescript interface ClusterOptions { minPoints?: number; // @default 2 maxZoom?: number; radius?: number; // @default 50 properties?: Record; } ``` ```svelte ``` -------------------------------- ### Initialize Layer Context Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Initializes layer and event contexts, with an optional interactive flag for mouse event handling. ```typescript function updatedLayerContext(interactive?: boolean): { layer: Box; layerEvent: Box; } ``` -------------------------------- ### Using the Generic Layer Component Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Utilize the base Layer component for layer types that do not have dedicated specialized components. ```svelte ``` -------------------------------- ### Implement RasterTileSource Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/05-SOURCE-COMPONENTS.md Basic usage of the RasterTileSource component with a nested RasterLayer. ```svelte ``` -------------------------------- ### SymbolLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Renders text labels and icons. ```APIDOC ## SymbolLayer ### Description Renders text labels and icons. ### Import `import { SymbolLayer } from 'svelte-maplibre';` ### Props - **layout** (SymbolLayerSpecification['layout']) - Required - **paint** (SymbolLayerSpecification['paint']) - Optional ### Example ```svelte ``` ``` -------------------------------- ### HeatmapLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Renders a heatmap from points. ```APIDOC ## HeatmapLayer ### Description Renders a heatmap from points. ### Import `import { HeatmapLayer } from 'svelte-maplibre';` ### Props - **paint** (HeatmapLayerSpecification['paint']) - Required ### Example ```svelte ``` ``` -------------------------------- ### Implement GeoJSON Clustering Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/09-QUICK-START-PATTERNS.md Configures point clustering for GeoJSON data using the cluster prop and conditional paint properties for styling clusters versus individual points. ```svelte ``` -------------------------------- ### Wait for Images to Load Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/09-QUICK-START-PATTERNS.md Use the allImagesLoaded slot prop to ensure images are ready before rendering dependent layers. ```svelte {#if allImagesLoaded} {/if} ``` -------------------------------- ### Implement RasterDEMTileSource Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/05-SOURCE-COMPONENTS.md Usage of the RasterDEMTileSource component paired with a Terrain component for 3D visualization. ```svelte ``` -------------------------------- ### Add a map source with lifecycle handling Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/03-UTILITIES.md Adds a source to the map, waiting for any pending removals of the same ID to complete first. The okToAdd callback should be used to verify the component is still mounted. ```typescript function addSource( map: Map, sourceId: string, source: SourceSpecification, okToAdd: (sourceId: string) => boolean, cb: () => void ): void ``` ```typescript import { addSource } from 'svelte-maplibre'; import { GeoJSON } from 'geojson'; const geojsonSource = { type: 'geojson', data: featureCollection }; addSource( map, 'my-source', geojsonSource, (id) => id === 'my-source', // Don't add if source ID changed () => { console.log('Source added'); } ); ``` -------------------------------- ### Compare bounds with boundsEqual Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/02-TYPES.md Compares two bounds for equality using floating-point tolerance. Requires importing LngLatBounds from maplibre-gl. ```typescript function boundsEqual( param: LngLatBoundsLike, mapBounds: LngLatBounds | undefined ): { equal: boolean; bounds: LngLatBounds } ``` ```typescript import { boundsEqual } from 'svelte-maplibre'; import { LngLatBounds } from 'maplibre-gl'; const bounds = [[-74, 40], [-73, 41]]; const mapBounds = new LngLatBounds([-74, 40], [-73, 41]); const { equal } = boundsEqual(bounds, mapBounds); console.log(equal); // true ``` -------------------------------- ### Render Markers with Popups Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/09-QUICK-START-PATTERNS.md Displays multiple markers on a map using an each block, with associated popups for displaying location details. ```svelte {#each locations as location (location.id)}

{location.name}

{/each}
``` -------------------------------- ### Use flush to clean objects Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/03-UTILITIES.md Demonstrates removing null and undefined properties from an object configuration. ```typescript import { flush } from 'svelte-maplibre'; const options = { center: [0, 0], zoom: undefined, pitch: 45, bearing: null, interactive: true }; const clean = flush(options); // Result: { center: [0, 0], pitch: 45, interactive: true } ``` -------------------------------- ### Render Vector Tiles Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/09-QUICK-START-PATTERNS.md Displays vector data sources with specific layers for lines and symbols. ```svelte ``` -------------------------------- ### Implement Data-Driven Styling with CircleLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/09-QUICK-START-PATTERNS.md Uses MapLibre expressions to dynamically style circle layers based on feature properties like magnitude and temperature. ```svelte ``` -------------------------------- ### convertBoundsToUserFormat(bounds: LngLatBounds, param: LngLatBoundsLike | undefined) Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/02-TYPES.md Converts bounds back to the format used by the user, preserving the input format. ```APIDOC ## convertBoundsToUserFormat(bounds: LngLatBounds, param: LngLatBoundsLike | undefined) ### Description Convert bounds back to the format used by the user (preserves input format). ### Parameters - **bounds** (LngLatBounds) - Internal bounds object - **param** (LngLatBoundsLike) - Original bounds format from user ### Returns Bounds in the same format as `param` input ### Example ```typescript // If user passed [[lng, lat], [lng, lat]], returns same format const result1 = convertBoundsToUserFormat(bounds, [[0, 0], [10, 10]]); // result1 → [[0, 0], [10, 10]] // If user passed [lng, lat, lng, lat], returns same format const result2 = convertBoundsToUserFormat(bounds, [0, 0, 10, 10]); // result2 → [0, 0, 10, 10] ``` ``` -------------------------------- ### getId(prefix: string): string Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Generates a unique ID string with a specified prefix, useful for identifying map layers or sources. ```APIDOC ## getId(prefix: string) ### Description Generates a unique ID with the given prefix. Uses the current timestamp to avoid ID reuse during hot module replacement. ### Parameters - **prefix** (string) - Required - Prefix for the generated ID (e.g., 'layer', 'source') ### Returns - **string** - Unique string ID in format `{prefix}-{incrementing number}` ``` -------------------------------- ### addSource(map, sourceId, source, okToAdd, cb) Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/03-UTILITIES.md Adds a source to the map with lifecycle handling, ensuring that if a source with the same ID is being removed, the new one is added only after removal completes. ```APIDOC ## addSource(map, sourceId, source, okToAdd, cb) ### Description Adds a source to the map with proper handling of source replacement. If a source with the same ID is being removed, it waits for the removal to complete before adding the new one. ### Parameters - **map** (Map) - Required - MapLibre map instance - **sourceId** (string) - Required - Unique source identifier - **source** (SourceSpecification) - Required - Source configuration object - **okToAdd** (function) - Required - Callback to check if source should be added (prevents adding if component unmounted) - **cb** (function) - Required - Callback invoked after source is added ### Returns - **void** ``` -------------------------------- ### Initialize Zoom Range Context Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/01-CONTEXT-API.md Creates a new zoom range context that inherits unspecified limits from parent contexts. ```typescript function updatedZoomRangeContext( minzoom: number | undefined, maxzoom: number | undefined ): { originalMinZoom: number; originalMaxZoom: number; minzoom: number; maxzoom: number; } ``` -------------------------------- ### Load custom images and layers Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/04-MAPLIBRE-COMPONENT.md Registers custom images with the map and waits for them to load before rendering dependent layers. ```svelte {#if allImagesLoaded} {/if} ``` -------------------------------- ### flush(obj) Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/03-UTILITIES.md Removes all null and undefined values from an object to create clean configuration objects. ```APIDOC ## flush(obj) ### Description Removes all undefined and null values from an object. This is used to create clean configuration objects for MapLibre APIs that do not accept undefined values. ### Parameters - **obj** (Record) - Required - The object to filter. ### Returns - **Object** - A new object with all null and undefined values removed. ### Example ```typescript import { flush } from 'svelte-maplibre'; const options = { center: [0, 0], zoom: undefined, pitch: 45 }; const clean = flush(options); // Result: { center: [0, 0], pitch: 45 } ``` ``` -------------------------------- ### FillLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Renders filled polygons. ```APIDOC ## FillLayer ### Description Renders filled polygons. ### Import `import { FillLayer } from 'svelte-maplibre';` ### Props - **paint** (FillLayerSpecification['paint']) - Required - **layout** (FillLayerSpecification['layout']) - Optional ### Example ```svelte { console.log('Clicked polygon:', info.features[0].properties); }} /> ``` ``` -------------------------------- ### RasterLayer Source: https://github.com/dimfeld/svelte-maplibre/blob/master/_autodocs/06-LAYER-COMPONENTS.md Renders raster tiles. ```APIDOC ## RasterLayer ### Description Renders raster tiles. ### Import `import { RasterLayer } from 'svelte-maplibre';` ### Props - **paint** (RasterLayerSpecification['paint']) - Optional ```