leaflet-js 0.6.beta4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. checksums.yaml +6 -14
  2. data/CHANGELOG.rdoc +3 -0
  3. data/leaflet-js.gemspec +2 -2
  4. data/lib/leaflet.draw/CHANGELOG.md +45 -0
  5. data/lib/leaflet.draw/README.md +70 -23
  6. data/lib/leaflet.draw/build/deps.js +1 -0
  7. data/lib/leaflet.draw/dist/images/spritesheet-2x.png +0 -0
  8. data/lib/leaflet.draw/dist/images/spritesheet.png +0 -0
  9. data/lib/leaflet.draw/dist/leaflet.draw-src.js +489 -136
  10. data/lib/leaflet.draw/dist/leaflet.draw.css +34 -2
  11. data/lib/leaflet.draw/dist/leaflet.draw.ie.css +5 -0
  12. data/lib/leaflet.draw/dist/leaflet.draw.js +2 -2
  13. data/lib/leaflet.draw/examples/basic.html +14 -7
  14. data/lib/leaflet.draw/examples/libs/images/layers-2x.png +0 -0
  15. data/lib/leaflet.draw/examples/libs/images/layers.png +0 -0
  16. data/lib/leaflet.draw/examples/libs/images/marker-icon-2x.png +0 -0
  17. data/lib/leaflet.draw/examples/libs/leaflet-src.js +1129 -608
  18. data/lib/leaflet.draw/examples/libs/leaflet.css +85 -66
  19. data/lib/leaflet.draw/package.json +2 -2
  20. data/lib/leaflet.draw/spec/suites/DrawControlSpec.js +1 -1
  21. data/lib/leaflet.draw/spec/suites/GeometryUtilSpec.js +25 -0
  22. data/lib/leaflet.draw/spec/suites/LatLngUtilSpec.js +9 -0
  23. data/lib/leaflet.draw/src/Control.Draw.js +1 -0
  24. data/lib/leaflet.draw/src/Leaflet.draw.js +89 -1
  25. data/lib/leaflet.draw/src/Toolbar.js +2 -6
  26. data/lib/leaflet.draw/src/Tooltip.js +20 -7
  27. data/lib/leaflet.draw/src/draw/DrawToolbar.js +26 -22
  28. data/lib/leaflet.draw/src/draw/handler/Draw.Circle.js +11 -6
  29. data/lib/leaflet.draw/src/draw/handler/Draw.Feature.js +6 -2
  30. data/lib/leaflet.draw/src/draw/handler/Draw.Marker.js +7 -2
  31. data/lib/leaflet.draw/src/draw/handler/Draw.Polygon.js +29 -7
  32. data/lib/leaflet.draw/src/draw/handler/Draw.Polyline.js +44 -21
  33. data/lib/leaflet.draw/src/draw/handler/Draw.Rectangle.js +3 -3
  34. data/lib/leaflet.draw/src/draw/handler/Draw.SimpleShape.js +14 -1
  35. data/lib/leaflet.draw/src/edit/EditToolbar.js +86 -16
  36. data/lib/leaflet.draw/src/edit/handler/Edit.Poly.js +10 -7
  37. data/lib/leaflet.draw/src/edit/handler/Edit.SimpleShape.js +1 -2
  38. data/lib/leaflet.draw/src/edit/handler/EditToolbar.Delete.js +15 -3
  39. data/lib/leaflet.draw/src/edit/handler/EditToolbar.Edit.js +56 -38
  40. data/lib/leaflet.draw/src/ext/GeometryUtil.js +68 -0
  41. data/lib/leaflet.draw/src/images/spritesheet.svg +41 -0
  42. data/lib/leaflet.label/CHANGELOG.md +32 -0
  43. data/lib/leaflet.label/README.md +21 -4
  44. data/lib/leaflet.label/build/build.js +2 -2
  45. data/lib/leaflet.label/build/deps.js +2 -0
  46. data/lib/leaflet.label/build/hintrc.js +4 -0
  47. data/lib/leaflet.label/dist/leaflet.label-src.js +266 -83
  48. data/lib/leaflet.label/dist/leaflet.label.css +23 -4
  49. data/lib/leaflet.label/dist/leaflet.label.js +1 -1
  50. data/lib/leaflet.label/example/label.html +6 -3
  51. data/lib/leaflet.label/libs/leaflet/images/layers-2x.png +0 -0
  52. data/lib/leaflet.label/libs/leaflet/images/layers.png +0 -0
  53. data/lib/leaflet.label/libs/leaflet/images/marker-icon-2x.png +0 -0
  54. data/lib/leaflet.label/libs/leaflet/leaflet-src.js +1129 -608
  55. data/lib/leaflet.label/libs/leaflet/leaflet.css +85 -66
  56. data/lib/leaflet.label/libs/leaflet/leaflet.js +6 -5
  57. data/lib/leaflet.label/package.json +19 -0
  58. data/lib/leaflet.label/src/BaseMarkerMethods.js +129 -0
  59. data/lib/leaflet.label/src/CircleMarker.Label.js +7 -0
  60. data/lib/leaflet.label/src/Label.js +161 -37
  61. data/lib/leaflet.label/src/Leaflet.label.js +1 -1
  62. data/lib/leaflet.label/src/Map.Label.js +0 -2
  63. data/lib/leaflet.label/src/Marker.Label.js +15 -120
  64. data/lib/leaflet.label/src/Path.Label.js +11 -11
  65. data/lib/leaflet/CHANGELOG.md +299 -31
  66. data/lib/leaflet/CONTRIBUTING.md +3 -3
  67. data/lib/leaflet/FAQ.md +138 -0
  68. data/lib/leaflet/Jakefile.js +24 -4
  69. data/lib/leaflet/PLUGIN-GUIDE.md +127 -0
  70. data/lib/leaflet/README.md +10 -6
  71. data/lib/leaflet/build/build.html +3 -19
  72. data/lib/leaflet/build/build.js +21 -51
  73. data/lib/leaflet/build/deps.js +10 -7
  74. data/lib/leaflet/build/hintrc.js +6 -4
  75. data/lib/leaflet/debug/hacks/jitter.html +0 -1
  76. data/lib/leaflet/debug/map/canvas.html +11 -12
  77. data/lib/leaflet/debug/map/controls.html +3 -4
  78. data/lib/leaflet/debug/map/geolocation.html +0 -1
  79. data/lib/leaflet/debug/map/iframe.html +11 -0
  80. data/lib/leaflet/debug/map/image-overlay.html +0 -1
  81. data/lib/leaflet/debug/map/map-mobile.html +0 -1
  82. data/lib/leaflet/debug/map/map.html +1 -2
  83. data/lib/leaflet/debug/map/max-bounds.html +2 -1
  84. data/lib/leaflet/debug/map/opacity.html +223 -0
  85. data/lib/leaflet/debug/map/scroll.html +6 -1
  86. data/lib/leaflet/debug/map/simple-proj.html +0 -1
  87. data/lib/leaflet/debug/map/wms-marble.html +4 -5
  88. data/lib/leaflet/debug/map/wms.html +0 -1
  89. data/lib/leaflet/debug/map/zoomlevels.html +0 -1
  90. data/lib/leaflet/debug/tests/add_remove_layers.html +5 -6
  91. data/lib/leaflet/debug/tests/bringtoback.html +0 -1
  92. data/lib/leaflet/debug/tests/canvasloop.html +47 -0
  93. data/lib/leaflet/debug/tests/click_on_canvas.html +0 -1
  94. data/lib/leaflet/debug/tests/dragging_and_copyworldjump.html +61 -0
  95. data/lib/leaflet/debug/tests/opacity.html +0 -1
  96. data/lib/leaflet/debug/tests/popupcontextmenuclicks.html +59 -0
  97. data/lib/leaflet/debug/tests/remove_while_dragging.html +4 -5
  98. data/lib/leaflet/debug/tests/removetilewhilepan.html +0 -1
  99. data/lib/leaflet/debug/tests/reuse_popups.html +0 -1
  100. data/lib/leaflet/debug/tests/rtl.html +42 -0
  101. data/lib/leaflet/debug/tests/rtl2.html +27 -0
  102. data/lib/leaflet/debug/tests/set_icon_reuse_dom.html +43 -0
  103. data/lib/leaflet/debug/tests/svg_clicks.html +3 -4
  104. data/lib/leaflet/debug/vector/bounds-extend.html +0 -1
  105. data/lib/leaflet/debug/vector/feature-group-bounds.html +0 -1
  106. data/lib/leaflet/debug/vector/geojson.html +0 -1
  107. data/lib/leaflet/debug/vector/rectangle.html +0 -1
  108. data/lib/leaflet/debug/vector/touchzoomemu.html +2 -3
  109. data/lib/leaflet/debug/vector/vector-bounds.html +0 -1
  110. data/lib/leaflet/debug/vector/vector-canvas.html +0 -1
  111. data/lib/leaflet/debug/vector/vector-mobile.html +0 -1
  112. data/lib/leaflet/debug/vector/vector-simple.html +0 -1
  113. data/lib/leaflet/debug/vector/vector.html +0 -1
  114. data/lib/leaflet/dist/images/layers-2x.png +0 -0
  115. data/lib/leaflet/dist/images/layers.png +0 -0
  116. data/lib/leaflet/dist/leaflet.css +85 -66
  117. data/lib/leaflet/package.json +25 -20
  118. data/lib/leaflet/spec/after.js +1 -1
  119. data/lib/leaflet/spec/index.html +21 -13
  120. data/lib/leaflet/spec/karma.conf.js +51 -50
  121. data/lib/leaflet/spec/spec.hintrc.js +25 -0
  122. data/lib/leaflet/spec/suites/LeafletSpec.js +2 -2
  123. data/lib/leaflet/spec/suites/SpecHelper.js +37 -21
  124. data/lib/leaflet/spec/suites/control/Control.LayersSpec.js +1 -1
  125. data/lib/leaflet/spec/suites/core/ClassSpec.js +12 -12
  126. data/lib/leaflet/spec/suites/core/EventsSpec.js +74 -18
  127. data/lib/leaflet/spec/suites/core/UtilSpec.js +69 -25
  128. data/lib/leaflet/spec/suites/dom/DomEventSpec.js +16 -16
  129. data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +9 -16
  130. data/lib/leaflet/spec/suites/dom/PosAnimationSpec.js +27 -0
  131. data/lib/leaflet/spec/suites/geo/CRSSpec.js +47 -0
  132. data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +22 -14
  133. data/lib/leaflet/spec/suites/geo/LatLngSpec.js +22 -8
  134. data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +21 -20
  135. data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +15 -15
  136. data/lib/leaflet/spec/suites/geometry/PointSpec.js +12 -12
  137. data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +4 -4
  138. data/lib/leaflet/spec/suites/layer/FeatureGroupSpec.js +59 -9
  139. data/lib/leaflet/spec/suites/layer/GeoJSONSpec.js +213 -17
  140. data/lib/leaflet/spec/suites/layer/LayerGroupSpec.js +6 -6
  141. data/lib/leaflet/spec/suites/layer/PopupSpec.js +65 -5
  142. data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +16 -15
  143. data/lib/leaflet/spec/suites/layer/marker/MarkerSpec.js +94 -0
  144. data/lib/leaflet/spec/suites/layer/vector/CircleMarkerSpec.js +7 -7
  145. data/lib/leaflet/spec/suites/layer/vector/PolygonSpec.js +38 -2
  146. data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +4 -4
  147. data/lib/leaflet/spec/suites/layer/vector/PolylineSpec.js +2 -2
  148. data/lib/leaflet/spec/suites/map/MapSpec.js +318 -26
  149. data/lib/leaflet/spec/suites/map/handler/Map.DragSpec.js +38 -0
  150. data/lib/leaflet/src/Leaflet.js +2 -2
  151. data/lib/leaflet/src/control/Control.Attribution.js +6 -0
  152. data/lib/leaflet/src/control/Control.Layers.js +33 -24
  153. data/lib/leaflet/src/control/Control.Zoom.js +12 -4
  154. data/lib/leaflet/src/control/Control.js +10 -0
  155. data/lib/leaflet/src/copyright.js +2 -1
  156. data/lib/leaflet/src/core/Browser.js +11 -10
  157. data/lib/leaflet/src/core/Events.js +15 -11
  158. data/lib/leaflet/src/core/Util.js +19 -14
  159. data/lib/leaflet/src/dom/DomEvent.DoubleTap.js +13 -12
  160. data/lib/leaflet/src/dom/DomEvent.Pointer.js +155 -0
  161. data/lib/leaflet/src/dom/DomEvent.js +57 -19
  162. data/lib/leaflet/src/dom/DomUtil.js +89 -34
  163. data/lib/leaflet/src/dom/Draggable.js +26 -89
  164. data/lib/leaflet/src/dom/PosAnimation.js +13 -2
  165. data/lib/leaflet/src/geo/LatLng.js +16 -5
  166. data/lib/leaflet/src/geo/LatLngBounds.js +5 -2
  167. data/lib/leaflet/src/geo/crs/CRS.EPSG3395.js +2 -2
  168. data/lib/leaflet/src/geo/crs/CRS.js +5 -0
  169. data/lib/leaflet/src/geo/projection/Projection.Mercator.js +3 -3
  170. data/lib/leaflet/src/geometry/LineUtil.js +2 -2
  171. data/lib/leaflet/src/images/layers.svg +8 -0
  172. data/lib/leaflet/src/images/marker.svg +61 -1
  173. data/lib/leaflet/src/layer/FeatureGroup.js +24 -7
  174. data/lib/leaflet/src/layer/GeoJSON.js +97 -56
  175. data/lib/leaflet/src/layer/ImageOverlay.js +9 -0
  176. data/lib/leaflet/src/layer/LayerGroup.js +8 -3
  177. data/lib/leaflet/src/layer/Popup.js +56 -34
  178. data/lib/leaflet/src/layer/marker/DivIcon.js +4 -2
  179. data/lib/leaflet/src/layer/marker/Icon.Default.js +1 -1
  180. data/lib/leaflet/src/layer/marker/Icon.js +15 -18
  181. data/lib/leaflet/src/layer/marker/Marker.Drag.js +7 -5
  182. data/lib/leaflet/src/layer/marker/Marker.Popup.js +22 -5
  183. data/lib/leaflet/src/layer/marker/Marker.js +75 -32
  184. data/lib/leaflet/src/layer/tile/TileLayer.Anim.js +14 -26
  185. data/lib/leaflet/src/layer/tile/TileLayer.Canvas.js +7 -6
  186. data/lib/leaflet/src/layer/tile/TileLayer.WMS.js +14 -10
  187. data/lib/leaflet/src/layer/tile/TileLayer.js +53 -32
  188. data/lib/leaflet/src/layer/vector/CircleMarker.js +11 -0
  189. data/lib/leaflet/src/layer/vector/MultiPoly.js +10 -0
  190. data/lib/leaflet/src/layer/vector/Path.SVG.js +14 -3
  191. data/lib/leaflet/src/layer/vector/Path.VML.js +12 -2
  192. data/lib/leaflet/src/layer/vector/Path.js +7 -3
  193. data/lib/leaflet/src/layer/vector/Polygon.js +14 -3
  194. data/lib/leaflet/src/layer/vector/canvas/CircleMarker.Canvas.js +9 -0
  195. data/lib/leaflet/src/layer/vector/canvas/Path.Canvas.js +1 -0
  196. data/lib/leaflet/src/map/Map.js +192 -125
  197. data/lib/leaflet/src/map/anim/Map.PanAnimation.js +29 -19
  198. data/lib/leaflet/src/map/anim/Map.ZoomAnimation.js +21 -9
  199. data/lib/leaflet/src/map/ext/Map.Geolocation.js +11 -4
  200. data/lib/leaflet/src/map/handler/Map.BoxZoom.js +26 -12
  201. data/lib/leaflet/src/map/handler/Map.DoubleClickZoom.js +10 -3
  202. data/lib/leaflet/src/map/handler/Map.Drag.js +12 -6
  203. data/lib/leaflet/src/map/handler/Map.Keyboard.js +5 -2
  204. data/lib/leaflet/src/map/handler/Map.ScrollWheelZoom.js +7 -1
  205. data/lib/leaflet/src/map/handler/Map.Tap.js +107 -0
  206. data/lib/leaflet/src/map/handler/Map.TouchZoom.js +9 -3
  207. data/vendor/assets/images/layers-2x.png +0 -0
  208. data/vendor/assets/images/layers.png +0 -0
  209. data/vendor/assets/images/spritesheet-2x.png +0 -0
  210. data/vendor/assets/images/spritesheet.png +0 -0
  211. data/vendor/assets/javascripts/leaflet.draw.js +2 -4
  212. data/vendor/assets/javascripts/leaflet.js +3 -1
  213. data/vendor/assets/javascripts/leaflet.label.js +2 -0
  214. data/vendor/assets/stylesheets/leaflet.css.erb +337 -318
  215. data/vendor/assets/stylesheets/leaflet.draw.css.erb +35 -3
  216. data/vendor/assets/stylesheets/leaflet.draw.ie.css +5 -0
  217. data/vendor/assets/stylesheets/leaflet.label.css +23 -4
  218. metadata +40 -14
  219. data/lib/leaflet.draw/examples/libs/leaflet.ie.css +0 -51
  220. data/lib/leaflet.label/libs/leaflet/leaflet.ie.css +0 -51
  221. data/lib/leaflet/dist/leaflet-src.js +0 -8579
  222. data/lib/leaflet/dist/leaflet.ie.css +0 -51
  223. data/lib/leaflet/dist/leaflet.js +0 -8
  224. data/lib/leaflet/spec/happen.js +0 -93
  225. data/lib/leaflet/src/dom/DomEvent.MsTouch.js +0 -146
  226. data/vendor/assets/stylesheets/leaflet.ie.css +0 -51
