[Maps] Correctly handle single-feature joins (#30409) (#30471)

This commit is contained in:
Thomas Neirynck 2019-02-07 22:38:31 -05:00 committed by GitHub
parent 2ea8c33834
commit 273549eca5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -219,10 +219,21 @@ export class VectorStyle extends AbstractStyle {
max = Math.max(max, newValue);
}
}
//scale to [0,1]
const diff = max - min;
const propName = VectorStyle.getComputedFieldName(fieldName);
//scale to [0,1] domain
for (let i = 0; i < features.length; i++) {
features[i].properties[propName] = (features[i].properties[fieldName] - min) / (max - min);
const unscaledValue = features[i].properties[fieldName];
let scaledValue;
if (typeof unscaledValue !== 'number' || isNaN(unscaledValue)) {//cannot scale
scaledValue = -1;//put outside range
} else if (diff === 0) {//values are identical
scaledValue = 1;//snap to end of color range
} else {
scaledValue = (features[i].properties[fieldName] - min) / diff;
}
features[i].properties[propName] = scaledValue;
}
featureCollection.computed.push(fieldName);
return true;