Skip to content

Commit

Permalink
Merge pull request #6932 from TerriaJS/fix-wms-allowfeaturepicking
Browse files Browse the repository at this point in the history
Fix WMS allowFeaturePicking
  • Loading branch information
nf-s authored Oct 12, 2023
2 parents 89f4ca2 + 34490a6 commit 0c8cc07
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 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.3.7)

- Fix `WebMapServiceCatalogItem` `allowFeaturePicking`
- Allow translation of TableStylingWorkflow.
- Fix "Remove all" not removing selected/picked features
- [The next improvement]
Expand Down
9 changes: 6 additions & 3 deletions lib/Models/Catalog/Ows/WebMapServiceCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ class WebMapServiceCatalogItem
return undefined;
}

imageryProvider.enablePickFeatures = true;
// Reset feature picking for the current imagery layer.
// We disable feature picking for the next imagery layer.
imageryProvider.enablePickFeatures = this.allowFeaturePicking;

return {
imageryProvider,
Expand All @@ -422,6 +424,7 @@ class WebMapServiceCatalogItem
return undefined;
}

// Disable feature picking for the next imagery layer.
imageryProvider.enablePickFeatures = false;

return {
Expand Down Expand Up @@ -574,8 +577,8 @@ class WebMapServiceCatalogItem
tilingScheme: this.tilingScheme,
maximumLevel: this.getMaximumLevel(true) ?? this.maximumLevel,
minimumLevel: this.minimumLevel,
credit: this.attribution,
enablePickFeatures: this.allowFeaturePicking
credit: this.attribution
// Note: we set enablePickFeatures in _currentImageryParts and _nextImageryParts
};

if (isDefined(this.getFeatureInfoFormat?.type)) {
Expand Down
79 changes: 79 additions & 0 deletions test/Models/Catalog/Ows/WebMapServiceCatalogItemSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,85 @@ describe("WebMapServiceCatalogItem", function () {
);
});

it('creates "next" imagery provider when animating', async function () {
const terria = new Terria();
const wmsItem = new WebMapServiceCatalogItem("some-layer", terria);
runInAction(() => {
wmsItem.setTrait(CommonStrata.definition, "url", "http://example.com");
wmsItem.setTrait(
CommonStrata.definition,
"getCapabilitiesUrl",
"test/WMS/styles_and_dimensions.xml"
);
wmsItem.setTrait(CommonStrata.definition, "layers", "C");
wmsItem.setTrait(
CommonStrata.definition,
"currentTime",
"2002-01-01T00:00:00.000Z"
);
});

terria.timelineStack.addToTop(wmsItem);
terria.timelineStack.activate();

(await wmsItem.loadMapItems()).throwIfError();

expect(wmsItem.mapItems.length).toBe(1);
expect(wmsItem.isPaused).toBe(true);

runInAction(() => {
wmsItem.setTrait(CommonStrata.definition, "isPaused", false);
});

expect(wmsItem.mapItems.length).toBe(2);
expect(wmsItem.isPaused).toBe(false);

const currentImageryProvider = wmsItem.mapItems[0]
.imageryProvider as WebMapServiceImageryProvider;
expect(currentImageryProvider instanceof WebMapServiceImageryProvider).toBe(
true
);
expect(currentImageryProvider.enablePickFeatures).toBe(true);

const nextMapItem = wmsItem.mapItems[1];
const nextImageryProvider =
nextMapItem.imageryProvider as WebMapServiceImageryProvider;
expect(nextImageryProvider instanceof WebMapServiceImageryProvider).toBe(
true
);
expect(nextImageryProvider.enablePickFeatures).toBe(false);
expect(nextMapItem.alpha).toBe(0);
expect(nextMapItem.show).toBe(true);
});

it("sets enableFeaturePicking to false", async function () {
const terria = new Terria();
const wmsItem = new WebMapServiceCatalogItem("some-layer", terria);
runInAction(() => {
wmsItem.setTrait(CommonStrata.definition, "url", "http://example.com");
wmsItem.setTrait(CommonStrata.definition, "allowFeaturePicking", false);
wmsItem.setTrait(
CommonStrata.definition,
"getCapabilitiesUrl",
"test/WMS/styles_and_dimensions.xml"
);
wmsItem.setTrait(CommonStrata.definition, "layers", "C");
});

(await wmsItem.loadMetadata()).throwIfError();

expect(wmsItem.mapItems.length).toBe(1);
expect(wmsItem.allowFeaturePicking).toBe(false);

const imageryProvider = wmsItem.mapItems[0]
.imageryProvider as WebMapServiceImageryProvider;
expect(
imageryProvider instanceof WebMapServiceImageryProvider
).toBeTruthy();

expect(imageryProvider.enablePickFeatures).toBe(false);
});

it("dimensions and styles for a 'real' WMS layer", function (done) {
const terria = new Terria();
const wmsItem = new WebMapServiceCatalogItem("some-layer", terria);
Expand Down

0 comments on commit 0c8cc07

Please sign in to comment.