Javascript-基于其他json过滤geojson';s值

Javascript-基于其他json过滤geojson';s值,javascript,json,filter,geojson,Javascript,Json,Filter,Geojson,我正在努力根据另一个JSON的值过滤一个geojson。具体来说,我正试图根据另一个json中的id来过滤geojson。每次过滤后的geojson都返回null 我已经创建了一个JSfiddle来显示我正在尝试做什么 代码是 mygeojson={crs: {properties: {name: "EPSG:4326"}, type: "name"}, features: [ {geometry: {coordinates: [25, 37], type: "Point"},p

我正在努力根据另一个JSON的值过滤一个geojson。具体来说,我正试图根据另一个json中的id来过滤geojson。每次过滤后的geojson都返回null

我已经创建了一个JSfiddle来显示我正在尝试做什么

代码是

    mygeojson={crs: {properties: {name: "EPSG:4326"}, type: "name"},
features: [
    {geometry: {coordinates: [25, 37], type: "Point"},properties: {"wineryid":3},type:"Feature"},
  {geometry: {coordinates: [26, 37], type: "Point"},properties: {"wineryid":45},type:"Feature"},
  {geometry: {coordinates: [25, 38], type: "Point"},properties: {"wineryid":34},type:"Feature"},
  {geometry: {coordinates: [28, 37], type: "Point"},properties: {"wineryid":42},type:"Feature"},
  {geometry: {coordinates: [25, 342], type: "Point"},properties: {"wineryid":80},type:"Feature"},
  {geometry: {coordinates: [25.24, 37.12], type: "Point"},properties: {"wineryid":120},type:"Feature"}], type:"FeatureCollection"};
mylist=[{id:1, name:"test1"},{id:34,name:"test2"}];
tempgeojson = mygeojson.features.filter(function (item) {
  return (mylist.every(f => item.properties.id === f.id) )
});
filteredgeojson={};
filteredgeojson.features=tempgeojson;
filteredgeojson.crs=mygeojson.crs;
filteredgeojson.type="FeatureCollection";

如何获得所需的已过滤geojson?(在本例中,预期的geojson是关于id的1和34。)

尝试以下代码进行功能过滤

filteredgeojson.features = mygeojson.features.filter(item => { 
     if(mylist.filter(myitem => myitem.id === item.properties.wineryid).length > 0) { 
          return item;
      }
});

回答得好!简单,短,工作速度快。接受,谢谢!