首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >过滤geojson TS

过滤geojson TS
EN

Stack Overflow用户
提问于 2019-12-04 01:09:20
回答 1查看 70关注 0票数 0

我使用angular 8。我的资源文件夹中有一个geojson文件:

代码语言:javascript
复制
{ "type": "FeatureCollection",
  "features": [
    { "type": "Feature", "geometry": {"type": "Point", "coordinates": [9.15926605,41.38718765]},"properties": {"f":"2A0000212","n":"HOPITAL LOCAL DE BONIFACIO","c":"20169 BONIFACIO","t":"2"}},
    { "type": "Feature", "geometry": {"type": "Point", "coordinates": [9.15926605,41.38718765]},"properties": {"f":"2A0003141","n":"ANTENNE DU SMUR  BONIFACIO","c":"20169 BONIFACIO","t":"2"}},
    ...
]}

我希望通过属性"t“(使用mat-select-form和NgModel )过滤geojson数据。

例如,过滤json中具有属性"t“=2的项。

代码语言:javascript
复制
//Component.ts

json;

constructor( private http: HttpClient) {}

ngOnInit() {this.http.get('assets/es.json').subscribe((json: any) => { this.json = json;});}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-04 01:55:06

以下rxjs运算符应按您所需的方式进行过滤:

代码语言:javascript
复制
import { of } from 'rxjs'; 
import { filter, flatMap, map } from 'rxjs/operators';

let filteredData = this.http.get('assets/es.json').pipe(
  map(response => JSON.parse(response)),
  flatMap(obj => obj.features),
  filter((feature: any) => feature.properties.t == 2)
);

filteredData.subscribe(x => {
  console.log(x);
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59162128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档