我使用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-form和NgModel )过滤geojson数据。
例如,过滤json中具有属性"t“=2的项。
//Component.ts
json;
constructor( private http: HttpClient) {}
ngOnInit() {this.http.get('assets/es.json').subscribe((json: any) => { this.json = json;});}发布于 2019-12-04 01:55:06
以下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);
});https://stackoverflow.com/questions/59162128
复制相似问题