-
Notifications
You must be signed in to change notification settings - Fork 362
/
WebMapServiceCatalogItem.ts
809 lines (720 loc) · 25.2 KB
/
WebMapServiceCatalogItem.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
// const mobx = require('mobx');
// const mobxUtils = require('mobx-utils');
// Problems in current architecture:
// 1. After loading, can't tell what user actually set versus what came from e.g. GetCapabilities.
// Solution: layering
// 2. CkanCatalogItem producing a WebMapServiceCatalogItem on load
// 3. Observable spaghetti
// Solution: think in terms of pipelines with computed observables, document patterns.
// 4. All code for all catalog item types needs to be loaded before we can do anything.
import i18next from "i18next";
import { computed, makeObservable, override, runInAction } from "mobx";
import GeographicTilingScheme from "terriajs-cesium/Source/Core/GeographicTilingScheme";
import JulianDate from "terriajs-cesium/Source/Core/JulianDate";
import WebMercatorTilingScheme from "terriajs-cesium/Source/Core/WebMercatorTilingScheme";
import combine from "terriajs-cesium/Source/Core/combine";
import GetFeatureInfoFormat from "terriajs-cesium/Source/Scene/GetFeatureInfoFormat";
import WebMapServiceImageryProvider from "terriajs-cesium/Source/Scene/WebMapServiceImageryProvider";
import URI from "urijs";
import { JsonObject } from "../../../Core/Json";
import TerriaError from "../../../Core/TerriaError";
import createTransformerAllowUndefined from "../../../Core/createTransformerAllowUndefined";
import filterOutUndefined from "../../../Core/filterOutUndefined";
import isDefined from "../../../Core/isDefined";
import CatalogMemberMixin, {
getName
} from "../../../ModelMixins/CatalogMemberMixin";
import DiffableMixin, { DiffStratum } from "../../../ModelMixins/DiffableMixin";
import ExportWebCoverageServiceMixin from "../../../ModelMixins/ExportWebCoverageServiceMixin";
import GetCapabilitiesMixin from "../../../ModelMixins/GetCapabilitiesMixin";
import MappableMixin, {
ImageryParts
} from "../../../ModelMixins/MappableMixin";
import MinMaxLevelMixin from "../../../ModelMixins/MinMaxLevelMixin";
import TileErrorHandlerMixin from "../../../ModelMixins/TileErrorHandlerMixin";
import UrlMixin from "../../../ModelMixins/UrlMixin";
import {
TimeSeriesFeatureInfoContext,
csvFeatureInfoContext
} from "../../../Table/tableFeatureInfoContext";
import WebMapServiceCatalogItemTraits, {
SUPPORTED_CRS_3857,
SUPPORTED_CRS_4326
} from "../../../Traits/TraitsClasses/WebMapServiceCatalogItemTraits";
import CommonStrata from "../../Definition/CommonStrata";
import CreateModel from "../../Definition/CreateModel";
import LoadableStratum from "../../Definition/LoadableStratum";
import { BaseModel } from "../../Definition/Model";
import StratumOrder from "../../Definition/StratumOrder";
import TerriaFeature from "../../Feature/Feature";
import FeatureInfoContext from "../../Feature/FeatureInfoContext";
import SelectableDimensions, {
SelectableDimensionEnum
} from "../../SelectableDimensions/SelectableDimensions";
import Terria from "../../Terria";
import proxyCatalogItemUrl from "../proxyCatalogItemUrl";
import WebMapServiceCapabilities from "./WebMapServiceCapabilities";
import WebMapServiceCapabilitiesStratum from "./WebMapServiceCapabilitiesStratum";
import WebMapServiceCatalogGroup from "./WebMapServiceCatalogGroup";
// Remove problematic query parameters from URLs (GetCapabilities, GetMap, ...) - these are handled separately
const QUERY_PARAMETERS_TO_REMOVE = [
"request",
"service",
"x",
"y",
"width",
"height",
"bbox",
"layers",
"styles",
"version",
"format",
"srs",
"crs"
];
/** This LoadableStratum is responsible for setting WMS version based on CatalogItem.url */
export class WebMapServiceUrlStratum extends LoadableStratum(
WebMapServiceCatalogItemTraits
) {
static stratumName = "wms-url-stratum";
constructor(readonly catalogItem: WebMapServiceCatalogItem) {
super();
makeObservable(this);
}
duplicateLoadableStratum(model: BaseModel): this {
return new WebMapServiceUrlStratum(
model as WebMapServiceCatalogItem
) as this;
}
@computed get useWmsVersion130() {
if (
this.catalogItem.url?.toLowerCase().includes("version=1.1.0") ||
this.catalogItem.url?.toLowerCase().includes("version=1.1.1")
) {
return false;
}
}
}
// Order is important so that the traits are overridden correctly
StratumOrder.addLoadStratum(WebMapServiceUrlStratum.stratumName);
StratumOrder.addLoadStratum(DiffStratum.stratumName);
class WebMapServiceCatalogItem
extends TileErrorHandlerMixin(
ExportWebCoverageServiceMixin(
DiffableMixin(
MinMaxLevelMixin(
GetCapabilitiesMixin(
UrlMixin(
MappableMixin(
CatalogMemberMixin(CreateModel(WebMapServiceCatalogItemTraits))
)
)
)
)
)
)
)
implements SelectableDimensions, FeatureInfoContext
{
/**
* The collection of strings that indicate an Abstract property should be ignored. If these strings occur anywhere
* in the Abstract, the Abstract will not be used. This makes it easy to filter out placeholder data like
* Geoserver's "A compliant implementation of WMS..." stock abstract.
*/
static abstractsToIgnore = ["A compliant implementation of WMS"];
// hide elements in the info section which might show information about the datasource
_sourceInfoItemNames = [
i18next.t("models.webMapServiceCatalogItem.getCapabilitiesUrl")
];
_webMapServiceCatalogGroup: undefined | WebMapServiceCatalogGroup = undefined;
/** Default WMS parameters for version=1.3.0 */
static defaultParameters130 = {
transparent: true,
format: "image/png",
exceptions: "XML",
styles: "",
version: "1.3.0"
};
static defaultGetFeatureParameters130 = {
exceptions: "XML",
version: "1.3.0"
};
/** Default WMS parameters for version=1.1.1 */
static defaultParameters111 = {
transparent: true,
format: "image/png",
exceptions: "application/vnd.ogc.se_xml",
styles: "",
tiled: true,
version: "1.1.1"
};
static defaultGetFeatureParameters111 = {
exceptions: "application/vnd.ogc.se_xml",
version: "1.1.1"
};
static readonly type = "wms";
constructor(
id: string | undefined,
terria: Terria,
sourceReference?: BaseModel | undefined
) {
super(id, terria, sourceReference);
makeObservable(this);
this.strata.set(
WebMapServiceUrlStratum.stratumName,
new WebMapServiceUrlStratum(this)
);
}
get type() {
return WebMapServiceCatalogItem.type;
}
@override
get shortReport(): string | undefined {
if (
this.tilingScheme instanceof GeographicTilingScheme &&
this.terria.currentViewer.type === "Leaflet"
) {
return i18next.t("map.cesium.notWebMercatorTilingScheme", this);
}
return super.shortReport;
}
@computed
get colorScaleRange(): string | undefined {
if (this.supportsColorScaleRange) {
return `${this.colorScaleMinimum},${this.colorScaleMaximum}`;
}
return undefined;
}
async createGetCapabilitiesStratumFromParent(
capabilities: WebMapServiceCapabilities
) {
const stratum = await WebMapServiceCapabilitiesStratum.load(
this,
capabilities
);
runInAction(() => {
this.strata.set(GetCapabilitiesMixin.getCapabilitiesStratumName, stratum);
});
}
protected async forceLoadMapItems(): Promise<void> {
if (this.invalidLayers.length > 0)
throw new TerriaError({
sender: this,
title: i18next.t("models.webMapServiceCatalogItem.noLayerFoundTitle"),
message: i18next.t(
"models.webMapServiceCatalogItem.noLayerFoundMessage",
{ name: getName(this), layers: this.invalidLayers.join(", ") }
)
});
}
protected async forceLoadMetadata(): Promise<void> {
if (
this.strata.get(GetCapabilitiesMixin.getCapabilitiesStratumName) !==
undefined
)
return;
const stratum = await WebMapServiceCapabilitiesStratum.load(this);
runInAction(() => {
this.strata.set(GetCapabilitiesMixin.getCapabilitiesStratumName, stratum);
});
}
@override
get cacheDuration(): string {
if (isDefined(super.cacheDuration)) {
return super.cacheDuration;
}
return "0d";
}
@computed
get layersArray(): ReadonlyArray<string> {
if (Array.isArray(this.layers)) {
return this.layers;
} else if (this.layers) {
return this.layers.split(",");
} else {
return [];
}
}
/** LAYERS which are valid (i.e. exist in GetCapabilities).
* These can be fetched from the server (eg GetMap request)
*/
@computed get validLayers() {
const gcStratum: WebMapServiceCapabilitiesStratum | undefined =
this.strata.get(
GetCapabilitiesMixin.getCapabilitiesStratumName
) as WebMapServiceCapabilitiesStratum;
if (gcStratum)
return this.layersArray
.map((layer) => gcStratum.capabilities.findLayer(layer)?.Name)
.filter(isDefined);
return [];
}
/** LAYERS which are **INVALID** - they do **not** exist in GetCapabilities
* These layers can **not** be fetched the server (eg GetMap request)
*/
@computed get invalidLayers() {
const gcStratum: WebMapServiceCapabilitiesStratum | undefined =
this.strata.get(
GetCapabilitiesMixin.getCapabilitiesStratumName
) as WebMapServiceCapabilitiesStratum;
if (gcStratum)
return this.layersArray.filter(
(layer) => !isDefined(gcStratum.capabilities.findLayer(layer)?.Name)
);
return [];
}
@computed
get stylesArray(): ReadonlyArray<string> {
return this.styles?.split(",") ?? [];
}
@computed
get discreteTimes() {
const getCapabilitiesStratum: WebMapServiceCapabilitiesStratum | undefined =
this.strata.get(
GetCapabilitiesMixin.getCapabilitiesStratumName
) as WebMapServiceCapabilitiesStratum;
return getCapabilitiesStratum?.discreteTimes;
}
protected get defaultGetCapabilitiesUrl(): string | undefined {
if (this.uri) {
const baseUrl = QUERY_PARAMETERS_TO_REMOVE.reduce(
(url, parameter) =>
url
.removeQuery(parameter)
.removeQuery(parameter.toUpperCase())
.removeQuery(parameter.toLowerCase()),
this.uri.clone()
);
return baseUrl
.setSearch({
service: "WMS",
version: this.useWmsVersion130 ? "1.3.0" : "1.1.1",
request: "GetCapabilities"
})
.toString();
} else {
return undefined;
}
}
@computed
get canDiffImages(): boolean {
const hasValidDiffStyles = this.availableDiffStyles.some((diffStyle) =>
this.styleSelectableDimensions?.[0]?.options?.find(
(style) => style.id === diffStyle
)
);
return hasValidDiffStyles === true;
}
showDiffImage(
firstDate: JulianDate,
secondDate: JulianDate,
diffStyleId: string
) {
if (this.canDiffImages === false) {
return;
}
// A helper to get the diff tag given a date string
const firstDateStr = this.getTagForTime(firstDate);
const secondDateStr = this.getTagForTime(secondDate);
this.setTrait(CommonStrata.user, "firstDiffDate", firstDateStr);
this.setTrait(CommonStrata.user, "secondDiffDate", secondDateStr);
this.setTrait(CommonStrata.user, "diffStyleId", diffStyleId);
this.setTrait(CommonStrata.user, "isShowingDiff", true);
}
clearDiffImage() {
this.setTrait(CommonStrata.user, "firstDiffDate", undefined);
this.setTrait(CommonStrata.user, "secondDiffDate", undefined);
this.setTrait(CommonStrata.user, "diffStyleId", undefined);
this.setTrait(CommonStrata.user, "isShowingDiff", false);
}
getLegendUrlForStyle(
styleId: string,
firstDate?: JulianDate,
secondDate?: JulianDate
) {
const firstTag = firstDate && this.getTagForTime(firstDate);
const secondTag = secondDate && this.getTagForTime(secondDate);
const time = filterOutUndefined([firstTag, secondTag]).join(",");
const layerName = this.availableStyles.find((style) =>
style.styles.some((s) => s.name === styleId)
)?.layerName;
const uri = URI(
`${this.url}?service=WMS&version=1.1.0&request=GetLegendGraphic&format=image/png&transparent=True`
)
.addQuery("layer", encodeURIComponent(layerName || ""))
.addQuery("styles", encodeURIComponent(styleId));
if (time) {
uri.addQuery("time", time);
}
return uri.toString();
}
@computed
get mapItems() {
// Don't return anything if there are invalid layers
// See forceLoadMapItems for error message
if (this.invalidLayers.length > 0) return [];
if (this.isShowingDiff === true) {
return this._diffImageryParts ? [this._diffImageryParts] : [];
}
const result = [];
const current = this._currentImageryParts;
if (current) {
result.push(current);
}
const next = this._nextImageryParts;
if (next) {
result.push(next);
}
return result;
}
@computed
get tilingScheme() {
if (this.crs) {
if (SUPPORTED_CRS_3857.includes(this.crs))
return new WebMercatorTilingScheme();
if (SUPPORTED_CRS_4326.includes(this.crs))
return new GeographicTilingScheme();
}
return new WebMercatorTilingScheme();
}
@computed
private get _currentImageryParts(): ImageryParts | undefined {
const imageryProvider = this._createImageryProvider(
this.currentDiscreteTimeTag
);
if (imageryProvider === undefined) {
return undefined;
}
// Reset feature picking for the current imagery layer.
// We disable feature picking for the next imagery layer.
imageryProvider.enablePickFeatures = this.allowFeaturePicking;
return {
imageryProvider,
alpha: this.opacity,
show: this.show,
clippingRectangle: this.clipToRectangle ? this.cesiumRectangle : undefined
};
}
@computed
private get _nextImageryParts(): ImageryParts | undefined {
if (
this.terria.timelineStack.contains(this) &&
!this.isPaused &&
this.nextDiscreteTimeTag
) {
const imageryProvider = this._createImageryProvider(
this.nextDiscreteTimeTag
);
if (imageryProvider === undefined) {
return undefined;
}
// Disable feature picking for the next imagery layer.
imageryProvider.enablePickFeatures = false;
return {
imageryProvider,
alpha: 0.0,
show: true,
clippingRectangle: this.clipToRectangle
? this.cesiumRectangle
: undefined
};
} else {
return undefined;
}
}
@computed
private get _diffImageryParts(): ImageryParts | undefined {
const diffStyleId = this.diffStyleId;
if (
this.firstDiffDate === undefined ||
this.secondDiffDate === undefined ||
diffStyleId === undefined
) {
return;
}
const time = `${this.firstDiffDate},${this.secondDiffDate}`;
const imageryProvider = this._createImageryProvider(time);
if (imageryProvider) {
return {
imageryProvider,
alpha: this.opacity,
show: this.show,
clippingRectangle: this.clipToRectangle
? this.cesiumRectangle
: undefined
};
}
return undefined;
}
@computed
get diffModeParameters(): JsonObject {
return this.isShowingDiff ? { styles: this.diffStyleId } : {};
}
@computed
get diffModeGetFeatureInfoParameters(): JsonObject {
return this.isShowingDiff ? { styles: this.diffStyleId } : {};
}
getTagForTime(date: JulianDate): string | undefined {
const index = this.getDiscreteTimeIndex(date);
return index !== undefined
? this.discreteTimesAsSortedJulianDates?.[index].tag
: undefined;
}
private _createImageryProvider = createTransformerAllowUndefined(
(time: string | undefined): WebMapServiceImageryProvider | undefined => {
// Don't show anything on the map until GetCapabilities finishes loading.
if (this.isLoadingMetadata) {
return undefined;
}
if (this.url === undefined) {
return undefined;
}
console.log(`Creating new ImageryProvider for time ${time}`);
// Set dimensionParameters
const dimensionParameters = formatDimensionsForOws(this.dimensions);
if (time !== undefined) {
dimensionParameters.time = time;
}
// Construct parameters objects
// We use slightly different parameters for GetMap and GetFeatureInfo requests
const parameters: { [key: string]: any } = {
...(this.useWmsVersion130
? WebMapServiceCatalogItem.defaultParameters130
: WebMapServiceCatalogItem.defaultParameters111),
...this.parameters,
...dimensionParameters
};
const getFeatureInfoParameters: { [key: string]: any } = {
...(this.useWmsVersion130
? WebMapServiceCatalogItem.defaultGetFeatureParameters130
: WebMapServiceCatalogItem.defaultGetFeatureParameters111),
feature_count:
1 +
(this.maximumShownFeatureInfos ??
this.terria.configParameters.defaultMaximumShownFeatureInfos),
...this.parameters,
// Note order is important here, as getFeatureInfoParameters may override `time` dimension value
...dimensionParameters,
...this.getFeatureInfoParameters
};
if (this.supportsColorScaleRange) {
parameters.COLORSCALERANGE = this.colorScaleRange;
}
// Styles parameter is mandatory (for GetMap and GetFeatureInfo requests), but can be empty string to use default style
parameters.styles = this.styles ?? "";
getFeatureInfoParameters.styles = this.styles ?? "";
Object.assign(parameters, this.diffModeParameters);
Object.assign(
getFeatureInfoParameters,
this.diffModeGetFeatureInfoParameters
);
// Remove problematic query parameters from URL - these are handled by the parameters objects
const baseUrl = QUERY_PARAMETERS_TO_REMOVE.reduce(
(url, parameter) =>
url
.removeQuery(parameter)
.removeQuery(parameter.toUpperCase())
.removeQuery(parameter.toLowerCase()),
new URI(this.url)
);
// Set CRS for WMS 1.3.0
// Set SRS for WMS 1.1.1
const crs = this.useWmsVersion130 ? this.crs : undefined;
const srs = this.useWmsVersion130 ? undefined : this.crs;
const imageryOptions: WebMapServiceImageryProvider.ConstructorOptions = {
url: proxyCatalogItemUrl(this, baseUrl.toString()),
layers: this.validLayers.length > 0 ? this.validLayers.join(",") : "",
parameters,
crs,
srs,
getFeatureInfoParameters,
getFeatureInfoUrl: this.getFeatureInfoUrl,
tileWidth: this.tileWidth,
tileHeight: this.tileHeight,
tilingScheme: this.tilingScheme,
maximumLevel: this.getMaximumLevel(true) ?? this.maximumLevel,
minimumLevel: this.minimumLevel,
credit: this.attribution
// Note: we set enablePickFeatures in _currentImageryParts and _nextImageryParts
};
if (isDefined(this.getFeatureInfoFormat?.type)) {
imageryOptions.getFeatureInfoFormats = [
new GetFeatureInfoFormat(
this.getFeatureInfoFormat.type,
this.getFeatureInfoFormat.format
)
];
}
if (
imageryOptions.maximumLevel !== undefined &&
this.hideLayerAfterMinScaleDenominator
) {
// Make Cesium request one extra level so we can tell the user what's happening and return a blank image.
++imageryOptions.maximumLevel;
}
const imageryProvider = new WebMapServiceImageryProvider(imageryOptions);
return this.updateRequestImage(imageryProvider);
}
);
@computed
get styleSelectableDimensions(): SelectableDimensionEnum[] {
return this.availableStyles.map((layer, layerIndex) => {
let name = "Styles";
// If multiple layers -> prepend layer name to name
if (this.availableStyles.length > 1) {
// Attempt to get layer title from GetCapabilitiesStratum
const layerTitle =
layer.layerName &&
(
this.strata.get(
GetCapabilitiesMixin.getCapabilitiesStratumName
) as WebMapServiceCapabilitiesStratum
).capabilitiesLayers.get(layer.layerName)?.Title;
name = `${
layerTitle || layer.layerName || `Layer ${layerIndex + 1}`
} styles`;
}
const options = filterOutUndefined(
layer.styles.map(function (s) {
if (isDefined(s.name)) {
return {
name: s.title || s.name || "",
id: s.name as string
};
}
})
);
// Try to set selectedId to value stored in `styles` trait for this `layerIndex`
// The `styles` parameter is CSV, a style for each layer
const selectedId = this.styles?.split(",")?.[layerIndex];
return {
name,
id: `${this.uniqueId}-${layer.layerName}-styles`,
options,
selectedId,
setDimensionValue: (
stratumId: string,
newStyle: string | undefined
) => {
if (!newStyle) return;
runInAction(() => {
const styles = this.styleSelectableDimensions.map(
(style) => style.selectedId || ""
);
styles[layerIndex] = newStyle;
this.setTrait(stratumId, "styles", styles.join(","));
});
},
// There is no way of finding out default style if no style has been selected :(
// To use the default style, we just send empty "styles" to WMS server
// But if the server doesn't support GetLegendGraphic, then we can't request the default legend
// Therefore - we only add the "Default style" / undefined option if supportsGetLegendGraphic is true
allowUndefined: this.supportsGetLegendGraphic && options.length > 1,
undefinedLabel: i18next.t(
"models.webMapServiceCatalogItem.defaultStyleLabel"
),
disable: this.isShowingDiff
};
});
}
@computed
get wmsDimensionSelectableDimensions(): SelectableDimensionEnum[] {
const dimensions: SelectableDimensionEnum[] = [];
// For each layer -> For each dimension
this.availableDimensions.forEach((layer) => {
layer.dimensions.forEach((dim) => {
// Only add dimensions if hasn't already been added (multiple layers may have the same dimension)
if (
!isDefined(dim.name) ||
dim.values.length < 2 ||
dimensions.findIndex((findDim) => findDim.name === dim.name) !== -1
) {
return;
}
dimensions.push({
name: dim.name,
id: `${this.uniqueId}-${dim.name}`,
options: dim.values.map((value) => {
let name = value;
// Add units and unitSybol if defined
if (typeof dim.units === "string" && dim.units !== "") {
if (typeof dim.unitSymbol === "string" && dim.unitSymbol !== "") {
name = `${value} (${dim.units} ${dim.unitSymbol})`;
} else {
name = `${value} (${dim.units})`;
}
}
return {
name,
id: value
};
}),
// Set selectedId to value stored in `dimensions` trait, the default value, or the first available value
selectedId:
this.dimensions?.[dim.name]?.toString() ||
dim.default ||
dim.values[0],
setDimensionValue: (
stratumId: string,
newDimension: string | undefined
) => {
let newDimensions: any = {};
newDimensions[dim.name!] = newDimension;
if (isDefined(this.dimensions)) {
newDimensions = combine(newDimensions, this.dimensions);
}
runInAction(() => {
this.setTrait(stratumId, "dimensions", newDimensions);
});
}
});
});
});
return dimensions;
}
@override
get selectableDimensions() {
if (this.disableDimensionSelectors) {
return super.selectableDimensions;
}
return filterOutUndefined([
...super.selectableDimensions,
...this.wmsDimensionSelectableDimensions,
...this.styleSelectableDimensions
]);
}
/** If GetFeatureInfo/GetTimeseries request is returning CSV, we need to parse it into TimeSeriesFeatureInfoContext.
*/
@computed get featureInfoContext(): (
feature: TerriaFeature
) => TimeSeriesFeatureInfoContext {
if (this.getFeatureInfoFormat.format !== "text/csv") return () => ({});
return csvFeatureInfoContext(this);
}
}
/**
* Add `_dim` prefix to dimensions for OWS (WMS, WCS...) excluding time, styles and elevation
*/
export function formatDimensionsForOws(
dimensions: { [key: string]: string } | undefined
) {
if (!isDefined(dimensions)) {
return {};
}
return Object.entries(dimensions).reduce<{ [key: string]: string }>(
(formattedDimensions, [key, value]) =>
// elevation is specified as simply "elevation", styles is specified as "styles"
// Other (custom) dimensions are prefixed with 'dim_'.
// See WMS 1.3.0 spec section C.3.2 and C.3.3.
{
formattedDimensions[
["time", "styles", "elevation"].includes(key?.toLowerCase())
? key
: `dim_${key}`
] = value;
return formattedDimensions;
},
{}
);
}
export default WebMapServiceCatalogItem;