Search code examples
vue.jsopenlayersopenlayers-3

openlayers error on draw/modify (in vuejs)


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)

Solution

  • 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]);
       }
    });