leaflet-js 0.7.0.4 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (308) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +10 -3
  3. data/Rakefile +3 -3
  4. data/leaflet-js.gemspec +13 -7
  5. data/lib/leaflet-js.rb +2 -10
  6. data/lib/leaflet-js/engine.rb +7 -0
  7. data/lib/leaflet-js/version.rb +3 -0
  8. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/dist/images/spritesheet-2x.png +0 -0
  9. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/dist/images/spritesheet.png +0 -0
  10. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/Control.Draw.js +21 -19
  11. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/Leaflet.draw.js +8 -3
  12. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/Toolbar.js +75 -14
  13. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/Tooltip.js +0 -0
  14. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/copyright.js +0 -0
  15. data/vendor/assets/Leaflet.draw/src/draw/DrawToolbar.js +87 -0
  16. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/draw/handler/Draw.Circle.js +2 -3
  17. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/draw/handler/Draw.Feature.js +4 -4
  18. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/draw/handler/Draw.Marker.js +0 -0
  19. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/draw/handler/Draw.Polygon.js +9 -7
  20. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/draw/handler/Draw.Polyline.js +86 -36
  21. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/draw/handler/Draw.Rectangle.js +19 -1
  22. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/draw/handler/Draw.SimpleShape.js +18 -4
  23. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/edit/EditToolbar.js +34 -43
  24. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/edit/handler/Edit.Circle.js +0 -0
  25. data/vendor/assets/Leaflet.draw/src/edit/handler/Edit.Marker.js +75 -0
  26. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/edit/handler/Edit.Poly.js +16 -2
  27. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/edit/handler/Edit.Rectangle.js +3 -3
  28. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/edit/handler/Edit.SimpleShape.js +13 -3
  29. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/edit/handler/EditToolbar.Delete.js +11 -7
  30. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/edit/handler/EditToolbar.Edit.js +26 -94
  31. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/ext/GeometryUtil.js +3 -3
  32. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/ext/LatLngUtil.js +0 -0
  33. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/ext/LineUtil.Intersect.js +0 -0
  34. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/ext/Polygon.Intersect.js +0 -0
  35. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/ext/Polyline.Intersect.js +3 -3
  36. data/{lib/leaflet.draw → vendor/assets/Leaflet.draw}/src/images/spritesheet.svg +0 -0
  37. data/{lib/leaflet.label → vendor/assets/Leaflet.label}/src/BaseMarkerMethods.js +0 -0
  38. data/{lib/leaflet.label → vendor/assets/Leaflet.label}/src/CircleMarker.Label.js +0 -0
  39. data/{lib/leaflet.label → vendor/assets/Leaflet.label}/src/FeatureGroup.Label.js +0 -0
  40. data/{lib/leaflet.label → vendor/assets/Leaflet.label}/src/Label.js +5 -2
  41. data/{lib/leaflet.label → vendor/assets/Leaflet.label}/src/Leaflet.label.js +1 -1
  42. data/{lib/leaflet.label → vendor/assets/Leaflet.label}/src/Map.Label.js +0 -0
  43. data/{lib/leaflet.label → vendor/assets/Leaflet.label}/src/Marker.Label.js +0 -0
  44. data/{lib/leaflet.label → vendor/assets/Leaflet.label}/src/Path.Label.js +0 -0
  45. data/{lib/leaflet.label → vendor/assets/Leaflet.label}/src/copyright.js +0 -0
  46. data/{lib/leaflet.draw/examples/libs → vendor/assets/Leaflet/dist}/images/layers-2x.png +0 -0
  47. data/{lib/leaflet.draw/examples/libs → vendor/assets/Leaflet/dist}/images/layers.png +0 -0
  48. data/{lib/leaflet.draw/examples/libs → vendor/assets/Leaflet/dist}/images/marker-icon-2x.png +0 -0
  49. data/{lib/leaflet.draw/examples/libs → vendor/assets/Leaflet/dist}/images/marker-icon.png +0 -0
  50. data/{lib/leaflet.draw/examples/libs → vendor/assets/Leaflet/dist}/images/marker-shadow.png +0 -0
  51. data/{lib/leaflet → vendor/assets/Leaflet}/src/Leaflet.js +1 -1
  52. data/{lib/leaflet → vendor/assets/Leaflet}/src/control/Control.Attribution.js +0 -0
  53. data/{lib/leaflet → vendor/assets/Leaflet}/src/control/Control.Layers.js +2 -2
  54. data/{lib/leaflet → vendor/assets/Leaflet}/src/control/Control.Scale.js +0 -0
  55. data/{lib/leaflet → vendor/assets/Leaflet}/src/control/Control.Zoom.js +0 -0
  56. data/{lib/leaflet → vendor/assets/Leaflet}/src/control/Control.js +0 -0
  57. data/{lib/leaflet → vendor/assets/Leaflet}/src/copyright.js +0 -0
  58. data/{lib/leaflet → vendor/assets/Leaflet}/src/core/Browser.js +5 -36
  59. data/{lib/leaflet → vendor/assets/Leaflet}/src/core/Class.js +0 -0
  60. data/{lib/leaflet → vendor/assets/Leaflet}/src/core/Events.js +0 -0
  61. data/{lib/leaflet → vendor/assets/Leaflet}/src/core/Handler.js +0 -0
  62. data/{lib/leaflet → vendor/assets/Leaflet}/src/core/Util.js +9 -14
  63. data/{lib/leaflet → vendor/assets/Leaflet}/src/dom/DomEvent.DoubleTap.js +0 -0
  64. data/{lib/leaflet → vendor/assets/Leaflet}/src/dom/DomEvent.Pointer.js +3 -2
  65. data/{lib/leaflet → vendor/assets/Leaflet}/src/dom/DomEvent.js +7 -18
  66. data/{lib/leaflet → vendor/assets/Leaflet}/src/dom/DomUtil.js +0 -5
  67. data/{lib/leaflet → vendor/assets/Leaflet}/src/dom/Draggable.js +10 -4
  68. data/{lib/leaflet → vendor/assets/Leaflet}/src/dom/PosAnimation.Timer.js +0 -0
  69. data/{lib/leaflet → vendor/assets/Leaflet}/src/dom/PosAnimation.js +0 -0
  70. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/LatLng.js +0 -0
  71. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/LatLngBounds.js +0 -0
  72. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/crs/CRS.EPSG3395.js +0 -0
  73. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/crs/CRS.EPSG3857.js +0 -0
  74. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/crs/CRS.EPSG4326.js +0 -0
  75. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/crs/CRS.Simple.js +0 -0
  76. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/crs/CRS.js +0 -0
  77. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/projection/Projection.LonLat.js +0 -0
  78. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/projection/Projection.Mercator.js +0 -0
  79. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/projection/Projection.SphericalMercator.js +0 -0
  80. data/{lib/leaflet → vendor/assets/Leaflet}/src/geo/projection/Projection.js +0 -0
  81. data/{lib/leaflet → vendor/assets/Leaflet}/src/geometry/Bounds.js +0 -0
  82. data/{lib/leaflet → vendor/assets/Leaflet}/src/geometry/LineUtil.js +1 -1
  83. data/{lib/leaflet → vendor/assets/Leaflet}/src/geometry/Point.js +0 -0
  84. data/{lib/leaflet → vendor/assets/Leaflet}/src/geometry/PolyUtil.js +0 -0
  85. data/{lib/leaflet → vendor/assets/Leaflet}/src/geometry/Transformation.js +0 -0
  86. data/{lib/leaflet → vendor/assets/Leaflet}/src/images/layers.svg +0 -0
  87. data/{lib/leaflet → vendor/assets/Leaflet}/src/images/marker.svg +0 -0
  88. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/FeatureGroup.js +5 -3
  89. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/GeoJSON.js +0 -0
  90. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/ImageOverlay.js +0 -0
  91. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/LayerGroup.js +0 -0
  92. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/Popup.js +0 -0
  93. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/marker/DivIcon.js +0 -0
  94. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/marker/Icon.Default.js +0 -0
  95. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/marker/Icon.js +0 -0
  96. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/marker/Marker.Drag.js +0 -0
  97. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/marker/Marker.Popup.js +1 -0
  98. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/marker/Marker.js +2 -4
  99. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/tile/TileLayer.Anim.js +5 -0
  100. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/tile/TileLayer.Canvas.js +0 -0
  101. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/tile/TileLayer.WMS.js +0 -0
  102. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/tile/TileLayer.js +3 -5
  103. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/Circle.js +0 -0
  104. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/CircleMarker.js +1 -0
  105. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/MultiPoly.js +0 -0
  106. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/Path.Popup.js +0 -0
  107. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/Path.SVG.js +1 -1
  108. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/Path.VML.js +0 -0
  109. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/Path.js +0 -0
  110. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/Polygon.js +0 -0
  111. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/Polyline.js +0 -0
  112. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/Rectangle.js +0 -0
  113. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/canvas/Circle.Canvas.js +0 -0
  114. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/canvas/CircleMarker.Canvas.js +0 -0
  115. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/canvas/Path.Canvas.js +13 -6
  116. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/canvas/Polygon.Canvas.js +0 -0
  117. data/{lib/leaflet → vendor/assets/Leaflet}/src/layer/vector/canvas/Polyline.Canvas.js +0 -0
  118. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/Map.js +9 -8
  119. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/anim/Map.PanAnimation.js +0 -0
  120. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/anim/Map.ZoomAnimation.js +25 -16
  121. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/ext/Map.Geolocation.js +0 -0
  122. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/handler/Map.BoxZoom.js +0 -0
  123. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/handler/Map.DoubleClickZoom.js +0 -0
  124. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/handler/Map.Drag.js +0 -0
  125. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/handler/Map.Keyboard.js +0 -0
  126. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/handler/Map.ScrollWheelZoom.js +0 -0
  127. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/handler/Map.Tap.js +0 -0
  128. data/{lib/leaflet → vendor/assets/Leaflet}/src/map/handler/Map.TouchZoom.js +1 -1
  129. data/vendor/assets/{stylesheets/leaflet-js.css → leaflet-js.css} +0 -0
  130. data/vendor/assets/{javascripts/leaflet-js.js → leaflet-js.js} +2 -2
  131. data/{lib/leaflet.label/libs/leaflet/leaflet.css → vendor/assets/leaflet.css.erb} +2 -2
  132. data/vendor/assets/{stylesheets/leaflet.draw.css.erb → leaflet.draw.css.erb} +2 -2
  133. data/{lib/leaflet.draw/dist → vendor/assets}/leaflet.draw.ie.css +0 -0
  134. data/vendor/assets/leaflet.draw.js +38 -0
  135. data/vendor/assets/leaflet.js +155 -0
  136. data/{lib/leaflet.label/dist → vendor/assets}/leaflet.label.css +0 -0
  137. data/vendor/assets/leaflet.label.js +11 -0
  138. metadata +139 -302
  139. data/lib/leaflet.draw/BREAKINGCHANGES.md +0 -54
  140. data/lib/leaflet.draw/CHANGELOG.md +0 -118
  141. data/lib/leaflet.draw/Jakefile.js +0 -26
  142. data/lib/leaflet.draw/MIT-LICENCE.txt +0 -20
  143. data/lib/leaflet.draw/README.md +0 -411
  144. data/lib/leaflet.draw/TODO.md +0 -62
  145. data/lib/leaflet.draw/build/build.html +0 -243
  146. data/lib/leaflet.draw/build/build.js +0 -189
  147. data/lib/leaflet.draw/build/deps.js +0 -76
  148. data/lib/leaflet.draw/build/hintrc.js +0 -47
  149. data/lib/leaflet.draw/build/leaflet.draw-include.js +0 -42
  150. data/lib/leaflet.draw/dist/leaflet.draw-src.js +0 -2782
  151. data/lib/leaflet.draw/dist/leaflet.draw.css +0 -244
  152. data/lib/leaflet.draw/dist/leaflet.draw.js +0 -10
  153. data/lib/leaflet.draw/examples/basic.html +0 -113
  154. data/lib/leaflet.draw/examples/edithandlers.html +0 -67
  155. data/lib/leaflet.draw/examples/libs/images/marker-icon@2x.png +0 -0
  156. data/lib/leaflet.draw/examples/libs/leaflet-src.js +0 -9108
  157. data/lib/leaflet.draw/examples/libs/leaflet.css +0 -478
  158. data/lib/leaflet.draw/package.json +0 -37
  159. data/lib/leaflet.draw/spec/after.js +0 -2
  160. data/lib/leaflet.draw/spec/before.js +0 -3
  161. data/lib/leaflet.draw/spec/expect.js +0 -1253
  162. data/lib/leaflet.draw/spec/happen.js +0 -93
  163. data/lib/leaflet.draw/spec/index.html +0 -36
  164. data/lib/leaflet.draw/spec/karma.conf.js +0 -69
  165. data/lib/leaflet.draw/spec/sinon.js +0 -4223
  166. data/lib/leaflet.draw/spec/suites/DrawControlSpec.js +0 -15
  167. data/lib/leaflet.draw/spec/suites/GeometryUtilSpec.js +0 -25
  168. data/lib/leaflet.draw/spec/suites/LatLngUtilSpec.js +0 -9
  169. data/lib/leaflet.draw/spec/suites/SpecHelper.js +0 -26
  170. data/lib/leaflet.draw/src/draw/DrawToolbar.js +0 -111
  171. data/lib/leaflet.label/CHANGELOG.md +0 -67
  172. data/lib/leaflet.label/Jakefile.js +0 -21
  173. data/lib/leaflet.label/MIT-LICENCE.txt +0 -20
  174. data/lib/leaflet.label/README.md +0 -103
  175. data/lib/leaflet.label/build/build.js +0 -155
  176. data/lib/leaflet.label/build/deps.js +0 -26
  177. data/lib/leaflet.label/build/hint.js +0 -30
  178. data/lib/leaflet.label/build/hintrc.js +0 -51
  179. data/lib/leaflet.label/dist/images/death.png +0 -0
  180. data/lib/leaflet.label/dist/leaflet.label-src.js +0 -542
  181. data/lib/leaflet.label/dist/leaflet.label.js +0 -9
  182. data/lib/leaflet.label/example/label.html +0 -85
  183. data/lib/leaflet.label/libs/leaflet/images/layers-2x.png +0 -0
  184. data/lib/leaflet.label/libs/leaflet/images/layers.png +0 -0
  185. data/lib/leaflet.label/libs/leaflet/images/marker-icon-2x.png +0 -0
  186. data/lib/leaflet.label/libs/leaflet/images/marker-icon.png +0 -0
  187. data/lib/leaflet.label/libs/leaflet/images/marker-icon@2x.png +0 -0
  188. data/lib/leaflet.label/libs/leaflet/images/marker-shadow.png +0 -0
  189. data/lib/leaflet.label/libs/leaflet/leaflet-src.js +0 -9108
  190. data/lib/leaflet.label/libs/leaflet/leaflet.js +0 -9
  191. data/lib/leaflet.label/package.json +0 -19
  192. data/lib/leaflet/CHANGELOG.md +0 -905
  193. data/lib/leaflet/CONTRIBUTING.md +0 -155
  194. data/lib/leaflet/FAQ.md +0 -138
  195. data/lib/leaflet/Jakefile.js +0 -46
  196. data/lib/leaflet/LICENSE +0 -23
  197. data/lib/leaflet/PLUGIN-GUIDE.md +0 -127
  198. data/lib/leaflet/README.md +0 -34
  199. data/lib/leaflet/build/build.html +0 -227
  200. data/lib/leaflet/build/build.js +0 -163
  201. data/lib/leaflet/build/deps.js +0 -259
  202. data/lib/leaflet/build/hintrc.js +0 -39
  203. data/lib/leaflet/debug/css/mobile.css +0 -6
  204. data/lib/leaflet/debug/css/screen.css +0 -5
  205. data/lib/leaflet/debug/hacks/jitter.html +0 -42
  206. data/lib/leaflet/debug/leaflet-include.js +0 -59
  207. data/lib/leaflet/debug/map/canvas.html +0 -46
  208. data/lib/leaflet/debug/map/controls.html +0 -49
  209. data/lib/leaflet/debug/map/geolocation.html +0 -34
  210. data/lib/leaflet/debug/map/iframe.html +0 -11
  211. data/lib/leaflet/debug/map/image-overlay.html +0 -43
  212. data/lib/leaflet/debug/map/map-mobile.html +0 -34
  213. data/lib/leaflet/debug/map/map.html +0 -59
  214. data/lib/leaflet/debug/map/max-bounds.html +0 -38
  215. data/lib/leaflet/debug/map/opacity.html +0 -223
  216. data/lib/leaflet/debug/map/scroll.html +0 -41
  217. data/lib/leaflet/debug/map/simple-proj.html +0 -44
  218. data/lib/leaflet/debug/map/wms-marble.html +0 -30
  219. data/lib/leaflet/debug/map/wms.html +0 -40
  220. data/lib/leaflet/debug/map/zoomlevels.html +0 -45
  221. data/lib/leaflet/debug/tests/add_remove_layers.html +0 -87
  222. data/lib/leaflet/debug/tests/bringtoback.html +0 -37
  223. data/lib/leaflet/debug/tests/canvasloop.html +0 -47
  224. data/lib/leaflet/debug/tests/click_on_canvas.html +0 -58
  225. data/lib/leaflet/debug/tests/click_on_canvas_broken.html +0 -49
  226. data/lib/leaflet/debug/tests/dragging_and_copyworldjump.html +0 -61
  227. data/lib/leaflet/debug/tests/opacity.html +0 -56
  228. data/lib/leaflet/debug/tests/popupcontextmenuclicks.html +0 -59
  229. data/lib/leaflet/debug/tests/remove_while_dragging.html +0 -28
  230. data/lib/leaflet/debug/tests/removetilewhilepan.html +0 -41
  231. data/lib/leaflet/debug/tests/reuse_popups.html +0 -40
  232. data/lib/leaflet/debug/tests/rtl.html +0 -42
  233. data/lib/leaflet/debug/tests/rtl2.html +0 -27
  234. data/lib/leaflet/debug/tests/set_icon_reuse_dom.html +0 -43
  235. data/lib/leaflet/debug/tests/svg_clicks.html +0 -54
  236. data/lib/leaflet/debug/vector/bounds-extend.html +0 -88
  237. data/lib/leaflet/debug/vector/feature-group-bounds.html +0 -90
  238. data/lib/leaflet/debug/vector/geojson-sample.js +0 -53
  239. data/lib/leaflet/debug/vector/geojson.html +0 -173
  240. data/lib/leaflet/debug/vector/rectangle.html +0 -53
  241. data/lib/leaflet/debug/vector/route.js +0 -1
  242. data/lib/leaflet/debug/vector/touchzoomemu.html +0 -194
  243. data/lib/leaflet/debug/vector/us-states.js +0 -54
  244. data/lib/leaflet/debug/vector/vector-bounds.html +0 -69
  245. data/lib/leaflet/debug/vector/vector-canvas.html +0 -92
  246. data/lib/leaflet/debug/vector/vector-mobile.html +0 -38
  247. data/lib/leaflet/debug/vector/vector-simple.html +0 -48
  248. data/lib/leaflet/debug/vector/vector.html +0 -37
  249. data/lib/leaflet/dist/images/layers-2x.png +0 -0
  250. data/lib/leaflet/dist/images/layers.png +0 -0
  251. data/lib/leaflet/dist/images/marker-icon-2x.png +0 -0
  252. data/lib/leaflet/dist/images/marker-icon.png +0 -0
  253. data/lib/leaflet/dist/images/marker-shadow.png +0 -0
  254. data/lib/leaflet/dist/leaflet.css +0 -478
  255. data/lib/leaflet/package.json +0 -27
  256. data/lib/leaflet/spec/after.js +0 -2
  257. data/lib/leaflet/spec/before.js +0 -3
  258. data/lib/leaflet/spec/expect.js +0 -1253
  259. data/lib/leaflet/spec/index.html +0 -86
  260. data/lib/leaflet/spec/karma.conf.js +0 -65
  261. data/lib/leaflet/spec/sinon.js +0 -4223
  262. data/lib/leaflet/spec/spec.hintrc.js +0 -25
  263. data/lib/leaflet/spec/suites/LeafletSpec.js +0 -13
  264. data/lib/leaflet/spec/suites/SpecHelper.js +0 -42
  265. data/lib/leaflet/spec/suites/control/Control.AttributionSpec.js +0 -68
  266. data/lib/leaflet/spec/suites/control/Control.LayersSpec.js +0 -67
  267. data/lib/leaflet/spec/suites/control/Control.ScaleSpec.js +0 -6
  268. data/lib/leaflet/spec/suites/core/ClassSpec.js +0 -156
  269. data/lib/leaflet/spec/suites/core/EventsSpec.js +0 -392
  270. data/lib/leaflet/spec/suites/core/UtilSpec.js +0 -256
  271. data/lib/leaflet/spec/suites/dom/DomEventSpec.js +0 -102
  272. data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +0 -82
  273. data/lib/leaflet/spec/suites/dom/PosAnimationSpec.js +0 -27
  274. data/lib/leaflet/spec/suites/geo/CRSSpec.js +0 -47
  275. data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +0 -144
  276. data/lib/leaflet/spec/suites/geo/LatLngSpec.js +0 -132
  277. data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +0 -48
  278. data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +0 -87
  279. data/lib/leaflet/spec/suites/geometry/LineUtilSpec.js +0 -75
  280. data/lib/leaflet/spec/suites/geometry/PointSpec.js +0 -104
  281. data/lib/leaflet/spec/suites/geometry/PolyUtilSpec.js +0 -27
  282. data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +0 -31
  283. data/lib/leaflet/spec/suites/layer/FeatureGroupSpec.js +0 -86
  284. data/lib/leaflet/spec/suites/layer/GeoJSONSpec.js +0 -282
  285. data/lib/leaflet/spec/suites/layer/LayerGroupSpec.js +0 -58
  286. data/lib/leaflet/spec/suites/layer/PopupSpec.js +0 -119
  287. data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +0 -88
  288. data/lib/leaflet/spec/suites/layer/marker/MarkerSpec.js +0 -94
  289. data/lib/leaflet/spec/suites/layer/vector/CircleMarkerSpec.js +0 -53
  290. data/lib/leaflet/spec/suites/layer/vector/CircleSpec.js +0 -17
  291. data/lib/leaflet/spec/suites/layer/vector/PolygonSpec.js +0 -91
  292. data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +0 -35
  293. data/lib/leaflet/spec/suites/layer/vector/PolylineSpec.js +0 -55
  294. data/lib/leaflet/spec/suites/map/MapSpec.js +0 -536
  295. data/lib/leaflet/spec/suites/map/handler/Map.DragSpec.js +0 -38
  296. data/vendor/assets/images/layers-2x.png +0 -0
  297. data/vendor/assets/images/layers.png +0 -0
  298. data/vendor/assets/images/marker-icon-2x.png +0 -0
  299. data/vendor/assets/images/marker-icon.png +0 -0
  300. data/vendor/assets/images/marker-shadow.png +0 -0
  301. data/vendor/assets/images/spritesheet-2x.png +0 -0
  302. data/vendor/assets/images/spritesheet.png +0 -0
  303. data/vendor/assets/javascripts/leaflet.draw.js +0 -37
  304. data/vendor/assets/javascripts/leaflet.js +0 -147
  305. data/vendor/assets/javascripts/leaflet.label.js +0 -11
  306. data/vendor/assets/stylesheets/leaflet.css.erb +0 -478
  307. data/vendor/assets/stylesheets/leaflet.draw.ie.css +0 -49
  308. data/vendor/assets/stylesheets/leaflet.label.css +0 -52
