问题描述
我需要从具有Open Layers(和纯Javascript)的多个WebMapServer(我公司的)中获取图像。 基本上可以。问题是某些服务器需要HTTP基本身份验证。 OL文档和一个相关的SO问题说应该通过imageLoadFunction内部的XMLHttpRequest来完成:
https://openlayers.org/en/latest/apidoc/module-ol_Image.html
How to assign basic authentication header to XMLHTTPREQUEST?
首先,我想使用XMLHttpRequest获取图像,而无需基本身份验证:
var map = new ol.Map({
target: 'map',layers: [
new ol.layer.Image({
source: new ol.source.ImageWMS({
ratio: 1,params: { LAYERS: 'ENC',CSBOOL: '2083',CSVALUE: ',3'},url: 'https://wms-without-basic-auth.com/?',imageLoadFunction: function(image,src) {
image.getImage().src = src;
/*
var client = new XMLHttpRequest();
client.open('GET',src,true);
client.setRequestHeader( 'Content-Type','image/png' );
client.setRequestHeader( 'Accept','image/png' );
client.onload(function() {
image.getImage().src = src;
});
client.send();
*/
},})
})
],view: new ol.View({
center: ol.proj.fromLonLat([6,54]),zoom: 6
})
});
imageLoadFunction仅适用于行
image.getImage().src = src;
,但不带有注释的XMLHttpRequest。 我认为必须在client.onload函数中分配加载的图像,但是我不确定如何执行此操作。 那么我应该如何在imageLoadFunction中使用XMLHttpRequest?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)