我已经开始使用 OpenLayers,我尝试的第一件事是从开放库中进行开箱即用的教程练习。我选择了这个:https://openlayers.org/en/latest/examples/center.html,不知怎的,它不能开箱即用,我无法确定到底为什么。
我复制粘贴了这三个文件,每次出现 getGeometry 时都会出现以下错误:
main.js:56 Uncaught TypeError: Cannot read properties of undefined (reading 'getGeometry') at HTMLButtonElement.<anonymous> (main.js:56:31)
。
我很困惑,因为我可以单击 getGeometry,因此导入似乎可以正常工作。我的 GeoJSON 可能有问题吗?
我尝试单独导入 Geometry.js 但这不起作用;我还尝试了简单的可访问地图示例,并且效果很好,所以也许我的导入或数据处理方式有问题。
我可以通过将 GeoJSON 添加到顶层的
data/
文件夹来解决此问题。