@@ -1,76 +0,0 @@
1
- var deps = {
2
- Core: {
3
- src: [
4
- 'Leaflet.draw.js'
5
- ],
6
- desc: 'The core of the plugin. Currently only includes the version.'
7
- },
8
-
9
- DrawHandlers: {
10
- src: [
11
- 'draw/handler/Draw.Feature.js',
12
- 'draw/handler/Draw.Polyline.js',
13
- 'draw/handler/Draw.Polygon.js',
14
- 'draw/handler/Draw.SimpleShape.js',
15
- 'draw/handler/Draw.Rectangle.js',
16
- 'draw/handler/Draw.Circle.js',
17
- 'draw/handler/Draw.Marker.js'
18
- ],
19
- desc: 'Drawing handlers for: polylines, polygons, rectangles, circles and markers.',
20
- deps: ['Core']
21
- },
22
-
23
- EditHandlers: {
24
- src: [
25
- 'edit/handler/Edit.Poly.js',
26
- 'edit/handler/Edit.SimpleShape.js',
27
- 'edit/handler/Edit.Rectangle.js',
28
- 'edit/handler/Edit.Circle.js'
29
- ],
30
- desc: 'Editing handlers for: polylines, polygons, rectangles, and circles.',
31
- deps: ['Core']
32
- },
33
-
34
- Extensions: {
35
- src: [
36
- 'ext/LatLngUtil.js',
37
- 'ext/GeometryUtil.js',
38
- 'ext/LineUtil.Intersect.js',
39
- 'ext/Polyline.Intersect.js',
40
- 'ext/Polygon.Intersect.js'
41
- ],
42
- desc: 'Extensions of leaflet classes.'
43
- },
44
-
45
- CommonUI: {
46
- src: [
47
- 'Control.Draw.js',
48
- 'Toolbar.js',
49
- 'Tooltip.js'
50
- ],
51
- desc: 'Common UI components used.',
52
- deps: ['Extensions']
53
- },
54
-
55
- DrawUI: {
56
- src: [
57
- 'draw/DrawToolbar.js'
58
- ],
59
- desc: 'Draw toolbar.',
60
- deps: ['DrawHandlers', 'CommonUI']
61
- },
62
-
63
- EditUI: {
64
- src: [
65
- 'edit/EditToolbar.js',
66
- 'edit/handler/EditToolbar.Edit.js',
67
- 'edit/handler/EditToolbar.Delete.js'
68
- ],
69
- desc: 'Edit toolbar.',
70
- deps: ['EditHandlers', 'CommonUI']
71
- }
72
- };
73
-
74
- if (typeof exports !== 'undefined') {
75
- exports.deps = deps;
76
- }
@@ -1,47 +0,0 @@
1
- exports.config = {
2
- "browser": true,
3
- "node": true,
4
- "predef": ["L"],
5
-
6
- "debug": false,
7
- "devel": false,
8
-
9
- "es5": false,
10
- "strict": false,
11
- "globalstrict": false,
12
-
13
- "asi": false,
14
- "laxbreak": false,
15
- "bitwise": true,
16
- "boss": false,
17
- "curly": true,
18
- "eqnull": false,
19
- "evil": false,
20
- "expr": false,
21
- "forin": true,
22
- "immed": true,
23
- "latedef": true,
24
- "loopfunc": false,
25
- "noarg": true,
26
- "regexp": true,
27
- "regexdash": false,
28
- "scripturl": false,
29
- "shadow": false,
30
- "supernew": false,
31
- "undef": true,
32
- "funcscope": false,
33
-
34
- "newcap": true,
35
- "noempty": true,
36
- "nonew": true,
37
- "nomen": false,
38
- "onevar": false,
39
- "plusplus": false,
40
- "sub": false,
41
- "indent": 4,
42
-
43
- "eqeqeq": true,
44
- "trailing": true,
45
- "white": true,
46
- "smarttabs": true
47
- };
@@ -1,42 +0,0 @@
1
- (function() {
2
- function getFiles() {
3
- var memo = {},
4
- files = [],
5
- i, src;
6
-
7
- function addFiles(srcs) {
8
- for (var j = 0, len = srcs.length; j < len; j++) {
9
- memo[srcs[j]] = true;
10
- }
11
- }
12
-
13
- for (i in deps) {
14
- addFiles(deps[i].src);
15
- }
16
-
17
- for (src in memo) {
18
- files.push(src);
19
- }
20
-
21
- return files;
22
- }
23
- var scripts = getFiles();
24
-
25
- function getSrcUrl() {
26
- var scripts = document.getElementsByTagName('script');
27
- for (var i = 0; i < scripts.length; i++) {
28
- var src = scripts[i].src;
29
- if (src) {
30
- var res = src.match(/^(.*)leaflet.draw-include\.js$/);
31
- if (res) {
32
- return res[1] + '../src/';
33
- }
34
- }
35
- }
36
- }
37
-
38
- var path = getSrcUrl();
39
- for (var i = 0; i < scripts.length; i++) {
40
- document.writeln("<script src='" + path + scripts[i] + "'></script>");
41
- }
42
- })();
@@ -1,2782 +0,0 @@
1
- /*
2
- Leaflet.draw, a plugin that adds drawing and editing tools to Leaflet powered maps.
3
- (c) 2012-2013, Jacob Toye, Smartrak
4
-
5
- https://github.com/Leaflet/Leaflet.draw
6
- http://leafletjs.com
7
- https://github.com/jacobtoye
8
- */
9
- (function (window, document, undefined) {
10
- /*
11
- * Leaflet.draw assumes that you have already included the Leaflet library.
12
- */
13
-
14
- L.drawVersion = '0.2.3-dev';
15
-
16
- L.drawLocal = {
17
- draw: {
18
- toolbar: {
19
- actions: {
20
- title: 'Cancel drawing',
21
- text: 'Cancel'
22
- },
23
- buttons: {
24
- polyline: 'Draw a polyline',
25
- polygon: 'Draw a polygon',
26
- rectangle: 'Draw a rectangle',
27
- circle: 'Draw a circle',
28
- marker: 'Draw a marker'
29
- }
30
- },
31
- handlers: {
32
- circle: {
33
- tooltip: {
34
- start: 'Click and drag to draw circle.'
35
- }
36
- },
37
- marker: {
38
- tooltip: {
39
- start: 'Click map to place marker.'
40
- }
41
- },
42
- polygon: {
43
- tooltip: {
44
- start: 'Click to start drawing shape.',
45
- cont: 'Click to continue drawing shape.',
46
- end: 'Click first point to close this shape.'
47
- }
48
- },
49
- polyline: {
50
- error: '<strong>Error:</strong> shape edges cannot cross!',
51
- tooltip: {
52
- start: 'Click to start drawing line.',
53
- cont: 'Click to continue drawing line.',
54
- end: 'Click last point to finish line.'
55
- }
56
- },
57
- rectangle: {
58
- tooltip: {
59
- start: 'Click and drag to draw rectangle.'
60
- }
61
- },
62
- simpleshape: {
63
- tooltip: {
64
- end: 'Release mouse to finish drawing.'
65
- }
66
- }
67
- }
68
- },
69
- edit: {
70
- toolbar: {
71
- actions: {
72
- save: {
73
- title: 'Save changes.',
74
- text: 'Save'
75
- },
76
- cancel: {
77
- title: 'Cancel editing, discards all changes.',
78
- text: 'Cancel'
79
- }
80
- },
81
- buttons: {
82
- edit: 'Edit layers.',
83
- editDisabled: 'No layers to edit.',
84
- remove: 'Delete layers.',
85
- removeDisabled: 'No layers to delete.'
86
- }
87
- },
88
- handlers: {
89
- edit: {
90
- tooltip: {
91
- text: 'Drag handles, or marker to edit feature.',
92
- subtext: 'Click cancel to undo changes.'
93
- }
94
- },
95
- remove: {
96
- tooltip: {
97
- text: 'Click on a feature to remove'
98
- }
99
- }
100
- }
101
- }
102
- };
103
-
104
- L.Draw = {};
105
-
106
- L.Draw.Feature = L.Handler.extend({
107
- includes: L.Mixin.Events,
108
-
109
- initialize: function (map, options) {
110
- this._map = map;
111
- this._container = map._container;
112
- this._overlayPane = map._panes.overlayPane;
113
- this._popupPane = map._panes.popupPane;
114
-
115
- // Merge default shapeOptions options with custom shapeOptions
116
- if (options && options.shapeOptions) {
117
- options.shapeOptions = L.Util.extend({}, this.options.shapeOptions, options.shapeOptions);
118
- }
119
- L.setOptions(this, options);
120
- },
121
-
122
- enable: function () {
123
- if (this._enabled) { return; }
124
-
125
- L.Handler.prototype.enable.call(this);
126
-
127
- this.fire('enabled', { handler: this.type });
128
-
129
- this._map.fire('draw:drawstart', { layerType: this.type });
130
- },
131
-
132
- disable: function () {
133
- if (!this._enabled) { return; }
134
-
135
- L.Handler.prototype.disable.call(this);
136
-
137
- this.fire('disabled', { handler: this.type });
138
-
139
- this._map.fire('draw:drawstop', { layerType: this.type });
140
- },
141
-
142
- addHooks: function () {
143
- var map = this._map;
144
-
145
- if (map) {
146
- L.DomUtil.disableTextSelection();
147
-
148
- map.getContainer().focus();
149
-
150
- this._tooltip = new L.Tooltip(this._map);
151
-
152
- L.DomEvent.addListener(this._container, 'keyup', this._cancelDrawing, this);
153
- }
154
- },
155
-
156
- removeHooks: function () {
157
- if (this._map) {
158
- L.DomUtil.enableTextSelection();
159
-
160
- this._tooltip.dispose();
161
- this._tooltip = null;
162
-
163
- L.DomEvent.removeListener(this._container, 'keyup', this._cancelDrawing);
164
- }
165
- },
166
-
167
- setOptions: function (options) {
168
- L.setOptions(this, options);
169
- },
170
-
171
- _fireCreatedEvent: function (layer) {
172
- this._map.fire('draw:created', { layer: layer, layerType: this.type });
173
- },
174
-
175
- // Cancel drawing when the escape key is pressed
176
- _cancelDrawing: function (e) {
177
- if (e.keyCode === 27) {
178
- this.disable();
179
- }
180
- }
181
- });
182
-
183
- L.Draw.Polyline = L.Draw.Feature.extend({
184
- statics: {
185
- TYPE: 'polyline'
186
- },
187
-
188
- Poly: L.Polyline,
189
-
190
- options: {
191
- allowIntersection: true,
192
- repeatMode: false,
193
- drawError: {
194
- color: '#b00b00',
195
- timeout: 2500
196
- },
197
- icon: new L.DivIcon({
198
- iconSize: new L.Point(8, 8),
199
- className: 'leaflet-div-icon leaflet-editing-icon'
200
- }),
201
- guidelineDistance: 20,
202
- shapeOptions: {
203
- stroke: true,
204
- color: '#f06eaa',
205
- weight: 4,
206
- opacity: 0.5,
207
- fill: false,
208
- clickable: true
209
- },
210
- metric: true, // Whether to use the metric meaurement system or imperial
211
- showLength: true, // Whether to display distance in the tooltip
212
- zIndexOffset: 2000 // This should be > than the highest z-index any map layers
213
- },
214
-
215
- initialize: function (map, options) {
216
- // Need to set this here to ensure the correct message is used.
217
- this.options.drawError.message = L.drawLocal.draw.handlers.polyline.error;
218
-
219
- // Merge default drawError options with custom options
220
- if (options && options.drawError) {
221
- options.drawError = L.Util.extend({}, this.options.drawError, options.drawError);
222
- }
223
-
224
- // Save the type so super can fire, need to do this as cannot do this.TYPE :(
225
- this.type = L.Draw.Polyline.TYPE;
226
-
227
- L.Draw.Feature.prototype.initialize.call(this, map, options);
228
- },
229
-
230
- addHooks: function () {
231
- L.Draw.Feature.prototype.addHooks.call(this);
232
- if (this._map) {
233
- this._markers = [];
234
-
235
- this._markerGroup = new L.LayerGroup();
236
- this._map.addLayer(this._markerGroup);
237
-
238
- this._poly = new L.Polyline([], this.options.shapeOptions);
239
-
240
- this._tooltip.updateContent(this._getTooltipText());
241
-
242
- // Make a transparent marker that will used to catch click events. These click
243
- // events will create the vertices. We need to do this so we can ensure that
244
- // we can create vertices over other map layers (markers, vector layers). We
245
- // also do not want to trigger any click handlers of objects we are clicking on
246
- // while drawing.
247
- if (!this._mouseMarker) {
248
- this._mouseMarker = L.marker(this._map.getCenter(), {
249
- icon: L.divIcon({
250
- className: 'leaflet-mouse-marker',
251
- iconAnchor: [20, 20],
252
- iconSize: [40, 40]
253
- }),
254
- opacity: 0,
255
- zIndexOffset: this.options.zIndexOffset
256
- });
257
- }
258
-
259
- this._mouseMarker
260
- .on('click', this._onClick, this)
261
- .addTo(this._map);
262
-
263
- this._map
264
- .on('mousemove', this._onMouseMove, this)
265
- .on('zoomend', this._onZoomEnd, this);
266
- }
267
- },
268
-
269
- removeHooks: function () {
270
- L.Draw.Feature.prototype.removeHooks.call(this);
271
-
272
- this._clearHideErrorTimeout();
273
-
274
- this._cleanUpShape();
275
-
276
- // remove markers from map
277
- this._map.removeLayer(this._markerGroup);
278
- delete this._markerGroup;
279
- delete this._markers;
280
-
281
- this._map.removeLayer(this._poly);
282
- delete this._poly;
283
-
284
- this._mouseMarker.off('click', this._onClick, this);
285
- this._map.removeLayer(this._mouseMarker);
286
- delete this._mouseMarker;
287
-
288
- // clean up DOM
289
- this._clearGuides();
290
-
291
- this._map
292
- .off('mousemove', this._onMouseMove, this)
293
- .off('zoomend', this._onZoomEnd, this);
294
- },
295
-
296
- _finishShape: function () {
297
- var intersects = this._poly.newLatLngIntersects(this._poly.getLatLngs()[0], true);
298
-
299
- if ((!this.options.allowIntersection && intersects) || !this._shapeIsValid()) {
300
- this._showErrorTooltip();
301
- return;
302
- }
303
-
304
- this._fireCreatedEvent();
305
- this.disable();
306
- if (this.options.repeatMode) {
307
- this.enable();
308
- }
309
- },
310
-
311
- //Called to verify the shape is valid when the user tries to finish it
312
- //Return false if the shape is not valid
313
- _shapeIsValid: function () {
314
- return true;
315
- },
316
-
317
- _onZoomEnd: function () {
318
- this._updateGuide();
319
- },
320
-
321
- _onMouseMove: function (e) {
322
- var newPos = e.layerPoint,
323
- latlng = e.latlng;
324
-
325
- // Save latlng
326
- // should this be moved to _updateGuide() ?
327
- this._currentLatLng = latlng;
328
-
329
- this._updateTooltip(latlng);
330
-
331
- // Update the guide line
332
- this._updateGuide(newPos);
333
-
334
- // Update the mouse marker position
335
- this._mouseMarker.setLatLng(latlng);
336
-
337
- L.DomEvent.preventDefault(e.originalEvent);
338
- },
339
-
340
- _onClick: function (e) {
341
- var latlng = e.target.getLatLng(),
342
- markerCount = this._markers.length;
343
-
344
- if (markerCount > 0 && !this.options.allowIntersection && this._poly.newLatLngIntersects(latlng)) {
345
- this._showErrorTooltip();
346
- return;
347
- }
348
- else if (this._errorShown) {
349
- this._hideErrorTooltip();
350
- }
351
-
352
- this._markers.push(this._createMarker(latlng));
353
-
354
- this._poly.addLatLng(latlng);
355
-
356
- if (this._poly.getLatLngs().length === 2) {
357
- this._map.addLayer(this._poly);
358
- }
359
-
360
- this._updateFinishHandler();
361
-
362
- this._vertexAdded(latlng);
363
-
364
- this._clearGuides();
365
-
366
- this._updateTooltip();
367
- },
368
-
369
- _updateFinishHandler: function () {
370
- var markerCount = this._markers.length;
371
- // The last marker should have a click handler to close the polyline
372
- if (markerCount > 1) {
373
- this._markers[markerCount - 1].on('click', this._finishShape, this);
374
- }
375
-
376
- // Remove the old marker click handler (as only the last point should close the polyline)
377
- if (markerCount > 2) {
378
- this._markers[markerCount - 2].off('click', this._finishShape, this);
379
- }
380
- },
381
-
382
- _createMarker: function (latlng) {
383
- var marker = new L.Marker(latlng, {
384
- icon: this.options.icon,
385
- zIndexOffset: this.options.zIndexOffset * 2
386
- });
387
-
388
- this._markerGroup.addLayer(marker);
389
-
390
- return marker;
391
- },
392
-
393
- _updateGuide: function (newPos) {
394
- var markerCount = this._markers.length;
395
-
396
- if (markerCount > 0) {
397
- newPos = newPos || this._map.latLngToLayerPoint(this._currentLatLng);
398
-
399
- // draw the guide line
400
- this._clearGuides();
401
- this._drawGuide(
402
- this._map.latLngToLayerPoint(this._markers[markerCount - 1].getLatLng()),
403
- newPos
404
- );
405
- }
406
- },
407
-
408
- _updateTooltip: function (latLng) {
409
- var text = this._getTooltipText();
410
-
411
- if (latLng) {
412
- this._tooltip.updatePosition(latLng);
413
- }
414
-
415
- if (!this._errorShown) {
416
- this._tooltip.updateContent(text);
417
- }
418
- },
419
-
420
- _drawGuide: function (pointA, pointB) {
421
- var length = Math.floor(Math.sqrt(Math.pow((pointB.x - pointA.x), 2) + Math.pow((pointB.y - pointA.y), 2))),
422
- i,
423
- fraction,
424
- dashPoint,
425
- dash;
426
-
427
- //create the guides container if we haven't yet
428
- if (!this._guidesContainer) {
429
- this._guidesContainer = L.DomUtil.create('div', 'leaflet-draw-guides', this._overlayPane);
430
- }
431
-
432
- //draw a dash every GuildeLineDistance
433
- for (i = this.options.guidelineDistance; i < length; i += this.options.guidelineDistance) {
434
- //work out fraction along line we are
435
- fraction = i / length;
436
-
437
- //calculate new x,y point
438
- dashPoint = {
439
- x: Math.floor((pointA.x * (1 - fraction)) + (fraction * pointB.x)),
440
- y: Math.floor((pointA.y * (1 - fraction)) + (fraction * pointB.y))
441
- };
442
-
443
- //add guide dash to guide container
444
- dash = L.DomUtil.create('div', 'leaflet-draw-guide-dash', this._guidesContainer);
445
- dash.style.backgroundColor =
446
- !this._errorShown ? this.options.shapeOptions.color : this.options.drawError.color;
447
-
448
- L.DomUtil.setPosition(dash, dashPoint);
449
- }
450
- },
451
-
452
- _updateGuideColor: function (color) {
453
- if (this._guidesContainer) {
454
- for (var i = 0, l = this._guidesContainer.childNodes.length; i < l; i++) {
455
- this._guidesContainer.childNodes[i].style.backgroundColor = color;
456
- }
457
- }
458
- },
459
-
460
- // removes all child elements (guide dashes) from the guides container
461
- _clearGuides: function () {
462
- if (this._guidesContainer) {
463
- while (this._guidesContainer.firstChild) {
464
- this._guidesContainer.removeChild(this._guidesContainer.firstChild);
465
- }
466
- }
467
- },
468
-
469
- _getTooltipText: function () {
470
- var showLength = this.options.showLength,
471
- labelText, distance, distanceStr;
472
-
473
- if (this._markers.length === 0) {
474
- labelText = {
475
- text: L.drawLocal.draw.handlers.polyline.tooltip.start
476
- };
477
- } else {
478
- distanceStr = showLength ? this._getMeasurementString() : '';
479
-
480
- if (this._markers.length === 1) {
481
- labelText = {
482
- text: L.drawLocal.draw.handlers.polyline.tooltip.cont,
483
- subtext: distanceStr
484
- };
485
- } else {
486
- labelText = {
487
- text: L.drawLocal.draw.handlers.polyline.tooltip.end,
488
- subtext: distanceStr
489
- };
490
- }
491
- }
492
- return labelText;
493
- },
494
-
495
- _getMeasurementString: function () {
496
- var currentLatLng = this._currentLatLng,
497
- previousLatLng = this._markers[this._markers.length - 1].getLatLng(),
498
- distance;
499
-
500
- // calculate the distance from the last fixed point to the mouse position
501
- distance = this._measurementRunningTotal + currentLatLng.distanceTo(previousLatLng);
502
-
503
- return L.GeometryUtil.readableDistance(distance, this.options.metric);
504
- },
505
-
506
- _showErrorTooltip: function () {
507
- this._errorShown = true;
508
-
509
- // Update tooltip
510
- this._tooltip
511
- .showAsError()
512
- .updateContent({ text: this.options.drawError.message });
513
-
514
- // Update shape
515
- this._updateGuideColor(this.options.drawError.color);
516
- this._poly.setStyle({ color: this.options.drawError.color });
517
-
518
- // Hide the error after 2 seconds
519
- this._clearHideErrorTimeout();
520
- this._hideErrorTimeout = setTimeout(L.Util.bind(this._hideErrorTooltip, this), this.options.drawError.timeout);
521
- },
522
-
523
- _hideErrorTooltip: function () {
524
- this._errorShown = false;
525
-
526
- this._clearHideErrorTimeout();
527
-
528
- // Revert tooltip
529
- this._tooltip
530
- .removeError()
531
- .updateContent(this._getTooltipText());
532
-
533
- // Revert shape
534
- this._updateGuideColor(this.options.shapeOptions.color);
535
- this._poly.setStyle({ color: this.options.shapeOptions.color });
536
- },
537
-
538
- _clearHideErrorTimeout: function () {
539
- if (this._hideErrorTimeout) {
540
- clearTimeout(this._hideErrorTimeout);
541
- this._hideErrorTimeout = null;
542
- }
543
- },
544
-
545
- _vertexAdded: function (latlng) {
546
- if (this._markers.length === 1) {
547
- this._measurementRunningTotal = 0;
548
- }
549
- else {
550
- this._measurementRunningTotal +=
551
- latlng.distanceTo(this._markers[this._markers.length - 2].getLatLng());
552
- }
553
- },
554
-
555
- _cleanUpShape: function () {
556
- if (this._markers.length > 1) {
557
- this._markers[this._markers.length - 1].off('click', this._finishShape, this);
558
- }
559
- },
560
-
561
- _fireCreatedEvent: function () {
562
- var poly = new this.Poly(this._poly.getLatLngs(), this.options.shapeOptions);
563
- L.Draw.Feature.prototype._fireCreatedEvent.call(this, poly);
564
- }
565
- });
566
-
567
-
568
- L.Draw.Polygon = L.Draw.Polyline.extend({
569
- statics: {
570
- TYPE: 'polygon'
571
- },
572
-
573
- Poly: L.Polygon,
574
-
575
- options: {
576
- showArea: false,
577
- shapeOptions: {
578
- stroke: true,
579
- color: '#f06eaa',
580
- weight: 4,
581
- opacity: 0.5,
582
- fill: true,
583
- fillColor: null, //same as color by default
584
- fillOpacity: 0.2,
585
- clickable: true
586
- }
587
- },
588
-
589
- initialize: function (map, options) {
590
- L.Draw.Polyline.prototype.initialize.call(this, map, options);
591
-
592
- // Save the type so super can fire, need to do this as cannot do this.TYPE :(
593
- this.type = L.Draw.Polygon.TYPE;
594
- },
595
-
596
- _updateFinishHandler: function () {
597
- var markerCount = this._markers.length;
598
-
599
- // The first marker shold have a click handler to close the polygon
600
- if (markerCount === 1) {
601
- this._markers[0].on('click', this._finishShape, this);
602
- }
603
-
604
- // Add and update the double click handler
605
- if (markerCount > 2) {
606
- this._markers[markerCount - 1].on('dblclick', this._finishShape, this);
607
- // Only need to remove handler if has been added before
608
- if (markerCount > 3) {
609
- this._markers[markerCount - 2].off('dblclick', this._finishShape, this);
610
- }
611
- }
612
- },
613
-
614
- _getTooltipText: function () {
615
- var text, subtext;
616
-
617
- if (this._markers.length === 0) {
618
- text = L.drawLocal.draw.handlers.polygon.tooltip.start;
619
- } else if (this._markers.length < 3) {
620
- text = L.drawLocal.draw.handlers.polygon.tooltip.cont;
621
- } else {
622
- text = L.drawLocal.draw.handlers.polygon.tooltip.end;
623
- subtext = this._getMeasurementString();
624
- }
625
-
626
- return {
627
- text: text,
628
- subtext: subtext
629
- };
630
- },
631
-
632
- _getMeasurementString: function () {
633
- var area = this._area;
634
-
635
- if (!area) {
636
- return null;
637
- }
638
-
639
- return L.GeometryUtil.readableArea(area, this.options.metric);
640
- },
641
-
642
- _shapeIsValid: function () {
643
- return this._markers.length >= 3;
644
- },
645
-
646
- _vertexAdded: function () {
647
- // Check to see if we should show the area
648
- if (this.options.allowIntersection || !this.options.showArea) {
649
- return;
650
- }
651
-
652
- var latLngs = this._poly.getLatLngs();
653
-
654
- this._area = L.GeometryUtil.geodesicArea(latLngs);
655
- },
656
-
657
- _cleanUpShape: function () {
658
- var markerCount = this._markers.length;
659
-
660
- if (markerCount > 0) {
661
- this._markers[0].off('click', this._finishShape, this);
662
-
663
- if (markerCount > 2) {
664
- this._markers[markerCount - 1].off('dblclick', this._finishShape, this);
665
- }
666
- }
667
- }
668
- });
669
-
670
-
671
- L.SimpleShape = {};
672
-
673
- L.Draw.SimpleShape = L.Draw.Feature.extend({
674
- options: {
675
- repeatMode: false
676
- },
677
-
678
- initialize: function (map, options) {
679
- this._endLabelText = L.drawLocal.draw.handlers.simpleshape.tooltip.end;
680
-
681
- L.Draw.Feature.prototype.initialize.call(this, map, options);
682
- },
683
-
684
- addHooks: function () {
685
- L.Draw.Feature.prototype.addHooks.call(this);
686
- if (this._map) {
687
- this._map.dragging.disable();
688
- //TODO refactor: move cursor to styles
689
- this._container.style.cursor = 'crosshair';
690
-
691
- this._tooltip.updateContent({ text: this._initialLabelText });
692
-
693
- this._map
694
- .on('mousedown', this._onMouseDown, this)
695
- .on('mousemove', this._onMouseMove, this);
696
- }
697
- },
698
-
699
- removeHooks: function () {
700
- L.Draw.Feature.prototype.removeHooks.call(this);
701
- if (this._map) {
702
- this._map.dragging.enable();
703
- //TODO refactor: move cursor to styles
704
- this._container.style.cursor = '';
705
-
706
- this._map
707
- .off('mousedown', this._onMouseDown, this)
708
- .off('mousemove', this._onMouseMove, this);
709
-
710
- L.DomEvent.off(document, 'mouseup', this._onMouseUp);
711
-
712
- // If the box element doesn't exist they must not have moved the mouse, so don't need to destroy/return
713
- if (this._shape) {
714
- this._map.removeLayer(this._shape);
715
- delete this._shape;
716
- }
717
- }
718
- this._isDrawing = false;
719
- },
720
-
721
- _onMouseDown: function (e) {
722
- this._isDrawing = true;
723
- this._startLatLng = e.latlng;
724
-
725
- L.DomEvent
726
- .on(document, 'mouseup', this._onMouseUp, this)
727
- .preventDefault(e.originalEvent);
728
- },
729
-
730
- _onMouseMove: function (e) {
731
- var latlng = e.latlng;
732
-
733
- this._tooltip.updatePosition(latlng);
734
- if (this._isDrawing) {
735
- this._tooltip.updateContent({ text: this._endLabelText });
736
- this._drawShape(latlng);
737
- }
738
- },
739
-
740
- _onMouseUp: function () {
741
- if (this._shape) {
742
- this._fireCreatedEvent();
743
- }
744
-
745
- this.disable();
746
- if (this.options.repeatMode) {
747
- this.enable();
748
- }
749
- }
750
- });
751
-
752
- L.Draw.Rectangle = L.Draw.SimpleShape.extend({
753
- statics: {
754
- TYPE: 'rectangle'
755
- },
756
-
757
- options: {
758
- shapeOptions: {
759
- stroke: true,
760
- color: '#f06eaa',
761
- weight: 4,
762
- opacity: 0.5,
763
- fill: true,
764
- fillColor: null, //same as color by default
765
- fillOpacity: 0.2,
766
- clickable: true
767
- }
768
- },
769
-
770
- initialize: function (map, options) {
771
- // Save the type so super can fire, need to do this as cannot do this.TYPE :(
772
- this.type = L.Draw.Rectangle.TYPE;
773
-
774
- this._initialLabelText = L.drawLocal.draw.handlers.rectangle.tooltip.start;
775
-
776
- L.Draw.SimpleShape.prototype.initialize.call(this, map, options);
777
- },
778
-
779
- _drawShape: function (latlng) {
780
- if (!this._shape) {
781
- this._shape = new L.Rectangle(new L.LatLngBounds(this._startLatLng, latlng), this.options.shapeOptions);
782
- this._map.addLayer(this._shape);
783
- } else {
784
- this._shape.setBounds(new L.LatLngBounds(this._startLatLng, latlng));
785
- }
786
- },
787
-
788
- _fireCreatedEvent: function () {
789
- var rectangle = new L.Rectangle(this._shape.getBounds(), this.options.shapeOptions);
790
- L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, rectangle);
791
- }
792
- });
793
-
794
-
795
- L.Draw.Circle = L.Draw.SimpleShape.extend({
796
- statics: {
797
- TYPE: 'circle'
798
- },
799
-
800
- options: {
801
- shapeOptions: {
802
- stroke: true,
803
- color: '#f06eaa',
804
- weight: 4,
805
- opacity: 0.5,
806
- fill: true,
807
- fillColor: null, //same as color by default
808
- fillOpacity: 0.2,
809
- clickable: true
810
- },
811
- showRadius: true,
812
- metric: true // Whether to use the metric meaurement system or imperial
813
- },
814
-
815
- initialize: function (map, options) {
816
- // Save the type so super can fire, need to do this as cannot do this.TYPE :(
817
- this.type = L.Draw.Circle.TYPE;
818
-
819
- this._initialLabelText = L.drawLocal.draw.handlers.circle.tooltip.start;
820
-
821
- L.Draw.SimpleShape.prototype.initialize.call(this, map, options);
822
- },
823
-
824
- _drawShape: function (latlng) {
825
- if (!this._shape) {
826
- this._shape = new L.Circle(this._startLatLng, this._startLatLng.distanceTo(latlng), this.options.shapeOptions);
827
- this._map.addLayer(this._shape);
828
- } else {
829
- this._shape.setRadius(this._startLatLng.distanceTo(latlng));
830
- }
831
- },
832
-
833
- _fireCreatedEvent: function () {
834
- var circle = new L.Circle(this._startLatLng, this._shape.getRadius(), this.options.shapeOptions);
835
- L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, circle);
836
- },
837
-
838
- _onMouseMove: function (e) {
839
- var latlng = e.latlng,
840
- metric = this.options.metric,
841
- showRadius = this.options.showRadius,
842
- useMetric = this.options.metric,
843
- radius;
844
-
845
- this._tooltip.updatePosition(latlng);
846
- if (this._isDrawing) {
847
- this._drawShape(latlng);
848
-
849
- // Get the new radius (rouded to 1 dp)
850
- radius = this._shape.getRadius().toFixed(1);
851
-
852
- this._tooltip.updateContent({
853
- text: this._endLabelText,
854
- subtext: showRadius ? 'Radius: ' + L.GeometryUtil.readableDistance(radius, useMetric) : ''
855
- });
856
- }
857
- }
858
- });
859
-
860
-
861
- L.Draw.Marker = L.Draw.Feature.extend({
862
- statics: {
863
- TYPE: 'marker'
864
- },
865
-
866
- options: {
867
- icon: new L.Icon.Default(),
868
- repeatMode: false,
869
- zIndexOffset: 2000 // This should be > than the highest z-index any markers
870
- },
871
-
872
- initialize: function (map, options) {
873
- // Save the type so super can fire, need to do this as cannot do this.TYPE :(
874
- this.type = L.Draw.Marker.TYPE;
875
-
876
- L.Draw.Feature.prototype.initialize.call(this, map, options);
877
- },
878
-
879
- addHooks: function () {
880
- L.Draw.Feature.prototype.addHooks.call(this);
881
-
882
- if (this._map) {
883
- this._tooltip.updateContent({ text: L.drawLocal.draw.handlers.marker.tooltip.start });
884
-
885
- // Same mouseMarker as in Draw.Polyline
886
- if (!this._mouseMarker) {
887
- this._mouseMarker = L.marker(this._map.getCenter(), {
888
- icon: L.divIcon({
889
- className: 'leaflet-mouse-marker',
890
- iconAnchor: [20, 20],
891
- iconSize: [40, 40]
892
- }),
893
- opacity: 0,
894
- zIndexOffset: this.options.zIndexOffset
895
- });
896
- }
897
-
898
- this._mouseMarker
899
- .on('click', this._onClick, this)
900
- .addTo(this._map);
901
-
902
- this._map.on('mousemove', this._onMouseMove, this);
903
- }
904
- },
905
-
906
- removeHooks: function () {
907
- L.Draw.Feature.prototype.removeHooks.call(this);
908
-
909
- if (this._map) {
910
- if (this._marker) {
911
- this._marker.off('click', this._onClick, this);
912
- this._map
913
- .off('click', this._onClick, this)
914
- .removeLayer(this._marker);
915
- delete this._marker;
916
- }
917
-
918
- this._mouseMarker.off('click', this._onClick, this);
919
- this._map.removeLayer(this._mouseMarker);
920
- delete this._mouseMarker;
921
-
922
- this._map.off('mousemove', this._onMouseMove, this);
923
- }
924
- },
925
-
926
- _onMouseMove: function (e) {
927
- var latlng = e.latlng;
928
-
929
- this._tooltip.updatePosition(latlng);
930
- this._mouseMarker.setLatLng(latlng);
931
-
932
- if (!this._marker) {
933
- this._marker = new L.Marker(latlng, {
934
- icon: this.options.icon,
935
- zIndexOffset: this.options.zIndexOffset
936
- });
937
- // Bind to both marker and map to make sure we get the click event.
938
- this._marker.on('click', this._onClick, this);
939
- this._map
940
- .on('click', this._onClick, this)
941
- .addLayer(this._marker);
942
- }
943
- else {
944
- latlng = this._mouseMarker.getLatLng();
945
- this._marker.setLatLng(latlng);
946
- }
947
- },
948
-
949
- _onClick: function () {
950
- this._fireCreatedEvent();
951
-
952
- this.disable();
953
- if (this.options.repeatMode) {
954
- this.enable();
955
- }
956
- },
957
-
958
- _fireCreatedEvent: function () {
959
- var marker = new L.Marker(this._marker.getLatLng(), { icon: this.options.icon });
960
- L.Draw.Feature.prototype._fireCreatedEvent.call(this, marker);
961
- }
962
- });
963
-
964
-
965
- L.Edit = L.Edit || {};
966
-
967
- /*
968
- * L.Edit.Poly is an editing handler for polylines and polygons.
969
- */
970
-
971
- L.Edit.Poly = L.Handler.extend({
972
- options: {
973
- icon: new L.DivIcon({
974
- iconSize: new L.Point(8, 8),
975
- className: 'leaflet-div-icon leaflet-editing-icon'
976
- })
977
- },
978
-
979
- initialize: function (poly, options) {
980
- this._poly = poly;
981
- L.setOptions(this, options);
982
- },
983
-
984
- addHooks: function () {
985
- if (this._poly._map) {
986
- if (!this._markerGroup) {
987
- this._initMarkers();
988
- }
989
- this._poly._map.addLayer(this._markerGroup);
990
- }
991
- },
992
-
993
- removeHooks: function () {
994
- if (this._poly._map) {
995
- this._poly._map.removeLayer(this._markerGroup);
996
- delete this._markerGroup;
997
- delete this._markers;
998
- }
999
- },
1000
-
1001
- updateMarkers: function () {
1002
- this._markerGroup.clearLayers();
1003
- this._initMarkers();
1004
- },
1005
-
1006
- _initMarkers: function () {
1007
- if (!this._markerGroup) {
1008
- this._markerGroup = new L.LayerGroup();
1009
- }
1010
- this._markers = [];
1011
-
1012
- var latlngs = this._poly._latlngs,
1013
- i, j, len, marker;
1014
-
1015
- // TODO refactor holes implementation in Polygon to support it here
1016
-
1017
- for (i = 0, len = latlngs.length; i < len; i++) {
1018
-
1019
- marker = this._createMarker(latlngs[i], i);
1020
- marker.on('click', this._onMarkerClick, this);
1021
- this._markers.push(marker);
1022
- }
1023
-
1024
- var markerLeft, markerRight;
1025
-
1026
- for (i = 0, j = len - 1; i < len; j = i++) {
1027
- if (i === 0 && !(L.Polygon && (this._poly instanceof L.Polygon))) {
1028
- continue;
1029
- }
1030
-
1031
- markerLeft = this._markers[j];
1032
- markerRight = this._markers[i];
1033
-
1034
- this._createMiddleMarker(markerLeft, markerRight);
1035
- this._updatePrevNext(markerLeft, markerRight);
1036
- }
1037
- },
1038
-
1039
- _createMarker: function (latlng, index) {
1040
- var marker = new L.Marker(latlng, {
1041
- draggable: true,
1042
- icon: this.options.icon
1043
- });
1044
-
1045
- marker._origLatLng = latlng;
1046
- marker._index = index;
1047
-
1048
- marker.on('drag', this._onMarkerDrag, this);
1049
- marker.on('dragend', this._fireEdit, this);
1050
-
1051
- this._markerGroup.addLayer(marker);
1052
-
1053
- return marker;
1054
- },
1055
-
1056
- _removeMarker: function (marker) {
1057
- var i = marker._index;
1058
-
1059
- this._markerGroup.removeLayer(marker);
1060
- this._markers.splice(i, 1);
1061
- this._poly.spliceLatLngs(i, 1);
1062
- this._updateIndexes(i, -1);
1063
-
1064
- marker
1065
- .off('drag', this._onMarkerDrag, this)
1066
- .off('dragend', this._fireEdit, this)
1067
- .off('click', this._onMarkerClick, this);
1068
- },
1069
-
1070
- _fireEdit: function () {
1071
- this._poly.edited = true;
1072
- this._poly.fire('edit');
1073
- },
1074
-
1075
- _onMarkerDrag: function (e) {
1076
- var marker = e.target;
1077
-
1078
- L.extend(marker._origLatLng, marker._latlng);
1079
-
1080
- if (marker._middleLeft) {
1081
- marker._middleLeft.setLatLng(this._getMiddleLatLng(marker._prev, marker));
1082
- }
1083
- if (marker._middleRight) {
1084
- marker._middleRight.setLatLng(this._getMiddleLatLng(marker, marker._next));
1085
- }
1086
-
1087
- this._poly.redraw();
1088
- },
1089
-
1090
- _onMarkerClick: function (e) {
1091
- var minPoints = L.Polygon && (this._poly instanceof L.Polygon) ? 4 : 3,
1092
- marker = e.target;
1093
-
1094
- // If removing this point would create an invalid polyline/polygon don't remove
1095
- if (this._poly._latlngs.length < minPoints) {
1096
- return;
1097
- }
1098
-
1099
- // remove the marker
1100
- this._removeMarker(marker);
1101
-
1102
- // update prev/next links of adjacent markers
1103
- this._updatePrevNext(marker._prev, marker._next);
1104
-
1105
- // remove ghost markers near the removed marker
1106
- if (marker._middleLeft) {
1107
- this._markerGroup.removeLayer(marker._middleLeft);
1108
- }
1109
- if (marker._middleRight) {
1110
- this._markerGroup.removeLayer(marker._middleRight);
1111
- }
1112
-
1113
- // create a ghost marker in place of the removed one
1114
- if (marker._prev && marker._next) {
1115
- this._createMiddleMarker(marker._prev, marker._next);
1116
-
1117
- } else if (!marker._prev) {
1118
- marker._next._middleLeft = null;
1119
-
1120
- } else if (!marker._next) {
1121
- marker._prev._middleRight = null;
1122
- }
1123
-
1124
- this._fireEdit();
1125
- },
1126
-
1127
- _updateIndexes: function (index, delta) {
1128
- this._markerGroup.eachLayer(function (marker) {
1129
- if (marker._index > index) {
1130
- marker._index += delta;
1131
- }
1132
- });
1133
- },
1134
-
1135
- _createMiddleMarker: function (marker1, marker2) {
1136
- var latlng = this._getMiddleLatLng(marker1, marker2),
1137
- marker = this._createMarker(latlng),
1138
- onClick,
1139
- onDragStart,
1140
- onDragEnd;
1141
-
1142
- marker.setOpacity(0.6);
1143
-
1144
- marker1._middleRight = marker2._middleLeft = marker;
1145
-
1146
- onDragStart = function () {
1147
- var i = marker2._index;
1148
-
1149
- marker._index = i;
1150
-
1151
- marker
1152
- .off('click', onClick, this)
1153
- .on('click', this._onMarkerClick, this);
1154
-
1155
- latlng.lat = marker.getLatLng().lat;
1156
- latlng.lng = marker.getLatLng().lng;
1157
- this._poly.spliceLatLngs(i, 0, latlng);
1158
- this._markers.splice(i, 0, marker);
1159
-
1160
- marker.setOpacity(1);
1161
-
1162
- this._updateIndexes(i, 1);
1163
- marker2._index++;
1164
- this._updatePrevNext(marker1, marker);
1165
- this._updatePrevNext(marker, marker2);
1166
- };
1167
-
1168
- onDragEnd = function () {
1169
- marker.off('dragstart', onDragStart, this);
1170
- marker.off('dragend', onDragEnd, this);
1171
-
1172
- this._createMiddleMarker(marker1, marker);
1173
- this._createMiddleMarker(marker, marker2);
1174
- };
1175
-
1176
- onClick = function () {
1177
- onDragStart.call(this);
1178
- onDragEnd.call(this);
1179
- this._fireEdit();
1180
- };
1181
-
1182
- marker
1183
- .on('click', onClick, this)
1184
- .on('dragstart', onDragStart, this)
1185
- .on('dragend', onDragEnd, this);
1186
-
1187
- this._markerGroup.addLayer(marker);
1188
- },
1189
-
1190
- _updatePrevNext: function (marker1, marker2) {
1191
- if (marker1) {
1192
- marker1._next = marker2;
1193
- }
1194
- if (marker2) {
1195
- marker2._prev = marker1;
1196
- }
1197
- },
1198
-
1199
- _getMiddleLatLng: function (marker1, marker2) {
1200
- var map = this._poly._map,
1201
- p1 = map.project(marker1.getLatLng()),
1202
- p2 = map.project(marker2.getLatLng());
1203
-
1204
- return map.unproject(p1._add(p2)._divideBy(2));
1205
- }
1206
- });
1207
-
1208
- L.Polyline.addInitHook(function () {
1209
-
1210
- // Check to see if handler has already been initialized. This is to support versions of Leaflet that still have L.Handler.PolyEdit
1211
- if (this.editing) {
1212
- return;
1213
- }
1214
-
1215
- if (L.Edit.Poly) {
1216
- this.editing = new L.Edit.Poly(this);
1217
-
1218
- if (this.options.editable) {
1219
- this.editing.enable();
1220
- }
1221
- }
1222
-
1223
- this.on('add', function () {
1224
- if (this.editing && this.editing.enabled()) {
1225
- this.editing.addHooks();
1226
- }
1227
- });
1228
-
1229
- this.on('remove', function () {
1230
- if (this.editing && this.editing.enabled()) {
1231
- this.editing.removeHooks();
1232
- }
1233
- });
1234
- });
1235
-
1236
-
1237
- L.Edit = L.Edit || {};
1238
-
1239
- L.Edit.SimpleShape = L.Handler.extend({
1240
- options: {
1241
- moveIcon: new L.DivIcon({
1242
- iconSize: new L.Point(8, 8),
1243
- className: 'leaflet-div-icon leaflet-editing-icon leaflet-edit-move'
1244
- }),
1245
- resizeIcon: new L.DivIcon({
1246
- iconSize: new L.Point(8, 8),
1247
- className: 'leaflet-div-icon leaflet-editing-icon leaflet-edit-resize'
1248
- })
1249
- },
1250
-
1251
- initialize: function (shape, options) {
1252
- this._shape = shape;
1253
- L.Util.setOptions(this, options);
1254
- },
1255
-
1256
- addHooks: function () {
1257
- if (this._shape._map) {
1258
- this._map = this._shape._map;
1259
-
1260
- if (!this._markerGroup) {
1261
- this._initMarkers();
1262
- }
1263
- this._map.addLayer(this._markerGroup);
1264
- }
1265
- },
1266
-
1267
- removeHooks: function () {
1268
- if (this._shape._map) {
1269
- this._unbindMarker(this._moveMarker);
1270
-
1271
- for (var i = 0, l = this._resizeMarkers.length; i < l; i++) {
1272
- this._unbindMarker(this._resizeMarkers[i]);
1273
- }
1274
- this._resizeMarkers = null;
1275
-
1276
- this._map.removeLayer(this._markerGroup);
1277
- delete this._markerGroup;
1278
- }
1279
-
1280
- this._map = null;
1281
- },
1282
-
1283
- updateMarkers: function () {
1284
- this._markerGroup.clearLayers();
1285
- this._initMarkers();
1286
- },
1287
-
1288
- _initMarkers: function () {
1289
- if (!this._markerGroup) {
1290
- this._markerGroup = new L.LayerGroup();
1291
- }
1292
-
1293
- // Create center marker
1294
- this._createMoveMarker();
1295
-
1296
- // Create edge marker
1297
- this._createResizeMarker();
1298
- },
1299
-
1300
- _createMoveMarker: function () {
1301
- // Children override
1302
- },
1303
-
1304
- _createResizeMarker: function () {
1305
- // Children override
1306
- },
1307
-
1308
- _createMarker: function (latlng, icon) {
1309
- var marker = new L.Marker(latlng, {
1310
- draggable: true,
1311
- icon: icon,
1312
- zIndexOffset: 10
1313
- });
1314
-
1315
- this._bindMarker(marker);
1316
-
1317
- this._markerGroup.addLayer(marker);
1318
-
1319
- return marker;
1320
- },
1321
-
1322
- _bindMarker: function (marker) {
1323
- marker
1324
- .on('dragstart', this._onMarkerDragStart, this)
1325
- .on('drag', this._onMarkerDrag, this)
1326
- .on('dragend', this._onMarkerDragEnd, this);
1327
- },
1328
-
1329
- _unbindMarker: function (marker) {
1330
- marker
1331
- .off('dragstart', this._onMarkerDragStart, this)
1332
- .off('drag', this._onMarkerDrag, this)
1333
- .off('dragend', this._onMarkerDragEnd, this);
1334
- },
1335
-
1336
- _onMarkerDragStart: function (e) {
1337
- var marker = e.target;
1338
- marker.setOpacity(0);
1339
- },
1340
-
1341
- _fireEdit: function () {
1342
- this._shape.edited = true;
1343
- this._shape.fire('edit');
1344
- },
1345
-
1346
- _onMarkerDrag: function (e) {
1347
- var marker = e.target,
1348
- latlng = marker.getLatLng();
1349
-
1350
- if (marker === this._moveMarker) {
1351
- this._move(latlng);
1352
- } else {
1353
- this._resize(latlng);
1354
- }
1355
-
1356
- this._shape.redraw();
1357
- },
1358
-
1359
- _onMarkerDragEnd: function (e) {
1360
- var marker = e.target;
1361
- marker.setOpacity(1);
1362
-
1363
- this._fireEdit();
1364
- },
1365
-
1366
- _move: function () {
1367
- // Children override
1368
- },
1369
-
1370
- _resize: function () {
1371
- // Children override
1372
- }
1373
- });
1374
-
1375
-
1376
- L.Edit = L.Edit || {};
1377
-
1378
- L.Edit.Rectangle = L.Edit.SimpleShape.extend({
1379
- _createMoveMarker: function () {
1380
- var bounds = this._shape.getBounds(),
1381
- center = bounds.getCenter();
1382
-
1383
- this._moveMarker = this._createMarker(center, this.options.moveIcon);
1384
- },
1385
-
1386
- _createResizeMarker: function () {
1387
- var corners = this._getCorners();
1388
-
1389
- this._resizeMarkers = [];
1390
-
1391
- for (var i = 0, l = corners.length; i < l; i++) {
1392
- this._resizeMarkers.push(this._createMarker(corners[i], this.options.resizeIcon));
1393
- // Monkey in the corner index as we will need to know this for dragging
1394
- this._resizeMarkers[i]._cornerIndex = i;
1395
- }
1396
- },
1397
-
1398
- _onMarkerDragStart: function (e) {
1399
- L.Edit.SimpleShape.prototype._onMarkerDragStart.call(this, e);
1400
-
1401
- // Save a reference to the opposite point
1402
- var corners = this._getCorners(),
1403
- marker = e.target,
1404
- currentCornerIndex = marker._cornerIndex;
1405
-
1406
- this._oppositeCorner = corners[(currentCornerIndex + 2) % 4];
1407
-
1408
- this._toggleCornerMarkers(0, currentCornerIndex);
1409
- },
1410
-
1411
- _onMarkerDragEnd: function (e) {
1412
- var marker = e.target,
1413
- bounds, center;
1414
-
1415
- // Reset move marker position to the center
1416
- if (marker === this._moveMarker) {
1417
- bounds = this._shape.getBounds();
1418
- center = bounds.getCenter();
1419
-
1420
- marker.setLatLng(center);
1421
- }
1422
-
1423
- this._toggleCornerMarkers(1);
1424
-
1425
- this._repositionCornerMarkers();
1426
-
1427
- L.Edit.SimpleShape.prototype._onMarkerDragEnd.call(this, e);
1428
- },
1429
-
1430
- _move: function (newCenter) {
1431
- var latlngs = this._shape.getLatLngs(),
1432
- bounds = this._shape.getBounds(),
1433
- center = bounds.getCenter(),
1434
- offset, newLatLngs = [];
1435
-
1436
- // Offset the latlngs to the new center
1437
- for (var i = 0, l = latlngs.length; i < l; i++) {
1438
- offset = [latlngs[i].lat - center.lat, latlngs[i].lng - center.lng];
1439
- newLatLngs.push([newCenter.lat + offset[0], newCenter.lng + offset[1]]);
1440
- }
1441
-
1442
- this._shape.setLatLngs(newLatLngs);
1443
-
1444
- // Respoition the resize markers
1445
- this._repositionCornerMarkers();
1446
- },
1447
-
1448
- _resize: function (latlng) {
1449
- var bounds;
1450
-
1451
- // Update the shape based on the current position of this corner and the opposite point
1452
- this._shape.setBounds(L.latLngBounds(latlng, this._oppositeCorner));
1453
-
1454
- // Respoition the move marker
1455
- bounds = this._shape.getBounds();
1456
- this._moveMarker.setLatLng(bounds.getCenter());
1457
- },
1458
-
1459
- _getCorners: function () {
1460
- var bounds = this._shape.getBounds(),
1461
- nw = bounds.getNorthWest(),
1462
- ne = bounds.getNorthEast(),
1463
- se = bounds.getSouthEast(),
1464
- sw = bounds.getSouthWest();
1465
-
1466
- return [nw, ne, se, sw];
1467
- },
1468
-
1469
- _toggleCornerMarkers: function (opacity) {
1470
- for (var i = 0, l = this._resizeMarkers.length; i < l; i++) {
1471
- this._resizeMarkers[i].setOpacity(opacity);
1472
- }
1473
- },
1474
-
1475
- _repositionCornerMarkers: function () {
1476
- var corners = this._getCorners();
1477
-
1478
- for (var i = 0, l = this._resizeMarkers.length; i < l; i++) {
1479
- this._resizeMarkers[i].setLatLng(corners[i]);
1480
- }
1481
- }
1482
- });
1483
-
1484
- L.Rectangle.addInitHook(function () {
1485
- if (L.Edit.Rectangle) {
1486
- this.editing = new L.Edit.Rectangle(this);
1487
-
1488
- if (this.options.editable) {
1489
- this.editing.enable();
1490
- }
1491
- }
1492
- });
1493
-
1494
- L.Edit = L.Edit || {};
1495
-
1496
- L.Edit.Circle = L.Edit.SimpleShape.extend({
1497
- _createMoveMarker: function () {
1498
- var center = this._shape.getLatLng();
1499
-
1500
- this._moveMarker = this._createMarker(center, this.options.moveIcon);
1501
- },
1502
-
1503
- _createResizeMarker: function () {
1504
- var center = this._shape.getLatLng(),
1505
- resizemarkerPoint = this._getResizeMarkerPoint(center);
1506
-
1507
- this._resizeMarkers = [];
1508
- this._resizeMarkers.push(this._createMarker(resizemarkerPoint, this.options.resizeIcon));
1509
- },
1510
-
1511
- _getResizeMarkerPoint: function (latlng) {
1512
- // From L.shape.getBounds()
1513
- var delta = this._shape._radius * Math.cos(Math.PI / 4),
1514
- point = this._map.project(latlng);
1515
- return this._map.unproject([point.x + delta, point.y - delta]);
1516
- },
1517
-
1518
- _move: function (latlng) {
1519
- var resizemarkerPoint = this._getResizeMarkerPoint(latlng);
1520
-
1521
- // Move the resize marker
1522
- this._resizeMarkers[0].setLatLng(resizemarkerPoint);
1523
-
1524
- // Move the circle
1525
- this._shape.setLatLng(latlng);
1526
- },
1527
-
1528
- _resize: function (latlng) {
1529
- var moveLatLng = this._moveMarker.getLatLng(),
1530
- radius = moveLatLng.distanceTo(latlng);
1531
-
1532
- this._shape.setRadius(radius);
1533
- }
1534
- });
1535
-
1536
- L.Circle.addInitHook(function () {
1537
- if (L.Edit.Circle) {
1538
- this.editing = new L.Edit.Circle(this);
1539
-
1540
- if (this.options.editable) {
1541
- this.editing.enable();
1542
- }
1543
- }
1544
-
1545
- this.on('add', function () {
1546
- if (this.editing && this.editing.enabled()) {
1547
- this.editing.addHooks();
1548
- }
1549
- });
1550
-
1551
- this.on('remove', function () {
1552
- if (this.editing && this.editing.enabled()) {
1553
- this.editing.removeHooks();
1554
- }
1555
- });
1556
- });
1557
-
1558
- /*
1559
- * L.LatLngUtil contains different utility functions for LatLngs.
1560
- */
1561
-
1562
- L.LatLngUtil = {
1563
- // Clones a LatLngs[], returns [][]
1564
- cloneLatLngs: function (latlngs) {
1565
- var clone = [];
1566
- for (var i = 0, l = latlngs.length; i < l; i++) {
1567
- clone.push(this.cloneLatLng(latlngs[i]));
1568
- }
1569
- return clone;
1570
- },
1571
-
1572
- cloneLatLng: function (latlng) {
1573
- return L.latLng(latlng.lat, latlng.lng);
1574
- }
1575
- };
1576
-
1577
- L.GeometryUtil = {
1578
- // Ported from the OpenLayers implementation. See https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Geometry/LinearRing.js#L270
1579
- geodesicArea: function (latLngs) {
1580
- var pointsCount = latLngs.length,
1581
- area = 0.0,
1582
- d2r = L.LatLng.DEG_TO_RAD,
1583
- p1, p2;
1584
-
1585
- if (pointsCount > 2) {
1586
- for (var i = 0; i < pointsCount; i++) {
1587
- p1 = latLngs[i];
1588
- p2 = latLngs[(i + 1) % pointsCount];
1589
- area += ((p2.lng - p1.lng) * d2r) *
1590
- (2 + Math.sin(p1.lat * d2r) + Math.sin(p2.lat * d2r));
1591
- }
1592
- area = area * 6378137.0 * 6378137.0 / 2.0;
1593
- }
1594
-
1595
- return Math.abs(area);
1596
- },
1597
-
1598
- readableArea: function (area, isMetric) {
1599
- var areaStr;
1600
-
1601
- if (isMetric) {
1602
- if (area >= 10000) {
1603
- areaStr = (area * 0.0001).toFixed(2) + ' ha';
1604
- } else {
1605
- areaStr = area.toFixed(2) + ' m&sup2;';
1606
- }
1607
- } else {
1608
- area *= 0.836127; // Square yards in 1 meter
1609
-
1610
- if (area >= 3097600) { //3097600 square yards in 1 square mile
1611
- areaStr = (area / 3097600).toFixed(2) + ' mi&sup2;';
1612
- } else if (area >= 4840) {//48040 square yards in 1 acre
1613
- areaStr = (area / 4840).toFixed(2) + ' acres';
1614
- } else {
1615
- areaStr = Math.ceil(area) + ' yd&sup2;';
1616
- }
1617
- }
1618
-
1619
- return areaStr;
1620
- },
1621
-
1622
- readableDistance: function (distance, isMetric) {
1623
- var distanceStr;
1624
-
1625
- if (isMetric) {
1626
- // show metres when distance is < 1km, then show km
1627
- if (distance > 1000) {
1628
- distanceStr = (distance / 1000).toFixed(2) + ' km';
1629
- } else {
1630
- distanceStr = Math.ceil(distance) + ' m';
1631
- }
1632
- } else {
1633
- distance *= 1.09361;
1634
-
1635
- if (distance > 1760) {
1636
- distanceStr = (distance / 1760).toFixed(2) + ' miles';
1637
- } else {
1638
- distanceStr = Math.ceil(distance) + ' yd';
1639
- }
1640
- }
1641
-
1642
- return distanceStr;
1643
- }
1644
- };
1645
-
1646
- L.Util.extend(L.LineUtil, {
1647
- // Checks to see if two line segments intersect. Does not handle degenerate cases.
1648
- // http://compgeom.cs.uiuc.edu/~jeffe/teaching/373/notes/x06-sweepline.pdf
1649
- segmentsIntersect: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2, /*Point*/ p3) {
1650
- return this._checkCounterclockwise(p, p2, p3) !==
1651
- this._checkCounterclockwise(p1, p2, p3) &&
1652
- this._checkCounterclockwise(p, p1, p2) !==
1653
- this._checkCounterclockwise(p, p1, p3);
1654
- },
1655
-
1656
- // check to see if points are in counterclockwise order
1657
- _checkCounterclockwise: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
1658
- return (p2.y - p.y) * (p1.x - p.x) > (p1.y - p.y) * (p2.x - p.x);
1659
- }
1660
- });
1661
-
1662
- L.Polyline.include({
1663
- // Check to see if this polyline has any linesegments that intersect.
1664
- // NOTE: does not support detecting intersection for degenerate cases.
1665
- intersects: function () {
1666
- var points = this._originalPoints,
1667
- len = points ? points.length : 0,
1668
- i, p, p1;
1669
-
1670
- if (this._tooFewPointsForIntersection()) {
1671
- return false;
1672
- }
1673
-
1674
- for (i = len - 1; i >= 3; i--) {
1675
- p = points[i - 1];
1676
- p1 = points[i];
1677
-
1678
-
1679
- if (this._lineSegmentsIntersectsRange(p, p1, i - 2)) {
1680
- return true;
1681
- }
1682
- }
1683
-
1684
- return false;
1685
- },
1686
-
1687
- // Check for intersection if new latlng was added to this polyline.
1688
- // NOTE: does not support detecting intersection for degenerate cases.
1689
- newLatLngIntersects: function (latlng, skipFirst) {
1690
- // Cannot check a polyline for intersecting lats/lngs when not added to the map
1691
- if (!this._map) {
1692
- return false;
1693
- }
1694
-
1695
- return this.newPointIntersects(this._map.latLngToLayerPoint(latlng), skipFirst);
1696
- },
1697
-
1698
- // Check for intersection if new point was added to this polyline.
1699
- // newPoint must be a layer point.
1700
- // NOTE: does not support detecting intersection for degenerate cases.
1701
- newPointIntersects: function (newPoint, skipFirst) {
1702
- var points = this._originalPoints,
1703
- len = points ? points.length : 0,
1704
- lastPoint = points ? points[len - 1] : null,
1705
- // The previous previous line segment. Previous line segement doesn't need testing.
1706
- maxIndex = len - 2;
1707
-
1708
- if (this._tooFewPointsForIntersection(1)) {
1709
- return false;
1710
- }
1711
-
1712
- return this._lineSegmentsIntersectsRange(lastPoint, newPoint, maxIndex, skipFirst ? 1 : 0);
1713
- },
1714
-
1715
- // Polylines with 2 sides can only intersect in cases where points are collinear (we don't support detecting these).
1716
- // Cannot have intersection when < 3 line segments (< 4 points)
1717
- _tooFewPointsForIntersection: function (extraPoints) {
1718
- var points = this._originalPoints,
1719
- len = points ? points.length : 0;
1720
- // Increment length by extraPoints if present
1721
- len += extraPoints || 0;
1722
-
1723
- return !this._originalPoints || len <= 3;
1724
- },
1725
-
1726
- // Checks a line segment intersections with any line segements before its predecessor.
1727
- // Don't need to check the predecessor as will never intersect.
1728
- _lineSegmentsIntersectsRange: function (p, p1, maxIndex, minIndex) {
1729
- var points = this._originalPoints,
1730
- p2, p3;
1731
-
1732
- minIndex = minIndex || 0;
1733
-
1734
- // Check all previous line segments (beside the immediately previous) for intersections
1735
- for (var j = maxIndex; j > minIndex; j--) {
1736
- p2 = points[j - 1];
1737
- p3 = points[j];
1738
-
1739
- if (L.LineUtil.segmentsIntersect(p, p1, p2, p3)) {
1740
- return true;
1741
- }
1742
- }
1743
-
1744
- return false;
1745
- }
1746
- });
1747
-
1748
- L.Polygon.include({
1749
- // Checks a polygon for any intersecting line segments. Ignores holes.
1750
- intersects: function () {
1751
- var polylineIntersects,
1752
- points = this._originalPoints,
1753
- len, firstPoint, lastPoint, maxIndex;
1754
-
1755
- if (this._tooFewPointsForIntersection()) {
1756
- return false;
1757
- }
1758
-
1759
- polylineIntersects = L.Polyline.prototype.intersects.call(this);
1760
-
1761
- // If already found an intersection don't need to check for any more.
1762
- if (polylineIntersects) {
1763
- return true;
1764
- }
1765
-
1766
- len = points.length;
1767
- firstPoint = points[0];
1768
- lastPoint = points[len - 1];
1769
- maxIndex = len - 2;
1770
-
1771
- // Check the line segment between last and first point. Don't need to check the first line segment (minIndex = 1)
1772
- return this._lineSegmentsIntersectsRange(lastPoint, firstPoint, maxIndex, 1);
1773
- }
1774
- });
1775
-
1776
- L.Control.Draw = L.Control.extend({
1777
-
1778
- options: {
1779
- position: 'topleft',
1780
- draw: {},
1781
- edit: false
1782
- },
1783
-
1784
- initialize: function (options) {
1785
- if (L.version <= "0.5.1") {
1786
- throw new Error('Leaflet.draw 0.2.0+ requires Leaflet 0.6.0+. Download latest from https://github.com/Leaflet/Leaflet/');
1787
- }
1788
-
1789
- L.Control.prototype.initialize.call(this, options);
1790
-
1791
- var id, toolbar;
1792
-
1793
- this._toolbars = {};
1794
-
1795
- // Initialize toolbars
1796
- if (L.DrawToolbar && this.options.draw) {
1797
- toolbar = new L.DrawToolbar(this.options.draw);
1798
- id = L.stamp(toolbar);
1799
- this._toolbars[id] = toolbar;
1800
-
1801
- // Listen for when toolbar is enabled
1802
- this._toolbars[id].on('enable', this._toolbarEnabled, this);
1803
- }
1804
-
1805
- if (L.EditToolbar && this.options.edit) {
1806
- toolbar = new L.EditToolbar(this.options.edit);
1807
- id = L.stamp(toolbar);
1808
- this._toolbars[id] = toolbar;
1809
-
1810
- // Listen for when toolbar is enabled
1811
- this._toolbars[id].on('enable', this._toolbarEnabled, this);
1812
- }
1813
- },
1814
-
1815
- onAdd: function (map) {
1816
- var container = L.DomUtil.create('div', 'leaflet-draw'),
1817
- addedTopClass = false,
1818
- topClassName = 'leaflet-draw-toolbar-top',
1819
- toolbarContainer;
1820
-
1821
- for (var toolbarId in this._toolbars) {
1822
- if (this._toolbars.hasOwnProperty(toolbarId)) {
1823
- toolbarContainer = this._toolbars[toolbarId].addToolbar(map);
1824
-
1825
- // Add class to the first toolbar to remove the margin
1826
- if (!addedTopClass) {
1827
- if (!L.DomUtil.hasClass(toolbarContainer, topClassName)) {
1828
- L.DomUtil.addClass(toolbarContainer.childNodes[0], topClassName);
1829
- }
1830
- addedTopClass = true;
1831
- }
1832
-
1833
- container.appendChild(toolbarContainer);
1834
- }
1835
- }
1836
-
1837
- return container;
1838
- },
1839
-
1840
- onRemove: function () {
1841
- for (var toolbarId in this._toolbars) {
1842
- if (this._toolbars.hasOwnProperty(toolbarId)) {
1843
- this._toolbars[toolbarId].removeToolbar();
1844
- }
1845
- }
1846
- },
1847
-
1848
- setDrawingOptions: function (options) {
1849
- for (var toolbarId in this._toolbars) {
1850
- if (this._toolbars[toolbarId] instanceof L.DrawToolbar) {
1851
- this._toolbars[toolbarId].setOptions(options);
1852
- }
1853
- }
1854
- },
1855
-
1856
- _toolbarEnabled: function (e) {
1857
- var id = '' + L.stamp(e.target);
1858
-
1859
- for (var toolbarId in this._toolbars) {
1860
- if (this._toolbars.hasOwnProperty(toolbarId) && toolbarId !== id) {
1861
- this._toolbars[toolbarId].disable();
1862
- }
1863
- }
1864
- }
1865
- });
1866
-
1867
- L.Map.mergeOptions({
1868
- drawControlTooltips: true,
1869
- drawControl: false
1870
- });
1871
-
1872
- L.Map.addInitHook(function () {
1873
- if (this.options.drawControl) {
1874
- this.drawControl = new L.Control.Draw();
1875
- this.addControl(this.drawControl);
1876
- }
1877
- });
1878
-
1879
- L.Toolbar = L.Class.extend({
1880
- includes: [L.Mixin.Events],
1881
-
1882
- initialize: function (options) {
1883
- L.setOptions(this, options);
1884
-
1885
- this._modes = {};
1886
- this._actionButtons = [];
1887
- this._activeMode = null;
1888
- },
1889
-
1890
- enabled: function () {
1891
- return this._activeMode !== null;
1892
- },
1893
-
1894
- disable: function () {
1895
- if (!this.enabled()) { return; }
1896
-
1897
- this._activeMode.handler.disable();
1898
- },
1899
-
1900
- removeToolbar: function () {
1901
- // Dispose each handler
1902
- for (var handlerId in this._modes) {
1903
- if (this._modes.hasOwnProperty(handlerId)) {
1904
- // Unbind handler button
1905
- this._disposeButton(this._modes[handlerId].button, this._modes[handlerId].handler.enable);
1906
-
1907
- // Make sure is disabled
1908
- this._modes[handlerId].handler.disable();
1909
-
1910
- // Unbind handler
1911
- this._modes[handlerId].handler
1912
- .off('enabled', this._handlerActivated, this)
1913
- .off('disabled', this._handlerDeactivated, this);
1914
- }
1915
- }
1916
- this._modes = {};
1917
-
1918
- // Dispose the actions toolbar
1919
- for (var i = 0, l = this._actionButtons.length; i < l; i++) {
1920
- this._disposeButton(this._actionButtons[i].button, this._actionButtons[i].callback);
1921
- }
1922
- this._actionButtons = [];
1923
- this._actionsContainer = null;
1924
- },
1925
-
1926
- _initModeHandler: function (handler, container, buttonIndex, classNamePredix, buttonTitle) {
1927
- var type = handler.type;
1928
-
1929
- this._modes[type] = {};
1930
-
1931
- this._modes[type].handler = handler;
1932
-
1933
- this._modes[type].button = this._createButton({
1934
- title: buttonTitle,
1935
- className: classNamePredix + '-' + type,
1936
- container: container,
1937
- callback: this._modes[type].handler.enable,
1938
- context: this._modes[type].handler
1939
- });
1940
-
1941
- this._modes[type].buttonIndex = buttonIndex;
1942
-
1943
- this._modes[type].handler
1944
- .on('enabled', this._handlerActivated, this)
1945
- .on('disabled', this._handlerDeactivated, this);
1946
- },
1947
-
1948
- _createButton: function (options) {
1949
- var link = L.DomUtil.create('a', options.className || '', options.container);
1950
- link.href = '#';
1951
-
1952
- if (options.text) {
1953
- link.innerHTML = options.text;
1954
- }
1955
-
1956
- if (options.title) {
1957
- link.title = options.title;
1958
- }
1959
-
1960
- L.DomEvent
1961
- .on(link, 'click', L.DomEvent.stopPropagation)
1962
- .on(link, 'mousedown', L.DomEvent.stopPropagation)
1963
- .on(link, 'dblclick', L.DomEvent.stopPropagation)
1964
- .on(link, 'click', L.DomEvent.preventDefault)
1965
- .on(link, 'click', options.callback, options.context);
1966
-
1967
- return link;
1968
- },
1969
-
1970
- _disposeButton: function (button, callback) {
1971
- L.DomEvent
1972
- .off(button, 'click', L.DomEvent.stopPropagation)
1973
- .off(button, 'mousedown', L.DomEvent.stopPropagation)
1974
- .off(button, 'dblclick', L.DomEvent.stopPropagation)
1975
- .off(button, 'click', L.DomEvent.preventDefault)
1976
- .off(button, 'click', callback);
1977
- },
1978
-
1979
- _handlerActivated: function (e) {
1980
- // Disable active mode (if present)
1981
- if (this._activeMode && this._activeMode.handler.enabled()) {
1982
- this._activeMode.handler.disable();
1983
- }
1984
-
1985
- // Cache new active feature
1986
- this._activeMode = this._modes[e.handler];
1987
-
1988
- L.DomUtil.addClass(this._activeMode.button, 'leaflet-draw-toolbar-button-enabled');
1989
-
1990
- this._showActionsToolbar();
1991
-
1992
- this.fire('enable');
1993
- },
1994
-
1995
- _handlerDeactivated: function () {
1996
- this._hideActionsToolbar();
1997
-
1998
- L.DomUtil.removeClass(this._activeMode.button, 'leaflet-draw-toolbar-button-enabled');
1999
-
2000
- this._activeMode = null;
2001
-
2002
- this.fire('disable');
2003
- },
2004
-
2005
- _createActions: function (buttons) {
2006
- var container = L.DomUtil.create('ul', 'leaflet-draw-actions'),
2007
- l = buttons.length,
2008
- li, button;
2009
-
2010
- for (var i = 0; i < l; i++) {
2011
- li = L.DomUtil.create('li', '', container);
2012
-
2013
- button = this._createButton({
2014
- title: buttons[i].title,
2015
- text: buttons[i].text,
2016
- container: li,
2017
- callback: buttons[i].callback,
2018
- context: buttons[i].context
2019
- });
2020
-
2021
- this._actionButtons.push({
2022
- button: button,
2023
- callback: buttons[i].callback
2024
- });
2025
- }
2026
-
2027
- return container;
2028
- },
2029
-
2030
- _showActionsToolbar: function () {
2031
- var buttonIndex = this._activeMode.buttonIndex,
2032
- lastButtonIndex = this._lastButtonIndex,
2033
- buttonHeight = 26, // TODO: this should be calculated
2034
- borderHeight = 1, // TODO: this should also be calculated
2035
- toolbarPosition = (buttonIndex * buttonHeight) + (buttonIndex * borderHeight) - 1;
2036
-
2037
- // Correctly position the cancel button
2038
- this._actionsContainer.style.top = toolbarPosition + 'px';
2039
-
2040
- if (buttonIndex === 0) {
2041
- L.DomUtil.addClass(this._toolbarContainer, 'leaflet-draw-toolbar-notop');
2042
- L.DomUtil.addClass(this._actionsContainer, 'leaflet-draw-actions-top');
2043
- }
2044
-
2045
- if (buttonIndex === lastButtonIndex) {
2046
- L.DomUtil.addClass(this._toolbarContainer, 'leaflet-draw-toolbar-nobottom');
2047
- L.DomUtil.addClass(this._actionsContainer, 'leaflet-draw-actions-bottom');
2048
- }
2049
-
2050
- this._actionsContainer.style.display = 'block';
2051
- },
2052
-
2053
- _hideActionsToolbar: function () {
2054
- this._actionsContainer.style.display = 'none';
2055
-
2056
- L.DomUtil.removeClass(this._toolbarContainer, 'leaflet-draw-toolbar-notop');
2057
- L.DomUtil.removeClass(this._toolbarContainer, 'leaflet-draw-toolbar-nobottom');
2058
- L.DomUtil.removeClass(this._actionsContainer, 'leaflet-draw-actions-top');
2059
- L.DomUtil.removeClass(this._actionsContainer, 'leaflet-draw-actions-bottom');
2060
- }
2061
- });
2062
-
2063
- L.Tooltip = L.Class.extend({
2064
- initialize: function (map) {
2065
- this._map = map;
2066
- this._popupPane = map._panes.popupPane;
2067
-
2068
- this._container = map.options.drawControlTooltips ? L.DomUtil.create('div', 'leaflet-draw-tooltip', this._popupPane) : null;
2069
- this._singleLineLabel = false;
2070
- },
2071
-
2072
- dispose: function () {
2073
- if (this._container) {
2074
- this._popupPane.removeChild(this._container);
2075
- this._container = null;
2076
- }
2077
- },
2078
-
2079
- updateContent: function (labelText) {
2080
- if (!this._container) {
2081
- return this;
2082
- }
2083
- labelText.subtext = labelText.subtext || '';
2084
-
2085
- // update the vertical position (only if changed)
2086
- if (labelText.subtext.length === 0 && !this._singleLineLabel) {
2087
- L.DomUtil.addClass(this._container, 'leaflet-draw-tooltip-single');
2088
- this._singleLineLabel = true;
2089
- }
2090
- else if (labelText.subtext.length > 0 && this._singleLineLabel) {
2091
- L.DomUtil.removeClass(this._container, 'leaflet-draw-tooltip-single');
2092
- this._singleLineLabel = false;
2093
- }
2094
-
2095
- this._container.innerHTML =
2096
- (labelText.subtext.length > 0 ? '<span class="leaflet-draw-tooltip-subtext">' + labelText.subtext + '</span>' + '<br />' : '') +
2097
- '<span>' + labelText.text + '</span>';
2098
-
2099
- return this;
2100
- },
2101
-
2102
- updatePosition: function (latlng) {
2103
- var pos = this._map.latLngToLayerPoint(latlng),
2104
- tooltipContainer = this._container;
2105
-
2106
- if (this._container) {
2107
- tooltipContainer.style.visibility = 'inherit';
2108
- L.DomUtil.setPosition(tooltipContainer, pos);
2109
- }
2110
-
2111
- return this;
2112
- },
2113
-
2114
- showAsError: function () {
2115
- if (this._container) {
2116
- L.DomUtil.addClass(this._container, 'leaflet-error-draw-tooltip');
2117
- }
2118
- return this;
2119
- },
2120
-
2121
- removeError: function () {
2122
- if (this._container) {
2123
- L.DomUtil.removeClass(this._container, 'leaflet-error-draw-tooltip');
2124
- }
2125
- return this;
2126
- }
2127
- });
2128
-
2129
- L.DrawToolbar = L.Toolbar.extend({
2130
-
2131
- options: {
2132
- polyline: {},
2133
- polygon: {},
2134
- rectangle: {},
2135
- circle: {},
2136
- marker: {}
2137
- },
2138
-
2139
- initialize: function (options) {
2140
- // Ensure that the options are merged correctly since L.extend is only shallow
2141
- for (var type in this.options) {
2142
- if (this.options.hasOwnProperty(type)) {
2143
- if (options[type]) {
2144
- options[type] = L.extend({}, this.options[type], options[type]);
2145
- }
2146
- }
2147
- }
2148
-
2149
- L.Toolbar.prototype.initialize.call(this, options);
2150
- },
2151
-
2152
- addToolbar: function (map) {
2153
- var container = L.DomUtil.create('div', 'leaflet-draw-section'),
2154
- buttonIndex = 0,
2155
- buttonClassPrefix = 'leaflet-draw-draw';
2156
-
2157
- this._toolbarContainer = L.DomUtil.create('div', 'leaflet-draw-toolbar leaflet-bar');
2158
-
2159
-
2160
- if (this.options.polyline) {
2161
- this._initModeHandler(
2162
- new L.Draw.Polyline(map, this.options.polyline),
2163
- this._toolbarContainer,
2164
- buttonIndex++,
2165
- buttonClassPrefix,
2166
- L.drawLocal.draw.toolbar.buttons.polyline
2167
- );
2168
- }
2169
-
2170
- if (this.options.polygon) {
2171
- this._initModeHandler(
2172
- new L.Draw.Polygon(map, this.options.polygon),
2173
- this._toolbarContainer,
2174
- buttonIndex++,
2175
- buttonClassPrefix,
2176
- L.drawLocal.draw.toolbar.buttons.polygon
2177
- );
2178
- }
2179
-
2180
- if (this.options.rectangle) {
2181
- this._initModeHandler(
2182
- new L.Draw.Rectangle(map, this.options.rectangle),
2183
- this._toolbarContainer,
2184
- buttonIndex++,
2185
- buttonClassPrefix,
2186
- L.drawLocal.draw.toolbar.buttons.rectangle
2187
- );
2188
- }
2189
-
2190
- if (this.options.circle) {
2191
- this._initModeHandler(
2192
- new L.Draw.Circle(map, this.options.circle),
2193
- this._toolbarContainer,
2194
- buttonIndex++,
2195
- buttonClassPrefix,
2196
- L.drawLocal.draw.toolbar.buttons.circle
2197
- );
2198
- }
2199
-
2200
- if (this.options.marker) {
2201
- this._initModeHandler(
2202
- new L.Draw.Marker(map, this.options.marker),
2203
- this._toolbarContainer,
2204
- buttonIndex++,
2205
- buttonClassPrefix,
2206
- L.drawLocal.draw.toolbar.buttons.marker
2207
- );
2208
- }
2209
-
2210
- // Save button index of the last button, -1 as we would have ++ after the last button
2211
- this._lastButtonIndex = --buttonIndex;
2212
-
2213
- // Create the actions part of the toolbar
2214
- this._actionsContainer = this._createActions([
2215
- {
2216
- title: L.drawLocal.draw.toolbar.actions.title,
2217
- text: L.drawLocal.draw.toolbar.actions.text,
2218
- callback: this.disable,
2219
- context: this
2220
- }
2221
- ]);
2222
-
2223
- // Add draw and cancel containers to the control container
2224
- container.appendChild(this._toolbarContainer);
2225
- container.appendChild(this._actionsContainer);
2226
-
2227
- return container;
2228
- },
2229
-
2230
- setOptions: function (options) {
2231
- L.setOptions(this, options);
2232
-
2233
- for (var type in this._modes) {
2234
- if (this._modes.hasOwnProperty(type) && options.hasOwnProperty(type)) {
2235
- this._modes[type].handler.setOptions(options[type]);
2236
- }
2237
- }
2238
- }
2239
- });
2240
-
2241
- /*L.Map.mergeOptions({
2242
- editControl: true
2243
- });*/
2244
-
2245
- L.EditToolbar = L.Toolbar.extend({
2246
- options: {
2247
- edit: {
2248
- selectedPathOptions: {
2249
- color: '#fe57a1', /* Hot pink all the things! */
2250
- opacity: 0.6,
2251
- dashArray: '10, 10',
2252
-
2253
- fill: true,
2254
- fillColor: '#fe57a1',
2255
- fillOpacity: 0.1
2256
- }
2257
- },
2258
- remove: {},
2259
- featureGroup: null /* REQUIRED! TODO: perhaps if not set then all layers on the map are selectable? */
2260
- },
2261
-
2262
- initialize: function (options) {
2263
- // Need to set this manually since null is an acceptable value here
2264
- if (options.edit) {
2265
- if (typeof options.edit.selectedPathOptions === 'undefined') {
2266
- options.edit.selectedPathOptions = this.options.edit.selectedPathOptions;
2267
- }
2268
- options.edit = L.extend({}, this.options.edit, options.edit);
2269
- }
2270
-
2271
- if (options.remove) {
2272
- options.remove = L.extend({}, this.options.remove, options.remove);
2273
- }
2274
-
2275
- L.Toolbar.prototype.initialize.call(this, options);
2276
-
2277
- this._selectedFeatureCount = 0;
2278
- },
2279
-
2280
- addToolbar: function (map) {
2281
- var container = L.DomUtil.create('div', 'leaflet-draw-section'),
2282
- buttonIndex = 0,
2283
- buttonClassPrefix = 'leaflet-draw-edit',
2284
- featureGroup = this.options.featureGroup;
2285
-
2286
- this._toolbarContainer = L.DomUtil.create('div', 'leaflet-draw-toolbar leaflet-bar');
2287
-
2288
- this._map = map;
2289
-
2290
- if (this.options.edit) {
2291
- this._initModeHandler(
2292
- new L.EditToolbar.Edit(map, {
2293
- featureGroup: featureGroup,
2294
- selectedPathOptions: this.options.edit.selectedPathOptions
2295
- }),
2296
- this._toolbarContainer,
2297
- buttonIndex++,
2298
- buttonClassPrefix,
2299
- L.drawLocal.edit.toolbar.buttons.edit
2300
- );
2301
- }
2302
-
2303
- if (this.options.remove) {
2304
- this._initModeHandler(
2305
- new L.EditToolbar.Delete(map, {
2306
- featureGroup: featureGroup
2307
- }),
2308
- this._toolbarContainer,
2309
- buttonIndex++,
2310
- buttonClassPrefix,
2311
- L.drawLocal.edit.toolbar.buttons.remove
2312
- );
2313
- }
2314
-
2315
- // Save button index of the last button, -1 as we would have ++ after the last button
2316
- this._lastButtonIndex = --buttonIndex;
2317
-
2318
- // Create the actions part of the toolbar
2319
- this._actionsContainer = this._createActions([
2320
- {
2321
- title: L.drawLocal.edit.toolbar.actions.save.title,
2322
- text: L.drawLocal.edit.toolbar.actions.save.text,
2323
- callback: this._save,
2324
- context: this
2325
- },
2326
- {
2327
- title: L.drawLocal.edit.toolbar.actions.cancel.title,
2328
- text: L.drawLocal.edit.toolbar.actions.cancel.text,
2329
- callback: this.disable,
2330
- context: this
2331
- }
2332
- ]);
2333
-
2334
- // Add draw and cancel containers to the control container
2335
- container.appendChild(this._toolbarContainer);
2336
- container.appendChild(this._actionsContainer);
2337
-
2338
- this._checkDisabled();
2339
-
2340
- featureGroup.on('layeradd layerremove', this._checkDisabled, this);
2341
-
2342
- return container;
2343
- },
2344
-
2345
- removeToolbar: function () {
2346
- L.Toolbar.prototype.removeToolbar.call(this);
2347
-
2348
- this.options.featureGroup.off('layeradd layerremove', this._checkDisabled, this);
2349
- },
2350
-
2351
- disable: function () {
2352
- if (!this.enabled()) { return; }
2353
-
2354
- this._activeMode.handler.revertLayers();
2355
-
2356
- L.Toolbar.prototype.disable.call(this);
2357
- },
2358
-
2359
- _save: function () {
2360
- this._activeMode.handler.save();
2361
- this._activeMode.handler.disable();
2362
- },
2363
-
2364
- _checkDisabled: function () {
2365
- var featureGroup = this.options.featureGroup,
2366
- hasLayers = featureGroup.getLayers().length !== 0,
2367
- button;
2368
-
2369
- if (this.options.edit) {
2370
- button = this._modes[L.EditToolbar.Edit.TYPE].button;
2371
-
2372
- if (hasLayers) {
2373
- L.DomUtil.removeClass(button, 'leaflet-disabled');
2374
- } else {
2375
- L.DomUtil.addClass(button, 'leaflet-disabled');
2376
- }
2377
-
2378
- button.setAttribute(
2379
- 'title',
2380
- hasLayers ?
2381
- L.drawLocal.edit.toolbar.buttons.edit
2382
- : L.drawLocal.edit.toolbar.buttons.editDisabled
2383
- );
2384
- }
2385
-
2386
- if (this.options.remove) {
2387
- button = this._modes[L.EditToolbar.Delete.TYPE].button;
2388
-
2389
- if (hasLayers) {
2390
- L.DomUtil.removeClass(button, 'leaflet-disabled');
2391
- } else {
2392
- L.DomUtil.addClass(button, 'leaflet-disabled');
2393
- }
2394
-
2395
- button.setAttribute(
2396
- 'title',
2397
- hasLayers ?
2398
- L.drawLocal.edit.toolbar.buttons.remove
2399
- : L.drawLocal.edit.toolbar.buttons.removeDisabled
2400
- );
2401
- }
2402
- }
2403
- });
2404
-
2405
-
2406
- L.EditToolbar.Edit = L.Handler.extend({
2407
- statics: {
2408
- TYPE: 'edit'
2409
- },
2410
-
2411
- includes: L.Mixin.Events,
2412
-
2413
- initialize: function (map, options) {
2414
- L.Handler.prototype.initialize.call(this, map);
2415
-
2416
- // Set options to the default unless already set
2417
- this._selectedPathOptions = options.selectedPathOptions;
2418
-
2419
- // Store the selectable layer group for ease of access
2420
- this._featureGroup = options.featureGroup;
2421
-
2422
- if (!(this._featureGroup instanceof L.FeatureGroup)) {
2423
- throw new Error('options.featureGroup must be a L.FeatureGroup');
2424
- }
2425
-
2426
- this._uneditedLayerProps = {};
2427
-
2428
- // Save the type so super can fire, need to do this as cannot do this.TYPE :(
2429
- this.type = L.EditToolbar.Edit.TYPE;
2430
- },
2431
-
2432
- enable: function () {
2433
- if (this._enabled || !this._hasAvailableLayers()) {
2434
- return;
2435
- }
2436
-
2437
- L.Handler.prototype.enable.call(this);
2438
-
2439
- this._featureGroup
2440
- .on('layeradd', this._enableLayerEdit, this)
2441
- .on('layerremove', this._disableLayerEdit, this);
2442
-
2443
- this.fire('enabled', {handler: this.type});
2444
- this._map.fire('draw:editstart', { handler: this.type });
2445
- },
2446
-
2447
- disable: function () {
2448
- if (!this._enabled) { return; }
2449
-
2450
- this.fire('disabled', {handler: this.type});
2451
- this._map.fire('draw:editstop', { handler: this.type });
2452
-
2453
- this._featureGroup
2454
- .off('layeradd', this._enableLayerEdit, this)
2455
- .off('layerremove', this._disableLayerEdit, this);
2456
-
2457
- L.Handler.prototype.disable.call(this);
2458
- },
2459
-
2460
- addHooks: function () {
2461
- var map = this._map;
2462
-
2463
- if (map) {
2464
- map.getContainer().focus();
2465
-
2466
- this._featureGroup.eachLayer(this._enableLayerEdit, this);
2467
-
2468
- this._tooltip = new L.Tooltip(this._map);
2469
- this._tooltip.updateContent({
2470
- text: L.drawLocal.edit.handlers.edit.tooltip.text,
2471
- subtext: L.drawLocal.edit.handlers.edit.tooltip.subtext
2472
- });
2473
-
2474
- this._map.on('mousemove', this._onMouseMove, this);
2475
- }
2476
- },
2477
-
2478
- removeHooks: function () {
2479
- if (this._map) {
2480
- // Clean up selected layers.
2481
- this._featureGroup.eachLayer(this._disableLayerEdit, this);
2482
-
2483
- // Clear the backups of the original layers
2484
- this._uneditedLayerProps = {};
2485
-
2486
- this._tooltip.dispose();
2487
- this._tooltip = null;
2488
-
2489
- this._map.off('mousemove', this._onMouseMove, this);
2490
- }
2491
- },
2492
-
2493
- revertLayers: function () {
2494
- this._featureGroup.eachLayer(function (layer) {
2495
- this._revertLayer(layer);
2496
- }, this);
2497
- },
2498
-
2499
- save: function () {
2500
- var editedLayers = new L.LayerGroup();
2501
- this._featureGroup.eachLayer(function (layer) {
2502
- if (layer.edited) {
2503
- editedLayers.addLayer(layer);
2504
- layer.edited = false;
2505
- }
2506
- });
2507
- this._map.fire('draw:edited', {layers: editedLayers});
2508
- },
2509
-
2510
- _backupLayer: function (layer) {
2511
- var id = L.Util.stamp(layer);
2512
-
2513
- if (!this._uneditedLayerProps[id]) {
2514
- // Polyline, Polygon or Rectangle
2515
- if (layer instanceof L.Polyline || layer instanceof L.Polygon || layer instanceof L.Rectangle) {
2516
- this._uneditedLayerProps[id] = {
2517
- latlngs: L.LatLngUtil.cloneLatLngs(layer.getLatLngs())
2518
- };
2519
- } else if (layer instanceof L.Circle) {
2520
- this._uneditedLayerProps[id] = {
2521
- latlng: L.LatLngUtil.cloneLatLng(layer.getLatLng()),
2522
- radius: layer.getRadius()
2523
- };
2524
- } else { // Marker
2525
- this._uneditedLayerProps[id] = {
2526
- latlng: L.LatLngUtil.cloneLatLng(layer.getLatLng())
2527
- };
2528
- }
2529
- }
2530
- },
2531
-
2532
- _revertLayer: function (layer) {
2533
- var id = L.Util.stamp(layer);
2534
- layer.edited = false;
2535
- if (this._uneditedLayerProps.hasOwnProperty(id)) {
2536
- // Polyline, Polygon or Rectangle
2537
- if (layer instanceof L.Polyline || layer instanceof L.Polygon || layer instanceof L.Rectangle) {
2538
- layer.setLatLngs(this._uneditedLayerProps[id].latlngs);
2539
- } else if (layer instanceof L.Circle) {
2540
- layer.setLatLng(this._uneditedLayerProps[id].latlng);
2541
- layer.setRadius(this._uneditedLayerProps[id].radius);
2542
- } else { // Marker
2543
- layer.setLatLng(this._uneditedLayerProps[id].latlng);
2544
- }
2545
- }
2546
- },
2547
-
2548
- _toggleMarkerHighlight: function (marker) {
2549
- if (!marker._icon) {
2550
- return;
2551
- }
2552
- // This is quite naughty, but I don't see another way of doing it. (short of setting a new icon)
2553
- var icon = marker._icon;
2554
-
2555
- icon.style.display = 'none';
2556
-
2557
- if (L.DomUtil.hasClass(icon, 'leaflet-edit-marker-selected')) {
2558
- L.DomUtil.removeClass(icon, 'leaflet-edit-marker-selected');
2559
- // Offset as the border will make the icon move.
2560
- this._offsetMarker(icon, -4);
2561
-
2562
- } else {
2563
- L.DomUtil.addClass(icon, 'leaflet-edit-marker-selected');
2564
- // Offset as the border will make the icon move.
2565
- this._offsetMarker(icon, 4);
2566
- }
2567
-
2568
- icon.style.display = '';
2569
- },
2570
-
2571
- _offsetMarker: function (icon, offset) {
2572
- var iconMarginTop = parseInt(icon.style.marginTop, 10) - offset,
2573
- iconMarginLeft = parseInt(icon.style.marginLeft, 10) - offset;
2574
-
2575
- icon.style.marginTop = iconMarginTop + 'px';
2576
- icon.style.marginLeft = iconMarginLeft + 'px';
2577
- },
2578
-
2579
- _enableLayerEdit: function (e) {
2580
- var layer = e.layer || e.target || e,
2581
- isMarker = layer instanceof L.Marker,
2582
- pathOptions;
2583
-
2584
- // Don't do anything if this layer is a marker but doesn't have an icon. Markers
2585
- // should usually have icons. If using Leaflet.draw with Leafler.markercluster there
2586
- // is a chance that a marker doesn't.
2587
- if (isMarker && !layer._icon) {
2588
- return;
2589
- }
2590
-
2591
- // Back up this layer (if haven't before)
2592
- this._backupLayer(layer);
2593
-
2594
- // Update layer style so appears editable
2595
- if (this._selectedPathOptions) {
2596
- pathOptions = L.Util.extend({}, this._selectedPathOptions);
2597
-
2598
- if (isMarker) {
2599
- this._toggleMarkerHighlight(layer);
2600
- } else {
2601
- layer.options.previousOptions = layer.options;
2602
-
2603
- // Make sure that Polylines are not filled
2604
- if (!(layer instanceof L.Circle) && !(layer instanceof L.Polygon) && !(layer instanceof L.Rectangle)) {
2605
- pathOptions.fill = false;
2606
- }
2607
-
2608
- layer.setStyle(pathOptions);
2609
- }
2610
- }
2611
-
2612
- if (isMarker) {
2613
- layer.dragging.enable();
2614
- layer.on('dragend', this._onMarkerDragEnd);
2615
- } else {
2616
- layer.editing.enable();
2617
- }
2618
- },
2619
-
2620
- _disableLayerEdit: function (e) {
2621
- var layer = e.layer || e.target || e;
2622
- layer.edited = false;
2623
-
2624
- // Reset layer styles to that of before select
2625
- if (this._selectedPathOptions) {
2626
- if (layer instanceof L.Marker) {
2627
- this._toggleMarkerHighlight(layer);
2628
- } else {
2629
- // reset the layer style to what is was before being selected
2630
- layer.setStyle(layer.options.previousOptions);
2631
- // remove the cached options for the layer object
2632
- delete layer.options.previousOptions;
2633
- }
2634
- }
2635
-
2636
- if (layer instanceof L.Marker) {
2637
- layer.dragging.disable();
2638
- layer.off('dragend', this._onMarkerDragEnd, this);
2639
- } else {
2640
- layer.editing.disable();
2641
- }
2642
- },
2643
-
2644
- _onMarkerDragEnd: function (e) {
2645
- var layer = e.target;
2646
- layer.edited = true;
2647
- },
2648
-
2649
- _onMouseMove: function (e) {
2650
- this._tooltip.updatePosition(e.latlng);
2651
- },
2652
-
2653
- _hasAvailableLayers: function () {
2654
- return this._featureGroup.getLayers().length !== 0;
2655
- }
2656
- });
2657
-
2658
-
2659
- L.EditToolbar.Delete = L.Handler.extend({
2660
- statics: {
2661
- TYPE: 'remove' // not delete as delete is reserved in js
2662
- },
2663
-
2664
- includes: L.Mixin.Events,
2665
-
2666
- initialize: function (map, options) {
2667
- L.Handler.prototype.initialize.call(this, map);
2668
-
2669
- L.Util.setOptions(this, options);
2670
-
2671
- // Store the selectable layer group for ease of access
2672
- this._deletableLayers = this.options.featureGroup;
2673
-
2674
- if (!(this._deletableLayers instanceof L.FeatureGroup)) {
2675
- throw new Error('options.featureGroup must be a L.FeatureGroup');
2676
- }
2677
-
2678
- // Save the type so super can fire, need to do this as cannot do this.TYPE :(
2679
- this.type = L.EditToolbar.Delete.TYPE;
2680
- },
2681
-
2682
- enable: function () {
2683
- if (this._enabled || !this._hasAvailableLayers()) {
2684
- return;
2685
- }
2686
-
2687
- L.Handler.prototype.enable.call(this);
2688
-
2689
- this._deletableLayers
2690
- .on('layeradd', this._enableLayerDelete, this)
2691
- .on('layerremove', this._disableLayerDelete, this);
2692
-
2693
- this.fire('enabled', { handler: this.type});
2694
- this._map.fire('draw:editstart', { handler: this.type });
2695
- },
2696
-
2697
- disable: function () {
2698
- if (!this._enabled) { return; }
2699
-
2700
- L.Handler.prototype.disable.call(this);
2701
-
2702
- this._deletableLayers
2703
- .off('layeradd', this._enableLayerDelete, this)
2704
- .off('layerremove', this._disableLayerDelete, this);
2705
-
2706
- this.fire('disabled', { handler: this.type});
2707
- this._map.fire('draw:editstop', { handler: this.type });
2708
- },
2709
-
2710
- addHooks: function () {
2711
- var map = this._map;
2712
-
2713
- if (map) {
2714
- map.getContainer().focus();
2715
-
2716
- this._deletableLayers.eachLayer(this._enableLayerDelete, this);
2717
- this._deletedLayers = new L.layerGroup();
2718
-
2719
- this._tooltip = new L.Tooltip(this._map);
2720
- this._tooltip.updateContent({ text: L.drawLocal.edit.handlers.remove.tooltip.text });
2721
-
2722
- this._map.on('mousemove', this._onMouseMove, this);
2723
- }
2724
- },
2725
-
2726
- removeHooks: function () {
2727
- if (this._map) {
2728
- this._deletableLayers.eachLayer(this._disableLayerDelete, this);
2729
- this._deletedLayers = null;
2730
-
2731
- this._tooltip.dispose();
2732
- this._tooltip = null;
2733
-
2734
- this._map.off('mousemove', this._onMouseMove, this);
2735
- }
2736
- },
2737
-
2738
- revertLayers: function () {
2739
- // Iterate of the deleted layers and add them back into the featureGroup
2740
- this._deletedLayers.eachLayer(function (layer) {
2741
- this._deletableLayers.addLayer(layer);
2742
- }, this);
2743
- },
2744
-
2745
- save: function () {
2746
- this._map.fire('draw:deleted', { layers: this._deletedLayers });
2747
- },
2748
-
2749
- _enableLayerDelete: function (e) {
2750
- var layer = e.layer || e.target || e;
2751
-
2752
- layer.on('click', this._removeLayer, this);
2753
- },
2754
-
2755
- _disableLayerDelete: function (e) {
2756
- var layer = e.layer || e.target || e;
2757
-
2758
- layer.off('click', this._removeLayer, this);
2759
-
2760
- // Remove from the deleted layers so we can't accidently revert if the user presses cancel
2761
- this._deletedLayers.removeLayer(layer);
2762
- },
2763
-
2764
- _removeLayer: function (e) {
2765
- var layer = e.layer || e.target || e;
2766
-
2767
- this._deletableLayers.removeLayer(layer);
2768
-
2769
- this._deletedLayers.addLayer(layer);
2770
- },
2771
-
2772
- _onMouseMove: function (e) {
2773
- this._tooltip.updatePosition(e.latlng);
2774
- },
2775
-
2776
- _hasAvailableLayers: function () {
2777
- return this._deletableLayers.getLayers().length !== 0;
2778
- }
2779
- });
2780
-
2781
-
2782
- }(this, document));