Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mwu2018 committed Sep 11, 2023
1 parent bd1cdef commit ea01a46
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 8 deletions.
14 changes: 11 additions & 3 deletions lib/Models/Catalog/Esri/ArcGisMapServerCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,22 @@ export default class ArcGisMapServerCatalogItem extends UrlMixin(
windowDuration: number | undefined,
timeUnit: string | undefined
): number | undefined {
if (windowDuration === undefined || timeUnit === undefined) {
if (
windowDuration === undefined ||
windowDuration === 0 ||
timeUnit === undefined
) {
return undefined;
}

const rawTimeWindowData: any = {};
rawTimeWindowData[timeUnit] = windowDuration;
const duration = moment.duration(rawTimeWindowData);
return duration.asMilliseconds();
const duration = moment.duration(rawTimeWindowData).asMilliseconds();
if (duration === 0) {
return undefined;
} else {
return duration;
}
}

function getTimeWindowQueryString(
Expand Down
69 changes: 64 additions & 5 deletions test/Models/Catalog/esri/ArcGisMapServerCatalogItemSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ describe("ArcGisMapServerCatalogItem", function () {
});

describe("time-enabled layer", function () {
it("can load a time-enabled layer", async function () {
it("can load a layer, querying time without window", async function () {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
item.setTrait(
Expand All @@ -467,26 +467,49 @@ describe("ArcGisMapServerCatalogItem", function () {
}
expect(item.startTime).toBe("2004-11-26T09:43:22.000000000Z");
expect(item.stopTime).toBe("2019-11-03T14:00:00.000000000Z");
const expectedTimeQueryString = 1572789600000; // from json file
const imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.parameters.time).toBe(expectedTimeQueryString);
});

it("can load a time-enabled layer without interval specified by model dimensions", async function () {
it("can load a layer, querying time without window if timeWindowDuration is not defined", async function () {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
item.setTrait(
CommonStrata.definition,
"url",
"http://example.com/cadastre_history/MapServer"
);
item.setTrait(CommonStrata.user, "timeUnit", "year");
});
const defaultCurrentTime = 1572789600000; // from json file
await item.loadMapItems();
const expectedTimeQueryString = defaultCurrentTime;
const imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.parameters.time).toBe(expectedTimeQueryString);
});

it("can load a layer, querying time without window if timeUnit is not defined", async function () {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
item.setTrait(
CommonStrata.definition,
"url",
"http://example.com/cadastre_history/MapServer"
);
item.setTrait(CommonStrata.user, "timeWindowDuration", 2);
});
const defaultCurrentTime = 1572789600000; // from json file
await item.loadMapItems();
const expectedTimeQueryString = 1572789600000; // from json file
const expectedTimeQueryString = defaultCurrentTime;
const imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.parameters.time).toBe(expectedTimeQueryString);
});

it("can load a time-enabled layer with current time and forward interval specified by model dimensions", async function () {
it("can load a layer, querying time with forward window", async function () {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
item.setTrait(
Expand All @@ -507,7 +530,7 @@ describe("ArcGisMapServerCatalogItem", function () {
expect(imageryProvider.parameters.time).toBe(expectedTimeQueryString);
});

it("can load a time-enabled layer with current time and backward interval specified by model iimensions", async function () {
it("can load a layer, querying time with backward time window", async function () {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
item.setTrait(
Expand All @@ -527,6 +550,42 @@ describe("ArcGisMapServerCatalogItem", function () {
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.parameters.time).toBe(expectedTimeQueryString);
});

it("can load a layer, querying time without window if timeWindowDuration is 0", async function () {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
item.setTrait(
CommonStrata.definition,
"url",
"http://example.com/cadastre_history/MapServer"
);
item.setTrait(CommonStrata.user, "timeWindowDuration", 0);
item.setTrait(CommonStrata.user, "timeUnit", "year");
});
const defaultCurrentTime = 1572789600000; // from json file
await item.loadMapItems();
const imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.parameters.time).toBe(defaultCurrentTime);
});

it("can load a layer, querying time without window if timeUnit is invalid", async function () {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
item.setTrait(
CommonStrata.definition,
"url",
"http://example.com/cadastre_history/MapServer"
);
item.setTrait(CommonStrata.user, "timeWindowDuration", 2);
item.setTrait(CommonStrata.user, "timeUnit", "fortnight");
});
const defaultCurrentTime = 1572789600000; // from json file
await item.loadMapItems();
const imageryProvider = item.mapItems[0]
.imageryProvider as ArcGisMapServerImageryProvider;
expect(imageryProvider.parameters.time).toBe(defaultCurrentTime);
});
});

describe("TilesOnly + single fused map cache server", function () {
Expand Down

0 comments on commit ea01a46

Please sign in to comment.