2019-11-21 17:52:18 +08:00
|
|
|
import { Scene, Marker } from '@antv/l7';
|
2019-11-27 14:54:53 +08:00
|
|
|
import { GaodeMap } from '@antv/l7-maps';
|
2019-11-20 17:26:24 +08:00
|
|
|
import * as G2 from '@antv/g2';
|
2019-11-26 17:51:29 +08:00
|
|
|
|
2019-11-14 11:50:12 +08:00
|
|
|
const scene = new Scene({
|
|
|
|
id: 'map',
|
2019-11-27 14:54:53 +08:00
|
|
|
map: new GaodeMap({
|
2019-11-26 17:51:29 +08:00
|
|
|
style: 'light',
|
|
|
|
center: [ 2.6125016864608597, 49.359131 ],
|
|
|
|
pitch: 0,
|
2019-11-26 19:17:39 +08:00
|
|
|
zoom: 4.19
|
|
|
|
})
|
2019-11-14 11:50:12 +08:00
|
|
|
});
|
2020-03-15 20:09:16 +08:00
|
|
|
scene.on('loaded', () => {
|
|
|
|
addChart();
|
|
|
|
scene.render();
|
|
|
|
});
|
2019-11-15 15:43:59 +08:00
|
|
|
function addChart() {
|
2019-11-20 17:26:24 +08:00
|
|
|
fetch(
|
|
|
|
'https://gw.alipayobjects.com/os/basement_prod/0b96cca4-7e83-449a-93d0-2a77053e74ab.json'
|
|
|
|
)
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(data => {
|
|
|
|
data.nodes.forEach(function(item) {
|
|
|
|
const el = document.createElement('div');
|
|
|
|
const total =
|
|
|
|
item.gdp.Agriculture + item.gdp.Industry + item.gdp.Service;
|
2019-11-15 15:43:59 +08:00
|
|
|
|
2019-11-20 17:26:24 +08:00
|
|
|
const size = Math.min(parseInt(total / 30000, 10), 70);
|
|
|
|
if (size < 30) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const itemData = [
|
|
|
|
{
|
|
|
|
item: 'Agriculture',
|
|
|
|
count: item.gdp.Agriculture,
|
|
|
|
percent: item.gdp.Agriculture / total
|
|
|
|
},
|
|
|
|
{
|
|
|
|
item: 'Industry',
|
|
|
|
count: item.gdp.Industry,
|
|
|
|
percent: item.gdp.Industry / total
|
|
|
|
},
|
|
|
|
{
|
|
|
|
item: 'Service',
|
|
|
|
count: item.gdp.Service,
|
|
|
|
percent: item.gdp.Service / total
|
|
|
|
}
|
|
|
|
];
|
2019-11-17 17:31:01 +08:00
|
|
|
|
2019-11-20 17:26:24 +08:00
|
|
|
const chart = new G2.Chart({
|
|
|
|
container: el,
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
render: 'svg',
|
|
|
|
padding: 0
|
|
|
|
});
|
|
|
|
chart.legend(false);
|
|
|
|
chart.source(itemData);
|
|
|
|
chart.tooltip(false);
|
|
|
|
chart.axis('count', {
|
|
|
|
grid: false
|
|
|
|
});
|
|
|
|
chart
|
|
|
|
.interval()
|
|
|
|
.position('item*count')
|
|
|
|
.color('item', [ '#5CCEA1', '#5D7092', '#5B8FF9' ])
|
|
|
|
.opacity(1);
|
|
|
|
chart.render();
|
2019-11-28 17:25:56 +08:00
|
|
|
const marker = new Marker({
|
2019-11-20 17:26:24 +08:00
|
|
|
element: el
|
2019-12-02 15:16:45 +08:00
|
|
|
}).setLnglat({
|
|
|
|
lng: item.coordinates[0],
|
2019-12-02 17:27:39 +08:00
|
|
|
lat: item.coordinates[1]
|
2019-12-02 15:16:45 +08:00
|
|
|
});
|
2019-11-28 17:25:56 +08:00
|
|
|
scene.addMarker(marker);
|
2019-11-15 15:43:59 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|