Basi c Аутентификация с использованием OL и Geoserver - PullRequest
0 голосов
/ 03 марта 2020

Я разработал приложение в Angular 8, Ol 6 и Geoserver 2.14.

В angular я создаю слой без аутентификации и работаю. Но теперь я хочу создать слой с базовой аутентификацией c.

// Create layer
    const layerNuevasConexiones = new ImageLayer({
      extend: fromLonLat([-140.544839, -69.337348, 16.301895, 83.547396]), // Version 5.2
      name: 'NuevasConexiones',
      base: false,
      aux: false,
      ref: false,
      pers: false,
      visible: true,
      min_zoom:14,
      max_zoom:30,  
      titulo: 'NuevasConeciones',
      source: new ImageWMS({
        // source: new OlSourceTileWMS({
        url: this.URLGeoServer + 'wms',
        params: { 'LAYERS': 'Nuevas_Conexiones', 'VERSION': '1.1.0', 'TILED': true },
        imageLoadFunction: this.imageLoader,
        serverType: 'geoserver',
        projection: miprojeccion,
        transition: 0,
        crossOrigin: 'anonymous'
      })
    });


  imageLoader(tile, src) { 
    const client = new XMLHttpRequest();
    client.open('GET', src);
    client.responseType = 'blob';
    client.setRequestHeader('Authorization', 'Basic ' + AppconfigService.settings.geoserver.auth); 
    client.setRequestHeader('Accept', 'image/webp,image/apng,image/*,*/*;q=0.8'); 
    client.setRequestHeader('Content-Type', 'image/png'); 

    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.onerror = function(e) {
      console.log("request.error called. Error: " + e);
      console.log(e);
    };
    client.onreadystatechange = function(){
      console.log("request.onreadystatechange called. readyState: " + this.readyState);
    };
    client.send();

  }

И ответить этой ошибкой

Access to XMLHttpRequest at 'http://nc.----.com:8081/geoserver/wms?SERVICE=WMS&VERSION=1.1.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=itssa%3ALineas&TILED=true&cql_filter=Tipo_Sistema%3D%27SI%27%20AND%20Codigo_Sistema%3D%201%20AND%20Nivel_Tension%3D%27BT%27&SRS=EPSG%3A4326&STYLES=&WIDTH=3671&HEIGHT=553&BBOX=-67.58611492077658%2C-39.026576788164476%2C-67.57845707922341%2C-39.02542320974473' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

В моем геосервере у меня включены cors

 <!-- Uncomment following filter to enable CORS -->
   <filter>
        <filter-name>cross-origin</filter-name>
        <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
    </filter> 


   <!-- Uncomment following filter to enable CORS -->
    <filter-mapping>
        <filter-name>cross-origin</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Что я делаю не так?

Спасибо

С уважением

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...