Skip to content

Commit f35149b

Browse files
committed
clean up public api
1 parent c6b921d commit f35149b

File tree

1 file changed

+34
-63
lines changed

1 file changed

+34
-63
lines changed

API.md

+34-63
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@ mapbox.Draw({
8989

9090
`mapboxgl.Draw()` returns an instance of the `Draw` class which has the following public API methods for getting and setting data:
9191

92-
###`.add(Object: GeoJSONFeature, [Object]: options) -> String`
92+
###`.add(Object: GeoJSONFeature) -> String`
9393

9494
This method takes any valid GeoJSON and adds it to Draw. The object will be turned into a GeoJSON feature and will be assigned a unique `drawId` that can be used to identify it. This method return the new feature's `drawId`. If an id is provided with the feature that ID will be used.
9595

96-
The second argument is an optional options object to add information to the geometry when creating the new element. Currently the only used option is `permanent`, which, if set to true, will cause the element to ignore click events, `Draw.select(:id:)` and `Draw.selectAll()`.
97-
9896
Draw does not enforce unique IDs to be passed to `.add`, but it does enforce unique ids inside of it. This means that if you provide an id for a feature that is not unqiue, Draw will override the exhisting feature with your new feature. You can think of this like PUT in http verbs.
9997

10098
If a FeatureCollection is provided to `.add` Draw will break it up into many features as if you looped through the features in the collection and added them one at a time. This is good for bulk adding, though it is no faster than looping yourself.
@@ -136,7 +134,6 @@ console.log(Draw.get(id));
136134

137135
This method returns all features added to Draw in a single GeoJSON FeatureCollection. The each feature's unique id will be found on the `id` attribute of the feature.
138136

139-
140137
Example:
141138

142139
```js
@@ -173,71 +170,27 @@ console.log(Draw.getAll());
173170
```
174171
---
175172

176-
###`.getSelected() -> Object`
177-
178-
Get all selected features.
179-
180-
---
181-
182-
###`.select(String: drawId) -> Draw`
183-
184-
This method takes the `drawId` of a feature and selects it. It returns `this` to allow for method chaining.
185-
186-
---
187-
188-
###`.selectAll() -> Draw`
189-
190-
This method selects all features. It returns `this` to allow for method chaining.
191-
192-
---
193-
194-
###`.deselect(String: drawId) -> Draw`
195173

196-
This method takes the `drawId` of a feature and deselects it if selected. It returns `this` to allow for method chaining.
174+
###`.delete(String: drawId) -> Draw`
197175

198-
---
199-
200-
####`.deselectAll() -> Draw`
176+
This method takes the `drawId` of feature and removes it from draw.
201177

202-
This method deselects all features. It returns `this` to allow for method chaining.
203-
204-
---
205-
206-
###`.destroy(String: drawId) -> Draw`
207-
208-
This method takes the `drawId` of feature and removes it from draw. It returns `this` to allow for method chaining.
178+
In `direct_select` mode, deleting the active feature will stop the mode and revert to the `default` mode.
209179

210180
Example:
211181

212182
```js
213183
var feature = { type: 'Point', coordinates: [0, 0] };
214184
var id = draw.add(feature)
215185
Draw
216-
.destroy(id)
186+
.delete(id)
217187
.getAll();
218188
// => { type: 'FeatureCollection', features: [] }
219189
```
220190

221191
---
222192

223-
###`.update(String: drawId, Object: GeoJSONFeature) -> Draw`
224-
225-
This method takes the `drawId` of an existing feature and a GeoJSON object and replaces that feature in draw with the new feature. It returns `this`.
226-
227-
Example:
228-
229-
```js
230-
var id = Draw.add({ type: 'Point', coordinates: [0, 0] });
231-
var newFeature = Draw
232-
.update(id, { type: 'Point', coordinates: [1, 1] })
233-
.get(id);
234-
console.log(newFeature);
235-
//=> { type: 'Feature', geometry: { type: 'Point', coordinates: [1, 1] } }
236-
```
237-
238-
---
239-
240-
###`.clear() -> Draw`
193+
###`.deleteAll() -> Draw`
241194

242195
This method removes all geometries in Draw.
243196

@@ -246,26 +199,44 @@ Example:
246199
```js
247200
Draw.add({ type: 'Point', coordinates: [0, 0] });
248201
Draw
249-
.clear()
202+
.deleteAll()
250203
.getAll();
251204
// => { type: 'FeatureCollection', features: [] }
252205
```
253206

254207
---
255208

256-
###`.startDrawing(Enum: { Draw.types.POINT | Draw.types.LINE | Draw.types.POLYGON })`
209+
### `.trash() -> Draw`
257210

258-
This method initiates drawing the specified type. The types are defined in constants in draw under `Draw.types.*`. The argument should be one of
211+
This envokes the current modes trash event. For the `default` mode this deletes all active features. For the `direct_select` mode this deletes the active vertecies. For the draw modes, these cancels the current process.
259212

260-
- `Draw.types.POINT`
261-
- `Draw.types.LINE`
262-
- `Draw.types.POLYGON`
213+
This is different from `delete` or `deleteAlll` in that it follows rules described by the current mode.
263214

264-
Example:
215+
---
265216

266-
```js
267-
Draw.startDrawing(Draw.types.LINE);
268-
```
217+
### `.startMode(String: mode, ?Any: options) -> Draw`
218+
219+
`startMode` triggers the mode switching process inside Draw. `mode` must be one of the below strings. Each mode takes its own arguments. They are descibed in detail below.
220+
221+
#### Mode: `default`
222+
223+
Lets you select, delete and drag features.
224+
225+
For `default` options is an array of featureIds. It is optional. If provided, these features will be active at the start of the mode. In this mode, features can have their active state changed by the user. To control what is active, react to changes as described in the events section below.
226+
227+
#### Mode: `direct_select`
228+
229+
Lets you select, delete and drag features.
230+
231+
For `direct_select`options is a single featureId. It is required. This feature will be active for the duration of the mode.
232+
233+
#### Draw modes:
234+
235+
The three draw modes work identically. They do not take an options argument.
236+
237+
- `draw_line_string`: Draws a LineString feature.
238+
- `draw_polygon`: Draws a Polygon feature.
239+
- `draw_point`: Draws a Point feature.
269240

270241
## Events
271242

0 commit comments

Comments
 (0)