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

WMTS image provider with subdomains drops query #9606

Merged
merged 12 commits into from
Jun 15, 2021
Merged
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

##### Fixes :wrench:

- Fixed an issue in `WebMapTileServiceImageryProvider` where using URL subdomains caused query parameters to be dropped from requests. [#9606](https://github.com/CesiumGS/cesium/pull/9606)
- Fixed an issue in `ScreenSpaceCameraController.tilt3DOnTerrain` that caused unexpected camera behavior when tilting terrain diagonally along the screen. [#9562](https://github.com/CesiumGS/cesium/pull/9562)
- Fixed error handling in `GlobeSurfaceTile` to print terrain tile request errors to console. [#9570](https://github.com/CesiumGS/cesium/pull/9570)
- Fixed broken image URL in the KML Sandcastle. [#9579](https://github.com/CesiumGS/cesium/pull/9579)
Expand Down
22 changes: 17 additions & 5 deletions Source/Scene/WebMapTileServiceImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,15 @@ function WebMapTileServiceImageryProvider(options) {
var style = options.style;
var tileMatrixSetID = options.tileMatrixSetID;
var url = resource.url;
if (url.indexOf("{") >= 0) {

var bracketMatch = url.match(/{/g);
if (
!defined(bracketMatch) ||
(bracketMatch.length === 1 && /{s}/.test(url))
) {
resource.setQueryParameters(defaultParameters);
this._useKvp = true;
} else {
var templateValues = {
style: style,
Style: style,
Expand All @@ -237,9 +245,6 @@ function WebMapTileServiceImageryProvider(options) {

resource.setTemplateValues(templateValues);
this._useKvp = false;
} else {
resource.setQueryParameters(defaultParameters);
this._useKvp = true;
}

this._resource = resource;
Expand Down Expand Up @@ -330,8 +335,9 @@ function requestImage(imageryProvider, col, row, level, request, interval) {
var dynamicIntervalData = defined(interval) ? interval.data : undefined;

var resource;
var templateValues;
if (!imageryProvider._useKvp) {
var templateValues = {
templateValues = {
TileMatrix: tileMatrix,
TileRow: row.toString(),
TileCol: col.toString(),
Expand Down Expand Up @@ -368,10 +374,16 @@ function requestImage(imageryProvider, col, row, level, request, interval) {
if (defined(dynamicIntervalData)) {
query = combine(query, dynamicIntervalData);
}

templateValues = {
s: subdomains[(col + row + level) % subdomains.length],
};

resource = imageryProvider._resource.getDerivedResource({
queryParameters: query,
request: request,
});
resource.setTemplateValues(templateValues);
}

return ImageryProvider.loadImage(imageryProvider, resource);
Expand Down
51 changes: 51 additions & 0 deletions Specs/Scene/WebMapTileServiceImageryProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,57 @@ describe("Scene/WebMapTileServiceImageryProvider", function () {
expect(parseInt(queryObject.tilerow, 10)).toEqual(tilerow);
});

it("generates expected tile urls for subdomains", function () {
ebogo1 marked this conversation as resolved.
Show resolved Hide resolved
var options = {
srothst1 marked this conversation as resolved.
Show resolved Hide resolved
url: "http://wmts{s}.invalid",
format: "image/png",
layer: "someLayer",
style: "someStyle",
tileMatrixSetID: "someTMS",
tileMatrixLabels: ["first", "second", "third"],
};

var provider = new WebMapTileServiceImageryProvider(options);

spyOn(ImageryProvider, "loadImage");

var tilecol = 12;
var tilerow = 5;
var level = 1;
provider.requestImage(tilecol, tilerow, level);
var uri = new Uri(ImageryProvider.loadImage.calls.mostRecent().args[1].url);
var queryObject = queryToObject(uri.query);

expect(queryObject.request).toEqual("GetTile");
expect(queryObject.service).toEqual("WMTS");
expect(queryObject.version).toEqual("1.0.0");
expect(queryObject.format).toEqual(options.format);
expect(queryObject.layer).toEqual(options.layer);
expect(queryObject.style).toEqual(options.style);
expect(parseInt(queryObject.tilecol, 10)).toEqual(tilecol);
expect(queryObject.tilematrixset).toEqual(options.tileMatrixSetID);
expect(queryObject.tilematrix).toEqual(options.tileMatrixLabels[level]);
expect(parseInt(queryObject.tilerow, 10)).toEqual(tilerow);

tilecol = 1;
tilerow = 3;
level = 2;
provider.requestImage(tilecol, tilerow, level);
uri = new Uri(ImageryProvider.loadImage.calls.mostRecent().args[1].url);
queryObject = queryToObject(uri.query);

expect(queryObject.request).toEqual("GetTile");
expect(queryObject.service).toEqual("WMTS");
expect(queryObject.version).toEqual("1.0.0");
expect(queryObject.format).toEqual(options.format);
expect(queryObject.layer).toEqual(options.layer);
expect(queryObject.style).toEqual(options.style);
expect(parseInt(queryObject.tilecol, 10)).toEqual(tilecol);
expect(queryObject.tilematrixset).toEqual(options.tileMatrixSetID);
expect(queryObject.tilematrix).toEqual(options.tileMatrixLabels[level]);
expect(parseInt(queryObject.tilerow, 10)).toEqual(tilerow);
});

it("supports subdomains string urls", function () {
var options = {
url: "{s}",
Expand Down