antv-l7/examples/polygon/fill/demo/population.js

65 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-11-16 22:22:13 +08:00
import { Scene } from '@l7/scene';
2019-11-20 17:26:24 +08:00
import { PolygonLayer, LineLayer } from '@l7/layers';
2019-11-16 22:22:13 +08:00
const scene = new Scene({
id: 'map',
pitch: 0,
type: 'mapbox',
style: 'light',
2019-11-20 17:26:24 +08:00
center: [ 3.438, 40.16797 ],
zoom: 0.51329
2019-11-16 22:22:13 +08:00
});
Promise.all([
2019-11-20 17:26:24 +08:00
fetch(
'https://gw.alipayobjects.com/os/antvdemo/assets/data/world.geo.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([ world, population ]) {
const popobj = {};
population.forEach(element => {
popobj[element.Code] =
element['Population, female (% of total) (% of total)'];
});
// 数据绑定
world.features = world.features.map(fe => {
fe.properties.female = popobj[fe.id] * 1 || 0;
return fe;
});
const colors = [
'#0A3663',
'#1558AC',
'#3771D9',
'#4D89E5',
'#64A5D3',
'#72BED6',
'#83CED6',
'#A6E1E0',
'#B8EFE2',
'#D7F9F0'
2019-11-17 17:31:01 +08:00
];
2019-11-20 17:26:24 +08:00
const layer = new PolygonLayer({})
.source(world)
.scale('female', {
type: 'quantile'
2019-11-16 22:22:13 +08:00
})
2019-11-20 17:26:24 +08:00
.color('female', colors)
.shape('fill')
.style({
opacity: 0.9
});
const layer2 = new LineLayer({
zIndex: 2
})
.source(world)
.color('#fff')
.size(0.3)
.style({
opacity: 1
});
2019-11-16 22:22:13 +08:00
scene.addLayer(layer);
scene.addLayer(layer2);
});