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

make sure addfeature is only called on readd #893

Merged
merged 2 commits into from
Jan 5, 2017
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
24 changes: 22 additions & 2 deletions spec/Layers/FeatureLayer/FeatureLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,30 @@ describe('L.esri.FeatureLayer', function () {
});

it('should add features back to a map', function () {
layer.removeLayers([1]);
layer = L.esri.featureLayer({
url: 'http://gis.example.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0',
timeField: 'time',
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, {
color: 'green'
});
}
}).addTo(map);

var createSpy = sinon.spy();
layer.on('createfeature', createSpy);

var removeSpy = sinon.spy();
layer.on('removefeature', removeSpy);

layer.createLayers(features);
layer.removeLayers([1, 2]);
layer.addLayers([1]);

expect(map.hasLayer(layer.getFeature(1))).to.equal(true);
expect(map.hasLayer(layer.getFeature(2))).to.equal(true);
expect(map.hasLayer(layer.getFeature(2))).to.equal(false);
expect(createSpy.callCount).to.equal(2);
expect(removeSpy.callCount).to.equal(2);
});

it('should fire a addfeature event', function () {
Expand Down
6 changes: 0 additions & 6 deletions src/Layers/FeatureLayer/FeatureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ export var FeatureLayer = FeatureManager.extend({

// add the layer if the current zoom level is inside the range defined for the layer, it is within the current time bounds or our layer is not time enabled
if (this._visibleZoom() && (!this.options.timeField || (this.options.timeField && this._featureWithinTimeRange(geojson)))) {
this.fire('addfeature', {
feature: newLayer.feature
}, true);
this._map.addLayer(newLayer);
}
}
Expand All @@ -133,9 +130,6 @@ export var FeatureLayer = FeatureManager.extend({
for (var i = ids.length - 1; i >= 0; i--) {
var layer = this._layers[ids[i]];
if (layer) {
this.fire('addfeature', {
feature: layer.feature
}, true);
this._map.addLayer(layer);
}
}
Expand Down