npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@icgcat/geocoder

v0.0.6

Published

A Svelte ICGC Geocoder

Readme

License Version X

Geocoder

The Geocoder component is a Svelte-based library for integrating geocoding and routing functionalities with a MapLibre GL map. It supports searching for places, drawing points, and handling routing layers on the map.

Features

  • Search Autocomplete: Provides a search bar for keyword-based geocoding.
  • Dynamic Map Updates: Automatically centers the map and adjusts zoom based on the selected place.
  • Routing Layer: Adds a visual marker for routing points on the map.
  • Interactivity: Automatically updates or removes layers based on user actions.

Installation

Install the component via npm:

npm install @icgcat/geocoder

Usage

Here’s a basic example to integrate Geocoder with a MapLibre map:

Example

<script>
    import Geocoder from "@icgcat/geocoder";
    import maplibregl from "maplibre-gl";

    let map;

    onMount(() => {
        map = new maplibregl.Map({
            container: "map",
            style: "https://geoserveis.icgc.cat/contextmaps/icgc_mapa_base_fosc.json",
            center: [2.1734, 41.3851], // Barcelona
            zoom: 10,
        });
    });
</script>

<Geocoder map={map} />
<div id="map" style="height: 500px;"></div>

Component Props

Geocoder

| Prop | Type | Default | Description | |-----------|--------------|---------|----------------------------------------------------------------------------| | map | object | null | Required. A MapLibre GL map instance to integrate with the geocoder. |


Methods Provided

changePlace(coords)

Updates the selected place and centers the map to the new location. It can handle both place-based and coordinate-based inputs.

  • Parameters:
    • coords: GeoJSON object representing the selected place or coordinates.

drawPointRouting(point, origin)

Draws a routing point on the map.

  • Parameters:
    • point: Object containing { lng, lat } of the point to be drawn.
    • origin: Boolean to indicate if this is the routing origin.

Behavior

Keyword Search

  • The geocoder uses a search autocomplete (SearchAutocomplete.svelte) to allow users to input place names or coordinates.
  • Upon selecting a result:
    • The map centers on the corresponding location.
    • The changePlaceStore is updated with the new coordinates.

Routing Layer

  • The routing layer (routing-in) is dynamically created when a point is added.
  • The routing layer is removed if no point is selected.

Zoom Logic

  • The zoom level is determined dynamically based on the type of place selected (determinaZoom function).

Events

The component leverages Svelte's reactive stores for state management:

  • changePlaceStore: Manages the selected place and map state.
  • drawPointRoutingStore: Tracks and updates the routing point.

Example Integration with Context

To integrate custom behavior using Svelte's context API:

<script>
    import { getContext } from "svelte";
    
    const changePlace = getContext("changePlace");
    const drawPointRouting = getContext("drawPointRouting");

    // Use changePlace to center the map
    changePlace({
        geometry: {
            coordinates: [2.1734, 41.3851],
        },
    });

    // Use drawPointRouting to add a routing point
    drawPointRouting({ lng: 2.1734, lat: 41.3851 }, true);
</script>

Styling

The routing layer uses the following default styles:

  • Circle Color: #FFA700 (orange).
  • Circle Radius: 10.
  • Circle Stroke: #FFA700, width 3.

License

This component is open-source and distributed under the MIT License.