javascriptopenlayers

Cannot read properties of undefined (reading 'getGeometry')


I've started playing around with OpenLayers, and the first thing I tried was to do one of the out-of-the-box tutorial exercises from the open library. I chose this one: https://openlayers.org/en/latest/examples/center.html and somehow it's not working out of the box, and I'm unable to determine why exactly.

I copy-pasted the three files, and I am getting the following error: main.js:56 Uncaught TypeError: Cannot read properties of undefined (reading 'getGeometry') at HTMLButtonElement.<anonymous> (main.js:56:31) at every occurrence of getGeometry.

I am confused, because I can click into getGeometry so the import seems to be working. Is there something wrong with my GeoJSON maybe?

I tried importing Geometry.js separately but that didn't work; and I also tried the simple accessible map example and that was working, so perhaps something is wrong with my imports or the way data is handled.


Solution

  • I was able to solve this issue by adding the GeoJSON to a data/ folder at the top level.