antv-l7/demos/demo/arc.js

42 lines
948 B
JavaScript
Raw Normal View History

2019-11-21 17:52:18 +08:00
import { Scene, LineLayer } from '@antv/l7';
import { Mapbox } from '@antv/l7-maps';
2019-11-10 21:20:26 +08:00
const scene = new Scene({
id: 'map',
map: new Mapbox({
pitch: 0,
style: 'dark',
2019-12-02 15:16:45 +08:00
center: [0, 23.107329],
zoom: 0,
}),
2019-11-10 21:20:26 +08:00
});
2019-11-20 17:26:24 +08:00
fetch(
2019-12-02 15:16:45 +08:00
'https://gw.alipayobjects.com/os/basement_prod/b83699f9-a96d-49b8-b2ea-f99299faebaf.json',
2019-11-20 17:26:24 +08:00
)
2019-12-02 15:16:45 +08:00
.then((res) => res.json())
.then((data) => {
2019-11-10 21:20:26 +08:00
function getAirportCoord(idx) {
2019-12-02 15:16:45 +08:00
return [data.airports[idx][3], data.airports[idx][4]];
2019-11-10 21:20:26 +08:00
}
2019-11-20 17:26:24 +08:00
const routes = data.routes.map(function(airline) {
2019-11-10 21:20:26 +08:00
return {
2019-12-02 15:16:45 +08:00
coord: [getAirportCoord(airline[1]), getAirportCoord(airline[2])],
2019-11-20 17:26:24 +08:00
};
2019-11-10 21:20:26 +08:00
});
2019-11-20 17:26:24 +08:00
const layer = new LineLayer({})
.source(routes, {
parser: {
type: 'json',
2019-12-02 15:16:45 +08:00
coordinates: 'coord',
},
2019-11-20 17:26:24 +08:00
})
.size(0.6)
.shape('arc')
.color('rgb(5, 5, 50)')
.style({
2019-12-02 15:16:45 +08:00
opacity: 0.05,
2019-11-20 17:26:24 +08:00
});
2019-11-10 21:20:26 +08:00
scene.addLayer(layer);
2019-11-20 17:26:24 +08:00
});