Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Jan 7, 2020
1 parent 742125e commit 646e677
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class VectorStyleEditor extends Component {

if (
!_.isEqual(supportedFeatures, this.state.supportedFeatures) ||
!_.isEqual(selectedFeature, this.state.selectedFeature)
selectedFeature !== this.state.selectedFeature
) {
this.setState({ supportedFeatures, selectedFeature });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export function isOnlySingleFeatureType(featureType, supportedFeatures, hasFeatu
return supportedFeatures[0] === featureType;
}

if (!hasFeatureType) {
return false;
}

const featureTypes = Object.keys(hasFeatureType);
return featureTypes.reduce((isOnlyTargetFeatureType, featureTypeKey) => {
const hasFeature = hasFeatureType[featureTypeKey];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,46 +220,47 @@ export class VectorStyle extends AbstractStyle {
const features = _.get(sourceDataRequest.getData(), 'features', []);

const supportedFeatures = await this._source.getSupportedShapeTypes();
let hasFeatureType;
const hasFeatureType = {
[VECTOR_SHAPE_TYPES.POINT]: false,
[VECTOR_SHAPE_TYPES.LINE]: false,
[VECTOR_SHAPE_TYPES.POLYGON]: false,
};
if (supportedFeatures.length > 1) {
let hasPoints = false;
let hasLines = false;
let hasPolygons = false;
for (let i = 0; i < features.length; i++) {
const feature = features[i];
if (!hasPoints && POINTS.includes(feature.geometry.type)) {
hasPoints = true;
if (!hasFeatureType[VECTOR_SHAPE_TYPES.POINT] && POINTS.includes(feature.geometry.type)) {
hasFeatureType[VECTOR_SHAPE_TYPES.POINT] = true;
}
if (!hasLines && LINES.includes(feature.geometry.type)) {
hasLines = true;
if (!hasFeatureType[VECTOR_SHAPE_TYPES.LINE] && LINES.includes(feature.geometry.type)) {
hasFeatureType[VECTOR_SHAPE_TYPES.LINE] = true;
}
if (!hasPolygons && POLYGONS.includes(feature.geometry.type)) {
hasPolygons = true;
if (
!hasFeatureType[VECTOR_SHAPE_TYPES.POLYGON] &&
POLYGONS.includes(feature.geometry.type)
) {
hasFeatureType[VECTOR_SHAPE_TYPES.POLYGON] = true;
}
}
hasFeatureType = {
[VECTOR_SHAPE_TYPES.POINT]: hasPoints,
[VECTOR_SHAPE_TYPES.LINE]: hasLines,
[VECTOR_SHAPE_TYPES.POLYGON]: hasPolygons,
};
}

const featuresMeta = {
isPointsOnly: isOnlySingleFeatureType(
VECTOR_SHAPE_TYPES.POINT,
supportedFeatures,
hasFeatureType
),
isLinesOnly: isOnlySingleFeatureType(
VECTOR_SHAPE_TYPES.LINE,
supportedFeatures,
hasFeatureType
),
isPolygonsOnly: isOnlySingleFeatureType(
VECTOR_SHAPE_TYPES.POLYGON,
supportedFeatures,
hasFeatureType
),
geometryTypes: {
isPointsOnly: isOnlySingleFeatureType(
VECTOR_SHAPE_TYPES.POINT,
supportedFeatures,
hasFeatureType
),
isLinesOnly: isOnlySingleFeatureType(
VECTOR_SHAPE_TYPES.LINE,
supportedFeatures,
hasFeatureType
),
isPolygonsOnly: isOnlySingleFeatureType(
VECTOR_SHAPE_TYPES.POLYGON,
supportedFeatures,
hasFeatureType
),
},
};

const dynamicProperties = this.getDynamicPropertiesArray();
Expand Down Expand Up @@ -305,15 +306,15 @@ export class VectorStyle extends AbstractStyle {
}

_getIsPointsOnly = () => {
return _.get(this._getStyleMeta(), 'isPointsOnly', false);
return _.get(this._getStyleMeta(), 'geometryTypes.isPointsOnly', false);
};

_getIsLinesOnly = () => {
return _.get(this._getStyleMeta(), 'isLinesOnly', false);
return _.get(this._getStyleMeta(), 'geometryTypes.isLinesOnly', false);
};

_getIsPolygonsOnly = () => {
return _.get(this._getStyleMeta(), 'isPolygonsOnly', false);
return _.get(this._getStyleMeta(), 'geometryTypes.isPolygonsOnly', false);
};

_getDynamicPropertyByFieldName(fieldName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ describe('pluckStyleMetaFromSourceDataRequest', () => {
const vectorStyle = new VectorStyle({}, new MockSource());

const featuresMeta = await vectorStyle.pluckStyleMetaFromSourceDataRequest(sourceDataRequest);
expect(featuresMeta.isPointsOnly).toBe(true);
expect(featuresMeta.isLinesOnly).toBe(false);
expect(featuresMeta.isPolygonsOnly).toBe(false);
expect(featuresMeta.geometryTypes.isPointsOnly).toBe(true);
expect(featuresMeta.geometryTypes.isLinesOnly).toBe(false);
expect(featuresMeta.geometryTypes.isPolygonsOnly).toBe(false);
});

it('Should identify when feature collection only contains lines', async () => {
Expand All @@ -187,9 +187,9 @@ describe('pluckStyleMetaFromSourceDataRequest', () => {
const vectorStyle = new VectorStyle({}, new MockSource());

const featuresMeta = await vectorStyle.pluckStyleMetaFromSourceDataRequest(sourceDataRequest);
expect(featuresMeta.isPointsOnly).toBe(false);
expect(featuresMeta.isLinesOnly).toBe(true);
expect(featuresMeta.isPolygonsOnly).toBe(false);
expect(featuresMeta.geometryTypes.isPointsOnly).toBe(false);
expect(featuresMeta.geometryTypes.isLinesOnly).toBe(true);
expect(featuresMeta.geometryTypes.isPolygonsOnly).toBe(false);
});
});

Expand Down Expand Up @@ -237,9 +237,9 @@ describe('pluckStyleMetaFromSourceDataRequest', () => {
);

const featuresMeta = await vectorStyle.pluckStyleMetaFromSourceDataRequest(sourceDataRequest);
expect(featuresMeta.isPointsOnly).toBe(true);
expect(featuresMeta.isLinesOnly).toBe(false);
expect(featuresMeta.isPolygonsOnly).toBe(false);
expect(featuresMeta.geometryTypes.isPointsOnly).toBe(true);
expect(featuresMeta.geometryTypes.isLinesOnly).toBe(false);
expect(featuresMeta.geometryTypes.isPolygonsOnly).toBe(false);
});

it('Should extract scaled field range', async () => {
Expand Down

0 comments on commit 646e677

Please sign in to comment.