Skip to content

Commit

Permalink
Merge pull request #7060 from TerriaJS/arcgis-tiles-trait
Browse files Browse the repository at this point in the history
Add `usePreCachedTilesIfAvailable` to `ArcGisMapServerCatalogItemTraits`
  • Loading branch information
nf-s authored Mar 3, 2024
2 parents 646d445 + bba7cc0 commit 83a92b3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### next release (8.5.2)

- Add `usePreCachedTilesIfAvailable` to `ArcGisMapServerCatalogItemTraits`.
- [The next improvement]

#### 8.5.1 - 2024-02-23
Expand Down
27 changes: 17 additions & 10 deletions lib/Models/Catalog/Esri/ArcGisMapServerCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ class MapServerStratum extends LoadableStratum(

return [createStratumInstance(LegendTraits, { items })];
}

/** Only used "pre-cached" tiles if we aren't requesting any specific layers
* If the `layersArray` property is specified, we request individual dynamic layers and ignore the fused map cache.
*/
@computed get usePreCachedTilesIfAvailable() {
if (this._item.parameters) return false;

return (
this._item.layersArray.length === 0 ||
!this._item.layers ||
setsAreEqual(
this._item.layersArray.map((l) => l.id),
this.allLayers.map((l) => l.id)
)
);
}
}

StratumOrder.addLoadStratum(MapServerStratum.stratumName);
Expand Down Expand Up @@ -572,16 +588,7 @@ export default class ArcGisMapServerCatalogItem extends UrlMixin(
tileWidth: this.tileWidth,
parameters: params,
enablePickFeatures: this.allowFeaturePicking,
/** Only used "pre-cached" tiles if we aren't requesting any specific layers
* If the `layersArray` property is specified, we request individual dynamic layers and ignore the fused map cache.
*/
usePreCachedTilesIfAvailable:
this.layersArray.length === 0 ||
!this.layers ||
setsAreEqual(
this.layersArray.map((l) => l.id),
stratum.allLayers.map((l) => l.id)
),
usePreCachedTilesIfAvailable: this.usePreCachedTilesIfAvailable,
mapServerData: stratum.mapServer,
token: stratum.token,
credit: this.attribution
Expand Down
8 changes: 8 additions & 0 deletions lib/Traits/TraitsClasses/ArcGisMapServerCatalogItemTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,12 @@ export default class ArcGisMapServerCatalogItemTraits extends mixTraits(
type: "boolean"
})
isForwardTimeWindow: boolean = true;

@primitiveTrait({
name: "Is Forward Time Window",
description:
"If true, the server's pre-cached tiles are used if they are available. If false, then the MapServer export endpoint will be used. This will default to true if no specific layers are fetched (i.e. all layers are fetched). Otherwise, it will default to false. This will also default to false if parameters have been specified",
type: "boolean"
})
usePreCachedTilesIfAvailable?: boolean;
}
23 changes: 23 additions & 0 deletions test/Models/Catalog/esri/ArcGisMapServerCatalogItemSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ describe("ArcGisMapServerCatalogItem", function () {
imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.usingPrecachedTiles).toBe(false);
expect(item.usePreCachedTilesIfAvailable).toBe(false);
});

it("usePreCachedTilesIfAvailable = false if requesting layer ID in url path", async function () {
Expand All @@ -292,6 +293,26 @@ describe("ArcGisMapServerCatalogItem", function () {
imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.usingPrecachedTiles).toBe(false);
expect(item.usePreCachedTilesIfAvailable).toBe(false);
});

it("usePreCachedTilesIfAvailable = false if parameters have been specified", async function () {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
item.setTrait(CommonStrata.definition, "url", mapServerUrl);
item.setTrait(CommonStrata.definition, "layers", undefined);
item.setTrait(CommonStrata.definition, "parameters", {
test: "something"
});
});
await item.loadMapItems();

expect(item.parameters).toEqual({ test: "something" });

imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.usingPrecachedTiles).toBe(false);
expect(item.usePreCachedTilesIfAvailable).toBe(false);
});

it("usePreCachedTilesIfAvailable = true if not requesting specific layers", async function () {
Expand All @@ -306,6 +327,7 @@ describe("ArcGisMapServerCatalogItem", function () {
imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.usingPrecachedTiles).toBe(true);
expect(item.usePreCachedTilesIfAvailable).toBe(true);
});

it("usePreCachedTilesIfAvailable = true if requesting all layers", async function () {
Expand All @@ -327,6 +349,7 @@ describe("ArcGisMapServerCatalogItem", function () {
imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.usingPrecachedTiles).toBe(true);
expect(item.usePreCachedTilesIfAvailable).toBe(true);
});
});
});
Expand Down

0 comments on commit 83a92b3

Please sign in to comment.