Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.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
Javascript 如何基于对象过滤GeoJson中的对象?_Javascript_Json_D3.js_Filter_Geojson - Fatal编程技术网

Javascript 如何基于对象过滤GeoJson中的对象?

Javascript 如何基于对象过滤GeoJson中的对象?,javascript,json,d3.js,filter,geojson,Javascript,Json,D3.js,Filter,Geojson,我想根据根据多选下拉菜单中的选择创建的对象过滤GeoJSON数据 GeoJSON数据 { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ -115.55783329999998,32.9646667 ] }, "properties": { "magType":"mb", "type":"earthquake","horizontalErr

我想根据根据多选下拉菜单中的选择创建的对象过滤GeoJSON数据

GeoJSON数据

    {
    "type": "Feature",
    "geometry": {
       "type": "Point",
       "coordinates":  [ -115.55783329999998,32.9646667 ]
    },
    "properties": {  "magType":"mb", "type":"earthquake","horizontalError":0.32,"depthError":0.58,    "city":"Brawley",    "state":"California",    "country":"US"}
  },
  {
    "type": "Feature",
    "geometry": {
       "type": "Point",
       "coordinates":  [ -115.54583329999998,32.98 ]
    },
    "properties": {   "magType":"mb", "type":"earthquake",    "horizontalError":0.24, "depthError":0.46,    "city":"Brawley",    "state":"California", "country":"US"
    }
  },
  {
    "type": "Feature",
    "geometry": {
       "type": "Point",
       "coordinates":  [ -118.13383329999999,33.777333299999995 ]
    },
    "properties": {"magType":"ml","type":"earthquake","horizontalError":0.77,"depthError":0.9, "city":"Brawley","state":"California","country":"US"
    }
  },
  {
    "type": "Feature",
    "geometry": {
       "type": "Point",
       "coordinates":  [ -115.555,32.967 ]
    },
    "properties": {"magType":"ml","type":"earthquake",    "horizontalError":0.43,    "depthError":0.67,    "city":"Isangel","state":"Tafea","country":"VU"
  },
  {
    "type": "Feature",
    "geometry": {
       "type": "Point",
       "coordinates":  [ -115.55216670000001,32.9658333 ]
    },
    "properties": {"magType":"mw","type":"tsunami", "horizontalError":0.79, "depthError":1.35, "city":"Zaybak", "state":"Badakhshan", "country":"AF"
    }
  },
选定值的对象:

sel_data_category = {country:['US','AF'], city: ['Brawley','Zaybak'], magType:['mw']}
sel_data_quant ={horizontalError:[0.68,0.90]}
我想根据这些选定值筛选数据。因此,预期的输出应该是-

{
    "type": "Feature",
    "geometry": {
       "type": "Point",
       "coordinates":  [ -115.55216670000001,32.9658333 ]
    },
    "properties": {"magType":"mw","type":"tsunami", "horizontalError":0.79, "depthError":1.35, "city":"Zaybak", "state":"Badakhshan", "country":"AF"
    }
  }
我有什么办法可以做到这一点吗

编辑:缺少可使用的水平错误值

解决方案1:特定过滤器参数

let arr=[{“类型”:“特征”,“几何体”:{“类型”:“点”,“坐标”:[-115.5578332999998,32.9646667],“属性”:{“magType”:“mb”,“类型”:“地震”,“水平误差”:0.32,“深度误差”:0.58,“城市”:“争吵”,“州”:“加利福尼亚”,“国家”:“美国”},{“类型”:“特征”,“几何体”:{“类型”:“点”,“坐标”:-115.54583329998,32.98],“财产”:{“磁类型”:“mb”,“类型”:“地震”,“水平误差”:0.24,“深度误差”:0.46,“城市”:“布劳利”,“州”:“加利福尼亚”,“国家”:“美国”},{“类型”:“特征”,“几何”:{“类型”:“点”,“坐标”:[-118.133833999999,33.77733329999995]},“财产”:{“磁类型”:“ml”,“类型”:“地震”,“水平误差”:0.77,“深度误差”:0.9,“城市”:”布劳利、州、加利福尼亚、国家、美国、城市、伊桑格尔、州、塔菲亚、国家、城市、城市、伊桑格尔、州、塔菲亚、国家、国家、VU、类型、特征、几何、类型、地震、水平误差、0.43、深度误差、0.67、坐标[-115.55216670001,32.9658333],“财产”:{“magType”:“mw”,“type”:“海啸”,“水平误差”:0.79,“偏差”:1.35,“城市”:“扎巴克”,“州”:“巴达赫尚”,“国家”:“AF”}];
让filterObj={country:['US','AF'],city:['Brawley','Zaybak'],magType:['mw']};
让result=arr.filter(o=>filterbj.country.includes(o.properties.country)
&&filterObj.city.includes(o.properties.city)
&&包括(o.properties.magType));

console.log(结果)
谢谢,Nikhil。解决方案2对我来说很有吸引力。但是我错过了HorizontalError的值,这是一个选定的值范围。请你检查一下好吗?@gkuhu-你能控制
过滤器对象吗
也就是说,你能按需要在范围内的类别进行分组,或者匹配数组和/或其他过滤器的精确值吗er标准?因为如果你正在寻找解决方案2,那么必须有一些通用的方法来分离类型。我可以有两个不同的对象,一个用于类别,一个用于范围,但我不知道如何根据这两种类型的过滤器过滤数据。你能研究一下吗?我刚刚做了一个编辑