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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@andrewdodd/react-leaflet-draw

v0.20.0

Published

React component for leaflet-draw

Readme

Fork of React-Leaflet-Draw

This is a fork of React-Leaflet-Draw, a component that wraps leaflet-draw in order to work with React-Leaflet.

This fork is mainly to provide an alternative MapControl component that more plainly wraps the Leafet.draw control and does not provide its own internal FeatureGroup. I implemented this, as the existing control did not work well with the redux store I was using for state. It also provides a component that has its own internal FeatureGroup for convenience.

This repo will not be maintained (I really don't have the time). I provide it as a convenience and as a guide.

NB: If the original repo wants to incorporate these changes, that's fine by me, but I think that given the tradeoff between the size of this code and the potential to break the existing client code it is probably easier to just copy-paste this code if you need it (or use the @andrewdodd/react-leaflet-draw dep instead).

Install

npm install @andrewdodd/react-leaflet-draw

Getting started

First, include leaflet-draw styles in your project

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.3/leaflet.draw.css"/>

or by including

node_modules/leaflet-draw/dist/leaflet.draw.css

or perhaps forcing the css to be included (this one is for my own benefit, in case I forget!)

import 'leaflet-draw/dist/leaflet.draw.css'

As per the original React-Leaflet-Draw, it is important to wrap EditControl component in a FeatureGroup component from react-leaflet. However, interfacing to the EditControl component is complex enough that I have supplied a 'helper' container to do this. Have a look at the example for more info!

NB: The code for this repo is not very long, so I would recommend reading it to get a better feel for what is happening. However, in summary:

  • EditControl - Acts as a go-between (an adapter) for the "React" way and the underlying Leaflet/Leaflet.draw way. It creates and manages the MapControl, it registers and unregisters from the Leaflet.draw events.
  • EditControlFeatureGroup - Combines both the necessary FeatureGroup and the LeafletDrawControl into a single component that manages the Leaflet.draw state changes, React-Leaflet child components and the underlying Leaflet.draw elements.

Running the examples

There are a few examples in the repo, which show the various levels of complexity you need to deal with (and why this plugin is the way it is).

  1. Basic example - this just shows how to use the EditControlFeatureGroup in a map, but does not attempt to manage any state.
  • Run npm run example-basic
  • And go to http://localhost:8000
  1. Full example - this shows how to manage the various events coming out of the EditControlFeatureGroup, how to update your application state, and how to pass configuration through to the underlying leaflet.draw plugin.
  • Run npm run example-full
  • And go to http://localhost:8000
  1. Custom example - this shows how to create an application that uses only programatically controlled functionality to manage the underlying leaflet.draw plugin. It does some pretty scary things, mainly because Leaflet and leaflet.draw are very DOM oriented, while React and React-Leavlet are not. I'm not really convinced that this is a good idea...but if you have to use Leaflet and leaflet.draw, and you have to use something other than the out-of-the-box controls I guess it is ok?
  • Run npm run example-custom
  • And go to http://localhost:8000