React-Leaflet-Draw

在 react-leaflet 基础上为 leaflet-draw 开发的 React 组件。「React component for leaflet-draw on top of react-leaflet」

Github星跟踪图

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

主要指标

概览
名称与所有者go-rod/rod
主编程语言Go
编程语言JavaScript (语言数: 5)
平台
许可证MIT License
所有者活动
创建于2020-01-21 20:09:45
推送于2024-12-07 14:51:24
最后一次提交
发布数367
最新版本名称v0.116.2 (发布于 )
第一版名称v0.0.1 (发布于 )
用户参与
星数5.9k
关注者数49
派生数380
提交数1.3k
已启用问题?
问题数957
打开的问题数159
拉请求数97
打开的拉请求数12
关闭的拉请求数45
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?