Skip to content

Commit

Permalink
Merge pull request #349 from kneemer/set-style-on-feature-layer-fix
Browse files Browse the repository at this point in the history
Set the options style in the setStyle function so it is applied to new features
  • Loading branch information
patrickarlt committed Sep 30, 2014
2 parents 1eedc5e + 7da1ffc commit ddac08a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
42 changes: 35 additions & 7 deletions spec/Layers/FeatureLayer/FeatureLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,50 @@ describe('L.esri.Layers.FeatureLayer', function () {

it('should change styles on features with an object', function(){
layer.setStyle({
fill: 'red'
color: 'red'
});

expect(layer.getFeature(1).options.fill).to.equal('red');
expect(layer.getFeature(2).options.fill).to.equal('red');
expect(layer.getFeature(1).options.color).to.equal('red');
expect(layer.getFeature(2).options.color).to.equal('red');

layer.createLayers([{
type: 'Feature',
id: 3,
geometry: {
type: 'LineString',
coordinates: [[-122, 45], [-121, 40]]
},
properties: {
time: new Date('Febuary 24 2014').valueOf()
}
}]);

expect(layer.getFeature(3).options.color).to.equal('red');
});

it('should change styles on feautres with a function', function(){
it('should change styles on features with a function', function(){
layer.setStyle(function(){
return {
fill: 'red'
color: 'red'
};
});

expect(layer.getFeature(1).options.fill).to.equal('red');
expect(layer.getFeature(2).options.fill).to.equal('red');
expect(layer.getFeature(1).options.color).to.equal('red');
expect(layer.getFeature(2).options.color).to.equal('red');

layer.createLayers([{
type: 'Feature',
id: 3,
geometry: {
type: 'LineString',
coordinates: [[-122, 45], [-121, 40]]
},
properties: {
time: new Date('Febuary 24 2014').valueOf()
}
}]);

expect(layer.getFeature(3).options.color).to.equal('red');
});

it('should propagate events from individual features', function(){
Expand Down
1 change: 1 addition & 0 deletions src/Layers/FeatureLayer/FeatureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ L.esri.Layers.FeatureLayer = L.esri.Layers.FeatureManager.extend({
},

setStyle: function (style) {
this.options.style = style;
this.eachFeature(function (layer) {
this.setFeatureStyle(layer.feature.id, style);
}, this);
Expand Down

0 comments on commit ddac08a

Please sign in to comment.