Skip to content

Commit

Permalink
drawing state is now synced with drawing button state
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofsumit committed Feb 20, 2016
1 parent bd189d1 commit 81cd053
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
3 changes: 1 addition & 2 deletions demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var map2 = L.map('example2').setView([51.505, -0.09], 13);

map2.on('pm:create', function(newPoly) {
alert('pm:create event fired');
console.log(newPoly);
alert('pm:create event fired');
});

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
Expand Down
17 changes: 14 additions & 3 deletions dist/leaflet.pm.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ L.PM = L.PM || {

var myButton = new L.Control.PMButton(drawPolyButton).addTo(map);

map.on('pm:create', function() {
// fire button click to toggle / disable
myButton._clicked();
map.on('pm:drawstart', function() {
if(!myButton.toggled()) {
myButton._clicked();
}
});

map.on('pm:drawend', function() {
if(myButton.toggled()) {
myButton._clicked();
}
});

return [myButton];
Expand Down Expand Up @@ -189,6 +196,8 @@ L.PM.Draw.Poly = {
self.disable();
};

this._map.fireEvent('pm:drawstart');

},
disable: function() {

Expand All @@ -198,6 +207,8 @@ L.PM.Draw.Poly = {

this._map.removeLayer(this._layerGroup);

this._map.fireEvent('pm:drawend');

},
_createPolygonPoint: function(e) {

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.

4 changes: 4 additions & 0 deletions src/js/L.PM.Draw.Poly.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ L.PM.Draw.Poly = {
self.disable();
};

this._map.fireEvent('pm:drawstart');

},
disable: function() {

Expand All @@ -29,6 +31,8 @@ L.PM.Draw.Poly = {

this._map.removeLayer(this._layerGroup);

this._map.fireEvent('pm:drawend');

},
_createPolygonPoint: function(e) {

Expand Down
13 changes: 10 additions & 3 deletions src/js/L.PM.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ L.PM = L.PM || {

var myButton = new L.Control.PMButton(drawPolyButton).addTo(map);

map.on('pm:create', function() {
// fire button click to toggle / disable
myButton._clicked();
map.on('pm:drawstart', function() {
if(!myButton.toggled()) {
myButton._clicked();
}
});

map.on('pm:drawend', function() {
if(myButton.toggled()) {
myButton._clicked();
}
});

return [myButton];
Expand Down

0 comments on commit 81cd053

Please sign in to comment.