Skip to content

Commit

Permalink
handle addData in geojson fixes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofsumit committed May 31, 2016
1 parent d20f42b commit 2a70d8a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ var geoJsonData = {
]
};
var geoJsonButton = document.getElementById('test-geojson');
var geoJsonLayer = L.geoJson(geoJsonData).addTo(map3);
var geoJsonLayer = L.geoJson().addTo(map3);
geoJsonLayer.addData(geoJsonData);
geoJsonLayer.pm.toggleEdit();
var bounds = geoJsonLayer.getBounds();
map3.fitBounds(bounds);
Expand Down
12 changes: 12 additions & 0 deletions dist/leaflet.pm.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,21 @@ L.PM.Edit.LayerGroup = L.Class.extend({
this._layerGroup = layerGroup;
this._layers = layerGroup.getLayers();

// listen to the edit event of the layers in this group
for(var i=0; i<this._layers.length; i++) {
this._layers[i].on('pm:edit', this._fireEdit, this);
}

// if a new layer is added to the group, reinitialize
this._layerGroup.on('layeradd', function(e) {
self.initialize(layerGroup);

// if editing was already enabled for this group, enable it again
// so the new layers are enabled
if(e.target.pm.enabled()) {
self.enable();
}
});
},
_fireEdit: function() {
this._layerGroup.fireEvent('pm:edit');
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.

12 changes: 12 additions & 0 deletions src/js/L.PM.LayerGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ L.PM.Edit.LayerGroup = L.Class.extend({
this._layerGroup = layerGroup;
this._layers = layerGroup.getLayers();

// listen to the edit event of the layers in this group
for(var i=0; i<this._layers.length; i++) {
this._layers[i].on('pm:edit', this._fireEdit, this);
}

// if a new layer is added to the group, reinitialize
this._layerGroup.on('layeradd', function(e) {
self.initialize(layerGroup);

// if editing was already enabled for this group, enable it again
// so the new layers are enabled
if(e.target.pm.enabled()) {
self.enable();
}
});
},
_fireEdit: function() {
this._layerGroup.fireEvent('pm:edit');
Expand Down

0 comments on commit 2a70d8a

Please sign in to comment.