Access to Image from origin 'null' has been blocked by CORS policy

前端 未结 8 1518
野的像风
野的像风 2020-12-01 04:09

I have JavaScript application in OpenLayers 3, and my base layer is created from local tiles. I work only in my computer so I do not know why I have CORS error.



        
相关标签:
8条回答
  • 2020-12-01 04:59

    A solution to this is to serve your code, and make it run on a server, you could use web server for chrome to easily serve your pages.

    0 讨论(0)
  • 2020-12-01 05:00

    In this case the CORS problem has been caused by using the wrong source constructor in OpenLayers. ol.source.OSM is intended for accessing the default OpenStreetMap tiles from the web and for that reason defaults to crossOrigin:'anonymous'. If you are using a local source URL you should use the generic ol.source.XYZ constructor which doesn't default the crossOrigin setting (which is why setting crossOrigin:null above happened to work). And it is perfectly legitimate want to use file protocol for maps, for example on an SD card of a mobile device.

    0 讨论(0)
提交回复
热议问题