Skip to content

Commit

Permalink
fix: quantile scale mutlipoygon 不准确 fix: #2086
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed Nov 30, 2023
1 parent 1940666 commit 117b626
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
74 changes: 74 additions & 0 deletions dev-demos/bugs/polygon/demos/quantile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//

// @ts-ignore
import { Scene, PolygonLayer, LineLayer, Popup } from '@antv/l7';
// @ts-ignore
import { GaodeMap, Map,Mapbox, GaodeMapV1 } from '@antv/l7-maps';
import React, { useEffect } from 'react';

export default () => {
useEffect(() => {

const scene = new Scene({
id: 'map',
map: new GaodeMap({
style: 'light',
center: [ -96, 37.8 ],
zoom: 3
})
});
scene.on('loaded', () => {
fetch(
'https://gw.alipayobjects.com/os/basement_prod/d36ad90e-3902-4742-b8a2-d93f7e5dafa2.json'
)
.then(res => res.json())
.then(data => {
const color = ['red', 'blue'];
const layer = new PolygonLayer({})
.source(data)
.scale('density', {
type: 'quantile'
})
.color(
'density', color
)
.shape('fill')
.active(true);
const layer2 = new LineLayer({
zIndex: 2
})
.source(data)
.color('#fff')
.active(true)
.size(1)
.style({
lineType: 'dash',
dashArray: [ 2, 2 ],
});
scene.addLayer(layer);
scene.addLayer(layer2);

layer.on('mousemove', e => {
const popup = new Popup({
offsets: [ 0, 0 ],
closeButton: false
})
.setLnglat(e.lngLat)
.setHTML(`<span>${e.feature.properties.name}: ${e.feature.properties.density}</span>`);
scene.addPopup(popup);
});
});
});


}, []);
return (
<div
id="map"
style={{
height: '500px',
position: 'relative',
}}
/>
);
};
2 changes: 2 additions & 0 deletions dev-demos/bugs/polygon/quantile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### polygon Quantile
<code src="./demos/quantile.tsx"></code>
14 changes: 13 additions & 1 deletion packages/layers/src/plugins/FeatureScalePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,19 @@ export default class FeatureScalePlugin implements ILayerPlugin {
const cfg: IScale = {
type,
};
const values = data?.map((item) => item[field]) || [];
// quantile domain 需要根据ID 进行去重
let values = []
if (type === ScaleTypes.QUANTILE) {
// 根据 obejct 属性 _id 进行去重
const idMap = new Map();
data?.forEach(obj => {
idMap.set(obj._id, obj[field]);
});
values = Array.from(idMap.values());
} else {
values = data?.map((item) => item[field]) || [];
}

if (scaleOption?.domain) {
cfg.domain = scaleOption?.domain;
} else if (type === ScaleTypes.CAT || type === ScaleTypes.IDENTITY) {
Expand Down

0 comments on commit 117b626

Please sign in to comment.