Socket
Socket
Sign inDemoInstall

leaflet-draw

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-draw

Vector drawing plugin for Leaflet


Version published
Weekly downloads
91K
decreased by-17.75%
Maintainers
2
Weekly downloads
 
Created

What is leaflet-draw?

The leaflet-draw npm package is an extension for the Leaflet library that adds support for drawing and editing vectors and markers on a map. It provides a user-friendly interface for creating, editing, and deleting various shapes such as polygons, polylines, rectangles, circles, and markers.

What are leaflet-draw's main functionalities?

Drawing Polygons

This feature allows users to draw polygons on the map. The code sample initializes a Leaflet map, adds a tile layer, and sets up the drawing control to enable polygon drawing. When a polygon is created, it is added to the drawn items layer.

L.drawLocal.draw.toolbar.buttons.polygon = 'Draw a polygon';
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  maxZoom: 19
}).addTo(map);
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
  edit: {
    featureGroup: drawnItems
  },
  draw: {
    polygon: true
  }
});
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function (event) {
  var layer = event.layer;
  drawnItems.addLayer(layer);
});

Drawing Polylines

This feature allows users to draw polylines on the map. The code sample initializes a Leaflet map, adds a tile layer, and sets up the drawing control to enable polyline drawing. When a polyline is created, it is added to the drawn items layer.

L.drawLocal.draw.toolbar.buttons.polyline = 'Draw a polyline';
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  maxZoom: 19
}).addTo(map);
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
  edit: {
    featureGroup: drawnItems
  },
  draw: {
    polyline: true
  }
});
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function (event) {
  var layer = event.layer;
  drawnItems.addLayer(layer);
});

Drawing Rectangles

This feature allows users to draw rectangles on the map. The code sample initializes a Leaflet map, adds a tile layer, and sets up the drawing control to enable rectangle drawing. When a rectangle is created, it is added to the drawn items layer.

L.drawLocal.draw.toolbar.buttons.rectangle = 'Draw a rectangle';
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  maxZoom: 19
}).addTo(map);
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
  edit: {
    featureGroup: drawnItems
  },
  draw: {
    rectangle: true
  }
});
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function (event) {
  var layer = event.layer;
  drawnItems.addLayer(layer);
});

Drawing Circles

This feature allows users to draw circles on the map. The code sample initializes a Leaflet map, adds a tile layer, and sets up the drawing control to enable circle drawing. When a circle is created, it is added to the drawn items layer.

L.drawLocal.draw.toolbar.buttons.circle = 'Draw a circle';
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  maxZoom: 19
}).addTo(map);
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
  edit: {
    featureGroup: drawnItems
  },
  draw: {
    circle: true
  }
});
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function (event) {
  var layer = event.layer;
  drawnItems.addLayer(layer);
});

Drawing Markers

This feature allows users to place markers on the map. The code sample initializes a Leaflet map, adds a tile layer, and sets up the drawing control to enable marker placement. When a marker is created, it is added to the drawn items layer.

L.drawLocal.draw.toolbar.buttons.marker = 'Draw a marker';
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  maxZoom: 19
}).addTo(map);
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
  edit: {
    featureGroup: drawnItems
  },
  draw: {
    marker: true
  }
});
map.addControl(drawControl);
map.on(L.Draw.Event.CREATED, function (event) {
  var layer = event.layer;
  drawnItems.addLayer(layer);
});

Other packages similar to leaflet-draw

Keywords

FAQs

Package last updated on 20 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc