Skip to content

Commit

Permalink
Merge pull request #16 from codeofsumit/develop
Browse files Browse the repository at this point in the history
new API to enable/disable draw on a map
  • Loading branch information
codeofsumit committed Feb 18, 2016
2 parents 1a6cef2 + 9de2029 commit d3aa259
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
30 changes: 18 additions & 12 deletions dist/leaflet.pm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ L.PM = L.PM || {



},
enableDraw: function(options) {

L.PM.Draw.Poly.enable(options.map);

},
addControls: function(map) {

Expand All @@ -31,13 +36,12 @@ L.PM = L.PM || {
},
'afterClick': function(e) {

var newPoly;

if(this.toggled()) {
newPoly = new L.PM.Draw.Poly(map);
newPoly.enable();
L.PM.enableDraw({
map: map
});
} else {
newPoly.disable();
map.disableDraw();
}
},
'doToggle': true,
Expand Down Expand Up @@ -156,15 +160,13 @@ L.Control.PMButton = L.Control.extend({

});

L.PM.Draw.Poly = L.Class.extend({
L.PM.Draw.Poly = {

initialize: function(map) {
this._map = map;
enable: function(map) {

var self = this;

},

enable: function() {
this._map = map;

this._layerGroup = new L.LayerGroup();
this._layerGroup.addTo(this._map);
Expand All @@ -176,6 +178,10 @@ L.PM.Draw.Poly = L.Class.extend({

this._map.on('click', this._createPolygonPoint, this);

this._map.disableDraw = function() {
self.disable();
};

},
disable: function() {

Expand Down Expand Up @@ -222,7 +228,7 @@ L.PM.Draw.Poly = L.Class.extend({
return marker;

},
});
};

L.PM.Edit.Poly = L.Class.extend({

Expand Down
2 changes: 1 addition & 1 deletion dist/leaflet.pm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/js/L.PM.Draw.Poly.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
L.PM.Draw.Poly = L.Class.extend({

initialize: function(map) {
this._map = map;
L.PM.Draw.Poly = {

enable: function(map) {

},
var self = this;

enable: function() {
this._map = map;

this._layerGroup = new L.LayerGroup();
this._layerGroup.addTo(this._map);
Expand All @@ -18,6 +16,10 @@ L.PM.Draw.Poly = L.Class.extend({

this._map.on('click', this._createPolygonPoint, this);

this._map.disableDraw = function() {
self.disable();
};

},
disable: function() {

Expand Down Expand Up @@ -64,4 +66,4 @@ L.PM.Draw.Poly = L.Class.extend({
return marker;

},
});
};
14 changes: 9 additions & 5 deletions src/js/L.PM.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ L.PM = L.PM || {



},
enableDraw: function(options) {

L.PM.Draw.Poly.enable(options.map);

},
addControls: function(map) {

Expand All @@ -31,13 +36,12 @@ L.PM = L.PM || {
},
'afterClick': function(e) {

var newPoly;

if(this.toggled()) {
newPoly = new L.PM.Draw.Poly(map);
newPoly.enable();
L.PM.enableDraw({
map: map
});
} else {
newPoly.disable();
map.disableDraw();
}
},
'doToggle': true,
Expand Down

0 comments on commit d3aa259

Please sign in to comment.