通过.each将数据从JSON文件推送到geoJSON数组

时间:2014-02-10 22:43:20

标签: jquery json each geojson mapbox

好的,我刚开始使用jQuery和Leaflet,所以请耐心等待。 我有一个包含17000行数据的大型JSON文件,我想转换为geoJSON,以便我可以在Mapbox中轻松实现它。我基于mapbox js网站的this示例。

这有效:

var geojson = [];
    geojson.push( 
{
"type": "Feature",
"geometry": {
  "type": "Point",
  "coordinates": [-77.03238901390978,38.913188059745586]
},
"properties": {
  "title": "Mapbox DC",
  "description": "1714 14th St NW, Washington DC",
  "marker-color": "#fc4353",
  "marker-size": "large",
  "marker-symbol": "monument"
}

这并没有,控制台没有错误,标记就消失了:

var geojson = [];
$.getJSON('data.json', function(raw){
$.each(raw, function(index, data){
geojson.push( 
{
"type": "Feature",
"geometry": {
  "type": "Point",
  "coordinates": [-77.03238901390978,38.913188059745586]
},
"properties": {
  "title": "Mapbox DC",
  "description": "1714 14th St NW, Washington DC",
  "marker-color": "#fc4353",
  "marker-size": "large",
  "marker-symbol": "monument"
}
}
);
});
});

正如我所做的那样:

L.mapbox.map('map', 'examples.map-9ijuk24y').setView([37.8, -96], 4).markerLayer.setGeoJSON(geojson);

我也做conole.log(geojson);在这两种情况下,两个数组的格式看起来完全相同。一个有一个条目,一个有1570个条目。

编辑:这是我的控制台。我展开了1570的阵列然后我展开了一个条目:

0 个答案:

没有答案