我正在尝试将Mapbox api实现到我的Web应用程序中,但是我遇到了障碍。我的目标是从阵列中获取经度和纬度并将它们插入坐标中。我试过使用循环但它似乎不起作用的循环。如果有人有任何解决方案,我们将不胜感激!请注意我拿出了我的访问令牌
>>> model_names = ['is1', 'is5', 'is10', 'im1', 'im5', 'im10']
>>> model_values = [0.1, 0.2, 0.1, 0.3, 0.2, 0.3]
>>> dominant(model_names, model_values)
['im1', 'im10']
答案 0 :(得分:0)
我没有mapbox经验,但基于this documentation page,我想出了以下内容;
您需要在for循环中创建要素集(数组),如下所示:
var featureCollection = []; // Initialize empty collection
// Your longLat collection
var longLat = [
[53.515333, -6.190796],
[53.342686, -6.403656],
[51.678091, -9.624023],
[52.768293, -1.560059]
];
// for every item object within longLat
for(var itemIndex in longLat) {
// push new feature to the collection
featureCollection.push({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": longLat[itemIndex]
},
"properties": {
"title": "Mapbox DC",
"icon": "monument"
}
});
}
尝试跳过属性(图标和标题)。现在它们都是硬编码的。
然后,你以这种方式将它们传递给地图:
map.on('load', function () {
map.addLayer({
"id": "points",
"type": "symbol",
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": featureCollection
}
},
"layout": {
"icon-image": "{icon}-15",
"text-field": "{title}",
"text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
"text-offset": [0, 0.6],
"text-anchor": "top"
}
});
});
我不确定所有内容的含义(例如layout
包含所有图标),但这只是从上述示例中提取的,所以它不应该破坏任何内容。