DrawToolbar.js 2.5 KB

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