Giter Club home page Giter Club logo

leaflet-freehandshapes's Introduction

Leaflet.FreeHandShapes

MIT License ย  Leaflet NPM

Initially forked from and inspired by L.FreeDraw

What Is This?

This is a Leaflet plugin for adding/manipulating polygons from a Leaflet map. It is a freehand drawer that supports mobile, canvas, and multiple instances. Each instance adds polygons to a Leaflet FeatureGroup, optionally merging with other polygons using TurfJS. Polygons can also be subtracted by other polygons using TurfJS.

See the demo

Screenshot

Installation

via npm:

npm install leaflet-freehandshapes --save

Usage

// initialize
require('leaflet-freehandshapes');
var drawer = new L.FreeHandShapes();

// enable drawing
drawer.setMode('add');

// stop drawing
drawer.setMode('view');

// enable substraction
drawer.setMode('subtract');

// enable click-to-delete
drawer.setMode('delete');

Options

L.FreeHandShapes takes the following options:

  • polygon (object) : Same options as L.Polygon

Default:

{
    className: 'leaflet-free-hand-shapes',
    smoothFactor: 1,
    fillOpacity : 0.5,
    noClip : true,
}

Default:

{
    color:'#5cb85c',
    opacity:1,
    smoothFactor: 0,
    noClip : true,
    clickable : false,
    weight:2
}
  • simplify_tolerance (float) : how much to simplify the polygon (argument given to L.LineUtil.simplify).

Default: 0.005

  • merge_polygons (boolean)

Default: `true

Controls

There is no default control available for this plugin, because it is made to be more flexible, allowing for multiple instances and two drawing methods (addition/subtraction). For an example on how to build your own, take a look at the example, where multiple instances are created for a sample land use development project and bound to some controls (built with Bootstrap CSS) :

  • HTML
  • JS (See Line 14 for iteration/creation of instances, and Line 246 for handlers bound to the control buttons)

Pull Requests

Please limit each PR to one clear improvement each (PR's offering several improvements are harder to read). Any number of bug fixes are welcome!

Goals

  • A built-in control (L.Control) for UI (probably for each instance)

leaflet-freehandshapes's People

Contributors

bozdoz avatar dependabot[bot] avatar avscta avatar cynthiameng avatar ivan-perez avatar

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.