Skip to content
Open
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
28 changes: 28 additions & 0 deletions doc/customizing/initialization-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Init files can be edited two ways:
| `showSplitter` | no | **`boolean`** | `false` | Show splitter initally. |
| `splitPosition` | no | **`number`** | `0.5` | The position of splitter. |
| `workbench` | no | **`string[]`** | | List of items ids to initially add to workbench. |
| `parameters` | no | [**`parameters`**](#parameters) | | Parameter overrides applied from init files (e.g. branding). |
| `previewedItemId` | no | **`string`** | | ID of the catalog member that is currently being previewed. |
| `settings` | no | [**`settings`**](#advanced-settings) | | Additional (more advanced) settings. |

Expand Down Expand Up @@ -303,6 +304,33 @@ Definition of the baseMap model.
| `y` | yes | **`number`** | | The Y component. |
| `z` | yes | **`number`** | | The Z component. |

### <a id="parameters"></a>`parameters`

Parameter overrides that are applied when the init file is loaded. These override values from the main `config.json` `parameters` object, allowing per-init-file customization of branding.

| Name | Required | Type | Default | Description |
| ----------------------- | -------- | -------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
| `brandBarElements` | no | **`string[]`** | | An array of strings of HTML that fill up the top left logo space (see `brandBarSmallElements` for small screens). |
| `brandBarSmallElements` | no | **`string[]`** | | An array of strings of HTML that fill up the top left logo space - used for small screens. |
| `displayOneBrand` | no | **`number`** | `0` | Index of which `brandBarElements` to show for mobile header. Used if `brandBarSmallElements` is not defined. |

**Example**

```json
{
"parameters": {
"brandBarElements": [
"<a href='https://example.com'><img src='images/my-logo.png' height='50' /></a>"
],
"brandBarSmallElements": [
"<a href='https://example.com'><img src='images/my-logo-small.png' height='30' /></a>"
],
"displayOneBrand": 0
},
"catalog": [...]
}
```

### <a id="advanced-settings"></a>`settings`

Additional more advanced settings.
Expand Down
5 changes: 5 additions & 0 deletions lib/Models/InitSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export interface ShareInitSourceData {
export interface InitSourceData {
stratum?: string;
corsDomains?: string[];
parameters?: {
brandBarElements?: string[];
brandBarSmallElements?: string[];
displayOneBrand?: number;
};
catalog?: JsonObject[];
elements?: Map<string, IElementConfig>;
stories?: StoryData[];
Expand Down
37 changes: 37 additions & 0 deletions lib/Models/Terria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,43 @@ export default class Terria {
? initData.stratum
: CommonStrata.definition;

if (isJsonObject(initData.parameters)) {
const parameterOverrides: Partial<ConfigParameters> = {};
let hasOverrides = false;

const { brandBarElements, brandBarSmallElements, displayOneBrand } =
initData.parameters;

const stringArrayFrom = (value: unknown): string[] | undefined => {
if (!Array.isArray(value)) return undefined;
return value.every((item) => typeof item === "string") &&
value.some((item) => item !== "")
? (value as string[]).slice()
: undefined;
};

const overrideBrandElements = stringArrayFrom(brandBarElements);
if (overrideBrandElements) {
parameterOverrides.brandBarElements = overrideBrandElements;
hasOverrides = true;
}

const overrideBrandSmallElements = stringArrayFrom(brandBarSmallElements);
if (overrideBrandSmallElements) {
parameterOverrides.brandBarSmallElements = overrideBrandSmallElements;
hasOverrides = true;
}

if (isJsonNumber(displayOneBrand)) {
parameterOverrides.displayOneBrand = Number(displayOneBrand);
hasOverrides = true;
}

if (hasOverrides) {
this.updateParameters(parameterOverrides as JsonObject);
}
}

// Extract the list of CORS-ready domains.
if (Array.isArray(initData.corsDomains)) {
this.corsProxy.corsDomains.push(...(initData.corsDomains as string[]));
Expand Down