@@ -20,11 +20,11 @@ L.Draw.Rectangle = L.Draw.SimpleShape.extend({
20
20
  // Save the type so super can fire, need to do this as cannot do this.TYPE :(
21
21
  this.type = L.Draw.Rectangle.TYPE;
22
22
 
23
+ this._initialLabelText = L.drawLocal.draw.handlers.rectangle.tooltip.start;
24
+
23
25
  L.Draw.SimpleShape.prototype.initialize.call(this, map, options);
24
26
  },
25
27
 
26
- _initialLabelText: 'Click and drag to draw rectangle.',
27
-
28
28
  _drawShape: function (latlng) {
29
29
  if (!this._shape) {
30
30
  this._shape = new L.Rectangle(new L.LatLngBounds(this._startLatLng, latlng), this.options.shapeOptions);
@@ -38,4 +38,4 @@ L.Draw.Rectangle = L.Draw.SimpleShape.extend({
38
38
  var rectangle = new L.Rectangle(this._shape.getBounds(), this.options.shapeOptions);
39
39
  L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, rectangle);
40
40
  }
41
- });
41
+ });
@@ -1,6 +1,16 @@
1
1
  L.SimpleShape = {};
2
2
 
3
3
  L.Draw.SimpleShape = L.Draw.Feature.extend({
4
+ options: {
5
+ repeatMode: false
6
+ },
7
+
8
+ initialize: function (map, options) {
9
+ this._endLabelText = L.drawLocal.draw.handlers.simpleshape.tooltip.end;
10
+
11
+ L.Draw.Feature.prototype.initialize.call(this, map, options);
12
+ },
13
+
4
14
  addHooks: function () {
5
15
  L.Draw.Feature.prototype.addHooks.call(this);
6
16
  if (this._map) {
@@ -52,7 +62,7 @@ L.Draw.SimpleShape = L.Draw.Feature.extend({
52
62
 
53
63
  this._tooltip.updatePosition(latlng);
54
64
  if (this._isDrawing) {
55
- this._tooltip.updateContent({ text: 'Release mouse to finish drawing.' });
65
+ this._tooltip.updateContent({ text: this._endLabelText });
56
66
  this._drawShape(latlng);
57
67
  }
58
68
  },
@@ -63,5 +73,8 @@ L.Draw.SimpleShape = L.Draw.Feature.extend({
63
73
  }
64
74
 
65
75
  this.disable();
76
+ if (this.options.repeatMode) {
77
+ this.enable();
78
+ }
66
79
  }
67
80
  });
@@ -5,16 +5,33 @@
5
5
  L.EditToolbar = L.Toolbar.extend({
6
6
  options: {
7
7
  edit: {
8
- title: 'Edit layers',
9
- selectedPathOptions: null // See Edit handler options, this is used to customize the style of selected paths
10
- },
11
- remove: {
12
- title: 'Delete layers'
8
+ selectedPathOptions: {
9
+ color: '#fe57a1', /* Hot pink all the things! */
10
+ opacity: 0.6,
11
+ dashArray: '10, 10',
12
+
13
+ fill: true,
14
+ fillColor: '#fe57a1',
15
+ fillOpacity: 0.1
16
+ }
13
17
  },
18
+ remove: {},
14
19
  featureGroup: null /* REQUIRED! TODO: perhaps if not set then all layers on the map are selectable? */
15
20
  },
16
21
 
17
22
  initialize: function (options) {
23
+ // Need to set this manually since null is an acceptable value here
24
+ if (options.edit) {
25
+ if (typeof options.edit.selectedPathOptions === 'undefined') {
26
+ options.edit.selectedPathOptions = this.options.edit.selectedPathOptions;
27
+ }
28
+ options.edit = L.extend({}, this.options.edit, options.edit);
29
+ }
30
+
31
+ if (options.remove) {
32
+ options.remove = L.extend({}, this.options.remove, options.remove);
33
+ }
34
+
18
35
  L.Toolbar.prototype.initialize.call(this, options);
19
36
 
20
37
  this._selectedFeatureCount = 0;
@@ -23,32 +40,35 @@ L.EditToolbar = L.Toolbar.extend({
23
40
  addToolbar: function (map) {
24
41
  var container = L.DomUtil.create('div', 'leaflet-draw-section'),
25
42
  buttonIndex = 0,
26
- buttonClassPrefix = 'leaflet-draw-edit';
43
+ buttonClassPrefix = 'leaflet-draw-edit',
44
+ featureGroup = this.options.featureGroup;
27
45
 
28
- this._toolbarContainer = L.DomUtil.create('div', 'leaflet-draw-toolbar leaflet-bar'),
46
+ this._toolbarContainer = L.DomUtil.create('div', 'leaflet-draw-toolbar leaflet-bar');
29
47
 
30
48
  this._map = map;
31
49
 
32
50
  if (this.options.edit) {
33
51
  this._initModeHandler(
34
52
  new L.EditToolbar.Edit(map, {
35
- featureGroup: this.options.featureGroup,
53
+ featureGroup: featureGroup,
36
54
  selectedPathOptions: this.options.edit.selectedPathOptions
37
55
  }),
38
56
  this._toolbarContainer,
39
57
  buttonIndex++,
40
- buttonClassPrefix
58
+ buttonClassPrefix,
59
+ L.drawLocal.edit.toolbar.buttons.edit
41
60
  );
42
61
  }
43
62
 
44
63
  if (this.options.remove) {
45
64
  this._initModeHandler(
46
65
  new L.EditToolbar.Delete(map, {
47
- featureGroup: this.options.featureGroup
66
+ featureGroup: featureGroup
48
67
  }),
49
68
  this._toolbarContainer,
50
69
  buttonIndex++,
51
- buttonClassPrefix
70
+ buttonClassPrefix,
71
+ L.drawLocal.edit.toolbar.buttons.remove
52
72
  );
53
73
  }
54
74
 
@@ -58,14 +78,14 @@ L.EditToolbar = L.Toolbar.extend({
58
78
  // Create the actions part of the toolbar
59
79
  this._actionsContainer = this._createActions([
60
80
  {
61
- title: 'Save changes.',
62
- text: 'Save',
81
+ title: L.drawLocal.edit.toolbar.actions.save.title,
82
+ text: L.drawLocal.edit.toolbar.actions.save.text,
63
83
  callback: this._save,
64
84
  context: this
65
85
  },
66
86
  {
67
- title: 'Cancel editing, discards all changes.',
68
- text: 'Cancel',
87
+ title: L.drawLocal.edit.toolbar.actions.cancel.title,
88
+ text: L.drawLocal.edit.toolbar.actions.cancel.text,
69
89
  callback: this.disable,
70
90
  context: this
71
91
  }
@@ -75,9 +95,19 @@ L.EditToolbar = L.Toolbar.extend({
75
95
  container.appendChild(this._toolbarContainer);
76
96
  container.appendChild(this._actionsContainer);
77
97
 
98
+ this._checkDisabled();
99
+
100
+ featureGroup.on('layeradd layerremove', this._checkDisabled, this);
101
+
78
102
  return container;
79
103
  },
80
104
 
105
+ removeToolbar: function () {
106
+ L.Toolbar.prototype.removeToolbar.call(this);
107
+
108
+ this.options.featureGroup.off('layeradd layerremove', this._checkDisabled, this);
109
+ },
110
+
81
111
  disable: function () {
82
112
  if (!this.enabled()) { return; }
83
113
 
@@ -89,5 +119,45 @@ L.EditToolbar = L.Toolbar.extend({
89
119
  _save: function () {
90
120
  this._activeMode.handler.save();
91
121
  this._activeMode.handler.disable();
122
+ },
123
+
124
+ _checkDisabled: function () {
125
+ var featureGroup = this.options.featureGroup,
126
+ hasLayers = featureGroup.getLayers().length !== 0,
127
+ button;
128
+
129
+ if (this.options.edit) {
130
+ button = this._modes[L.EditToolbar.Edit.TYPE].button;
131
+
132
+ if (hasLayers) {
133
+ L.DomUtil.removeClass(button, 'leaflet-disabled');
134
+ } else {
135
+ L.DomUtil.addClass(button, 'leaflet-disabled');
136
+ }
137
+
138
+ button.setAttribute(
139
+ 'title',
140
+ hasLayers ?
141
+ L.drawLocal.edit.toolbar.buttons.edit
142
+ : L.drawLocal.edit.toolbar.buttons.editDisabled
143
+ );
144
+ }
145
+
146
+ if (this.options.remove) {
147
+ button = this._modes[L.EditToolbar.Delete.TYPE].button;
148
+
149
+ if (hasLayers) {
150
+ L.DomUtil.removeClass(button, 'leaflet-disabled');
151
+ } else {
152
+ L.DomUtil.addClass(button, 'leaflet-disabled');
153
+ }
154
+
155
+ button.setAttribute(
156
+ 'title',
157
+ hasLayers ?
158
+ L.drawLocal.edit.toolbar.buttons.remove
159
+ : L.drawLocal.edit.toolbar.buttons.removeDisabled
160
+ );
161
+ }
92
162
  }
93
- });
163
+ });
@@ -46,7 +46,7 @@ L.Edit.Poly = L.Handler.extend({
46
46
  this._markers = [];
47
47
 
48
48
  var latlngs = this._poly._latlngs,
49
- i, j, len, marker;
49
+ i, j, len, marker;
50
50
 
51
51
  // TODO refactor holes implementation in Polygon to support it here
52
52
 
@@ -124,10 +124,13 @@ L.Edit.Poly = L.Handler.extend({
124
124
  },
125
125
 
126
126
  _onMarkerClick: function (e) {
127
- // we want to remove the marker on click, but if latlng count < 3, polyline would be invalid
128
- if (this._poly._latlngs.length < 3) { return; }
127
+ var minPoints = L.Polygon && (this._poly instanceof L.Polygon) ? 4 : 3,
128
+ marker = e.target;
129
129
 
130
- var marker = e.target;
130
+ // If removing this point would create an invalid polyline/polygon don't remove
131
+ if (this._poly._latlngs.length < minPoints) {
132
+ return;
133
+ }
131
134
 
132
135
  // remove the marker
133
136
  this._removeMarker(marker);
@@ -231,10 +234,10 @@ L.Edit.Poly = L.Handler.extend({
231
234
 
232
235
  _getMiddleLatLng: function (marker1, marker2) {
233
236
  var map = this._poly._map,
234
- p1 = map.latLngToLayerPoint(marker1.getLatLng()),
235
- p2 = map.latLngToLayerPoint(marker2.getLatLng());
237
+ p1 = map.project(marker1.getLatLng()),
238
+ p2 = map.project(marker2.getLatLng());
236
239
 
237
- return map.layerPointToLatLng(p1._add(p2)._divideBy(2));
240
+ return map.unproject(p1._add(p2)._divideBy(2));
238
241
  }
239
242
  });
240
243
 
@@ -124,7 +124,6 @@ L.Edit.SimpleShape = L.Handler.extend({
124
124
  var marker = e.target;
125
125
  marker.setOpacity(1);
126
126
 
127
- this._shape.fire('edit');
128
127
  this._fireEdit();
129
128
  },
130
129
 
@@ -135,4 +134,4 @@ L.Edit.SimpleShape = L.Handler.extend({
135
134
  _resize: function () {
136
135
  // Children override
137
136
  }
138
- });
137
+ });
@@ -22,7 +22,9 @@ L.EditToolbar.Delete = L.Handler.extend({
22
22
  },
23
23
 
24
24
  enable: function () {
25
- if (this._enabled) { return; }
25
+ if (this._enabled || !this._hasAvailableLayers()) {
26
+ return;
27
+ }
26
28
 
27
29
  L.Handler.prototype.enable.call(this);
28
30
 
@@ -31,6 +33,7 @@ L.EditToolbar.Delete = L.Handler.extend({
31
33
  .on('layerremove', this._disableLayerDelete, this);
32
34
 
33
35
  this.fire('enabled', { handler: this.type});
36
+ this._map.fire('draw:editstart', { handler: this.type });
34
37
  },
35
38
 
36
39
  disable: function () {
@@ -43,15 +46,20 @@ L.EditToolbar.Delete = L.Handler.extend({
43
46
  .off('layerremove', this._disableLayerDelete, this);
44
47
 
45
48
  this.fire('disabled', { handler: this.type});
49
+ this._map.fire('draw:editstop', { handler: this.type });
46
50
  },
47
51
 
48
52
  addHooks: function () {
49
- if (this._map) {
53
+ var map = this._map;
54
+
55
+ if (map) {
56
+ map.getContainer().focus();
57
+
50
58
  this._deletableLayers.eachLayer(this._enableLayerDelete, this);
51
59
  this._deletedLayers = new L.layerGroup();
52
60
 
53
61
  this._tooltip = new L.Tooltip(this._map);
54
- this._tooltip.updateContent({ text: 'Click on a feature to remove.' });
62
+ this._tooltip.updateContent({ text: L.drawLocal.edit.handlers.remove.tooltip.text });
55
63
 
56
64
  this._map.on('mousemove', this._onMouseMove, this);
57
65
  }
@@ -105,5 +113,9 @@ L.EditToolbar.Delete = L.Handler.extend({
105
113
 
106
114
  _onMouseMove: function (e) {
107
115
  this._tooltip.updatePosition(e.latlng);
116
+ },
117
+
118
+ _hasAvailableLayers: function () {
119
+ return this._deletableLayers.getLayers().length !== 0;
108
120
  }
109
121
  });
@@ -5,28 +5,14 @@ L.EditToolbar.Edit = L.Handler.extend({
5
5
 
6
6
  includes: L.Mixin.Events,
7
7
 
8
- options: {
9
- selectedPathOptions: {
10
- color: '#fe57a1', /* Hot pink all the things! */
11
- opacity: 0.6,
12
- dashArray: '10, 10',
13
-
14
- fill: true,
15
- fillColor: '#fe57a1',
16
- fillOpacity: 0.1
17
- }
18
- },
19
-
20
8
  initialize: function (map, options) {
21
9
  L.Handler.prototype.initialize.call(this, map);
22
10
 
23
11
  // Set options to the default unless already set
24
- options.selectedPathOptions = options.selectedPathOptions || this.options.selectedPathOptions;
25
-
26
- L.Util.setOptions(this, options);
12
+ this._selectedPathOptions = options.selectedPathOptions;
27
13
 
28
14
  // Store the selectable layer group for ease of access
29
- this._featureGroup = this.options.featureGroup;
15
+ this._featureGroup = options.featureGroup;
30
16
 
31
17
  if (!(this._featureGroup instanceof L.FeatureGroup)) {
32
18
  throw new Error('options.featureGroup must be a L.FeatureGroup');
@@ -39,7 +25,9 @@ L.EditToolbar.Edit = L.Handler.extend({
39
25
  },
40
26
 
41
27
  enable: function () {
42
- if (this._enabled) { return; }
28
+ if (this._enabled || !this._hasAvailableLayers()) {
29
+ return;
30
+ }
43
31
 
44
32
  L.Handler.prototype.enable.call(this);
45
33
 
@@ -48,12 +36,14 @@ L.EditToolbar.Edit = L.Handler.extend({
48
36
  .on('layerremove', this._disableLayerEdit, this);
49
37
 
50
38
  this.fire('enabled', {handler: this.type});
39
+ this._map.fire('draw:editstart', { handler: this.type });
51
40
  },
52
41
 
53
42
  disable: function () {
54
43
  if (!this._enabled) { return; }
55
44
 
56
45
  this.fire('disabled', {handler: this.type});
46
+ this._map.fire('draw:editstop', { handler: this.type });
57
47
 
58
48
  this._featureGroup
59
49
  .off('layeradd', this._enableLayerEdit, this)
@@ -63,11 +53,18 @@ L.EditToolbar.Edit = L.Handler.extend({
63
53
  },
64
54
 
65
55
  addHooks: function () {
66
- if (this._map) {
56
+ var map = this._map;
57
+
58
+ if (map) {
59
+ map.getContainer().focus();
60
+
67
61
  this._featureGroup.eachLayer(this._enableLayerEdit, this);
68
62
 
69
63
  this._tooltip = new L.Tooltip(this._map);
70
- this._tooltip.updateContent({ text: 'Drag handles, or marker to edit feature.', subtext: 'Click cancel to undo changes.' });
64
+ this._tooltip.updateContent({
65
+ text: L.drawLocal.edit.handlers.edit.tooltip.text,
66
+ subtext: L.drawLocal.edit.handlers.edit.tooltip.subtext
67
+ });
71
68
 
72
69
  this._map.on('mousemove', this._onMouseMove, this);
73
70
  }
@@ -144,6 +141,9 @@ L.EditToolbar.Edit = L.Handler.extend({
144
141
  },
145
142
 
146
143
  _toggleMarkerHighlight: function (marker) {
144
+ if (!marker._icon) {
145
+ return;
146
+ }
147
147
  // This is quite naughty, but I don't see another way of doing it. (short of setting a new icon)
148
148
  var icon = marker._icon;
149
149
 
@@ -173,26 +173,38 @@ L.EditToolbar.Edit = L.Handler.extend({
173
173
 
174
174
  _enableLayerEdit: function (e) {
175
175
  var layer = e.layer || e.target || e,
176
- options = L.Util.extend({}, this.options.selectedPathOptions);
176
+ isMarker = layer instanceof L.Marker,
177
+ pathOptions;
178
+
179
+ // Don't do anything if this layer is a marker but doesn't have an icon. Markers
180
+ // should usually have icons. If using Leaflet.draw with Leafler.markercluster there
181
+ // is a chance that a marker doesn't.
182
+ if (isMarker && !layer._icon) {
183
+ return;
184
+ }
177
185
 
178
186
  // Back up this layer (if haven't before)
179
187
  this._backupLayer(layer);
180
188
 
181
189
  // Update layer style so appears editable
182
- if (layer instanceof L.Marker) {
183
- this._toggleMarkerHighlight(layer);
184
- } else {
185
- layer.options.previousOptions = layer.options;
190
+ if (this._selectedPathOptions) {
191
+ pathOptions = L.Util.extend({}, this._selectedPathOptions);
186
192
 
187
- // Make sure that Polylines are not filled
188
- if (!(layer instanceof L.Circle) && !(layer instanceof L.Polygon) && !(layer instanceof L.Rectangle)) {
189
- options.fill = false;
190
- }
193
+ if (isMarker) {
194
+ this._toggleMarkerHighlight(layer);
195
+ } else {
196
+ layer.options.previousOptions = layer.options;
197
+
198
+ // Make sure that Polylines are not filled
199
+ if (!(layer instanceof L.Circle) && !(layer instanceof L.Polygon) && !(layer instanceof L.Rectangle)) {
200
+ pathOptions.fill = false;
201
+ }
191
202
 
192
- layer.setStyle(options);
203
+ layer.setStyle(pathOptions);
204
+ }
193
205
  }
194
206
 
195
- if (layer instanceof L.Marker) {
207
+ if (isMarker) {
196
208
  layer.dragging.enable();
197
209
  layer.on('dragend', this._onMarkerDragEnd);
198
210
  } else {
@@ -205,13 +217,15 @@ L.EditToolbar.Edit = L.Handler.extend({
205
217
  layer.edited = false;
206
218
 
207
219
  // Reset layer styles to that of before select
208
- if (layer instanceof L.Marker) {
209
- this._toggleMarkerHighlight(layer);
210
- } else {
211
- // reset the layer style to what is was before being selected
212
- layer.setStyle(layer.options.previousOptions);
213
- // remove the cached options for the layer object
214
- delete layer.options.previousOptions;
220
+ if (this._selectedPathOptions) {
221
+ if (layer instanceof L.Marker) {
222
+ this._toggleMarkerHighlight(layer);
223
+ } else {
224
+ // reset the layer style to what is was before being selected
225
+ layer.setStyle(layer.options.previousOptions);
226
+ // remove the cached options for the layer object
227
+ delete layer.options.previousOptions;
228
+ }
215
229
  }
216
230
 
217
231
  if (layer instanceof L.Marker) {
@@ -229,5 +243,9 @@ L.EditToolbar.Edit = L.Handler.extend({
229
243
 
230
244
  _onMouseMove: function (e) {
231
245
  this._tooltip.updatePosition(e.latlng);
246
+ },
247
+
248
+ _hasAvailableLayers: function () {
249
+ return this._featureGroup.getLayers().length !== 0;
232
250
  }
233
- });
251
+ });