leaflet-js 0.6.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +15 -0
  2. data/CHANGELOG.rdoc +32 -0
  3. data/LICENSE +21 -0
  4. data/README.rdoc +54 -0
  5. data/Rakefile +15 -0
  6. data/leaflet-js.gemspec +28 -0
  7. data/lib/leaflet-js.rb +10 -0
  8. data/lib/leaflet.draw/BREAKINGCHANGES.md +54 -0
  9. data/lib/leaflet.draw/CHANGELOG.md +73 -0
  10. data/lib/leaflet.draw/Jakefile.js +26 -0
  11. data/lib/leaflet.draw/MIT-LICENCE.txt +20 -0
  12. data/lib/leaflet.draw/README.md +364 -0
  13. data/lib/leaflet.draw/TODO.md +62 -0
  14. data/lib/leaflet.draw/build/build.html +243 -0
  15. data/lib/leaflet.draw/build/build.js +189 -0
  16. data/lib/leaflet.draw/build/deps.js +75 -0
  17. data/lib/leaflet.draw/build/hintrc.js +47 -0
  18. data/lib/leaflet.draw/build/leaflet.draw-include.js +42 -0
  19. data/lib/leaflet.draw/dist/images/spritesheet.png +0 -0
  20. data/lib/leaflet.draw/dist/leaflet.draw-src.js +2429 -0
  21. data/lib/leaflet.draw/dist/leaflet.draw.css +212 -0
  22. data/lib/leaflet.draw/dist/leaflet.draw.ie.css +44 -0
  23. data/lib/leaflet.draw/dist/leaflet.draw.js +10 -0
  24. data/lib/leaflet.draw/examples/basic.html +106 -0
  25. data/lib/leaflet.draw/examples/edithandlers.html +67 -0
  26. data/lib/leaflet.draw/examples/libs/images/layers.png +0 -0
  27. data/lib/leaflet.draw/examples/libs/images/marker-icon.png +0 -0
  28. data/lib/leaflet.draw/examples/libs/images/marker-icon@2x.png +0 -0
  29. data/lib/leaflet.draw/examples/libs/images/marker-shadow.png +0 -0
  30. data/lib/leaflet.draw/examples/libs/leaflet-src.js +8587 -0
  31. data/lib/leaflet.draw/examples/libs/leaflet.css +459 -0
  32. data/lib/leaflet.draw/examples/libs/leaflet.ie.css +51 -0
  33. data/lib/leaflet.draw/package.json +37 -0
  34. data/lib/leaflet.draw/spec/after.js +2 -0
  35. data/lib/leaflet.draw/spec/before.js +3 -0
  36. data/lib/leaflet.draw/spec/expect.js +1253 -0
  37. data/lib/leaflet.draw/spec/happen.js +93 -0
  38. data/lib/leaflet.draw/spec/index.html +36 -0
  39. data/lib/leaflet.draw/spec/karma.conf.js +69 -0
  40. data/lib/leaflet.draw/spec/sinon.js +4223 -0
  41. data/lib/leaflet.draw/spec/suites/DrawControlSpec.js +15 -0
  42. data/lib/leaflet.draw/spec/suites/SpecHelper.js +26 -0
  43. data/lib/leaflet.draw/src/Control.Draw.js +101 -0
  44. data/lib/leaflet.draw/src/Leaflet.draw.js +5 -0
  45. data/lib/leaflet.draw/src/Toolbar.js +187 -0
  46. data/lib/leaflet.draw/src/Tooltip.js +52 -0
  47. data/lib/leaflet.draw/src/copyright.js +8 -0
  48. data/lib/leaflet.draw/src/draw/DrawToolbar.js +107 -0
  49. data/lib/leaflet.draw/src/draw/handler/Draw.Circle.js +59 -0
  50. data/lib/leaflet.draw/src/draw/handler/Draw.Feature.js +74 -0
  51. data/lib/leaflet.draw/src/draw/handler/Draw.Marker.js +97 -0
  52. data/lib/leaflet.draw/src/draw/handler/Draw.Polygon.js +79 -0
  53. data/lib/leaflet.draw/src/draw/handler/Draw.Polyline.js +360 -0
  54. data/lib/leaflet.draw/src/draw/handler/Draw.Rectangle.js +41 -0
  55. data/lib/leaflet.draw/src/draw/handler/Draw.SimpleShape.js +67 -0
  56. data/lib/leaflet.draw/src/edit/EditToolbar.js +93 -0
  57. data/lib/leaflet.draw/src/edit/handler/Edit.Circle.js +63 -0
  58. data/lib/leaflet.draw/src/edit/handler/Edit.Poly.js +267 -0
  59. data/lib/leaflet.draw/src/edit/handler/Edit.Rectangle.js +117 -0
  60. data/lib/leaflet.draw/src/edit/handler/Edit.SimpleShape.js +138 -0
  61. data/lib/leaflet.draw/src/edit/handler/EditToolbar.Delete.js +109 -0
  62. data/lib/leaflet.draw/src/edit/handler/EditToolbar.Edit.js +233 -0
  63. data/lib/leaflet.draw/src/ext/LatLngUtil.js +18 -0
  64. data/lib/leaflet.draw/src/ext/LineUtil.Intersect.js +15 -0
  65. data/lib/leaflet.draw/src/ext/Polygon.Intersect.js +27 -0
  66. data/lib/leaflet.draw/src/ext/Polyline.Intersect.js +85 -0
  67. data/lib/leaflet.label/CHANGELOG.md +35 -0
  68. data/lib/leaflet.label/Jakefile.js +21 -0
  69. data/lib/leaflet.label/MIT-LICENCE.txt +20 -0
  70. data/lib/leaflet.label/README.md +86 -0
  71. data/lib/leaflet.label/build/build.js +155 -0
  72. data/lib/leaflet.label/build/deps.js +24 -0
  73. data/lib/leaflet.label/build/hint.js +30 -0
  74. data/lib/leaflet.label/build/hintrc.js +47 -0
  75. data/lib/leaflet.label/dist/images/death.png +0 -0
  76. data/lib/leaflet.label/dist/leaflet.label-src.js +359 -0
  77. data/lib/leaflet.label/dist/leaflet.label.css +33 -0
  78. data/lib/leaflet.label/dist/leaflet.label.js +9 -0
  79. data/lib/leaflet.label/example/label.html +82 -0
  80. data/lib/leaflet.label/libs/leaflet/images/layers.png +0 -0
  81. data/lib/leaflet.label/libs/leaflet/images/marker-icon.png +0 -0
  82. data/lib/leaflet.label/libs/leaflet/images/marker-icon@2x.png +0 -0
  83. data/lib/leaflet.label/libs/leaflet/images/marker-shadow.png +0 -0
  84. data/lib/leaflet.label/libs/leaflet/leaflet-src.js +8587 -0
  85. data/lib/leaflet.label/libs/leaflet/leaflet.css +459 -0
  86. data/lib/leaflet.label/libs/leaflet/leaflet.ie.css +51 -0
  87. data/lib/leaflet.label/libs/leaflet/leaflet.js +8 -0
  88. data/lib/leaflet.label/src/FeatureGroup.Label.js +20 -0
  89. data/lib/leaflet.label/src/Label.js +123 -0
  90. data/lib/leaflet.label/src/Leaflet.label.js +5 -0
  91. data/lib/leaflet.label/src/Map.Label.js +7 -0
  92. data/lib/leaflet.label/src/Marker.Label.js +160 -0
  93. data/lib/leaflet.label/src/Path.Label.js +55 -0
  94. data/lib/leaflet.label/src/copyright.js +8 -0
  95. data/lib/leaflet/CHANGELOG.md +637 -0
  96. data/lib/leaflet/CONTRIBUTING.md +155 -0
  97. data/lib/leaflet/Jakefile.js +26 -0
  98. data/lib/leaflet/LICENSE +23 -0
  99. data/lib/leaflet/README.md +30 -0
  100. data/lib/leaflet/build/build.html +243 -0
  101. data/lib/leaflet/build/build.js +193 -0
  102. data/lib/leaflet/build/deps.js +256 -0
  103. data/lib/leaflet/build/hintrc.js +37 -0
  104. data/lib/leaflet/debug/css/mobile.css +6 -0
  105. data/lib/leaflet/debug/css/screen.css +5 -0
  106. data/lib/leaflet/debug/hacks/jitter.html +43 -0
  107. data/lib/leaflet/debug/leaflet-include.js +59 -0
  108. data/lib/leaflet/debug/map/canvas.html +47 -0
  109. data/lib/leaflet/debug/map/controls.html +50 -0
  110. data/lib/leaflet/debug/map/geolocation.html +35 -0
  111. data/lib/leaflet/debug/map/image-overlay.html +44 -0
  112. data/lib/leaflet/debug/map/map-mobile.html +35 -0
  113. data/lib/leaflet/debug/map/map.html +60 -0
  114. data/lib/leaflet/debug/map/max-bounds.html +37 -0
  115. data/lib/leaflet/debug/map/scroll.html +36 -0
  116. data/lib/leaflet/debug/map/simple-proj.html +45 -0
  117. data/lib/leaflet/debug/map/wms-marble.html +31 -0
  118. data/lib/leaflet/debug/map/wms.html +41 -0
  119. data/lib/leaflet/debug/map/zoomlevels.html +46 -0
  120. data/lib/leaflet/debug/tests/add_remove_layers.html +88 -0
  121. data/lib/leaflet/debug/tests/bringtoback.html +38 -0
  122. data/lib/leaflet/debug/tests/click_on_canvas.html +59 -0
  123. data/lib/leaflet/debug/tests/click_on_canvas_broken.html +49 -0
  124. data/lib/leaflet/debug/tests/opacity.html +57 -0
  125. data/lib/leaflet/debug/tests/remove_while_dragging.html +29 -0
  126. data/lib/leaflet/debug/tests/removetilewhilepan.html +42 -0
  127. data/lib/leaflet/debug/tests/reuse_popups.html +41 -0
  128. data/lib/leaflet/debug/tests/svg_clicks.html +55 -0
  129. data/lib/leaflet/debug/vector/bounds-extend.html +89 -0
  130. data/lib/leaflet/debug/vector/feature-group-bounds.html +91 -0
  131. data/lib/leaflet/debug/vector/geojson-sample.js +53 -0
  132. data/lib/leaflet/debug/vector/geojson.html +174 -0
  133. data/lib/leaflet/debug/vector/rectangle.html +54 -0
  134. data/lib/leaflet/debug/vector/route.js +1 -0
  135. data/lib/leaflet/debug/vector/touchzoomemu.html +195 -0
  136. data/lib/leaflet/debug/vector/us-states.js +54 -0
  137. data/lib/leaflet/debug/vector/vector-bounds.html +70 -0
  138. data/lib/leaflet/debug/vector/vector-canvas.html +93 -0
  139. data/lib/leaflet/debug/vector/vector-mobile.html +39 -0
  140. data/lib/leaflet/debug/vector/vector-simple.html +49 -0
  141. data/lib/leaflet/debug/vector/vector.html +38 -0
  142. data/lib/leaflet/dist/images/layers.png +0 -0
  143. data/lib/leaflet/dist/images/marker-icon-2x.png +0 -0
  144. data/lib/leaflet/dist/images/marker-icon.png +0 -0
  145. data/lib/leaflet/dist/images/marker-shadow.png +0 -0
  146. data/lib/leaflet/dist/leaflet-src.js +8579 -0
  147. data/lib/leaflet/dist/leaflet.css +459 -0
  148. data/lib/leaflet/dist/leaflet.ie.css +51 -0
  149. data/lib/leaflet/dist/leaflet.js +8 -0
  150. data/lib/leaflet/package.json +22 -0
  151. data/lib/leaflet/spec/after.js +2 -0
  152. data/lib/leaflet/spec/before.js +3 -0
  153. data/lib/leaflet/spec/expect.js +1253 -0
  154. data/lib/leaflet/spec/happen.js +93 -0
  155. data/lib/leaflet/spec/index.html +78 -0
  156. data/lib/leaflet/spec/karma.conf.js +64 -0
  157. data/lib/leaflet/spec/sinon.js +4223 -0
  158. data/lib/leaflet/spec/suites/LeafletSpec.js +13 -0
  159. data/lib/leaflet/spec/suites/SpecHelper.js +26 -0
  160. data/lib/leaflet/spec/suites/control/Control.AttributionSpec.js +68 -0
  161. data/lib/leaflet/spec/suites/control/Control.LayersSpec.js +67 -0
  162. data/lib/leaflet/spec/suites/control/Control.ScaleSpec.js +6 -0
  163. data/lib/leaflet/spec/suites/core/ClassSpec.js +156 -0
  164. data/lib/leaflet/spec/suites/core/EventsSpec.js +336 -0
  165. data/lib/leaflet/spec/suites/core/UtilSpec.js +212 -0
  166. data/lib/leaflet/spec/suites/dom/DomEventSpec.js +102 -0
  167. data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +89 -0
  168. data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +136 -0
  169. data/lib/leaflet/spec/suites/geo/LatLngSpec.js +118 -0
  170. data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +47 -0
  171. data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +87 -0
  172. data/lib/leaflet/spec/suites/geometry/LineUtilSpec.js +75 -0
  173. data/lib/leaflet/spec/suites/geometry/PointSpec.js +104 -0
  174. data/lib/leaflet/spec/suites/geometry/PolyUtilSpec.js +27 -0
  175. data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +31 -0
  176. data/lib/leaflet/spec/suites/layer/FeatureGroupSpec.js +36 -0
  177. data/lib/leaflet/spec/suites/layer/GeoJSONSpec.js +86 -0
  178. data/lib/leaflet/spec/suites/layer/LayerGroupSpec.js +58 -0
  179. data/lib/leaflet/spec/suites/layer/PopupSpec.js +59 -0
  180. data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +87 -0
  181. data/lib/leaflet/spec/suites/layer/vector/CircleMarkerSpec.js +53 -0
  182. data/lib/leaflet/spec/suites/layer/vector/CircleSpec.js +17 -0
  183. data/lib/leaflet/spec/suites/layer/vector/PolygonSpec.js +55 -0
  184. data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +35 -0
  185. data/lib/leaflet/spec/suites/layer/vector/PolylineSpec.js +55 -0
  186. data/lib/leaflet/spec/suites/map/MapSpec.js +244 -0
  187. data/lib/leaflet/src/Leaflet.js +23 -0
  188. data/lib/leaflet/src/control/Control.Attribution.js +115 -0
  189. data/lib/leaflet/src/control/Control.Layers.js +243 -0
  190. data/lib/leaflet/src/control/Control.Scale.js +112 -0
  191. data/lib/leaflet/src/control/Control.Zoom.js +86 -0
  192. data/lib/leaflet/src/control/Control.js +107 -0
  193. data/lib/leaflet/src/copyright.js +4 -0
  194. data/lib/leaflet/src/core/Browser.js +96 -0
  195. data/lib/leaflet/src/core/Class.js +106 -0
  196. data/lib/leaflet/src/core/Events.js +174 -0
  197. data/lib/leaflet/src/core/Handler.js +28 -0
  198. data/lib/leaflet/src/core/Util.js +182 -0
  199. data/lib/leaflet/src/dom/DomEvent.DoubleTap.js +103 -0
  200. data/lib/leaflet/src/dom/DomEvent.MsTouch.js +146 -0
  201. data/lib/leaflet/src/dom/DomEvent.js +211 -0
  202. data/lib/leaflet/src/dom/DomUtil.js +239 -0
  203. data/lib/leaflet/src/dom/Draggable.js +198 -0
  204. data/lib/leaflet/src/dom/PosAnimation.Timer.js +67 -0
  205. data/lib/leaflet/src/dom/PosAnimation.js +83 -0
  206. data/lib/leaflet/src/geo/LatLng.js +88 -0
  207. data/lib/leaflet/src/geo/LatLngBounds.js +153 -0
  208. data/lib/leaflet/src/geo/crs/CRS.EPSG3395.js +14 -0
  209. data/lib/leaflet/src/geo/crs/CRS.EPSG3857.js +21 -0
  210. data/lib/leaflet/src/geo/crs/CRS.EPSG4326.js +10 -0
  211. data/lib/leaflet/src/geo/crs/CRS.Simple.js +12 -0
  212. data/lib/leaflet/src/geo/crs/CRS.js +27 -0
  213. data/lib/leaflet/src/geo/projection/Projection.LonLat.js +13 -0
  214. data/lib/leaflet/src/geo/projection/Projection.Mercator.js +56 -0
  215. data/lib/leaflet/src/geo/projection/Projection.SphericalMercator.js +27 -0
  216. data/lib/leaflet/src/geo/projection/Projection.js +5 -0
  217. data/lib/leaflet/src/geometry/Bounds.js +95 -0
  218. data/lib/leaflet/src/geometry/LineUtil.js +202 -0
  219. data/lib/leaflet/src/geometry/Point.js +119 -0
  220. data/lib/leaflet/src/geometry/PolyUtil.js +55 -0
  221. data/lib/leaflet/src/geometry/Transformation.js +31 -0
  222. data/lib/leaflet/src/images/marker.svg +1 -0
  223. data/lib/leaflet/src/layer/FeatureGroup.js +81 -0
  224. data/lib/leaflet/src/layer/GeoJSON.js +245 -0
  225. data/lib/leaflet/src/layer/ImageOverlay.js +132 -0
  226. data/lib/leaflet/src/layer/LayerGroup.js +110 -0
  227. data/lib/leaflet/src/layer/Popup.js +316 -0
  228. data/lib/leaflet/src/layer/marker/DivIcon.js +43 -0
  229. data/lib/leaflet/src/layer/marker/Icon.Default.js +51 -0
  230. data/lib/leaflet/src/layer/marker/Icon.js +101 -0
  231. data/lib/leaflet/src/layer/marker/Marker.Drag.js +66 -0
  232. data/lib/leaflet/src/layer/marker/Marker.Popup.js +72 -0
  233. data/lib/leaflet/src/layer/marker/Marker.js +275 -0
  234. data/lib/leaflet/src/layer/tile/TileLayer.Anim.js +117 -0
  235. data/lib/leaflet/src/layer/tile/TileLayer.Canvas.js +60 -0
  236. data/lib/leaflet/src/layer/tile/TileLayer.WMS.js +83 -0
  237. data/lib/leaflet/src/layer/tile/TileLayer.js +578 -0
  238. data/lib/leaflet/src/layer/vector/Circle.js +98 -0
  239. data/lib/leaflet/src/layer/vector/CircleMarker.js +33 -0
  240. data/lib/leaflet/src/layer/vector/MultiPoly.js +47 -0
  241. data/lib/leaflet/src/layer/vector/Path.Popup.js +65 -0
  242. data/lib/leaflet/src/layer/vector/Path.SVG.js +219 -0
  243. data/lib/leaflet/src/layer/vector/Path.VML.js +125 -0
  244. data/lib/leaflet/src/layer/vector/Path.js +115 -0
  245. data/lib/leaflet/src/layer/vector/Polygon.js +81 -0
  246. data/lib/leaflet/src/layer/vector/Polyline.js +164 -0
  247. data/lib/leaflet/src/layer/vector/Rectangle.js +27 -0
  248. data/lib/leaflet/src/layer/vector/canvas/Circle.Canvas.js +18 -0
  249. data/lib/leaflet/src/layer/vector/canvas/Path.Canvas.js +196 -0
  250. data/lib/leaflet/src/layer/vector/canvas/Polygon.Canvas.js +37 -0
  251. data/lib/leaflet/src/layer/vector/canvas/Polyline.Canvas.js +30 -0
  252. data/lib/leaflet/src/map/Map.js +743 -0
  253. data/lib/leaflet/src/map/anim/Map.PanAnimation.js +88 -0
  254. data/lib/leaflet/src/map/anim/Map.ZoomAnimation.js +90 -0
  255. data/lib/leaflet/src/map/ext/Map.Geolocation.js +91 -0
  256. data/lib/leaflet/src/map/handler/Map.BoxZoom.js +104 -0
  257. data/lib/leaflet/src/map/handler/Map.DoubleClickZoom.js +23 -0
  258. data/lib/leaflet/src/map/handler/Map.Drag.js +146 -0
  259. data/lib/leaflet/src/map/handler/Map.Keyboard.js +147 -0
  260. data/lib/leaflet/src/map/handler/Map.ScrollWheelZoom.js +56 -0
  261. data/lib/leaflet/src/map/handler/Map.TouchZoom.js +121 -0
  262. data/vendor/assets/images/layers.png +0 -0
  263. data/vendor/assets/images/marker-icon-2x.png +0 -0
  264. data/vendor/assets/images/marker-icon.png +0 -0
  265. data/vendor/assets/images/marker-shadow.png +0 -0
  266. data/vendor/assets/images/spritesheet.png +0 -0
  267. data/vendor/assets/javascripts/leaflet.draw.js +39 -0
  268. data/vendor/assets/javascripts/leaflet.js +145 -0
  269. data/vendor/assets/javascripts/leaflet.label.js +9 -0
  270. data/vendor/assets/stylesheets/leaflet.css.erb +459 -0
  271. data/vendor/assets/stylesheets/leaflet.draw.css.erb +212 -0
  272. data/vendor/assets/stylesheets/leaflet.draw.ie.css +44 -0
  273. data/vendor/assets/stylesheets/leaflet.ie.css +51 -0
  274. data/vendor/assets/stylesheets/leaflet.label.css +33 -0
  275. metadata +317 -0
