【问题标题】:Filter Feature's outside the viewport in Mapbox在 Mapbox 的视口之外过滤功能
【发布时间】:2020-05-24 02:16:59
【问题描述】:

我有一个包含大约 100K 特征的巨大 geojson 文件,我想过滤视口之外的特征。我尝试了多种方法:

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 的地图实例(new Map(config....))

我在这里做错了吗?

或者有没有其他方法可以从 geojson 获取特征?

提前谢谢你...

【问题讨论】:

    标签: javascript mapbox mapbox-gl


    【解决方案1】:

    当我在 mapbox-gl Github 上发布这个问题时:

    https://github.com/mapbox/mapbox-gl-js/issues/9720

    在当前的 mapbox-gl 版本中,没有直接的方法来获取视口之外的功能。因此,正如@steve-bennett 所回答的那样,我正在获取geojson url,保存为javascript oject 中的引用并对其应用过滤器现在对我有用...

    希望对你有帮助...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-07
      • 2012-09-09
      • 2012-03-26
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      相关资源
      最近更新 更多