Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 过滤geots_Angular_Typescript_Filter_Rxjs_Geojson - Fatal编程技术网

Angular 过滤geots

Angular 过滤geots,angular,typescript,filter,rxjs,geojson,Angular,Typescript,Filter,Rxjs,Geojson,我和angular 8一起工作。我的资产文件夹中有一个geojson文件: { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [9.15926605,41.38718765]},"properties": {"f":"2A0000212","n":"HOPITAL LOCAL DE BONIFACIO","c":"

我和angular 8一起工作。我的资产文件夹中有一个geojson文件:

{ "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表单和NgModel)过滤geojson数据

例如,为属性“t”=2的项过滤json


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

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);
});

的答案应该有助于您朝着正确的方向前进。谢谢我尝试理解答案^^谢谢..我使用过滤器进行测试,但我有以下错误:core.js:6014错误类型错误:无法读取未定义的属性“t”?每个项目的“属性”中始终有一个“t”?每个项目是否都有“属性”?如果没有,您可以更改该属性要筛选的ne((feature:any)=>feature.properties&&feature.properties.t==2)是的,我始终具有属性,并且存在堆栈闪电战:如果您获得“无法读取未定义的属性't',则您的一个或多个数据记录没有“属性”属性或结构稍有不同。请使用筛选器使其与数据集中出现的不同情况相匹配。
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);
});