@@ -0,0 +1,117 @@
1
+ L.Edit = L.Edit || {};
2
+
3
+ L.Edit.Rectangle = L.Edit.SimpleShape.extend({
4
+ _createMoveMarker: function () {
5
+ var bounds = this._shape.getBounds(),
6
+ center = bounds.getCenter();
7
+
8
+ this._moveMarker = this._createMarker(center, this.options.moveIcon);
9
+ },
10
+
11
+ _createResizeMarker: function () {
12
+ var corners = this._getCorners();
13
+
14
+ this._resizeMarkers = [];
15
+
16
+ for (var i = 0, l = corners.length; i < l; i++) {
17
+ this._resizeMarkers.push(this._createMarker(corners[i], this.options.resizeIcon));
18
+ // Monkey in the corner index as we will need to know this for dragging
19
+ this._resizeMarkers[i]._cornerIndex = i;
20
+ }
21
+ },
22
+
23
+ _onMarkerDragStart: function (e) {
24
+ L.Edit.SimpleShape.prototype._onMarkerDragStart.call(this, e);
25
+
26
+ // Save a reference to the opposite point
27
+ var corners = this._getCorners(),
28
+ marker = e.target,
29
+ currentCornerIndex = marker._cornerIndex;
30
+
31
+ this._oppositeCorner = corners[(currentCornerIndex + 2) % 4];
32
+
33
+ this._toggleCornerMarkers(0, currentCornerIndex);
34
+ },
35
+
36
+ _onMarkerDragEnd: function (e) {
37
+ var marker = e.target,
38
+ bounds, center;
39
+
40
+ // Reset move marker position to the center
41
+ if (marker === this._moveMarker) {
42
+ bounds = this._shape.getBounds();
43
+ center = bounds.getCenter();
44
+
45
+ marker.setLatLng(center);
46
+ }
47
+
48
+ this._toggleCornerMarkers(1);
49
+
50
+ this._repositionCornerMarkers();
51
+
52
+ L.Edit.SimpleShape.prototype._onMarkerDragEnd.call(this, e);
53
+ },
54
+
55
+ _move: function (newCenter) {
56
+ var latlngs = this._shape.getLatLngs(),
57
+ bounds = this._shape.getBounds(),
58
+ center = bounds.getCenter(),
59
+ offset, newLatLngs = [];
60
+
61
+ // Offset the latlngs to the new center
62
+ for (var i = 0, l = latlngs.length; i < l; i++) {
63
+ offset = [latlngs[i].lat - center.lat, latlngs[i].lng - center.lng];
64
+ newLatLngs.push([newCenter.lat + offset[0], newCenter.lng + offset[1]]);
65
+ }
66
+
67
+ this._shape.setLatLngs(newLatLngs);
68
+
69
+ // Respoition the resize markers
70
+ this._repositionCornerMarkers();
71
+ },
72
+
73
+ _resize: function (latlng) {
74
+ var bounds;
75
+
76
+ // Update the shape based on the current position of this corner and the opposite point
77
+ this._shape.setBounds(L.latLngBounds(latlng, this._oppositeCorner));
78
+
79
+ // Respoition the move marker
80
+ bounds = this._shape.getBounds();
81
+ this._moveMarker.setLatLng(bounds.getCenter());
82
+ },
83
+
84
+ _getCorners: function () {
85
+ var bounds = this._shape.getBounds(),
86
+ nw = bounds.getNorthWest(),
87
+ ne = bounds.getNorthEast(),
88
+ se = bounds.getSouthEast(),
89
+ sw = bounds.getSouthWest();
90
+
91
+ return [nw, ne, se, sw];
92
+ },
93
+
94
+ _toggleCornerMarkers: function (opacity) {
95
+ for (var i = 0, l = this._resizeMarkers.length; i < l; i++) {
96
+ this._resizeMarkers[i].setOpacity(opacity);
97
+ }
98
+ },
99
+
100
+ _repositionCornerMarkers: function () {
101
+ var corners = this._getCorners();
102
+
103
+ for (var i = 0, l = this._resizeMarkers.length; i < l; i++) {
104
+ this._resizeMarkers[i].setLatLng(corners[i]);
105
+ }
106
+ }
107
+ });
108
+
109
+ L.Rectangle.addInitHook(function () {
110
+ if (L.Edit.Rectangle) {
111
+ this.editing = new L.Edit.Rectangle(this);
112
+
113
+ if (this.options.editable) {
114
+ this.editing.enable();
115
+ }
116
+ }
117
+ });
@@ -0,0 +1,138 @@
1
+ L.Edit = L.Edit || {};
2
+
3
+ L.Edit.SimpleShape = L.Handler.extend({
4
+ options: {
5
+ moveIcon: new L.DivIcon({
6
+ iconSize: new L.Point(8, 8),
7
+ className: 'leaflet-div-icon leaflet-editing-icon leaflet-edit-move'
8
+ }),
9
+ resizeIcon: new L.DivIcon({
10
+ iconSize: new L.Point(8, 8),
11
+ className: 'leaflet-div-icon leaflet-editing-icon leaflet-edit-resize'
12
+ })
13
+ },
14
+
15
+ initialize: function (shape, options) {
16
+ this._shape = shape;
17
+ L.Util.setOptions(this, options);
18
+ },
19
+
20
+ addHooks: function () {
21
+ if (this._shape._map) {
22
+ this._map = this._shape._map;
23
+
24
+ if (!this._markerGroup) {
25
+ this._initMarkers();
26
+ }
27
+ this._map.addLayer(this._markerGroup);
28
+ }
29
+ },
30
+
31
+ removeHooks: function () {
32
+ if (this._shape._map) {
33
+ this._unbindMarker(this._moveMarker);
34
+
35
+ for (var i = 0, l = this._resizeMarkers.length; i < l; i++) {
36
+ this._unbindMarker(this._resizeMarkers[i]);
37
+ }
38
+ this._resizeMarkers = null;
39
+
40
+ this._map.removeLayer(this._markerGroup);
41
+ delete this._markerGroup;
42
+ }
43
+
44
+ this._map = null;
45
+ },
46
+
47
+ updateMarkers: function () {
48
+ this._markerGroup.clearLayers();
49
+ this._initMarkers();
50
+ },
51
+
52
+ _initMarkers: function () {
53
+ if (!this._markerGroup) {
54
+ this._markerGroup = new L.LayerGroup();
55
+ }
56
+
57
+ // Create center marker
58
+ this._createMoveMarker();
59
+
60
+ // Create edge marker
61
+ this._createResizeMarker();
62
+ },
63
+
64
+ _createMoveMarker: function () {
65
+ // Children override
66
+ },
67
+
68
+ _createResizeMarker: function () {
69
+ // Children override
70
+ },
71
+
72
+ _createMarker: function (latlng, icon) {
73
+ var marker = new L.Marker(latlng, {
74
+ draggable: true,
75
+ icon: icon,
76
+ zIndexOffset: 10
77
+ });
78
+
79
+ this._bindMarker(marker);
80
+
81
+ this._markerGroup.addLayer(marker);
82
+
83
+ return marker;
84
+ },
85
+
86
+ _bindMarker: function (marker) {
87
+ marker
88
+ .on('dragstart', this._onMarkerDragStart, this)
89
+ .on('drag', this._onMarkerDrag, this)
90
+ .on('dragend', this._onMarkerDragEnd, this);
91
+ },
92
+
93
+ _unbindMarker: function (marker) {
94
+ marker
95
+ .off('dragstart', this._onMarkerDragStart, this)
96
+ .off('drag', this._onMarkerDrag, this)
97
+ .off('dragend', this._onMarkerDragEnd, this);
98
+ },
99
+
100
+ _onMarkerDragStart: function (e) {
101
+ var marker = e.target;
102
+ marker.setOpacity(0);
103
+ },
104
+
105
+ _fireEdit: function () {
106
+ this._shape.edited = true;
107
+ this._shape.fire('edit');
108
+ },
109
+
110
+ _onMarkerDrag: function (e) {
111
+ var marker = e.target,
112
+ latlng = marker.getLatLng();
113
+
114
+ if (marker === this._moveMarker) {
115
+ this._move(latlng);
116
+ } else {
117
+ this._resize(latlng);
118
+ }
119
+
120
+ this._shape.redraw();
121
+ },
122
+
123
+ _onMarkerDragEnd: function (e) {
124
+ var marker = e.target;
125
+ marker.setOpacity(1);
126
+
127
+ this._shape.fire('edit');
128
+ this._fireEdit();
129
+ },
130
+
131
+ _move: function () {
132
+ // Children override
133
+ },
134
+
135
+ _resize: function () {
136
+ // Children override
137
+ }
138
+ });
@@ -0,0 +1,109 @@
1
+ L.EditToolbar.Delete = L.Handler.extend({
2
+ statics: {
3
+ TYPE: 'remove' // not delete as delete is reserved in js
4
+ },
5
+
6
+ includes: L.Mixin.Events,
7
+
8
+ initialize: function (map, options) {
9
+ L.Handler.prototype.initialize.call(this, map);
10
+
11
+ L.Util.setOptions(this, options);
12
+
13
+ // Store the selectable layer group for ease of access
14
+ this._deletableLayers = this.options.featureGroup;
15
+
16
+ if (!(this._deletableLayers instanceof L.FeatureGroup)) {
17
+ throw new Error('options.featureGroup must be a L.FeatureGroup');
18
+ }
19
+
20
+ // Save the type so super can fire, need to do this as cannot do this.TYPE :(
21
+ this.type = L.EditToolbar.Delete.TYPE;
22
+ },
23
+
24
+ enable: function () {
25
+ if (this._enabled) { return; }
26
+
27
+ L.Handler.prototype.enable.call(this);
28
+
29
+ this._deletableLayers
30
+ .on('layeradd', this._enableLayerDelete, this)
31
+ .on('layerremove', this._disableLayerDelete, this);
32
+
33
+ this.fire('enabled', { handler: this.type});
34
+ },
35
+
36
+ disable: function () {
37
+ if (!this._enabled) { return; }
38
+
39
+ L.Handler.prototype.disable.call(this);
40
+
41
+ this._deletableLayers
42
+ .off('layeradd', this._enableLayerDelete, this)
43
+ .off('layerremove', this._disableLayerDelete, this);
44
+
45
+ this.fire('disabled', { handler: this.type});
46
+ },
47
+
48
+ addHooks: function () {
49
+ if (this._map) {
50
+ this._deletableLayers.eachLayer(this._enableLayerDelete, this);
51
+ this._deletedLayers = new L.layerGroup();
52
+
53
+ this._tooltip = new L.Tooltip(this._map);
54
+ this._tooltip.updateContent({ text: 'Click on a feature to remove.' });
55
+
56
+ this._map.on('mousemove', this._onMouseMove, this);
57
+ }
58
+ },
59
+
60
+ removeHooks: function () {
61
+ if (this._map) {
62
+ this._deletableLayers.eachLayer(this._disableLayerDelete, this);
63
+ this._deletedLayers = null;
64
+
65
+ this._tooltip.dispose();
66
+ this._tooltip = null;
67
+
68
+ this._map.off('mousemove', this._onMouseMove, this);
69
+ }
70
+ },
71
+
72
+ revertLayers: function () {
73
+ // Iterate of the deleted layers and add them back into the featureGroup
74
+ this._deletedLayers.eachLayer(function (layer) {
75
+ this._deletableLayers.addLayer(layer);
76
+ }, this);
77
+ },
78
+
79
+ save: function () {
80
+ this._map.fire('draw:deleted', { layers: this._deletedLayers });
81
+ },
82
+
83
+ _enableLayerDelete: function (e) {
84
+ var layer = e.layer || e.target || e;
85
+
86
+ layer.on('click', this._removeLayer, this);
87
+ },
88
+
89
+ _disableLayerDelete: function (e) {
90
+ var layer = e.layer || e.target || e;
91
+
92
+ layer.off('click', this._removeLayer, this);
93
+
94
+ // Remove from the deleted layers so we can't accidently revert if the user presses cancel
95
+ this._deletedLayers.removeLayer(layer);
96
+ },
97
+
98
+ _removeLayer: function (e) {
99
+ var layer = e.layer || e.target || e;
100
+
101
+ this._deletableLayers.removeLayer(layer);
102
+
103
+ this._deletedLayers.addLayer(layer);
104
+ },
105
+
106
+ _onMouseMove: function (e) {
107
+ this._tooltip.updatePosition(e.latlng);
108
+ }
109
+ });
@@ -0,0 +1,233 @@
1
+ L.EditToolbar.Edit = L.Handler.extend({
2
+ statics: {
3
+ TYPE: 'edit'
4
+ },
5
+
6
+ includes: L.Mixin.Events,
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
+ initialize: function (map, options) {
21
+ L.Handler.prototype.initialize.call(this, map);
22
+
23
+ // Set options to the default unless already set
24
+ options.selectedPathOptions = options.selectedPathOptions || this.options.selectedPathOptions;
25
+
26
+ L.Util.setOptions(this, options);
27
+
28
+ // Store the selectable layer group for ease of access
29
+ this._featureGroup = this.options.featureGroup;
30
+
31
+ if (!(this._featureGroup instanceof L.FeatureGroup)) {
32
+ throw new Error('options.featureGroup must be a L.FeatureGroup');
33
+ }
34
+
35
+ this._uneditedLayerProps = {};
36
+
37
+ // Save the type so super can fire, need to do this as cannot do this.TYPE :(
38
+ this.type = L.EditToolbar.Edit.TYPE;
39
+ },
40
+
41
+ enable: function () {
42
+ if (this._enabled) { return; }
43
+
44
+ L.Handler.prototype.enable.call(this);
45
+
46
+ this._featureGroup
47
+ .on('layeradd', this._enableLayerEdit, this)
48
+ .on('layerremove', this._disableLayerEdit, this);
49
+
50
+ this.fire('enabled', {handler: this.type});
51
+ },
52
+
53
+ disable: function () {
54
+ if (!this._enabled) { return; }
55
+
56
+ this.fire('disabled', {handler: this.type});
57
+
58
+ this._featureGroup
59
+ .off('layeradd', this._enableLayerEdit, this)
60
+ .off('layerremove', this._disableLayerEdit, this);
61
+
62
+ L.Handler.prototype.disable.call(this);
63
+ },
64
+
65
+ addHooks: function () {
66
+ if (this._map) {
67
+ this._featureGroup.eachLayer(this._enableLayerEdit, this);
68
+
69
+ 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.' });
71
+
72
+ this._map.on('mousemove', this._onMouseMove, this);
73
+ }
74
+ },
75
+
76
+ removeHooks: function () {
77
+ if (this._map) {
78
+ // Clean up selected layers.
79
+ this._featureGroup.eachLayer(this._disableLayerEdit, this);
80
+
81
+ // Clear the backups of the original layers
82
+ this._uneditedLayerProps = {};
83
+
84
+ this._tooltip.dispose();
85
+ this._tooltip = null;
86
+
87
+ this._map.off('mousemove', this._onMouseMove, this);
88
+ }
89
+ },
90
+
91
+ revertLayers: function () {
92
+ this._featureGroup.eachLayer(function (layer) {
93
+ this._revertLayer(layer);
94
+ }, this);
95
+ },
96
+
97
+ save: function () {
98
+ var editedLayers = new L.LayerGroup();
99
+ this._featureGroup.eachLayer(function (layer) {
100
+ if (layer.edited) {
101
+ editedLayers.addLayer(layer);
102
+ layer.edited = false;
103
+ }
104
+ });
105
+ this._map.fire('draw:edited', {layers: editedLayers});
106
+ },
107
+
108
+ _backupLayer: function (layer) {
109
+ var id = L.Util.stamp(layer);
110
+
111
+ if (!this._uneditedLayerProps[id]) {
112
+ // Polyline, Polygon or Rectangle
113
+ if (layer instanceof L.Polyline || layer instanceof L.Polygon || layer instanceof L.Rectangle) {
114
+ this._uneditedLayerProps[id] = {
115
+ latlngs: L.LatLngUtil.cloneLatLngs(layer.getLatLngs())
116
+ };
117
+ } else if (layer instanceof L.Circle) {
118
+ this._uneditedLayerProps[id] = {
119
+ latlng: L.LatLngUtil.cloneLatLng(layer.getLatLng()),
120
+ radius: layer.getRadius()
121
+ };
122
+ } else { // Marker
123
+ this._uneditedLayerProps[id] = {
124
+ latlng: L.LatLngUtil.cloneLatLng(layer.getLatLng())
125
+ };
126
+ }
127
+ }
128
+ },
129
+
130
+ _revertLayer: function (layer) {
131
+ var id = L.Util.stamp(layer);
132
+ layer.edited = false;
133
+ if (this._uneditedLayerProps.hasOwnProperty(id)) {
134
+ // Polyline, Polygon or Rectangle
135
+ if (layer instanceof L.Polyline || layer instanceof L.Polygon || layer instanceof L.Rectangle) {
136
+ layer.setLatLngs(this._uneditedLayerProps[id].latlngs);
137
+ } else if (layer instanceof L.Circle) {
138
+ layer.setLatLng(this._uneditedLayerProps[id].latlng);
139
+ layer.setRadius(this._uneditedLayerProps[id].radius);
140
+ } else { // Marker
141
+ layer.setLatLng(this._uneditedLayerProps[id].latlng);
142
+ }
143
+ }
144
+ },
145
+
146
+ _toggleMarkerHighlight: function (marker) {
147
+ // This is quite naughty, but I don't see another way of doing it. (short of setting a new icon)
148
+ var icon = marker._icon;
149
+
150
+ icon.style.display = 'none';
151
+
152
+ if (L.DomUtil.hasClass(icon, 'leaflet-edit-marker-selected')) {
153
+ L.DomUtil.removeClass(icon, 'leaflet-edit-marker-selected');
154
+ // Offset as the border will make the icon move.
155
+ this._offsetMarker(icon, -4);
156
+
157
+ } else {
158
+ L.DomUtil.addClass(icon, 'leaflet-edit-marker-selected');
159
+ // Offset as the border will make the icon move.
160
+ this._offsetMarker(icon, 4);
161
+ }
162
+
163
+ icon.style.display = '';
164
+ },
165
+
166
+ _offsetMarker: function (icon, offset) {
167
+ var iconMarginTop = parseInt(icon.style.marginTop, 10) - offset,
168
+ iconMarginLeft = parseInt(icon.style.marginLeft, 10) - offset;
169
+
170
+ icon.style.marginTop = iconMarginTop + 'px';
171
+ icon.style.marginLeft = iconMarginLeft + 'px';
172
+ },
173
+
174
+ _enableLayerEdit: function (e) {
175
+ var layer = e.layer || e.target || e,
176
+ options = L.Util.extend({}, this.options.selectedPathOptions);
177
+
178
+ // Back up this layer (if haven't before)
179
+ this._backupLayer(layer);
180
+
181
+ // Update layer style so appears editable
182
+ if (layer instanceof L.Marker) {
183
+ this._toggleMarkerHighlight(layer);
184
+ } else {
185
+ layer.options.previousOptions = layer.options;
186
+
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
+ }
191
+
192
+ layer.setStyle(options);
193
+ }
194
+
195
+ if (layer instanceof L.Marker) {
196
+ layer.dragging.enable();
197
+ layer.on('dragend', this._onMarkerDragEnd);
198
+ } else {
199
+ layer.editing.enable();
200
+ }
201
+ },
202
+
203
+ _disableLayerEdit: function (e) {
204
+ var layer = e.layer || e.target || e;
205
+ layer.edited = false;
206
+
207
+ // 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;
215
+ }
216
+
217
+ if (layer instanceof L.Marker) {
218
+ layer.dragging.disable();
219
+ layer.off('dragend', this._onMarkerDragEnd, this);
220
+ } else {
221
+ layer.editing.disable();
222
+ }
223
+ },
224
+
225
+ _onMarkerDragEnd: function (e) {
226
+ var layer = e.target;
227
+ layer.edited = true;
228
+ },
229
+
230
+ _onMouseMove: function (e) {
231
+ this._tooltip.updatePosition(e.latlng);
232
+ }
233
+ });