antvis/G2

The issue has been closed
地图高亮失效 #4921
pearmini posted onGitHub
- 版本 5.0.4
- 问题:1. chart 没有 state api 2. state 配置没有生效 3.没有恢复高亮
/**
* A recreation of this demo: https://vega.github.io/vega-lite/examples/geo_choropleth.html
*/
import { feature } from 'topojson';
Promise.all([
fetch('https://assets.antv.antgroup.com/g2/us-10m.json').then((res) =>
res.json(),
),
fetch('https://assets.antv.antgroup.com/g2/unemployment2.json').then((res) =>
res.json(),
),
]).then((values) => {
const [us, unemployment] = values;
const counties = feature(us, us.objects.counties).features;
const chart = new Chart({
container: 'container',
theme: 'classic',
autoFit: true,
});
chart
.geoPath()
.coordinate({ type: 'albersUsa' })
.data({
value: counties,
transform: [
{
type: 'join',
join: unemployment,
on: ['id', 'id'],
select: ['rate'],
},
],
})
.scale('color', {
type: 'sequential',
palette: 'ylGnBu',
unknown: '#fff',
})
.encode('color', 'rate')
.state('active', { fill: 'orange' })
.state('inactive', { opacity: 0.5 });
chart.interaction('elementHighlight', true);
chart.render();
});