### Custom Protocol with PMTiles and RasterTileSource Source: https://svelte-maplibre-gl.mierune.dev/examples/custom-protocol Adds a custom resource loading function to handle URLs that start with a custom URL scheme. The example defines a load function that generates a checkered PNG tile for each requested z/x/y coordinate, registers it with the Protocol component, and uses it in a RasterTileSource. It also demonstrates using PMTilesProtocol for a VectorTileSource with PMTiles. ```svelte ``` -------------------------------- ### Launch a SvelteKit Project Source: https://svelte-maplibre-gl.mierune.dev/docs/quickstart Create a new SvelteKit project using the official CLI and install dependencies. Ensure the Tailwind CSS add-on is enabled for styling. ```bash npx sv create myapp # Make sure to enable the Tailwind CSS add-on, # as our examples use it for styling. cd myapp npm install ``` -------------------------------- ### Install Svelte MapLibre GL Source: https://svelte-maplibre-gl.mierune.dev/ Use npm to add the svelte-maplibre-gl package as a development dependency to your project. ```bash npm install --save-dev svelte-maplibre-gl ``` -------------------------------- ### PMTiles Protocol with Svelte MapLibre GL Source: https://svelte-maplibre-gl.mierune.dev/examples/pmtiles Use the PMTiles plugin and custom protocol to present a map. Requires the PMTilesProtocol component and the pmtiles:// URL scheme. The example fetches layer specifications from an OSM style and filters them for the openmaptiles source. ```svelte ``` -------------------------------- ### Custom Control with arbitrary HTML and IControl injection Source: https://svelte-maplibre-gl.mierune.dev/examples/custom-control This example shows how to use the CustomControl component to inject an IControl instance (useful for plugins) and to place arbitrary HTML content. It also demonstrates grouping controls and using Svelte state to toggle layers and change control positions. ```svelte
Arbitrary HTML
({center.lat.toFixed(4)}, {center.lng.toFixed(4)})
{#if isTerrainVisible} {/if} {#if isHillshadeVisible} {/if}
``` -------------------------------- ### Render Contour Lines with MapLibreContourSource Source: https://svelte-maplibre-gl.mierune.dev/examples/contour This example shows the implementation of a MapLibre map with contour lines, hillshading, and elevation labels using the MapLibreContourSource component. It requires the @svelte-maplibre-gl/contour package and configures thresholds for different zoom levels. ```svelte {#snippet children(demSource)} ', ['get', 'level'], 0]} layout={{ 'symbol-placement': 'line', 'text-size': 12, 'text-field': ['number-format', ['get', 'ele'], {}] }} paint={{ 'text-halo-color': 'white', 'text-halo-width': 1 }} /> {/snippet} ``` -------------------------------- ### Svelte script with MapLibre imports and reactive state Source: https://svelte-maplibre-gl.mierune.dev/examples/complex Svelte 5 runes setup for the map component. Imports required modules and PMTiles protocol, then declares reactive state for map options, layer toggles, colors, sizes, and control position. The `map` variable is a raw state holding the MapLibre map instance. ```svelte ``` -------------------------------- ### GPU-Animated Image with Svelte MapLibre GL Source: https://svelte-maplibre-gl.mierune.dev/examples/dynamic-image Renders an animated icon directly into the style image atlas using a WebGL shader. Requires the 'svelte-maplibre-gl/vite' import for GL JS v6+. The example defines a custom StyleImageInterface with a renderWithWebGL callback that draws a neon ring and spark on a framebuffer, and uses a GeoJSONSource with a SymbolLayer to display the icon on the map. ```svelte ({ type: 'Feature' as const, geometry: { type: 'Point' as const, coordinates }, properties: {} })) }} > ``` -------------------------------- ### Locate the User with GeolocateControl in Svelte MapLibre GL Source: https://svelte-maplibre-gl.mierune.dev/examples/geolocate The example displays a log area and a MapLibre map with a GeolocateControl. The control logs events such as trackuserlocationstart, trackuserlocationend, and geolocate with coordinates. The initial log message is 'Press the GeolocateControl button.' and the map uses the CartoDB Voyager style. ```text Press the GeolocateControl button. ``` ```svelte
{logString}
log('trackuserlocationstart')} ontrackuserlocationend={() => log('trackuserlocationend')} ongeolocate={(ev) => log(`geolocate ${JSON.stringify(ev.coords, null, 2)}`)} />
``` -------------------------------- ### Query source and rendered features with svelte-maplibre-gl Source: https://svelte-maplibre-gl.mierune.dev/examples/query-features Query source and rendered features from a MapLibre GL map to place markers and display a list. Uses QuerySourceFeatures and QueryRenderedFeatures components with bind:features to update the features array. The example includes a tabbed interface to switch between source and rendered modes, and requires Tailwind CSS and shadcn-svelte. ```svelte
{#if mode == 'source'} {#snippet children(feature: maplibregl.MapGeoJSONFeature)} {#if feature.geometry.type === 'Point'} {/if} {/snippet} {/if} {#if mode == 'rendered'} {#snippet children(feature: maplibregl.MapGeoJSONFeature)} {#if feature.geometry.type === 'Point'} {/if} {/snippet} {/if}
Source Rendered
    {#each features as feature (feature.id)}
  • {feature.properties.title}
  • {/each}
    {#each features as feature (feature.id)}
  • {feature.properties.title}
  • {/each}
``` -------------------------------- ### Svelte MapLibre GL 3D Terrain and Sky Example Source: https://svelte-maplibre-gl.mierune.dev/examples/terrain Svelte component that renders a MapLibre GL map with 3D terrain and sky. It includes a RasterDEMTileSource for terrain and hillshade, a Sky component, and UI controls for adjusting terrain exaggeration, hillshade settings, and sky colors. The script defines reactive state for all adjustable properties, including hillshade method options and anisotropic filter pitch. ```svelte ``` ```svelte {#if skyEnabled} {/if}
Terrain Sky
``` -------------------------------- ### Control panel and map state display Source: https://svelte-maplibre-gl.mierune.dev/examples/complex UI controls for toggling layers, adjusting colors and sizes, selecting control position, and flying to the marker. Includes checkboxes for Cities, Hillshade, Sky, Extrude, Heatmap, and Globe; color pickers for point and line colors; number inputs for circle radius and line width; a select for control position; and a Fly to button that calls `map?.flyTo` with the marker coordinates. Also displays live map state and marker coordinates, plus inputs for zoom, popup open, and hash. ```svelte
{`lat: ${center[1].toFixed(3)}, lng: ${center[0].toFixed(3)}, z: ${zoom.toFixed(1)}, pitch: ${pitch.toFixed(1)}, bearing: ${bearing.toFixed(1)}`}
marker: {`${markerLnglat.lat.toFixed(3)}, ${markerLnglat.lng.toFixed(3)}`}
``` -------------------------------- ### Change cursor on hover with MapLibre and CircleLayer Source: https://svelte-maplibre-gl.mierune.dev/examples/cursor Changes the map cursor on hover by binding the cursor prop to a state variable updated by CircleLayer mouse events. Requires the 'svelte-maplibre-gl/vite' import for GL JS v6+. The example uses Tailwind CSS and shadcn-svelte. ```svelte (cursor = e.features![0].properties.cursor)} onmouseleave={() => (cursor = undefined)} paint={{ 'circle-radius': 12, 'circle-color': '#007cbf', 'circle-stroke-color': '#fff', 'circle-stroke-width': 3 }} /> ``` -------------------------------- ### Put a Marker on the Map Source: https://svelte-maplibre-gl.mierune.dev/docs/quickstart Configure the initial zoom and center coordinates, then add a Marker component inside the MapLibre component. ```svelte ``` -------------------------------- ### Add the Simplest Map Source: https://svelte-maplibre-gl.mierune.dev/docs/quickstart Import the Vite adapter for GL JS v6 compatibility and add the MapLibre component to your page. A height must be defined for the map container. ```svelte ``` -------------------------------- ### 3D Floor Plan with FillExtrusionLayer Source: https://svelte-maplibre-gl.mierune.dev/examples/3d-extrusion-floorplan Creates a 3D indoor map using the fill-extrude-height paint property. Requires the svelte-maplibre-gl/vite import for GL JS v6+. Uses a GeoJSON source with properties for color, height, and base_height to drive the fill-extrusion layer. ```svelte ```