Skip to content

Commit

Permalink
Merge pull request #441 from KaiVolland/featuregrid-style-layer
Browse files Browse the repository at this point in the history
Modifies implementation of featurestyle prop of FeatureGrid
  • Loading branch information
KaiVolland authored Feb 28, 2018
2 parents 1b610e8 + b887683 commit 93dc14e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
21 changes: 7 additions & 14 deletions src/Grid/FeatureGrid/FeatureGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ export class FeatureGrid extends React.Component {
const {
map,
features,
featureStyle,
selectable
} = this.props;

Expand All @@ -320,7 +319,6 @@ export class FeatureGrid extends React.Component {
if (this._source) {
this._source.clear();
this._source.addFeatures(nextProps.features);
this._source.forEachFeature(feature => feature.setStyle(featureStyle));
}

if (nextProps.zoomToExtent) {
Expand Down Expand Up @@ -378,11 +376,10 @@ export class FeatureGrid extends React.Component {

const layer = new OlLayerVector({
name: layerName,
source: source
source: source,
style: featureStyle
});

source.forEachFeature(feature => feature.setStyle(featureStyle));

map.addLayer(layer);

this._source = source;
Expand Down Expand Up @@ -421,7 +418,6 @@ export class FeatureGrid extends React.Component {
const {
map,
features,
featureStyle,
highlightStyle,
selectStyle
} = this.props;
Expand All @@ -444,7 +440,7 @@ export class FeatureGrid extends React.Component {
if (selectedRowKeys.includes(key)) {
feature.setStyle(selectStyle);
} else {
feature.setStyle(featureStyle);
feature.setStyle(null);
}
});

Expand All @@ -467,7 +463,6 @@ export class FeatureGrid extends React.Component {
onMapSingleClick = olEvt => {
const {
map,
featureStyle,
selectStyle
} = this.props;

Expand All @@ -485,7 +480,7 @@ export class FeatureGrid extends React.Component {
const key = this.props.keyFunction(selectedFeature);
if (rowKeys.includes(key)) {
rowKeys = rowKeys.filter(rowKey => rowKey !== key);
selectedFeature.setStyle(featureStyle);
selectedFeature.setStyle(null);
} else {
rowKeys.push(key);
selectedFeature.setStyle(selectStyle);
Expand Down Expand Up @@ -730,7 +725,6 @@ export class FeatureGrid extends React.Component {
unhighlightFeatures = unhighlightFeatures => {
const {
map,
featureStyle,
selectStyle
} = this.props;

Expand All @@ -747,7 +741,7 @@ export class FeatureGrid extends React.Component {
if (selectedRowKeys.includes(key)) {
feature.setStyle(selectStyle);
} else {
feature.setStyle(featureStyle);
feature.setStyle(null);
}
});
}
Expand Down Expand Up @@ -776,15 +770,14 @@ export class FeatureGrid extends React.Component {
resetFeatureStyles = () => {
const {
map,
features,
featureStyle
features
} = this.props;

if (!(map instanceof OlMap)) {
return;
}

features.forEach(feature => feature.setStyle(featureStyle));
features.forEach(feature => feature.setStyle(null));
}

/**
Expand Down
20 changes: 7 additions & 13 deletions src/Grid/FeatureGrid/FeatureGrid.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ describe('<FeatureGrid />', () => {
expect(wrapper.instance()._layer).toBeInstanceOf(OlLayerVector);
});

it('sets the given featureStyle to each feature in the given features array', () => {
it('sets the given featureStyle to the featurelayer', () => {
const wrapper = TestUtil.mountComponent(FeatureGrid, {map, features});

features.forEach(feature => {
expect(feature.getStyle()).toEqual(wrapper.prop('featureStyle'));
});
expect(wrapper.instance()._layer.getStyle()).toEqual(wrapper.prop('featureStyle'));
});

it('removes the vector layer from the map on unmount', () => {
Expand Down Expand Up @@ -207,7 +204,7 @@ describe('<FeatureGrid />', () => {
if (feature.ol_uid === selectedFeatureUid) {
expect(feature.getStyle()).toEqual(wrapper.prop('selectStyle'));
} else {
expect(feature.getStyle()).toEqual(wrapper.prop('featureStyle'));
expect(feature.getStyle()).toBe(null);
}
});
});
Expand All @@ -228,7 +225,7 @@ describe('<FeatureGrid />', () => {
wrapper.instance().resetFeatureStyles(features);

features.forEach(feature => {
expect(feature.getStyle()).toEqual(wrapper.prop('featureStyle'));
expect(feature.getStyle()).toBe(null);
});
});

Expand All @@ -242,7 +239,7 @@ describe('<FeatureGrid />', () => {
if (selectedRowKeys.includes(feature.ol_uid)) {
expect(feature.getStyle()).toEqual(wrapper.prop('selectStyle'));
} else {
expect(feature.getStyle()).toEqual(wrapper.prop('featureStyle'));
expect(feature.getStyle()).toBe(null);
}
});

Expand Down Expand Up @@ -339,9 +336,6 @@ describe('<FeatureGrid />', () => {
});

expect(wrapper.instance()._source.getFeatures()).toEqual(features);
features.forEach(feature => {
expect(feature.getStyle()).toEqual(wrapper.prop('featureStyle'));
});
expect(zoomToFeaturesSpy).toHaveBeenCalled();

zoomToFeaturesSpy.mockReset();
Expand Down Expand Up @@ -383,8 +377,8 @@ describe('<FeatureGrid />', () => {

expect(features[0].getStyle()).toEqual(wrapper.prop('highlightStyle'));

expect(features[1].getStyle()).toEqual(wrapper.prop('featureStyle'));
expect(features[2].getStyle()).toEqual(wrapper.prop('featureStyle'));
expect(features[1].getStyle()).toEqual(null);
expect(features[2].getStyle()).toEqual(null);

getFeaturesAtPixelSpy.mockReset();
getFeaturesAtPixelSpy.mockRestore();
Expand Down
2 changes: 1 addition & 1 deletion src/Grid/FeatureGrid/FeatureGridWfs.example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class RemoteFeatureGrid extends React.Component {
color: color
})),
text: new OlStyleText({
text: feature.get('name'),
text: feature ? feature.get('name') : '',
fill: new OlStyleFill({
color: 'rgb(0, 0, 0)'
}),
Expand Down

0 comments on commit 93dc14e

Please sign in to comment.