2019-11-21 17:52:18 +08:00
|
|
|
import { Scene, Marker } from '@antv/l7';
|
2019-11-26 17:51:29 +08:00
|
|
|
import { AMap } from '@antv/l7-maps';
|
|
|
|
|
2019-11-14 17:25:16 +08:00
|
|
|
const scene = new Scene({
|
|
|
|
id: 'map',
|
2019-11-26 17:51:29 +08:00
|
|
|
map: new AMap({
|
|
|
|
style: 'light',
|
|
|
|
center: [ 105.790327, 36.495636 ],
|
|
|
|
pitch: 0,
|
2019-11-26 19:17:39 +08:00
|
|
|
zoom: 4
|
|
|
|
})
|
2019-11-14 17:25:16 +08:00
|
|
|
});
|
2019-11-21 18:46:52 +08:00
|
|
|
scene.render();
|
2019-11-20 17:26:24 +08:00
|
|
|
scene.on('loaded', () => {
|
2019-11-14 17:25:16 +08:00
|
|
|
addMarkers();
|
2019-11-20 17:26:24 +08:00
|
|
|
});
|
2019-11-14 17:25:16 +08:00
|
|
|
|
|
|
|
function addMarkers() {
|
2019-11-20 17:26:24 +08:00
|
|
|
fetch(
|
|
|
|
'https://gw.alipayobjects.com/os/basement_prod/67f47049-8787-45fc-acfe-e19924afe032.json'
|
|
|
|
)
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(nodes => {
|
|
|
|
for (let i = 0; i < nodes.length; i++) {
|
|
|
|
if (nodes[i].g !== '1' || nodes[i].v === '') { continue; }
|
|
|
|
const el = document.createElement('label');
|
|
|
|
el.className = 'lableclass';
|
|
|
|
el.textContent = nodes[i].v + '℃';
|
|
|
|
el.style.background = getColor(nodes[i].v);
|
|
|
|
el.style.borderColor = getColor(nodes[i].v);
|
|
|
|
new Marker({
|
|
|
|
element: el
|
|
|
|
})
|
|
|
|
.setLnglat({ lng: nodes[i].x * 1, lat: nodes[i].y })
|
|
|
|
.addTo(scene);
|
|
|
|
}
|
|
|
|
});
|
2019-11-14 17:25:16 +08:00
|
|
|
}
|
|
|
|
|
2019-11-20 17:26:24 +08:00
|
|
|
function getColor(v) {
|
|
|
|
return v > 50
|
|
|
|
? '#800026'
|
|
|
|
: v > 40
|
|
|
|
? '#BD0026'
|
|
|
|
: v > 30
|
|
|
|
? '#E31A1C'
|
|
|
|
: v > 20
|
|
|
|
? '#FC4E2A'
|
|
|
|
: v > 10
|
|
|
|
? '#FD8D3C'
|
|
|
|
: v > 5
|
|
|
|
? '#FEB24C'
|
|
|
|
: v > 0
|
|
|
|
? '#FED976'
|
|
|
|
: '#FFEDA0';
|
|
|
|
}
|