fix: d3 依赖版本ie 兼容问题 (#1216)

This commit is contained in:
@thinkinggis 2022-07-01 17:22:31 +08:00 committed by GitHub
parent ee886d70c7
commit ecbd4d52ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 31 deletions

View File

@ -19,17 +19,11 @@ scene.on('loaded', () => {
const color = [ 'rgb(255,255,217)', 'rgb(237,248,177)', 'rgb(199,233,180)', 'rgb(127,205,187)', 'rgb(65,182,196)', 'rgb(29,145,192)', 'rgb(34,94,168)', 'rgb(12,44,132)' ];
const layer = new PolygonLayer({})
.source(data)
.scale('density', {
type: 'quantize'
})
.color(
'density', d => {
return d > 1000 ? color[7] :
d > 500 ? color[6] :
d > 200 ? color[5] :
d > 100 ? color[4] :
d > 50 ? color[3] :
d > 20 ? color[2] :
d > 10 ? color[1] :
color[0];
}
'density', color
)
.shape('fill')
.active(true)

View File

@ -35,7 +35,7 @@
"@turf/union": "^6.5.0",
"d3-array": "1",
"d3-color": "^1.4.0",
"d3-interpolate": "1.4.0",
"d3-interpolate": "1.0.0",
"d3-scale": "2",
"earcut": "^2.2.1",
"eventemitter3": "^4.0.0",
@ -51,7 +51,7 @@
"devDependencies": {
"@types/d3-array": "^2.0.0",
"@types/d3-color": "^1.2.2",
"@types/d3-interpolate": "1.4.0",
"@types/d3-interpolate": "1.1.6",
"@types/d3-scale": "^2.1.1",
"@types/earcut": "^2.1.0",
"@types/gl-matrix": "^2.4.5",

View File

@ -129,27 +129,46 @@ export default class FeatureScalePlugin implements ILayerPlugin {
attributeScale.type = StyleScaleType.VARIABLE;
scales.forEach((scale) => {
// 如果设置了回调, 这不需要设置range
if (!attributeScale.callback) {
if (
attributeScale.values &&
attributeScale.values !== 'text' &&
scale.option?.type !== ScaleTypes.DIVERGING &&
scale.option?.type !== ScaleTypes.SEQUENTIAL
) {
scale.scale.range(attributeScale.values); // 判断常量, 默认值
} else if (scale.option?.type === ScaleTypes.CAT) {
// 如果没有设置初值且 类型为catrange ==domain;
scale.scale.range(scale.option.domain);
} else if (
scale.option?.type === ScaleTypes.DIVERGING ||
scale.option?.type === ScaleTypes.SEQUENTIAL
) {
scale.scale.interpolator(
// @ts-ignore
d3interpolate.interpolateRgbBasis(attributeScale.values),
);
if (!attributeScale.callback && attributeScale.values !== 'text') {
switch (scale.option?.type) {
case ScaleTypes.LOG:
case ScaleTypes.LINEAR:
case ScaleTypes.POWER:
if (
attributeScale.values &&
attributeScale.values.length > 2
) {
const tick = scale.scale.ticks(
attributeScale.values.length,
);
scale.scale.domain(tick);
}
attributeScale.values
? scale.scale.range(attributeScale.values)
: scale.scale.range(scale.option.domain);
break;
case ScaleTypes.QUANTILE:
case ScaleTypes.QUANTIZE:
case ScaleTypes.THRESHOLD:
scale.scale.range(attributeScale.values); //
break;
case ScaleTypes.CAT:
attributeScale.values
? scale.scale.range(attributeScale.values)
: scale.scale.range(scale.option.domain);
break;
case ScaleTypes.DIVERGING:
case ScaleTypes.SEQUENTIAL:
scale.scale.interpolator(
// @ts-ignore
d3interpolate.interpolateRgbBasis(attributeScale.values),
);
break;
}
}
if (attributeScale.values === 'text') {
scale.scale.range(scale.option?.domain);
}
});
} else {
// 设置attribute 常量值 常量直接在value取值