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

astro-leaflet

v1.8.1

Published

Leaflet astro component, to display maps: Google Maps, Openstreetmap, maps from Michelin, googlemaps, Open Street Map...

Readme

Demo


Installation

Get the latest version from NPM:

$ npm install astro-leaflet

Want to help?

Please open an issue to ask for:

  • bug fix
  • add a new feature, part of leaflet, but not implemented in astro-leaflet yet
  • having your favorite tile url be part of a friendly name. This helps everyone quickly chosing the right map.

Contributions and Pull Request are welcome.


Usage

Here is a minimal example that is using openstreetmap

---
import { Leaflet } from "astro-leaflet";
---
<Leaflet />

In case no map is displayed, or in case of any problem, please refer to the Troubleshooting section


Tutorials

astro-dev provides different ways of using astro-leaflet

Leaflet tutorials is a great way to learn Leaflet. Here is a list of the leaflet tutorials implemented with astro-leaflet.

  • Layer Groups and Layers Control: A tutorial on how to manage groups of layers and use the layer switching control. It demontrates how to use astro-leaflet components <ControlLayer>, <LayerGroup>, <BaseLayer> and <Overlay>

Components:

<LeafLet>

Main component to create a leaflet map. Check following examples (code is provided):

Usage:

<Leaflet options={{...}}>
</leaflet>

with the following option properties:

  • tileByName: friendly name of the layer to display. Check astro-dev for an interactive description and display of implemented human friendly name. Section tileByName gives more details on this parameter, and its possible values
  • tileLayer: if tileByName is not provided, this is the url of the main tile layer. Default is the one of openstreetmap when neither tileByName nor tileLayer is provided.
  • tileLayerOptions: Leaflet options to set the attribution,...
  • mapOptions: Leaflet options
  • setViewOptions: Leaflet options
  • center: array of latitude and longitude. Default is centered on south europe
  • zoom: a number for the zoom. Default is 2, that is a far view
  • markers: an array of AstroLeafletMarkerType
<Leaflet options={{ tileByName: 'Google' }} />

tileByName

This parameter is used in <LeafLet> and <TileLayer>. This is a friendly name to infer url address of the layer, as well as the associated options, such as subdomains,...

Please check astro-dev to list friendly names, and preview the result in Leaflet.

Here is a non-exhaustive list:

  • OSM
  • Google: default is satellite
    • Google&type=satellite
    • Google&type=street
    • Google&type=hybrid
    • Google&type=terrain
    • Google&type=hybrid&extra=transit,bike
    • The language can also be provided adding &lang=xx, such as for example Google&type=street&lang=en
  • Michelin: default is map
    • Michelin&map
    • Michelin&label

<TileLayer>

Component to add a layer on top of the main layer. This can be usefull for example to display labels on top of satellite images. Must be implemented in the <Leaflet> slot.

Usage:

<TileLayer
  urlTemplate='url of the tiles to overlay
  options={{ leaflet options of tileLayer() }}>

Full example can be found at:


<Polyline>

Components to draw polyline overlays on a map. Must be implemented in the <Leaflet> slot.

Usage:

<Polyline
  latlngs={array of LatLngTuple[]}
  options={{  leaflet options of polyline() }}>

Full example can be found at:


<FitBounds>

Components to automatically center the map on elements of the map, such as the points of a polyline. Must be in the slot of the element to center to.

<FitBounds/>

Full example can be found at:


<ImageOverlay>

Components to load and display a single image over specific bounds of the map.

  • imageUrl: URL of the image
  • bounds: geographical bounds it is tied to
  • options: optional leaflet options of the ImageOverlay: opacity,...

Example:

<ImageOverlay
  imageUrl="https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg"
  bounds={[[40.712216, -74.22655], [40.773941, -74.12544]]}
  options={{opacity:0.5}}
/>

Full example can be found at astro-dev#ImageOverlay


API

For each astro-leaflet components, there is a link to the full demo and code:


<CreateLeafletIcon>

Create a custom icon to be displayed in markers. Must be implemented before the <Leaflet> slot.

Note that only divicons are supported for the time-being.

Usage:

<CreateLeafletIcon
  name='name of the icon to be used in markers'
  options={{
    className:"leaflet-icon-myicon",
    iconSize: [20,20]
    ...
  }}/>
<Leaflet options={options}/>

<style is:global>
	/* class definition used to define the custom icon */
	.leaflet-icon-myicon {
		background:red;
		border:5px solid rgba(255,255,255,0.5);
		border-radius:50%;
	}
</style>

Full example can be found at:


Complex Examples

Please check the online doc for a fullset of examples.

Full code is provided.


License

Astro-leaflet is released under the MIT license.

Astro-leaflet is using leaflet. leaflet is a BSD-2-Clause license software


Troubleshooting

Map not displayed

If the map is not displayed, and you have the following error in the console

Uncaught SyntaxError: The requested module '/node_modules/leaflet/dist/leaflet-src.js?v=c7414b9d' does not provide an export named 'layerGroup' (at layergroup.ts?v=c7414b9d:1:10)

or

SyntaxError: Importing binding name 'default' cannot be resolved by star

then you have to add the following inside astro.config.mjs:

export default defineConfig({
  ...
  vite: {
    optimizeDeps: {
      include: ['leaflet'],
    }
  },
  ...
});