Openlayers 4 - Load WMS image layer require authentication

后端 未结 2 1601
天命终不由人
天命终不由人 2021-01-26 21:45

I try to load WMS image layer with openlayers 4.6 and angular 5, the code is:

const syr_layer = new ol_layer_Image({
  source: new ol_source_ImageWMS({
      url         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-26 22:15

    Thanks @Thomas, your answer isn't correct 100% but it clear the way for me to get the correct answer.

    This is the tileLoader function that worked for me:

    private tileLoader(tile, src) {
      const client = new XMLHttpRequest();
    
      client.open('GET', src);
      client.responseType = 'arraybuffer';
      client.setRequestHeader('Authorization', 'Basic ' + btoa(user + ':' + pass));
    
      client.onload = function () {
        const arrayBufferView = new Uint8Array(this.response);
        const blob = new Blob([arrayBufferView], { type: 'image/png' });
        const urlCreator = window.URL || (window as any).webkitURL;
        const imageUrl = urlCreator.createObjectURL(blob);
        tile.getImage().src = imageUrl;
      };
    
      client.send();
    }
    

提交回复
热议问题