|
1 /** |
|
2 * Leaflet.draw assumes that you have already included the Leaflet library. |
|
3 */ |
|
4 L.drawVersion = '0.4.2'; |
|
5 /** |
|
6 * @class L.Draw |
|
7 * @aka Draw |
|
8 * |
|
9 * |
|
10 * To add the draw toolbar set the option drawControl: true in the map options. |
|
11 * |
|
12 * @example |
|
13 * ```js |
|
14 * var map = L.map('map', {drawControl: true}).setView([51.505, -0.09], 13); |
|
15 * |
|
16 * L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { |
|
17 * attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' |
|
18 * }).addTo(map); |
|
19 * ``` |
|
20 * |
|
21 * ### Adding the edit toolbar |
|
22 * To use the edit toolbar you must initialise the Leaflet.draw control and manually add it to the map. |
|
23 * |
|
24 * ```js |
|
25 * var map = L.map('map').setView([51.505, -0.09], 13); |
|
26 * |
|
27 * L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { |
|
28 * attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' |
|
29 * }).addTo(map); |
|
30 * |
|
31 * // FeatureGroup is to store editable layers |
|
32 * var drawnItems = new L.FeatureGroup(); |
|
33 * map.addLayer(drawnItems); |
|
34 * |
|
35 * var drawControl = new L.Control.Draw({ |
|
36 * edit: { |
|
37 * featureGroup: drawnItems |
|
38 * } |
|
39 * }); |
|
40 * map.addControl(drawControl); |
|
41 * ``` |
|
42 * |
|
43 * The key here is the featureGroup option. This tells the plugin which FeatureGroup contains the layers that |
|
44 * should be editable. The featureGroup can contain 0 or more features with geometry types Point, LineString, and Polygon. |
|
45 * Leaflet.draw does not work with multigeometry features such as MultiPoint, MultiLineString, MultiPolygon, |
|
46 * or GeometryCollection. If you need to add multigeometry features to the draw plugin, convert them to a |
|
47 * FeatureCollection of non-multigeometries (Points, LineStrings, or Polygons). |
|
48 */ |
|
49 L.Draw = {}; |
|
50 |
|
51 /** |
|
52 * @class L.drawLocal |
|
53 * @aka L.drawLocal |
|
54 * |
|
55 * The core toolbar class of the API — it is used to create the toolbar ui |
|
56 * |
|
57 * @example |
|
58 * ```js |
|
59 * var modifiedDraw = L.drawLocal.extend({ |
|
60 * draw: { |
|
61 * toolbar: { |
|
62 * buttons: { |
|
63 * polygon: 'Draw an awesome polygon' |
|
64 * } |
|
65 * } |
|
66 * } |
|
67 * }); |
|
68 * ``` |
|
69 * |
|
70 * The default state for the control is the draw toolbar just below the zoom control. |
|
71 * This will allow map users to draw vectors and markers. |
|
72 * **Please note the edit toolbar is not enabled by default.** |
|
73 */ |
|
74 L.drawLocal = { |
|
75 // format: { |
|
76 // numeric: { |
|
77 // delimiters: { |
|
78 // thousands: ',', |
|
79 // decimal: '.' |
|
80 // } |
|
81 // } |
|
82 // }, |
|
83 draw: { |
|
84 toolbar: { |
|
85 // #TODO: this should be reorganized where actions are nested in actions |
|
86 // ex: actions.undo or actions.cancel |
|
87 actions: { |
|
88 title: 'Cancel drawing', |
|
89 text: 'Cancel' |
|
90 }, |
|
91 finish: { |
|
92 title: 'Finish drawing', |
|
93 text: 'Finish' |
|
94 }, |
|
95 undo: { |
|
96 title: 'Delete last point drawn', |
|
97 text: 'Delete last point' |
|
98 }, |
|
99 buttons: { |
|
100 polyline: 'Draw a polyline', |
|
101 polygon: 'Draw a polygon', |
|
102 rectangle: 'Draw a rectangle', |
|
103 circle: 'Draw a circle', |
|
104 marker: 'Draw a marker' |
|
105 } |
|
106 }, |
|
107 handlers: { |
|
108 circle: { |
|
109 tooltip: { |
|
110 start: 'Click and drag to draw circle.' |
|
111 }, |
|
112 radius: 'Radius' |
|
113 }, |
|
114 marker: { |
|
115 tooltip: { |
|
116 start: 'Click map to place marker.' |
|
117 } |
|
118 }, |
|
119 polygon: { |
|
120 tooltip: { |
|
121 start: 'Click to start drawing shape.', |
|
122 cont: 'Click to continue drawing shape.', |
|
123 end: 'Click first point to close this shape.' |
|
124 } |
|
125 }, |
|
126 polyline: { |
|
127 error: '<strong>Error:</strong> shape edges cannot cross!', |
|
128 tooltip: { |
|
129 start: 'Click to start drawing line.', |
|
130 cont: 'Click to continue drawing line.', |
|
131 end: 'Click last point to finish line.' |
|
132 } |
|
133 }, |
|
134 rectangle: { |
|
135 tooltip: { |
|
136 start: 'Click and drag to draw rectangle.' |
|
137 } |
|
138 }, |
|
139 simpleshape: { |
|
140 tooltip: { |
|
141 end: 'Release mouse to finish drawing.' |
|
142 } |
|
143 } |
|
144 } |
|
145 }, |
|
146 edit: { |
|
147 toolbar: { |
|
148 actions: { |
|
149 save: { |
|
150 title: 'Save changes.', |
|
151 text: 'Save' |
|
152 }, |
|
153 cancel: { |
|
154 title: 'Cancel editing, discards all changes.', |
|
155 text: 'Cancel' |
|
156 }, |
|
157 clearAll:{ |
|
158 title: 'clear all layers.', |
|
159 text: 'Clear All' |
|
160 } |
|
161 }, |
|
162 buttons: { |
|
163 edit: 'Edit layers.', |
|
164 editDisabled: 'No layers to edit.', |
|
165 remove: 'Delete layers.', |
|
166 removeDisabled: 'No layers to delete.' |
|
167 } |
|
168 }, |
|
169 handlers: { |
|
170 edit: { |
|
171 tooltip: { |
|
172 text: 'Drag handles, or marker to edit feature.', |
|
173 subtext: 'Click cancel to undo changes.' |
|
174 } |
|
175 }, |
|
176 remove: { |
|
177 tooltip: { |
|
178 text: 'Click on a feature to remove' |
|
179 } |
|
180 } |
|
181 } |
|
182 } |
|
183 }; |