Openlayers 4 - Load WMS image layer require authentication

后端 未结 2 1559
天命终不由人
天命终不由人 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:05

    For you purpose, you may want to use tileLoadFunction (API doc) from ol.source.ImageWMS

    To illustrate, you can look below. The 2 "secrets" are customLoader and for authentication to uncomment req.setRequestHeader("Authorization", "Basic " + window.btoa(user + ":" + pass));

    
    
      
        Tiled WMS
        
        
        
        
      
      
        

    The answer is mainly borrowed from How to add a http header to openlayers3 requests? but with some adaptations as the syntax provided was not working.

提交回复
热议问题