0.2.2 • Published 3 years ago

react-leaflet-editable v0.2.2

Weekly downloads
91
License
ISC
Repository
github
Last release
3 years ago

react-leaflet-editable

npm.io to v0.1.1 base react-leaflet^2.x.x

This is a lightweight react component build on top of react-leaflet^3.x.x that integrate leaflet-editablefeature. It only provides map editing API, and you can easily organize your own UI.

Example

See the DEMO

GIF

How to use

Install

npm install react-leaflet-editable -S

Introducing dependency and import component

Note:

  • Install react-leaflet and leaflet-eidtable before import react-leaflet-editable
  • MapContainer component must have editable = true attribute
  • ReactLeafletEditable component must have map attribute
import React, { useRef } from 'react'
import L, { Icon } from 'leaflet'
import 'leaflet-editable'
import ReactLeafletEditable from 'react-leaflet-editable';
import { MapContainer, TileLayer } from 'react-leaflet'
import 'leaflet/dist/leaflet.css'

function Demo (){
    const editRef = useRef();
    const [map, setMap] = useState();
    // 编辑一个多边形
    const editPolygon = () => {
        editRef.current.startPolygon()
    }
    render(){
        return(
             <ReactLeafletEditable
                ref={editRef}
                map={map}
             >
                <MapContainer
                    editable={true}
                    zoom={4}
                    maxZoom={18}
                    center={[35, 105]}
                    whenCreated={setMap}>
                    <button
                        onClick={editPolygon}
                        className="editable-btn"
                    >polygon</button>
                    <TileLayer url="xxx" />
                </MapContainer>
            </ReactLeafletEditable>
        )
    }
}

Component API

Props

nametypedescriptionparams
onEditingfunctionhook to leaflet-editable editable:editing(e,map)
onEnablefunctionhook to leaflet-editable editable:enable(e,map)
onDisablefunctionhook to leaflet-editable editable:disable(e,map)
onStartDrawingfunctionhook to leaflet-editable editable:drawing:start(e,map)
onDrawingClickfunctionhook to leaflet-editable editable:drawing:click(e,map)
onDrawingCommitfunctionhook to leaflet-editable editable:drawing:commit(e,map)
onDrawingMouseDownfunctionhook to leaflet-editable editable:drawing:mousedown(e,map)
onDrawingMouseUpfunctionhook to leaflet-editable editable:drawing:mouseup(e,map)
onDrawingMovefunctionhook to leaflet-editable editable:drawing:move(e,map)
onCancelDrawingfunctionhook to leaflet-editable editable:drawing:cancel(e,map)
onEndDrawingfunctionhook to leaflet-editable editable:drawing:end(e,map)
onDragStartfunctionhook to leaflet-editable editable:dragstart(e,map)
onDragfunctionhook to leaflet-editable editable:drag(e,map)
onDragEndfunctionhook to leaflet-editable editable:dragend(e,map)
onVertexMarkerDragfunctionhook to leaflet-editable editable:vertex:drag(e,map)
onVertexMarkerDragStartfunctionhook to leaflet-editable editable:vertex:dragstart(e,map)
onVertexMarkerDragEndfunctionhook to leaflet-editable editable:vertex:dragend(e,map)
onVertextCtrlClickfunctionhook to leaflet-editable editable:vertex:ctrlclick(e,map)
onNewVertexfunctionhook to leaflet-editable editable:vertex:new(e,map)
onVertexMarkerClickfunctionhook to leaflet-editable editable:vertex:click(e,map)
onVertexRawMarkerClickfunctionhook to leaflet-editable editable:vertex:rawclick(e,map)
onVertexDeletedfunctionhook to leaflet-editable editable:vertex:deleted(e,map)
onVertexMarkerCtrlClickfunctionhook to leaflet-editable editable:vertex:ctrlclick(e,map)
onVertexMarkerShiftClickfunctionhook to leaflet-editable editable:vertex:shiftclick(e,map)
onVertexMarkerMetaKeyClickfunctionhook to leaflet-editable editable:vertex:metakeyclick(e,map)
onVertexMarkerAltClickfunctionhook to leaflet-editable editable:vertex:altclick(e,map)
onVertexMarkerContextMenufunctionhook to leaflet-editable editable:vertex:contextmenu(e,map)
onVertexMarkerMouseDownfunctionhook to leaflet-editable editable:vertex:mousedown(e,map)
onVertexMarkerMouseOverfunctionhook to leaflet-editable editable:vertex:mouseover(e,map)
onVertexMarkerMouseOutfunctionhook to leaflet-editable editable:vertex:mouseout(e,map)
onMiddleMarkerMouseDownfunctionhook to leaflet-editable editable:middlemarker:mousedown(e,map)
onShapeNewfunctionhook to leaflet-editable editable:shape:new(e,map)
onShapeDeletefunctionhook to leaflet-editable editable:shape:delete(e,map)
onShapeDeletedfunctionhook to leaflet-editable editable:shape:deleted(e,map)

Methods

nametypedescriptionparams
startPolygonfunctionstart edit a polygon layer
startPolylinefunctionstart edit a polyline layer
startMarkerfunctionstart edit a marker layer
startRectanglefunctionstart edit a rect layer
startCirclefunctionstart edit a circle layer
startHolefunctionstart edit a hole layer(editor,latlng)
clearAllfunctionclear all editing layers