Giter Club home page Giter Club logo

react-leaflet-freedraw's Introduction

react-leaflet-freedraw

Plugin for react-leaflet v3 to integrate Leaflet.FreeDraw.

Please checkout codesandbox EXAMPLE using this package with some primary use cases.

Install

npm install react-leaflet-freedraw --save

or

yarn add react-leaflet-freedraw

Make sure that you have the following peer dependencies installed.

npm install leaflet react-leaflet react react-dom --save

or

yarn add leaflet react-leaflet react react-dom

Getting started

Please make sure that you go through Leaflet.FreeDraw readme before integrating this component.

You need to wrap this component into MapContainer component and pass the options as shown below.

import React, { useRef } from 'react';
import { MapContainer } from 'react-leaflet';
import Freedraw, { ALL } from 'react-leaflet-freedraw';

const Component = () => {
  const freedrawRef = useRef(null);

  return (
    <MapContainer>
      <Freedraw
        mode={ALL}
        eventHandlers={{
          markers: (event) =>
            console.log(
              'markers drawn - latLngs',
              event.latLngs,
              'Polygons:',
              freedrawRef.current.size()
            ),
          mode: (event) => console.log('mode changed', event),
        }}
        ref={freedrawRef}
      />
    </MapContainer>
  );
};

It supports all the options mentioned in Leaflet.FreeDraw.

A detailed example of how to use this componenet is in the example folder of this repo. To run the example,

  1. Clone this repo
  2. Run npm i
  3. Run npm run example

react-leaflet-freedraw's People

Contributors

elangobharathi avatar elangobharathid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-leaflet-freedraw's Issues

Change state of layer based on a state

Hello,
Can we redraw the layer ocmpletelky based on a state?

I have a situation where there is toggling of different views and i want to basicvally remove the freeDraw layer to qa blanck screen every time the state changes

Add leaflet-freedraw as a dependency

Add leaflet-freedraw as a dependency, so that developers don't have to install it manually, or at least add some info on the readme and npm page, so that users do not forget to do it.

supermanagerhome.js:96 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

I add it to Ant-design-pro, error

ramda moderate severity warning

running npm audit --production shows a moderate severity warning in the ramda package.

image

Is it possible to bump up to 0.27.2 ?

[bug] Example broken : Uncaught ReferenceError: require is not defined

Situation and steps to reproduce (attempt to run the example locally) :

  • cloned the project
  • install all dependencies (add a dependencies key in package.json so that example/index.js can resolve dependencies)
  • run npm run example
  • build successful
  • navigate to http://localhost:8000
  • blank page, following messages in console :

Screen Shot 2019-04-15 at 10 41 47 AM

  • an external_"leaflet" seems to be created by Webpack :

Screen Shot 2019-04-15 at 10 45 25 AM

Also tried to implement the example in my own project and got the exact same situation.

The bug :

Unable to use the library, either in the example or in another context.

Desired behaviour :

Being able to run the example either in the context of the library, or in other projects.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.