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

mithril-leaflet

v0.4.3

Published

A Leaflet drawable map component for mithril.

Downloads

23

Readme

mithril-leaflet

This library offers a LeafletMap component for the mithril framework, which combines leaflet for displaying maps, and leaflet-draw for editing overlays (see the demo).

screenshot

If you set the view and zoom factor when creating the map, they are used for centring. Otherwise, all initial overlays are used to compute the bounds (see leaflet.fitBounds).

When editing, the last selected editable layer can be edited. So if you have multiple overlays, each of which can be edited, only the one you selected last can be changed. During editing, the same limitations apply as mentioned in leaflet-draw: markers can be moved, polylines and lines can be edited. There is no editing support, however, for multi-lines and multi-polygons.

When multiple overlays are present, a layer control is shown. You can also enable the scale control, optionally choosing between metric, imperial or both.

You can check out the API documentation here or review the example source code.

Installation

First, you need to install the required packages: note that this library does not contain leaflet, or leaflet-draw, so you need to install them yourself. It has been tested against leaflet v1.4.

npm i mithril leaflet leaflet-draw mithril-leaflet
# Also install the typings if you use TypeScript
npm i --save-dev @types/leaflet @types/leaflet-draw @types/geojson @types/mithril

Usage

Now you can use it in your mithril code.

import { LeafletMap } from 'mithril-leaflet';
import { Feature, Geometry } from 'geojson';
import { LatLngExpression, FeatureGroup, LeafletEvent, geoJSON } from 'leaflet'

...
m(LeafletMap, {
  style: 'height: 400px; margin-top: 20px;',
  // Default base layer, for others, see https://wiki.openstreetmap.org/wiki/Tile_servers
  baseLayers: {
    osm: {
      url: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
      options: {
        subdomains: ['a', 'b'],
        attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
        maxZoom: 19,
        maxNativeZoom: 17,
      },
    },
  },
  // Optionally, specify initial view and zoom. By default, fit bounds is applied.
  // view: [51.505, -0.09] as LatLngExpression,
  // zoom: 13,
  // Optionally, add overlay layers and specify which ones are visible.
  // overlays,
  // visible,
  editable: ['test', 'pois'],
  onMapClicked: console.log,
  showScale: { imperial: false },
  onLayerEdited: (f: FeatureGroup) => console.log(JSON.stringify(f.toGeoJSON(), null, 2)),
  onLoadedOverlaysChanged: (v: string[]) => (state.visible = v),
})

Build instructions

pnpm m i # You can also use `npm i`, but I prefer [pnpm](https://pnpm.js.org).
npm start # during development
npm run build:domain # for deploying it to GitHub