我正在尝试将来自后端的位置数据放入 react-map-gl 中,对此我有一个小障碍。
addLines = () => {
const geo = this.state.geo;
const insideGeo = geo.map(dataItem => {
const json = new Buffer(dataItem.payload, "hex").toString();
if (json !== '')
return JSON.parse(json);
return json;
}).filter(item => (item !== ''));
const lat = insideGeo.map(item => item.eventData.location.latitude);
const lon = insideGeo.map(item => item.eventData.location.longitude);
console.log('Lat:', lat[4]);
console.log('Lon:', lon[4]);
const map = this.refs.map.getMap()
map.addLayer({
"id": "route",
"type": "line",
"source": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
lon[4], lat[4]
],
[
lon[5], lat[5]
],
]
}
}
},
"layout": {
"line-join": "round",
"line-cap": "round"
},
"paint": {
"line-color": "#18c3ea",
"line-width": 3
}
});
}
它的控制台日志屏幕 lon 和 lat 我想像这样放置整个坐标:{lon} {lat}
如何通过?
谢谢