Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print tool does not print WMS layers that requires credentials #1442

Closed
maan002 opened this issue Dec 6, 2023 · 5 comments
Closed

Print tool does not print WMS layers that requires credentials #1442

maan002 opened this issue Dec 6, 2023 · 5 comments
Assignees
Labels
Milestone

Comments

@maan002
Copy link
Contributor

maan002 commented Dec 6, 2023

Describe the bug
If you have a WMS layer that require credentials it will display correctly in the map. If you later want to print that map you will get a 401 error and the WMS layer is not included in the print.

Solution
In my investigation of the error I found that the problem seems to lie in the function exchangeLayer in the PrintModel.js file.

The code looks like this:

const imageSource = new ImageWMS({
        ...source.getProperties(),
        projection: source.getProjection(),
        crossOrigin: source.crossOrigin ?? "anonymous",
        params: { ...source.getParams() },
        ratio: 1,
        hidpi: false,
      });

However, if you check the values of the source object you will find that source.crossOrigin is undefined.

@maan002
Copy link
Contributor Author

maan002 commented Dec 6, 2023

The following code works:

      const imageSource = new ImageWMS({
        ...source.getProperties(),
        projection: source.getProjection(),
        crossOrigin: source.crossOrigin ?? source.crossOrigin_ ?? "anonymous",
        params: { ...source.getParams() },
        ratio: 1,
        hidpi: false,
      });

@maan002 maan002 added the bug label Dec 6, 2023
Hallbergs added a commit that referenced this issue Dec 6, 2023
For some reason the `crossOrigin` property is not exposed on `ImageWMS`... It feels wrong but i cannot find another way than checking the value of the private `crossOrigin_` property.

Tested the generic get:er (`source.get("crossOrigin")`) and it returns `undefined` as well.
@Hallbergs
Copy link
Member

Please test it out now. For some reason the crossOrigin property is not publicly available... Using the private property feels bad but it should do the trick.

@Hallbergs Hallbergs added this to the 3.13 milestone Dec 6, 2023
@jesade-vbg
Copy link
Contributor

Yes, it feels like a bug in OL. It seems to be working with TileWMS source but not with ImageWMS.
I vote for the sollution @maan002 presents, just add a nice comment :)

@maan002
Copy link
Contributor Author

maan002 commented Dec 7, 2023

Yes, in my testing I got a layer that had a value in the source.crossOrigin property.
So both should be used (as in my example).

@Hallbergs
Copy link
Member

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

3 participants