is it possible to add an L.Control button, so when the user clicks it, the user would be able to draw a polyline? I can easily add the default L.Control.Draw button, but this is not what I want, I just want the functionality of this button :)
Asked
Active
Viewed 1,358 times
0
-
To clarify, do you want to be able to call the draw initializing function with your own custom buttom? If yes, then this is a duplicate of https://stackoverflow.com/questions/15775103/leaflet-draw-mapping-how-to-initiate-the-draw-function-without-toolbar?rq=1 – raphael Dec 02 '15 at 03:15
2 Answers
1
Rather than overriding (hiding) functionality from the outside, you can use L.Control.Draw's (which I'm a big fan of) definition to show or not show what you want. So, to use L.Control.Draw to only show a button to define a polyline, you could set it up as:
var drawControl = new L.Control.Draw({
position: 'topleft',
draw: {
polyline: { <whatever options you want> },
polygon: false,
rectangle: false,
circle: false,
marker: false
},
edit: false
});

tschwaar
- 11
- 1
0
The simplest fix would be to add the CSS property display:none;
, which moves the control buttons up without messing up the UI. Here's the following classes you'd want to hide:
- leaflet-draw-draw-marker
- leaflet-draw-draw-circle
- leaflet-draw-draw-rectangle
- leaflet-draw-draw-polygon
Alternatively you could fork Leaflet.draw and just remove the parts pertaining to other geofeatures.

geraldarthur
- 1,494
- 1
- 12
- 19