Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusbotella authored Jun 24, 2019
1 parent 871e37f commit 649d7d1
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# mapboxgl-draw-rectangle-drag
A Mapbox GL Draw plugin to create a rectangle via click & drag
# Mapbox GL Draw Rectangle Drag
A Mapbox GL Draw plugin to create a rectangle via click & drag.

Based on [`thegisdev/mapbox-gl-draw-rectangle-mode`](https://github.com/thegisdev/mapbox-gl-draw-rectangle-mode) plugin code.

How to install
-----
You can install this plugin either using npm or JSDeliver.

### Using npm
We deliver ESM compatible code through our npm module, so that you can import it in your project and compile it without issues.
```
npm i mapboxgl-draw-rectangle-drag --save
```
The module exports a default binding to the module, so you can import it like:
```
import mapboxGLDrawRectangleDrag from 'mapboxgl-draw-rectangle-drag';
```

### Using JSDeliver
We have a script-compatible version of the plugin as well, ready to be imported in your HTML code using a `<script>` tag.
```
<script src="" />
```

A variable named `mapboxGLDrawRectangleDrag` is defined within the global scope to be included in your Mapbox GL Draw modes.

Add mode to Mapbox GL Draw
----
Once the module/script is imported, you need to include the new mode within Mapbox GL's predefined modes.

To do so, you need to include `modes` property in your Mapbox GL Draw configuration options.
```js
var MapboxGLDraw = new MapboxDraw({
modes: {
...MapboxDraw.modes,
'draw_rectangle_drag': mapboxGLDrawRectangleDrag
}
});
```

How to enable rectangle drag mode
---
To enable the rectangle drag mode, you need to execute [`changeMode`](https://github.com/mapbox/mapbox-gl-draw/blob/master/docs/API.md#changemodemode-string-options-object-draw) method on your Mapbox GL Draw instance.
```
drawInstance.changeMode('draw_rectangle_drag');
```

Unfortunately, custom modes cannot add custom controls to Mapbox GL Draw plugins. So, if you want to have a custom button to enable the control you need to create one by yourself. You can take some ideas from [this CodePen](https://codepen.io/roblabs/pen/zJjPzX)

0 comments on commit 649d7d1

Please sign in to comment.