1 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
好的,我想我得到了修復(fù)。如果我在開始 ajax 查詢之前移動(dòng)map.on('load', function(){,而不是將它放在我的 ajax 成功函數(shù)中,那么我的代碼似乎可以正常工作:
map.on('load', function(){
$.ajax({
url: "test.php",
type: "POST",
proccessData: false,
dataType: "JSON",
success: function (json) {
//alert(JSON.stringify(json));
// Add a new source from our GeoJSON data
map.addSource('route', {
type: 'geojson',
data: json
});
// Create layer from source
map.addLayer({
'id': 'route',
'type': 'line',
'source': 'route',
'layout': {
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': 'red',
'line-width': 2
}
});
},
error: function(xhr, status, error){
var errorMessage = xhr.status + ': ' + xhr.statusText
alert('Error - ' + errorMessage);
},
});
});
- 1 回答
- 0 關(guān)注
- 144 瀏覽
添加回答
舉報(bào)