TypeError: Cannot read property 'lat' of null
通过查看github issues发现Leaftlet.Draw插件并不支持multipolygon类型的要素
https://github.com/Leaflet/Leaflet.draw/issues/268
解决方法通过测试发现可以通过将multipolygon拆分成多个polygon要素的方法可以解决这个问题
拆分方法如下:
function multiPolygon2polygons (multiPolygon){ if(multiPolygon.type !== 'MultiPolygon'){ return } var polygons = []; multiPolygon.coordinates.forEach((item)=>{ var polygon = { type: "Polygon", coordinates: [] }; polygon.coordinates = item; polygons.push(polygon) }); return polygons; }