EditToolbar.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*L.Map.mergeOptions({
  2. editControl: true
  3. });*/
  4. L.EditToolbar = L.Toolbar.extend({
  5. options: {
  6. edit: {
  7. title: L.drawLocal.edit.toolbar.edit.title,
  8. selectedPathOptions: {
  9. color: '#fe57a1', /* Hot pink all the things! */
  10. opacity: 0.6,
  11. dashArray: '10, 10',
  12. fill: true,
  13. fillColor: '#fe57a1',
  14. fillOpacity: 0.1
  15. }
  16. },
  17. remove: {
  18. title: L.drawLocal.edit.toolbar.remove.title
  19. },
  20. favorite: {
  21. title: L.drawLocal.edit.toolbar.favorite.title
  22. },
  23. // stylePicker:{
  24. // title: L.drawLocal.style.toolbar.stylePicker.title
  25. // }
  26. /*print:{
  27. title: L.drawLocal.edit.toolbar.print.title
  28. },*/
  29. featureGroup: null /* REQUIRED! TODO: perhaps if not set then all layers on the map are selectable? */
  30. },
  31. initialize: function (options) {
  32. // Need to set this manually since null is an acceptable value here
  33. if (options.edit && typeof options.edit.selectedPathOptions === 'undefined') {
  34. options.edit.selectedPathOptions = this.options.edit.selectedPathOptions;
  35. }
  36. options.edit = L.extend({}, this.options.edit, options.edit);
  37. options.remove = L.extend({}, this.options.remove, options.remove);
  38. L.Toolbar.prototype.initialize.call(this, options);
  39. this._selectedFeatureCount = 0;
  40. },
  41. addToolbar: function (map) {
  42. var container = L.DomUtil.create('div', 'leaflet-draw-section'),
  43. buttonIndex = 0,
  44. buttonClassPrefix = 'leaflet-draw-edit';
  45. this._toolbarContainer = L.DomUtil.create('div', 'leaflet-draw-toolbar leaflet-bar');
  46. this._map = map;
  47. if (this.options.edit) {
  48. this._initModeHandler(
  49. new L.EditToolbar.Edit(map, {
  50. featureGroup: this.options.featureGroup,
  51. selectedPathOptions: this.options.edit.selectedPathOptions
  52. }),
  53. this._toolbarContainer,
  54. buttonIndex++,
  55. buttonClassPrefix
  56. );
  57. }
  58. if(this.options.favorite) {
  59. this._createButton({
  60. title: this.options.favorite.title,
  61. className: buttonClassPrefix + '-favorite',
  62. container: this._toolbarContainer,
  63. callback: function(){
  64. this._map.fire('favorite');
  65. },
  66. context: this
  67. });
  68. }
  69. if (this.options.remove) {
  70. this._initModeHandler(
  71. new L.EditToolbar.Delete(map, {
  72. featureGroup: this.options.featureGroup
  73. }),
  74. this._toolbarContainer,
  75. buttonIndex++,
  76. buttonClassPrefix
  77. );
  78. }
  79. if (this.options.stylePicker) {
  80. this._initModeHandler(
  81. new L.Style.StylePicker(map, this.options.stylePicker),
  82. this._toolbarContainer,
  83. buttonIndex++,
  84. buttonClassPrefix
  85. );
  86. }
  87. if(this.options.print) {
  88. // this._createButton({
  89. // title: this.options.print.title,
  90. // className: buttonClassPrefix + '-print',
  91. // container: this._toolbarContainer,
  92. // callback: function(){
  93. // this._map.fire('printDraw');
  94. // },
  95. // context: this
  96. // });
  97. }
  98. // Save button index of the last button, -1 as we would have ++ after the last button
  99. this._lastButtonIndex = --buttonIndex;
  100. // Create the actions part of the toolbar
  101. // this._actionsContainer = this._createActions(
  102. // [
  103. // {
  104. // title: L.drawLocal.edit.toolbar.edit.save.title,
  105. // text: L.drawLocal.edit.toolbar.edit.save.text,
  106. // callback: this._save,
  107. // context: this
  108. // },
  109. // {
  110. // title: L.drawLocal.edit.toolbar.edit.cancel.title,
  111. // text: L.drawLocal.edit.toolbar.edit.cancel.text,
  112. // callback: this.disable,
  113. // context: this
  114. // }
  115. // ]
  116. // );
  117. // Add draw and cancel containers to the control container
  118. container.appendChild(this._toolbarContainer);
  119. //container.appendChild(this._actionsContainer);
  120. return container;
  121. },
  122. disable: function () {
  123. if (!this.enabled()) { return; }
  124. //this._activeMode.handler.revertLayers();
  125. L.Toolbar.prototype.disable.call(this);
  126. },
  127. _save: function () {
  128. this._activeMode.handler.save();
  129. this._activeMode.handler.disable();
  130. }
  131. });