0

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)
TDawg
  • 833
  • 2
  • 8
  • 24
  • Where did you use *getGeometry()* in your current code, to begin with? In your previous question all of these methods were commented. That's pretty obvious you try to get the geometry of some _undefined_ object somewhere. – F3L1X79 Sep 14 '18 at 14:25
  • Actually, I don't see it in current code at all. So I wondered if it was being tracked by mouse location, or something, or if because it is vuejs the variable needed to be exported in the data object... – TDawg Sep 14 '18 at 16:42

1 Answers1

2

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]);
   }
});
F3L1X79
  • 2,575
  • 2
  • 29
  • 45
  • Your answer is correct, I have to say this project has shown me I need to bump up my skills in this area quite a bit, I had 2 such errors in the project. Whats odd is without vuejs there was no such error, and it all worked, I literally copy/pasted from my vanilla js code into these methods :) – TDawg Sep 14 '18 at 18:20