2015-06-09 48 views
0

構建與OL-銫一個應用程序,這取決於WMS,可能發生跨源錯誤:代理對WMS層

"Image from origin 'http://www.ifremer.fr' has been blocked 
from loading by Cross-Origin Resource Sharing policy: 
No 'Access-Control-Allow-Origin' header is present on 
the requested resource. Origin 'http://localhost:8080' 
is therefore not allowed access" 

我沒有設置所使用的WMS CORS頭中的能力(像這裏建議的https://github.com/openlayers/ol3-cesium/issues/127)。

它看起來像一個代理可以設置在銫水平(見https://cesiumjs.org/2013/01/04/Cesium-Imagery-Layers-Tutorial/)。

它可以設置在OL級別,以便它在銫水平上設置它?如果是,如何?

回答

0

查看OL3-Cesium的初始化代碼,沒有內置在OL級別應用代理的功能。

您可以嘗試複製它們創建的圖層的imageryProvider設置,並在新圖層上包含代理。

我還沒有試過這個,所以我不知道這是否可行,但如果OL3不打算立即發佈更新來修復此問題,那麼值得一試。

1

只需修改URL即可使用代理,而不是通過教授有關代理的OL3。例如,如果您的WMS服務器:

http://www.example.com/geoserver/ows 

您只需通過這個網址OL3,使其通過您的代理在/proxy

/proxy/http://www.example.com/geoserver/ows 
0

在OL3代碼庫A quick code search表明,你可以在OL級別設置代理。

只需通過公共CORS代理(首先)使用WMS URL即可。 我已經回答了a similar question 也許可以幫忙。

0

我沒有使用銫,只是ThreeJS,但沒有一點圖像複製技巧就得到了相同的CORS問題。這對我的作品 -

function loadWmsImage(url, params, cb){ 
    var tmpImage = new Image(); 
    var wmsPng = url + jQuery.param(params); 
    tmpImage.onload = function(){ 
    var canv = document.createElement('canvas'); 
    var ctx = canv.getContext('2d'); 
    canv.width = this.width; 
    canv.height = this.height; 
    ctx.drawImage(this, 0, 0); 
    cb(canv.toDataURL()); 
    } 
    tmpImage.crossOrigin = 'anonymous'; 
    tmpImage.src = wmsPng; 
} 

loadWmsImage(htMapUrl, htMapParams, 
    function(img){ 
    customUniforms.bumpTexture.value = 
     new THREE.ImageUtils.loadTexture(img); 
    });