1
我试图绘制一条街道,当用户在使用OSM数据并由Mapbox呈现的地图上单击它时。我从点击中获得坐标并将它们发送到服务器,然后我返回Nominatim为特定街道提供的LineStrings。我有一个更长的街道问题:它们看起来不完整(例如,100米的正确划线,然后100条街道丢失,然后再正常划线),一些更长的街道可以制成10甚至更多更多细分。在我看来,这个问题可能是由于osm有不完整的数据(尽管我怀疑这个),或者我没有正确地绘制/加载数据。我的代码看起来像这样:WRONLY绘制街道使用Mapbox和Nominatim绘制多个GeoJSON行
map.on("click", function(e) {
//get coordinates and send them to the server.
function getRequest() {
return $.ajax({
url: "/street",
data: clickCoords,
});
};
$.when(getRequest()).done(function(response, status, jqXHR) {
streetGEOJSON = response;
var feat = [];
for (var i = 0; i < streetGEOJSON.length; i++) {
feat[i] = {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": streetGEOJSON[i]
}
}
}
var lines = {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": feat
}
}
map.addSource("street", lines);
map.addLayer({
"id": "street",
"type": "line",
"source": "street",
"filter": ["==", "$type", "LineString"],
"layout": {
"line-join": "round",
"line-cap": "round"
},
"paint": {
"line-color": "#888",
"line-width": 8
}
});
});
也注意到了这一点:http://prntscr.com/erg0r0。传递给get response的数据可能长达3000或更多字符。我猜这就是问题所在,并且浏览器不会等待所有的坐标..
任何帮助或洞察力都将非常感激。