显示的代码已经可以工作,但我想清理它。它声明了一个名为placez其中包含 geojson 格式的信息,供代码的下一部分使用过滤器读取和加载到地图上。但实际上,要映射的点数量超过 50,000 个(此处示例仅显示 2 个)。我想知道的是如何加载来自同一目录中的文件的数据地点gj.geojson,其中 50,000 个数据条目将以 geojson 格式写入变量placez而不是像示例中那样手动编写它们。为了整洁起见,其余代码被省略,并且与功能无关。提前致谢!
var placez = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"icon": "theatre"
},
"geometry": {
"type": "Point",
"coordinates": [-77.038659, 38.931567]
}
}, {
"type": "Feature",
"properties": {
"icon": "music"
},
"geometry": {
"type": "Point",
"coordinates": [-77.007481, 38.876516]
}
}]
};
map.on('load', function() {
// Add a GeoJSON source containing place coordinates and information.
map.addSource("placer", {
"type": "geojson",
"data": placez
});
placez.features.forEach(function(feature) {
var symbol = feature.properties['icon'];
var layerID = 'poi-' + symbol;
Use the 获取API https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API读取文件。
function fetchJSON(url) {
return fetch(url)
.then(function(response) {
return response.json();
});
}
假设placesgj.geojson
位于同一目录中:
var data = fetchJSON('placesgj.geojson')
.then(function(data) {
// do what you want to do with `data` here...
data.features.forEach(function(feature) {
console.log(feature);
var symbol = feature.properties['icon'];
console.log(symbol);
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)