Leaflet.draw

Vector drawing plugin for Leaflet

#Leaflet.draw Adds support for drawing polys to Leaflet.

Check out the demo

This plugin was inspired by @brunob’s draw plugin. I decided to create a new repo rather than forking as I wanted to take the coding style and functionality in a different direction.

#Using the plugin If you are happy with the control being displayed below the zoom controls just set drawControl = true when declaring your Leaflet map.

E.g.:

var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18}),
map = new L.Map('map', {layers: [cloudmade], center: new L.LatLng(-37.7772, 175.2756), zoom: 15, drawControl: true });

If you would like to reposition the control, turn off a tyep or customize the styles then add the control manually:

var drawControl = new L.Control.Draw({
	position: 'topright',
	drawPolyline: false
});
map.addControl(drawControl);

See example/map-polydraw.html for a working example.

#Customize shape styles

L.Control.Draw can take an options object. You can specify a styles property like so:

var options = {
	styles: {
		polyine: {
			color: '#f357a1',
			width: 10
		},
		polygon: {
			color: '#bada55'
		},
		rectangle: {
			clickable: false
		}
	}
}

The shape styles are the leaflet Path and Polyline options.

#Official support Leaflet plan to include drawing in 0.4 so this is just a band-aid until it comes. See https://github.com/CloudMade/Leaflet/issues/174

Related Repositories

Leaflet.draw

Leaflet.draw

Vector drawing and editing plugin for Leaflet ...

leaflet-boundary-canvas

leaflet-boundary-canvas

Leaflet plugin to draw raster layers with arbitrary boundary ...

leaflet.draw.archive

leaflet.draw.archive

Drawing handler and control for Leaflet ...

react-leaflet-draw

react-leaflet-draw

React component for leaflet-draw ...

leaflet-custom-paths

leaflet-custom-paths

Draw custom paths with the Leaflet mapping library ...


Top Contributors

jacobtoye mphasize Guiswa