无效的 geoJson 对象 - Leaflet 和 Ajax
Invalid geoJson Object - Leaflet and Ajax
我有这段代码:
$.getJSON("https://nycdatastables.s3.amazonaws.com/2013-08-19T18:22:23.125Z/community-districts-polygon.geojson", function(data)
{
// Add GeoJSON layer to the map once the file is loaded
geojson = L.geoJson(data,
{
style: style,
onEachFeature: onEachFeature
}).addTo(map);
});
将一些数据加载到地图中。
但是,我想保留信息,并且由于 $.getJSON
是异步的,所以我使用适当的参数将其更改为 $.ajax
:
$.ajax({async: false, url: "https://nycdatastables.s3.amazonaws.com/2013-08-19T18:22:23.125Z/community-districts-polygon.geojson", success: function(data)
{
// Add GeoJSON layer to the map once the file is loaded
geojson = L.geoJson(data,
{
style: style,
onEachFeature: onEachFeature
}).addTo(map);
}});
第一段代码运行良好。但是,由于我改变了我得到的方法:
Error: Invalid GeoJSON object.
geometryToLayerleaflet.js:7:18482
addDataleaflet.js:7:17049
initializeleaflet.js:7:16778
eleaflet.js:5:2544
geoJsonleaflet.js:7:20518
successmap.js:38
jjquery-2.1.0.min.js:1:26681
fireWithjquery-2.1.0.min.js:1:27490
xjquery-2.1.0.min.js:3:10523
(anonymous function)jquery-2.1.0.min.js:3:14160
send
sendjquery-2.1.0.min.js:3:14347
ajaxjquery-2.1.0.min.js:3:9975
loadNeighborhoodsmap.js:35
(anonymous function)index.html:106
这恰好发生在 $.ajax
。
jQuery.getJSON() 是一个shorthand Ajax函数,相当于:
$.ajax({
dataType: "json",
url: url,
data: data,
success: success
});
所以在您的 ajax 调用中您忘记了 dataType 参数。
我有这段代码:
$.getJSON("https://nycdatastables.s3.amazonaws.com/2013-08-19T18:22:23.125Z/community-districts-polygon.geojson", function(data)
{
// Add GeoJSON layer to the map once the file is loaded
geojson = L.geoJson(data,
{
style: style,
onEachFeature: onEachFeature
}).addTo(map);
});
将一些数据加载到地图中。
但是,我想保留信息,并且由于 $.getJSON
是异步的,所以我使用适当的参数将其更改为 $.ajax
:
$.ajax({async: false, url: "https://nycdatastables.s3.amazonaws.com/2013-08-19T18:22:23.125Z/community-districts-polygon.geojson", success: function(data)
{
// Add GeoJSON layer to the map once the file is loaded
geojson = L.geoJson(data,
{
style: style,
onEachFeature: onEachFeature
}).addTo(map);
}});
第一段代码运行良好。但是,由于我改变了我得到的方法:
Error: Invalid GeoJSON object.
geometryToLayerleaflet.js:7:18482
addDataleaflet.js:7:17049
initializeleaflet.js:7:16778
eleaflet.js:5:2544
geoJsonleaflet.js:7:20518
successmap.js:38
jjquery-2.1.0.min.js:1:26681
fireWithjquery-2.1.0.min.js:1:27490
xjquery-2.1.0.min.js:3:10523
(anonymous function)jquery-2.1.0.min.js:3:14160
send
sendjquery-2.1.0.min.js:3:14347
ajaxjquery-2.1.0.min.js:3:9975
loadNeighborhoodsmap.js:35
(anonymous function)index.html:106
这恰好发生在 $.ajax
。
jQuery.getJSON() 是一个shorthand Ajax函数,相当于:
$.ajax({ dataType: "json", url: url, data: data, success: success });
所以在您的 ajax 调用中您忘记了 dataType 参数。