• Stars
    star
    222
  • Rank 179,123 (Top 4 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React component for leaflet-draw on top of react-leaflet

React-Leaflet-Draw

React component build on top of React-Leaflet that integrate leaflet-draw feature.

Install

npm install react-leaflet-draw

Getting started

First, include leaflet & leaflet-draw styles in your project

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

or by including

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

You might need to add one more rule missing in the current css:

  .sr-only {
    display: none;
  }

It's important to wrap EditControl component into FeatureGroup component from react-leaflet. The elements you draw will be added to this FeatureGroup layer, when you hit edit button only items in this layer will be edited.

import { Map, TileLayer, FeatureGroup, Circle } from 'react-leaflet';
import { EditControl } from "react-leaflet-draw"

const Component = () => (
  <FeatureGroup>
    <EditControl
      position='topright'
      onEdited={this._onEditPath}
      onCreated={this._onCreate}
      onDeleted={this._onDeleted}
      draw={{
        rectangle: false
      }}
    />
    <Circle center={[51.51, -0.06]} radius={200} />
  </FeatureGroup>
);

For more details on how to use this plugin check out the examples example.

  • yarn example:class to compile the class example
  • yarn example:hooks to compile and run the hooks example

You can pass more options on draw object, this informations can be found here

EditControl API

Props

name type description
position string control group position
draw object enable/disable draw controls
edit object enable/disable edit controls
onEdited function hook to leaflet-draw's draw:edited event
onCreated function hook to leaflet-draw's draw:created event
onDeleted function hook to leaflet-draw's draw:deleted event
onMounted function hook to leaflet-draw's draw:mounted event
onEditStart function hook to leaflet-draw's draw:editstart event
onEditStop function hook to leaflet-draw's draw:editstop event
onDeleteStart function hook to leaflet-draw's draw:deletestart event
onDeleteStop function hook to leaflet-draw's draw:deletestop event
onDrawStart function hook to leaflet-draw's draw:drawstart event
onDrawStop function hook to leaflet-draw's draw:drawstop event
onDrawVertex function hook to leaflet-draw's draw:drawvertex event
onEditMove function hook to leaflet-draw's draw:editmove event
onEditResize function hook to leaflet-draw's draw:editresize event
onEditVertex function hook to leaflet-draw's draw:editvertex event

Links to docs

More Repositories

1

react-mapbox-gl

A React binding of mapbox-gl-js
TypeScript
1,915
star
2

sensmove

Smart insole system which provide to the user the ability to visualize his foot forces simultaneously on his smartphone
Objective-C
56
star
3

gymbox-bot

Simplify the booking of a gymbox class.
JavaScript
23
star
4

react-typescript-starter

Simple starter-kit for react, redux, typescript, aphrodite, webpack
TypeScript
13
star
5

react-mapping

Projection mapping in React
TypeScript
12
star
6

react-mapbox-gl-debug

Simple boilerplate to start an app with react-mapbox-gl
HTML
11
star
7

node-express-ts

Minimalistic node express boilerplate in Typescript
TypeScript
3
star
8

food

Leave to algorithm the choice for your lunch.
Python
3
star
9

ts-pq

Typescript priority queue
TypeScript
3
star
10

numeractive

Full javascript Blog boilerplate
JavaScript
3
star
11

hackcessangels

iOS app to help people with disabilities get help from nearby agents in train stations.
Objective-C
2
star
12

elm-twitter

Twitter feed made with Elm
Elm
2
star
13

sharexp

An app to share expense between a group of users (Experimental project made in Elm)
Elm
2
star
14

express-fixturer

Express middleware to automatically generate and use fixtures
TypeScript
2
star
15

dotfiles

Some of my settings files
Vim Script
2
star
16

reselect-brownbag

Code from a brownbag about reselect
TypeScript
1
star
17

food-discovery

TypeScript
1
star
18

raclette-party

JavaScript
1
star
19

isomorphic-fetch-rx

Small wrapper on top of isomorphic that output an observable
TypeScript
1
star
20

gousto-app

TypeScript
1
star
21

euler-project-typescript

TypeScript
1
star
22

monzo-map

JavaScript
1
star
23

Jira-github-plugin

Lambdas to update Jira according to Github actions
JavaScript
1
star
24

awesome-lifehack-scripts

A curated list of scripts to improve your lifestyle and save you time
1
star