Cesium載入傾斜攝影模型,cors跨域的問題No 'Access-Control-Allow-Origin' header is present on the requested resource
用Cesium載入傾斜攝影模型時,會存在cors跨域的問題,報No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:61203' is therefore not allowed access錯誤,可通過修改傾斜攝影模型釋出的伺服器配置解決。
var tileset = new Cesium.Cesium3DTileset({ url: "http://192.168.7.208:80/Mode/Production.json", maximumScreenSpaceError: 1, //根據螢幕調整初始顯示精度 maximumNumberOfLoadedTiles: 1000, skipLevelOfDetail: true, baseScreenSpaceError: 1024, skipScreenSpaceErrorFactor: 16, skipLevels: 1, immediatelyLoadDesiredLevelOfDetail: false, loadSiblings: false, cullWithChildrenBounds: true, dynamicScreenSpaceError: true, dynamicScreenSpaceErrorDensity: 0.00278, dynamicScreenSpaceErrorFactor: 4.0, dynamicScreenSpaceErrorHeightFalloff: 0.25 });
1.模型通過IIS釋出傾斜攝影模型
在網站HTTP響應標頭新增如下標頭,重啟網站,即可解決
名稱:Access-Control-Allow-Headers 值:Content-Type,X-Requested-With,token
名稱:Access-Control-Allow-Methods 值:GET, POST, PUT, DELETE, OPTIONS
名稱:Access-Control-Allow-Origin 值:*
名稱:Access-Control-Request-Methods 值:GET, POST, PUT, DELETE, OPTIONS