OpenLayers 6:示例框选择错误

OpenLayers 6:示例框选择错误,openlayers,geojson,openlayers-6,Openlayers,Geojson,Openlayers 6,以下就是中openlayers站点的示例: 在本地,我有以下错误: Uncaught SyntaxError: Unexpected token <in JSON at position 0     at JSON.parse (<anonymous>)     at getObject (JSONFeature.js: 197)     at GeoJSON.JSONFeature.readFeatures (JSONFeature.js: 53)     at Vecto

以下就是中openlayers站点的示例:

在本地,我有以下错误:

Uncaught SyntaxError: Unexpected token <in JSON at position 0
    at JSON.parse (<anonymous>)
    at getObject (JSONFeature.js: 197)
    at GeoJSON.JSONFeature.readFeatures (JSONFeature.js: 53)
    at VectorSource. <anonymous> (featureloader.js: 94)
countries.geojson:

如何解决?我找到了解决办法

在OpenLayers中开发应用程序的过程中,不幸的是,由于CORS,在本地加载文件(geojson、png等)时出现问题

问题:

关于这个主题的优秀文章

为了解决这个问题,我使用了名为“”的Chrome扩展

启用它后,我可以轻松加载.geojson文件

这是一次成功

有更多方法可以在此地址停止您的开发环境的CORS:


我希望能在这方面帮助别人

对我来说工作正常。但是,如果您使用此版本6,它也会运行应用程序,但无法正常工作,因为它会尝试加载“好奇”,以便为您工作
var vectorSource = new VectorSource ({
  url: 'data/geojson/countries.geojson',
  format: new GeoJSON ()
});