Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement repeat mode feature to allow individual draw tools to be remain enabled after a shape is drawn #178

Merged
merged 1 commit into from
Aug 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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();
}
}
});