openlayers error on draw/modify (in vuejs)

[亡魂溺海] 提交于 2020-01-16 09:14:10

问题


The code I am using is in my previous question (resolved)

The interaction works perfectly and my goal is to get an array of coordinates, also works perfectly. Although everything works, I am getting an error in console every time I move the mouse in the display area. It doesn't affect functioning, but obviously I need to solve it... any ideas?

Draw.js?ac29:579 Uncaught TypeError: Cannot read property 'getGeometry' of null
    at Draw.modifyDrawing_ (Draw.js?ac29:579)
    at Draw.handlePointerMove_ (Draw.js?ac29:479)
    at Draw.handleEvent (Draw.js?ac29:871)
    at Map.handleMapBrowserEvent (PluggableMap.js?fe37:924)
    at MapBrowserEventHandler.boundListener (events.js?1e8d:41)
    at MapBrowserEventHandler.dispatchEvent (Target.js?0ec0:101)
    at MapBrowserEventHandler.handlePointerMove_ (MapBrowserEventHandler.js?2ad6:260)
    at PointerEventHandler.boundListener (events.js?1e8d:41)
    at PointerEventHandler.dispatchEvent (Target.js?0ec0:101)
    at PointerEventHandler.fireNativeEvent (PointerEventHandler.js?b114:397)

回答1:


I'm trying something quite random, but you maybe want to add some condition in you current code:

var modify = new Modify({source: source});
modify.on('modifyend',function(e){
   if(e.features && e.features.getArray().length) { //add this line
      console.log("feature id is",e.features.getArray()[0].getGeometry().getCoordinates()[0]);
   }
});


来源:https://stackoverflow.com/questions/52312737/openlayers-error-on-draw-modify-in-vuejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!