Skip to content

Commit

Permalink
Implement repeat mode feature to allow individual draw tools to be re…
Browse files Browse the repository at this point in the history
…main enabled after a shape is drawn
  • Loading branch information
Jay Hogan authored and Carlos Scheidegger committed Aug 21, 2013
1 parent 9fde651 commit cee8a31
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -173,6 +173,7 @@ Polyline and Polygon drawing handlers take the same options.
| shapeOptions | [Leaflet Polyline options](http://leafletjs.com/reference.html#polyline-options) | [See code](https://github.com/Leaflet/Leaflet.draw/blob/master/src/draw/handler/Draw.Polyline.js#L20) | The options used when drawing the polyline/polygon on the map.
| metric | Bool | `true` | Determines which measurement system (metric or imperial) is used.
| zIndexOffset | Number | `2000` | This should be a high number to ensure that you can draw over all other layers on the map.
| repeatMode | Bool | `false` | Determines if the draw tool remains enabled after drawing a shape.

<a name="polygonoptions" />
#### PolygonOptions
Expand All @@ -189,13 +190,15 @@ Polygon options include all of the Polyline options plus the option to show the
| Option | Type | Default | Description
| --- | --- | --- | ---
| shapeOptions | [Leaflet Path options](http://leafletjs.com/reference.html#path-options) | [See code](https://github.com/Leaflet/Leaflet.draw/blob/master/src/draw/handler/Draw.Rectangle.js#L7) | The options used when drawing the rectangle on the map.
| repeatMode | Bool | `false` | Determines if the draw tool remains enabled after drawing a shape.

<a name="circleoptions" />
#### CircleOptions

| Option | Type | Default | Description
| --- | --- | --- | ---
| shapeOptions | [Leaflet Path options](http://leafletjs.com/reference.html#path-options) | [See code](https://github.com/Leaflet/Leaflet.draw/blob/master/src/draw/handler/Draw.Circle.js#L7) | The options used when drawing the circle on the map.
| repeatMode | Bool | `false` | Determines if the draw tool remains enabled after drawing a shape.

<a name="markeroptions" />
#### MarkerOptions
Expand All @@ -204,6 +207,7 @@ Polygon options include all of the Polyline options plus the option to show the
| --- | --- | --- | ---
| icon | [Leaflet Icon](http://leafletjs.com/reference.html#icon) | `L.Icon.Default()` | The icon displayed when drawing a marker.
| zIndexOffset | Number | `2000` | This should be a high number to ensure that you can draw over all other layers on the map.
| repeatMode | Bool | `false` | Determines if the draw tool remains enabled after drawing a shape.

<a name="editoptions" />
### EditOptions
Expand Down
19 changes: 19 additions & 0 deletions dist/leaflet.draw-src.js
Expand Up @@ -183,6 +183,7 @@ L.Draw.Polyline = L.Draw.Feature.extend({

options: {
allowIntersection: true,
repeatMode: false,
drawError: {
color: '#b00b00',
message: L.drawLocal.draw.handlers.polyline.error,
Expand Down Expand Up @@ -293,6 +294,9 @@ L.Draw.Polyline = L.Draw.Feature.extend({

this._fireCreatedEvent();
this.disable();
if (this.options.repeatMode) {
this.enable();
}
},

//Called to verify the shape is valid when the user tries to finish it
Expand Down Expand Up @@ -694,6 +698,14 @@ L.Draw.Polygon = L.Draw.Polyline.extend({
L.SimpleShape = {};

L.Draw.SimpleShape = L.Draw.Feature.extend({
options: {
repeatMode: true
},

initialize: function (map, options) {
L.Draw.Feature.prototype.initialize.call(this, map, options);
},

addHooks: function () {
L.Draw.Feature.prototype.addHooks.call(this);
if (this._map) {
Expand Down Expand Up @@ -756,6 +768,9 @@ L.Draw.SimpleShape = L.Draw.Feature.extend({
}

this.disable();
if (this.options.repeatMode) {
this.enable();
}
}
});

Expand Down Expand Up @@ -868,6 +883,7 @@ L.Draw.Marker = L.Draw.Feature.extend({

options: {
icon: new L.Icon.Default(),
repeatMode: false,
zIndexOffset: 2000 // This should be > than the highest z-index any markers
},

Expand Down Expand Up @@ -951,6 +967,9 @@ L.Draw.Marker = L.Draw.Feature.extend({
this._fireCreatedEvent();

this.disable();
if (this.options.repeatMode) {
this.enable();
}
},

_fireCreatedEvent: function () {
Expand Down
2 changes: 1 addition & 1 deletion dist/leaflet.draw.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/draw/handler/Draw.Marker.js
Expand Up @@ -5,6 +5,7 @@ L.Draw.Marker = L.Draw.Feature.extend({

options: {
icon: new L.Icon.Default(),
repeatMode: false,
zIndexOffset: 2000 // This should be > than the highest z-index any markers
},

Expand Down Expand Up @@ -88,6 +89,9 @@ L.Draw.Marker = L.Draw.Feature.extend({
this._fireCreatedEvent();

this.disable();
if (this.options.repeatMode) {
this.enable();
}
},

_fireCreatedEvent: function () {
Expand Down
4 changes: 4 additions & 0 deletions src/draw/handler/Draw.Polyline.js
Expand Up @@ -7,6 +7,7 @@ L.Draw.Polyline = L.Draw.Feature.extend({

options: {
allowIntersection: true,
repeatMode: false,
drawError: {
color: '#b00b00',
message: L.drawLocal.draw.handlers.polyline.error,
Expand Down Expand Up @@ -117,6 +118,9 @@ L.Draw.Polyline = L.Draw.Feature.extend({

this._fireCreatedEvent();
this.disable();
if (this.options.repeatMode) {
this.enable();
}
},

//Called to verify the shape is valid when the user tries to finish it
Expand Down
11 changes: 11 additions & 0 deletions src/draw/handler/Draw.SimpleShape.js
@@ -1,6 +1,14 @@
L.SimpleShape = {};

L.Draw.SimpleShape = L.Draw.Feature.extend({
options: {
repeatMode: true
},

initialize: function (map, options) {
L.Draw.Feature.prototype.initialize.call(this, map, options);
},

addHooks: function () {
L.Draw.Feature.prototype.addHooks.call(this);
if (this._map) {
Expand Down Expand Up @@ -63,5 +71,8 @@ L.Draw.SimpleShape = L.Draw.Feature.extend({
}

this.disable();
if (this.options.repeatMode) {
this.enable();
}
}
});

0 comments on commit cee8a31

Please sign in to comment.