Skip to content

Commit b419f80

Browse files
Be able to load single sketch onto browse page (#608)
* initial attempt at differentiating when loading * differentiate more nicely and remove unused imports * Npm run fmt * remove logging * Always clear error message if not throwing * Update footer - header needs some thought * Use now-merged govuk svelte library * Match current behaviour for not showing schemes by default --------- Co-authored-by: Peter York <peter.york@dft.gov.uk>
1 parent d6499d4 commit b419f80

9 files changed

Lines changed: 51 additions & 14 deletions

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/browse/schemes/SchemesLayer.svelte

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@
88
SecondaryButton,
99
Select,
1010
} from "govuk-svelte";
11-
import { appVersion, Legend, WarningIcon } from "lib/common";
12-
import { downloadGeneratedFile } from "lib/common/files";
11+
import {
12+
appVersion,
13+
getAuthoritiesGeoJson,
14+
Legend,
15+
WarningIcon,
16+
} from "lib/common";
17+
import { downloadGeneratedFile, importFile } from "lib/common/files";
1318
import { constructMatchExpression } from "lib/maplibre";
1419
import type { DataDrivenPropertyValueSpecification } from "maplibre-gl";
1520
import { colorInterventionsBySchema, schemaLegend } from "schemas";
1621
import LayerControl from "../layers/LayerControl.svelte";
1722
import { showHideLayer } from "../layers/url";
1823
import { atfFundingProgrammes, currentMilestones } from "./colors";
19-
import { importAllLocalSketches, setupSchemes } from "./data";
24+
import {
25+
importAllLocalSketches,
26+
isSingleSketchFile,
27+
setupSchemes,
28+
} from "./data";
2029
import Filters from "./Filters.svelte";
2130
import InterventionLayer from "./InterventionLayer.svelte";
2231
import LoadRemoteSchemeData from "./LoadRemoteSchemeData.svelte";
@@ -63,18 +72,31 @@
6372
6473
function loadMainFile(filename: string, text: string) {
6574
try {
66-
setupSchemes(
67-
JSON.parse(text),
68-
atfSchemes,
69-
lcwipSchemes,
70-
finalInspectionsSchemes,
71-
);
75+
const geojson = JSON.parse(text);
76+
if (isSingleSketchFile(geojson)) {
77+
loadSketchFile(filename, text);
78+
} else {
79+
setupSchemes(
80+
geojson,
81+
atfSchemes,
82+
lcwipSchemes,
83+
finalInspectionsSchemes,
84+
);
85+
}
7286
errorMessage = "";
7387
} catch (err) {
7488
errorMessage = `The file you loaded is broken: ${err}`;
7589
}
7690
}
7791
92+
async function loadSketchFile(filename: string, text: string) {
93+
const authoritiesGj = await getAuthoritiesGeoJson();
94+
95+
importFile(filename, text, authoritiesGj);
96+
97+
importLocalSketches();
98+
}
99+
78100
function importLocalSketches() {
79101
$localSchemes = importAllLocalSketches();
80102
$localShow = true;

src/lib/browse/schemes/data.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import type { Writable } from "svelte/store";
22
import type { Feature, SchemeData, Schemes } from "types";
33

4+
export function isSingleSketchFile(gj: Schemes): boolean {
5+
const filteredSchemes = Object.entries(gj.schemes).filter(
6+
([scheme_reference, scheme]) => {
7+
return scheme.browse === undefined || scheme.browse === null;
8+
},
9+
);
10+
return filteredSchemes.length > 0;
11+
}
12+
413
// Takes a GeoJSON file representing a bunch of scheme files combined into one.
514
// Populates the two stores for each of ATF and LCWIP schemes.
615
export function setupSchemes(

src/pages/About.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@
104104
aboutHref="about.html"
105105
privacyHref="privacy.html"
106106
accessibilityHref="accessibility.html"
107+
footerTopBarColour="#007161"
107108
/>

src/pages/AccessibilityStatement.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,5 @@
136136
aboutHref="about.html"
137137
privacyHref="privacy.html"
138138
accessibilityHref="accessibility.html"
139+
footerTopBarColour="#007161"
139140
/>

src/pages/CleanLocalStorage.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,5 @@
120120
aboutHref="about.html"
121121
privacyHref="privacy.html"
122122
accessibilityHref="accessibility.html"
123+
footerTopBarColour="#007161"
123124
/>

src/pages/LandingPage.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@
5353
aboutHref="about.html"
5454
privacyHref="privacy.html"
5555
accessibilityHref="accessibility.html"
56+
footerTopBarColour="#007161"
5657
/>

src/pages/ManageFiles.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
aboutHref="about.html"
208208
privacyHref="privacy.html"
209209
accessibilityHref="accessibility.html"
210+
footerTopBarColour="#007161"
210211
/>
211212

212213
<style>

src/pages/PrivacyStatement.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,5 @@
111111
aboutHref="about.html"
112112
privacyHref="privacy.html"
113113
accessibilityHref="accessibility.html"
114+
footerTopBarColour="#007161"
114115
/>

0 commit comments

Comments
 (0)