我正在使用MapBox将多个坐标绘制到Map上,由于某种原因,我试图在返回对象中返回的经度和纬度是未定义的。我是否缺少某种将数据带入对象的配置?
我以前做过这个,效果很好。
Data ("index") photo
密码-
targetLocations() {
const data = []
const timer = setInterval(() => {
for (let i = 0; i < store.state.location.locations.length; i++) {
this.coordinates = [store.state.location.locations[i]]
data.push(this.coordinates)
}
this.map.getSource('data-source').setData({
"type": "FeatureCollection",
"features": data.map(this.targetElements)
});
}, 1000);
},
targetElements(index) { // index returns the totals I expect
console.log(index)
const { longitude, latitude, userName, dateTimeStored } = index;
return {
"type": "Feature",
"properties": {
'description': "PID: " + userName + "<br />" + "Lng/Lat: " + index[0] + " / " + index[1] + "<br />" + "Captured At: " + dateTimeStored,
'name': userName,
'capturedAt': dateTimeStored,
},
"geometry": {
"type": "Point",
"coordinates": [longitude, latitude]
}
};
},
1条答案
按热度按时间wvmv3b1j1#
你正在推
coordinates = [...]
,所以数据中的每个元素都是一个数组。数据是一个矩阵,数组的数组。你应该销毁
like const [...] = index
,但你也可以只使用index.location等。