我有一个巨大的geojson文件,具有大约10万个要素,我想在视口外过滤要素。我尝试了多种方法:
https://github.com/mapbox/mapbox-gl-js/issues/8350和https://gis.stackexchange.com/questions/300292/how-to-load-geojson-features-outside-view-with-mapbox-gl?rq=1
但是似乎没有任何作用。我的代码是:
//Here i have already added empty geojson source
this.instance.addSource('seats_geojson', {
type: 'geojson',
data: {
"type": "FeatureCollection",
"features": []
}
});
//Here i have axios call with await and i am getting all the feature's in console
//console.log(e.data.featuresCollection.features) <--- 100K features
this.instance.once('idle', () => {
//Once i have the reponse ready I am setting source using setData
this.instance.getSource('seats_geojson').setData(e.data.featuresCollection);
//Here i am creating empty layer with above source
this.instance.addLayer({
id: "rowSelectionDup",
type: 'circle',
source: 'seats_geojson',
paint: {
'circle-color': "#4400d9"
},
filter: [
"in", "s", ""
]
});
});
但是要做类似的事情:
this.instance.querySourceFeatures('seats_geojson', {
sourceLayer: 'rowSelectionDup',
filter: ['in', 's', "1C"] //This section "s" 1C is in viewport and i am getting 207 feature's
});
this.instance.querySourceFeatures('seats_geojson', {
sourceLayer: 'rowSelectionDup',
filter: ['in', 's', "7C"]. //This section is outside viewport and result is []
});
注意:this.instance是mapbox-gl的地图实例(新Map(config ..))
我在这里做错什么了吗?
或还有其他方法可从geojson获取特征吗?
谢谢你...
当我在mapbox-gl Github上发布此问题时:
https://github.com/mapbox/mapbox-gl-js/issues/9720
从当前的mapbox-gl版本开始,没有直接方法可以在视口之外提取地图项。因此,正如@ steve-bennett回答的那样,我正在获取geojson网址,另存为javascript oject中的引用,并对其应用过滤器现在对我有效...
希望有帮助...