antv-l7/examples/point/chart/demo/ring.js

111 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-11-21 17:52:18 +08:00
import { Scene, Marker } from '@antv/l7';
2019-11-20 17:26:24 +08:00
import * as G2 from '@antv/g2';
2019-11-17 17:31:01 +08:00
const CSS = `.l7-marker .g2-guide-html {
width: 50px;
height: 50px;
vertical-align: middle;
text-align: center;
line-height: 0.1
}
l7-marker .g2-guide-html .title {
font-size: 12px;
color: #8c8c8c;
font-weight: 300;
}
l7-marker .g2-guide-html .value {
font-size: 18px;
color: #000;
font-weight: bold;
}
2019-11-20 17:26:24 +08:00
`;
2019-11-17 17:31:01 +08:00
function loadCssCode(code) {
2019-11-20 17:26:24 +08:00
const style = document.createElement('style');
2019-11-17 17:31:01 +08:00
style.type = 'text/css';
style.rel = 'stylesheet';
// for Chrome Firefox Opera Safari
style.appendChild(document.createTextNode(code));
// for IE
// style.styleSheet.cssText = code;
2019-11-20 17:26:24 +08:00
const head = document.getElementsByTagName('head')[0];
2019-11-17 17:31:01 +08:00
head.appendChild(style);
}
loadCssCode(CSS);
2019-11-16 22:22:13 +08:00
const scene = new Scene({
id: 'map',
pitch: 0,
type: 'mapbox',
style: 'dark',
2019-11-20 17:26:24 +08:00
center: [ 52.21496184144132, 24.121126851768906 ],
zoom: 3.802
2019-11-16 22:22:13 +08:00
});
2019-11-17 17:31:01 +08:00
window.mapScene = scene;
2019-11-16 22:22:13 +08:00
scene.on('loaded', () => {
Promise.all([
2019-11-20 17:26:24 +08:00
fetch(
'https://gw.alipayobjects.com/os/basement_prod/5b772136-a1f4-4fc5-9a80-9f9974b4b182.json'
).then(d => d.json()),
fetch(
'https://gw.alipayobjects.com/os/basement_prod/f3c467a4-9ae0-4f08-bb5f-11f9c869b2cb.json'
).then(d => d.json())
]).then(function onLoad([ center, population ]) {
2019-11-16 22:22:13 +08:00
const popobj = {};
population.forEach(element => {
2019-11-20 17:26:24 +08:00
popobj[element.Code] =
element['Population, female (% of total) (% of total)'];
2019-11-16 22:22:13 +08:00
});
// 数据绑定
2019-11-20 17:26:24 +08:00
center.features = center.features.map(fe => {
2019-11-16 22:22:13 +08:00
fe.properties.female = popobj[fe.properties.id] * 1 || 0;
return fe;
2019-11-20 17:26:24 +08:00
});
center.features.forEach(point => {
2019-11-16 22:22:13 +08:00
const el = document.createElement('div');
const coord = point.geometry.coordinates;
const v = point.properties.female * 1;
2019-11-20 17:26:24 +08:00
if (v < 1 || (v > 46 && v < 54)) { return; }
2019-11-17 17:31:01 +08:00
const size = 60;
2019-11-20 17:26:24 +08:00
const data = [
{
type: '男性',
value: 100.0 - v.toFixed(2)
},
{
type: '女性',
value: v.toFixed(2) * 1
}
];
2019-11-16 22:22:13 +08:00
const chart = new G2.Chart({
container: el,
width: size,
height: size,
2019-11-17 17:31:01 +08:00
render: 'svg',
2019-11-16 22:22:13 +08:00
padding: 0
});
chart.source(data);
chart.legend(false);
chart.tooltip(false);
chart.coord('theta', {
radius: 0.9,
2019-11-17 17:31:01 +08:00
innerRadius: 0.6
2019-11-16 22:22:13 +08:00
});
2019-11-20 17:26:24 +08:00
chart
.intervalStack()
.position('value')
.color('type', [ '#5CCEA1', '#5B8FF9' ])
.opacity(1);
2019-11-16 22:22:13 +08:00
chart.render();
2019-11-20 17:26:24 +08:00
new Marker({ element: el })
.setLnglat({
lng: coord[0],
lat: coord[1]
})
.addTo(scene);
});
2019-11-16 22:22:13 +08:00
});
2019-11-20 17:26:24 +08:00
});