无法将单独的geojson文件加载到Mapbox的javascript变量中

时间:2017-04-09 21:24:14

标签: javascript mapbox geojson

使用Mapbox示例商店定位器,我已经构建了自己的版本here

但是,Mapbox示例包含html本身中的所有geojson数据,这对于我不断增长的数据集来说会变得相当笨拙。相反,我希望能够将geojson数据与html文件分开。所以我把它拉进了'test.geojson'并检查以确保它有效。我读了几个关于如何从单独的本地文件(或url)加载geojson数据的解释,所以I tried this

//I replaced the geojson data that had previously been in the html with this to try and create a variable that loads the geojson data from a separate file
var stores = L.mapbox.featureLayer()
.loadURL('test.geojson')
.addTo(map);

// This was what was in the original code I got from the mapbox example
map.on('load', function (e) {
map.addSource("places", {
  "type": "geojson",
  "data": stores
});
buildLocationList(stores);
});

但正如您在链接中看到的那样,它并不起作用。我在javascript中缺少什么?

0 个答案:

没有答案