Leaflet geojson搜索错误(无法读取属性' lat' undefined)

时间:2017-12-16 12:39:23

标签: javascript search leaflet

在传单地图中,我正在添加搜索功能。基于属性' Clean_Feature_Name'在具有多边形坐标的geojson文件中。 但是,它不搜索,只显示以下错误消息。它似乎不基于propertyName进行搜索。可以请别人帮忙吗?

uncaught TypeError: Cannot read property 'lat' of undefined
at T.getCenter (leaflet.js:5)
at e._searchInLayer (leaflet-search.min.js:17)
at leaflet-search.min.js:17
at eachLayer (leaflet.js:5)
at e._recordsFromLayer (leaflet-search.min.js:17)
at e._fillRecordsCache (leaflet-search.min.js:17)
at leaflet-search.min.js:17

我的geojson数据

var Mars = 
{
 "type": "FeatureCollection",
 "features": [
  {
   "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [[[-68.42836570739746, 74.97826194763184], [-68.86942863464355, 74.8109302520752], [-69.42859840393066, 74.8525562286377], [-75.43949317932129, 76.16095542907715], [-75.46052360534668, 76.43600654602051], [-75.25974464416504, 77.1826000213623], [-75.18795585632324, 78.65801429748535], [-75.20999717712402, 78.6591625213623], [-74.92653465270996, 78.78381538391113], [-66.64877128601074, 77.87516212463379], [-66.60500526428223, 77.76282691955566], [-68.42836570739746, 74.97826194763184]]]
  },
  "properties": {
    "Feature_ID": 4,
    "Clean_Feature_Name": "Abalos Colles",
      }
 }
 ]
}

for(var i in Mars.features)
    Mars.features[i].properties.color = getColor(Mars.features[i].properties.number_of_papers );

这是我的代码(与此示例https://github.com/stefanocudini/leaflet-search/blob/master/examples/geojson-layer.html几乎相同)

var data = Mars;

   var featuresLayer = new L.GeoJSON(data, {
     style: function(feature) {
       return {color: feature.properties.color };
    },
    }

   map.addLayer(featuresLayer);
     var searchControl = new L.Control.Search({
      layer: featuresLayer,
      propertyName: 'Clean_Feature_Name',
      }
     });

  map.addControl( searchControl );  //inizialize search control

0 个答案:

没有答案
相关问题