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

ArcGisMapServerCatalogItem layer ID and legends bug #5179

Merged
merged 5 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Change Log
* Added a new `lineAndPoint` chart type
* CustomChartComponent now has a "chart-type" attribute
* Added `AttributionTraits` to mappable and send it as property when creating Cesium's data sources and imagery providers. [#5167](https://github.com/TerriaJS/terriajs/pull/5167)
* Fix `ArcGisMapServerCatalogItem` layer ID and legends bug
* Re-add region mapping `applyReplacements`.
* Added `SearchParameterTraits` to item search for setting a human readable `name` or passing index specific `queryOptions` for each parameter through the catalog.
* Added `AttributionTraits` to mappable and send it as property when creating Cesium's data sources and imagery providers. [#5167](https://github.com/TerriaJS/terriajs/pull/5167)
Expand Down
28 changes: 18 additions & 10 deletions lib/Models/ArcGisMapServerCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,29 @@ class MapServerStratum extends LoadableStratum(
});
}

let layersMetadata = await getJson(item, layersUri);
let layersMetadataResponse = await getJson(item, layersUri);
const legendMetadata = await getJson(item, legendUri);

// TODO: some error handling on these requests would be nice

let layers: Layer[] | undefined;

// Use the slightly more basic layer metadata
if (layersMetadata === undefined) {
layersMetadata = serviceMetadata.layers;
if (
isDefined(layersMetadataResponse) &&
isDefined(serviceMetadata.layers)
) {
layers = serviceMetadata.layers;
} else {
if (layersMetadata.layers !== undefined) {
layersMetadata = layersMetadata.layers;
} else if (layersMetadata.id) {
layersMetadata = [layersMetadata];
if (isDefined(layersMetadataResponse.layers)) {
layers = layersMetadataResponse.layers;
// If layersMetadata is only a single layer -> shove into an array
} else if (isDefined(layersMetadataResponse.id)) {
layers = [layersMetadataResponse];
}
}

if (!isDefined(layersMetadata) || layersMetadata.length === 0) {
if (!isDefined(layers) || layers.length === 0) {
throw new TerriaError({
title: i18next.t(
"models.arcGisMapServerCatalogItem.noLayersFoundMessage"
Expand All @@ -196,7 +204,7 @@ class MapServerStratum extends LoadableStratum(
const stratum = new MapServerStratum(
item,
serviceMetadata,
layersMetadata,
layers,
legendMetadata,
token
);
Expand Down Expand Up @@ -303,7 +311,7 @@ class MapServerStratum extends LoadableStratum(
if (
layers.length > 0 &&
layers.indexOf(l.layerId.toString()) < 0 &&
layers.indexOf(l.layerName.toLowerCase()) < 0
layers.indexOf(l.layerName) < 0
) {
// layer not selected
return;
Expand Down
14 changes: 5 additions & 9 deletions test/Models/ArcGisMapServerCatalogItemSpec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import i18next from "i18next";
import { configure, runInAction } from "mobx";
import Rectangle from "terriajs-cesium/Source/Core/Rectangle";
import WebMercatorTilingScheme from "terriajs-cesium/Source/Core/WebMercatorTilingScheme";
import ArcGisMapServerImageryProvider from "terriajs-cesium/Source/Scene/ArcGisMapServerImageryProvider";
import when from "terriajs-cesium/Source/ThirdParty/when";
import isDefined from "../../lib/Core/isDefined";
import _loadWithXhr from "../../lib/Core/loadWithXhr";
import ArcGisMapServerCatalogItem from "../../lib/Models/ArcGisMapServerCatalogItem";
import Terria from "../../lib/Models/Terria";
import { RectangleTraits } from "../../lib/Traits/MappableTraits";
import createStratumInstance from "../../lib/Models/createStratumInstance";
import i18next from "i18next";

configure({
enforceActions: "observed",
Expand Down Expand Up @@ -235,10 +231,10 @@ describe("ArcGisMapServerCatalogItem", function() {

it("defines a rectangle", function() {
expect(item.rectangle).toBeDefined();
expect(item.rectangle.west).toEqual(97.90759300700006);
expect(item.rectangle.south).toEqual(-54.25906877199998);
expect(item.rectangle.east).toEqual(167.2820957260001);
expect(item.rectangle.north).toEqual(0.9835908000000587);
expect(item.rectangle.west).toEqual(100.14442693296783);
expect(item.rectangle.south).toEqual(-49.98407725285527);
expect(item.rectangle.east).toEqual(169.16154003177758);
expect(item.rectangle.north).toEqual(-2.3882536190571813);
});

it("defines info", function() {
Expand Down