|
1 /** |
|
2 * @class L.DrawToolbar |
|
3 * @aka Toolbar |
|
4 */ |
|
5 L.DrawToolbar = L.Toolbar.extend({ |
|
6 |
|
7 statics: { |
|
8 TYPE: 'draw' |
|
9 }, |
|
10 |
|
11 options: { |
|
12 polyline: {}, |
|
13 polygon: {}, |
|
14 rectangle: {}, |
|
15 circle: {}, |
|
16 marker: {} |
|
17 }, |
|
18 |
|
19 // @method initialize(): void |
|
20 initialize: function (options) { |
|
21 // Ensure that the options are merged correctly since L.extend is only shallow |
|
22 for (var type in this.options) { |
|
23 if (this.options.hasOwnProperty(type)) { |
|
24 if (options[type]) { |
|
25 options[type] = L.extend({}, this.options[type], options[type]); |
|
26 } |
|
27 } |
|
28 } |
|
29 |
|
30 this._toolbarClass = 'leaflet-draw-draw'; |
|
31 L.Toolbar.prototype.initialize.call(this, options); |
|
32 }, |
|
33 |
|
34 // @method getModeHandlers(): object |
|
35 // Get mode handlers information |
|
36 getModeHandlers: function (map) { |
|
37 return [ |
|
38 { |
|
39 enabled: this.options.polyline, |
|
40 handler: new L.Draw.Polyline(map, this.options.polyline), |
|
41 title: L.drawLocal.draw.toolbar.buttons.polyline |
|
42 }, |
|
43 { |
|
44 enabled: this.options.polygon, |
|
45 handler: new L.Draw.Polygon(map, this.options.polygon), |
|
46 title: L.drawLocal.draw.toolbar.buttons.polygon |
|
47 }, |
|
48 { |
|
49 enabled: this.options.rectangle, |
|
50 handler: new L.Draw.Rectangle(map, this.options.rectangle), |
|
51 title: L.drawLocal.draw.toolbar.buttons.rectangle |
|
52 }, |
|
53 { |
|
54 enabled: this.options.circle, |
|
55 handler: new L.Draw.Circle(map, this.options.circle), |
|
56 title: L.drawLocal.draw.toolbar.buttons.circle |
|
57 }, |
|
58 { |
|
59 enabled: this.options.marker, |
|
60 handler: new L.Draw.Marker(map, this.options.marker), |
|
61 title: L.drawLocal.draw.toolbar.buttons.marker |
|
62 } |
|
63 ]; |
|
64 }, |
|
65 |
|
66 // @method getActions(): object |
|
67 // Get action information |
|
68 getActions: function (handler) { |
|
69 return [ |
|
70 { |
|
71 enabled: handler.completeShape, |
|
72 title: L.drawLocal.draw.toolbar.finish.title, |
|
73 text: L.drawLocal.draw.toolbar.finish.text, |
|
74 callback: handler.completeShape, |
|
75 context: handler |
|
76 }, |
|
77 { |
|
78 enabled: handler.deleteLastVertex, |
|
79 title: L.drawLocal.draw.toolbar.undo.title, |
|
80 text: L.drawLocal.draw.toolbar.undo.text, |
|
81 callback: handler.deleteLastVertex, |
|
82 context: handler |
|
83 }, |
|
84 { |
|
85 title: L.drawLocal.draw.toolbar.actions.title, |
|
86 text: L.drawLocal.draw.toolbar.actions.text, |
|
87 callback: this.disable, |
|
88 context: this |
|
89 } |
|
90 ]; |
|
91 }, |
|
92 |
|
93 // @method setOptions(): void |
|
94 // Sets the options to the toolbar |
|
95 setOptions: function (options) { |
|
96 L.setOptions(this, options); |
|
97 |
|
98 for (var type in this._modes) { |
|
99 if (this._modes.hasOwnProperty(type) && options.hasOwnProperty(type)) { |
|
100 this._modes[type].handler.setOptions(options[type]); |
|
101 } |
|
102 } |
|
103 } |
|
104 }); |