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

Fixed WmscRequest query string #167

Merged
merged 1 commit into from
Mar 1, 2022

Conversation

JBou
Copy link
Contributor

@JBou JBou commented Feb 13, 2022

This PR fixes the appending of the query string.

I wanted to use this service in MapsUi: https://geoservices5.civis.bz.it/geoserver/p_bz-Cadastre/ows

When using it like above, the query string got added like this:
https://geoservices5.civis.bz.it/geoserver/p_bz-Cadastre/ows&SERVICE=WMS&REQUEST=GetMap&BBOX=... wich resulted in an error 404.

I then added ?REQUEST=GetCapabilities to my service url:
https://geoservices5.civis.bz.it/geoserver/p_bz-Cadastre/ows?REQUEST=GetCapabilities
which created this url: /geoserver/p_bz-Cadastre/ows?REQUEST=GetCapabilities&SERVICE=WMS&REQUEST=GetMap&BBOX=
and this error:

<?xml version="1.0" encoding="UTF-8"?>
<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows https://geoservices5.civis.bz.it/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
	<ows:Exception exceptionCode="InvalidParameterValue" locator="request">
		<ows:ExceptionText>Single value expected for request parameter request but instead found: [GetCapabilities, GetMap]</ows:ExceptionText>
	</ows:Exception>
</ows:ExceptionReport>

There are 2 workarounds:

  • Add request as lowercase string as in the wms sample
    https://geoservices5.civis.bz.it/geoserver/p_bz-Cadastre/ows?request=GetCapabilities
    In this case there is still a REQUEST=GetMap added and the lowercase request makes some confusion.

  • Add any dummy parameter
    https://geoservices5.civis.bz.it/geoserver/p_bz-Cadastre/ows?dummy

With this PR you can use the url without query parameters as source (e.g. https://geoservices5.civis.bz.it/geoserver/p_bz-Cadastre/ows) which makes it more obvious.

We could further improve it to completely replace the existing query parameters. I already prepared a solution, can push it if you decide to go this way (it uses an utility class named QueryString):

            var url = new UriBuilder(_baseUrl.AbsoluteUri);
            var query = new QueryString();

            query.Set("SERVICE", "WMS");
            if (!string.IsNullOrEmpty(_version)) query.Set("VERSION", _version);
            query.Set("REQUEST", "GetMap");
            query.Set("BBOX", TileTransform.TileToWorld(new TileRange(info.Index.Col, info.Index.Row), info.Index.Level, _schema).ToString());
            query.Set("FORMAT", _schema.Format);
            query.Set("WIDTH", _schema.GetTileWidth(info.Index.Level).ToString());
            query.Set("HEIGHT", _schema.GetTileHeight(info.Index.Level).ToString());
            var crsParameterName = !string.IsNullOrEmpty(_version) && string.CompareOrdinal(_version, "1.3.0") >= 0 ? "CRS" : "SRS";
            query.Set(crsParameterName, _schema.Srs);
            query.Set("LAYERS", ToCommaSeparatedValues(_layers));
            if (_styles != null && _styles.Count > 0) query.Set("STYLES", ToCommaSeparatedValues(_styles));
            AppendCustomParameters(query);
            url.Query = query.ToString();
            return new Uri(url.ToString());

@JBou
Copy link
Contributor Author

JBou commented Feb 13, 2022

I was on an old source code, I saw that you updated to netstandard2.0 in the meantime.
in that case we can use HttpUtility.ParseQueryString() instead of the QueryString class.

@pauldendulk
Copy link
Contributor

I was on an old source code, I saw that you updated to netstandard2.0 in the meantime. in that case we can use HttpUtility.ParseQueryString() instead of the QueryString class.

Is this something you want to add as part of this PR?

@pauldendulk pauldendulk merged commit 7c34fc5 into BruTile:master Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants