|
8 | 8 | SecondaryButton, |
9 | 9 | Select, |
10 | 10 | } 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"; |
13 | 18 | import { constructMatchExpression } from "lib/maplibre"; |
14 | 19 | import type { DataDrivenPropertyValueSpecification } from "maplibre-gl"; |
15 | 20 | import { colorInterventionsBySchema, schemaLegend } from "schemas"; |
16 | 21 | import LayerControl from "../layers/LayerControl.svelte"; |
17 | 22 | import { showHideLayer } from "../layers/url"; |
18 | 23 | import { atfFundingProgrammes, currentMilestones } from "./colors"; |
19 | | - import { importAllLocalSketches, setupSchemes } from "./data"; |
| 24 | + import { |
| 25 | + importAllLocalSketches, |
| 26 | + isSingleSketchFile, |
| 27 | + setupSchemes, |
| 28 | + } from "./data"; |
20 | 29 | import Filters from "./Filters.svelte"; |
21 | 30 | import InterventionLayer from "./InterventionLayer.svelte"; |
22 | 31 | import LoadRemoteSchemeData from "./LoadRemoteSchemeData.svelte"; |
|
63 | 72 |
|
64 | 73 | function loadMainFile(filename: string, text: string) { |
65 | 74 | 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 | + } |
72 | 86 | errorMessage = ""; |
73 | 87 | } catch (err) { |
74 | 88 | errorMessage = `The file you loaded is broken: ${err}`; |
75 | 89 | } |
76 | 90 | } |
77 | 91 |
|
| 92 | + async function loadSketchFile(filename: string, text: string) { |
| 93 | + const authoritiesGj = await getAuthoritiesGeoJson(); |
| 94 | +
|
| 95 | + importFile(filename, text, authoritiesGj); |
| 96 | +
|
| 97 | + importLocalSketches(); |
| 98 | + } |
| 99 | +
|
78 | 100 | function importLocalSketches() { |
79 | 101 | $localSchemes = importAllLocalSketches(); |
80 | 102 | $localShow = true; |
|
0 commit comments