2 回答
TA贡献1836条经验 获得超13个赞
您可以complaintLayer
为标记控件放入一个数组,但该变量必须在正确的范围内 - 从您发布的代码来看,它看起来像是它所填充的函数的局部变量,因此它在外部不可见。
TA贡献1797条经验 获得超4个赞
根据 peeebeee 的建议,我通过加载数据并将它们放入“承诺”中来解决该问题。
您可以在下面看到一个工作示例:https : //jsfiddle.net/4x3sk1va/
下面的承诺示例(取自https://glitch.com/@ebrelsford)
// Fetch collisions data from our Glitch project
var collisionsFetch = fetch('https://cdn.glitch.com/03830164-a70e-47de-a9a1-ad757904d618%2Fpratt-collisions.geojson?1538625759015')
.then(function (response) {
// Read data as JSON
return response.json();
});
// Fetch lanes data from our Glitch project
var lanesFetch = fetch('https://cdn.glitch.com/fcedf615-7fef-4396-aa74-2e03fc324d71%2Fpratt-bike-routes.geojson?1538628711035')
.then(function (response) {
// Read data as JSON
return response.json();
});
// Once both have loaded, do some work with them
Promise.all([collisionsFetch, lanesFetch])
.then(function (fetchedData) {
console.log('Both datasets have loaded');
// Unpack the data from the Promise
var collisionsData = fetchedData[0];
var laneData = fetchedData[1];
// Add data in the order you want--first goes on the bottom
L.geoJson(collisionsData).addTo(map);
L.geoJson(laneData).addTo(map);
});
添加回答
举报