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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@svelte-parts/map

v0.0.24

Published

Leaflet map components for svelte

Downloads

59

Readme

@svelte-parts/map

Map components using leaflet. Lets you create very basic maps with tiles, markers and geojson. If you need something beyond that, use these components for inspiration and create your own. More about that below.

Demo

Try it out in the svelte REPL

Install

npm install @svelte-parts/map

Usage

<script>
  import Map from '@svelte-parts/map'
  import Marker from '@svelte-parts/map/marker'
  import Tiles from '@svelte-parts/map/tiles'
</script>

<Map width="100%" height="300px" lon={0} lat={51.5}>
  <Tiles />
  <Marker lon={0} lat={51.5} popup="Hello, I am a popup" />
</Map>

Map

This is the wrapper. Other map components must be inside it.

Properties

  • lat (default: 0)
  • lon (default: 0)
  • zoom (default: 5)
  • width (default: 100%)
  • height (default: 100px)

Tiles

The background tiles.

Properties

  • url (default: https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png)
  • maxZoom (default: 19)
  • attribution (default: &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors)

Find more tile providers here.

Marker

Properties

  • lat (default: 0)
  • lon (default: 0)
  • popup (default: undefined)

Geojson

Properties

CSS

In order to see a map at all, you need to use the css file node_modules/leaflet/dist/leaflet.css. Add it to your project however you want.

Important: the folder node_modules/leaflet/dist/images needs to be served in your build from the same folder as the css file.

Creating your own components

Leaflet is a very capable library. These components barely scratch the surface of what you can do. The api and documentation are easy to get into. You may want to create your own components. Have a look at how I made the Marker.

Access the leaflet map instance with:

const { getMap } = getContext('leaflet_map')
const map = getMap()

Import the leaflet functions and properties you need to create new components.

The Map component, to initialise the leaflet instance, is also straight forward. You may not need this library after all.