【问题标题】:OpenLayers parsing GeoJSON error 'Uncaught TypeError: feature.getId is not a function'OpenLayers 解析 GeoJSON 错误 \'Uncaught TypeError: feature.getId is not a function\'
【发布时间】:2023-01-30 22:00:45
【问题描述】:

使用以下代码,我试图从地图上的多边形绘图中获取坐标,但我收到此控制台错误,而不是“Uncaught TypeError: feature.getId is not a function”

const drawInteraction = new Draw({
  type:'Polygon',
  freehand:true
})
map.addInteraction(drawInteraction);
drawInteraction.on('drawend',function(e){
  let parser= new GeoJSON();
  let drawnFeatures = parser.writeFeatureObject([e.feature]);
  console.log(drawnFeatures);
})      

【问题讨论】:

  • 你在哪里实现了 feature.getId?

标签: javascript


【解决方案1】:

实际上我发现了错误 让 drawnFeatures = parser.writeFeatures([e.feature]); 并不是 let drawnFeatures = parser.writeFeatureObject([e.feature]);

【讨论】:

    猜你喜欢
    • 2018-07-17
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 2014-08-15
    • 2021-12-16
    • 2018-04-20
    相关资源
    最近更新 更多