Skip to content

Commit

Permalink
Merge pull request #21 from codeofsumit/develop
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
codeofsumit committed Feb 21, 2016
2 parents 41304c0 + 81cd053 commit 42ee15a
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
4 changes: 4 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
var map2 = L.map('example2').setView([51.505, -0.09], 13);

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

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map2);
Expand Down
24 changes: 20 additions & 4 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 @@ -141,7 +148,6 @@ L.Control.PMButton = L.Control.extend({
image.setAttribute('src', button.iconUrl);

L.DomEvent
.addListener(newButton, 'click', L.DomEvent.stop)
.addListener(newButton, 'click', button.onClick, this)
.addListener(newButton, 'click', this._clicked, this)
.addListener(newButton, 'click', button.afterClick, this);
Expand Down Expand Up @@ -190,6 +196,8 @@ L.PM.Draw.Poly = {
self.disable();
};

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

},
disable: function() {

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

this._map.removeLayer(this._layerGroup);

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

},
_createPolygonPoint: function(e) {

Expand Down Expand Up @@ -255,6 +265,8 @@ L.PM.Edit.Poly = L.Class.extend({

enable: function() {

var self = this;

if(!this.enabled()) {
this._enabled = true;

Expand All @@ -266,6 +278,10 @@ L.PM.Edit.Poly = L.Class.extend({
}

this._poly._map.addLayer(this._markerGroup);

this._poly.on('remove', function() {
self.disable();
});
}

},
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.

1 change: 0 additions & 1 deletion src/js/L.Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ L.Control.PMButton = L.Control.extend({
image.setAttribute('src', button.iconUrl);

L.DomEvent
.addListener(newButton, 'click', L.DomEvent.stop)
.addListener(newButton, 'click', button.onClick, this)
.addListener(newButton, 'click', this._clicked, this)
.addListener(newButton, 'click', button.afterClick, this);
Expand Down
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
6 changes: 6 additions & 0 deletions src/js/L.PM.Edit.Poly.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ L.PM.Edit.Poly = L.Class.extend({

enable: function() {

var self = this;

if(!this.enabled()) {
this._enabled = true;

Expand All @@ -26,6 +28,10 @@ L.PM.Edit.Poly = L.Class.extend({
}

this._poly._map.addLayer(this._markerGroup);

this._poly.on('remove', function() {
self.disable();
});
}

},
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 42ee15a

Please sign in to comment.