Skip to content

Commit

Permalink
feat: Add minimap
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Sep 5, 2024
1 parent a63ba91 commit 8de56fc
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 14 deletions.
3 changes: 2 additions & 1 deletion website/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ declare module "@deck.gl/layers" {
export const GeoJsonLayer: $FixMe;
export const LineLayer: $FixMe;
export const PathLayer: $FixMe;
export const ScatterplotLayer: $FixMe;
}

declare module "@deck.gl/react" {
export const DeckGL: $FixMe;
export default DeckGL;
}
}
53 changes: 53 additions & 0 deletions website/src/components/Mutations/Minimap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { GeoJsonLayer, ScatterplotLayer } from "@deck.gl/layers";
import DeckGL from "@deck.gl/react";
import { useGeoData } from "src/domain/geodata";

const Minimap = ({
viewState,
extentViewState,
}: {
viewState: { longitude: number; latitude: number; zoom: number };
extentViewState: { longitude: number; latitude: number; zoom: number };
}) => {
const { data: geoDataMinimap } = useGeoData({
year: "2022",
format: "topojson",
simplify: 0.02,
shapes: new Set(["country"]),
projection: "wgs84",
color: "default",
dimensions: { width: 800, height: 600 },
withName: false,
});

return (
<DeckGL initialViewState={viewState} controller={false}>
<GeoJsonLayer
pickable={false}
stroked={true}
filled={true}
getFillColor={[100, 100, 100, 50]}
extruded={false}
id="minimap"
data={geoDataMinimap.country}
/>
<ScatterplotLayer
id="window"
stroked
filled
getRadius={() => 10000}
getPosition={(d) => d.coordinates}
getFillColor={[0, 0, 255, 50]}
getLineColor={[0, 0, 0]}
getLineWidth={10}
data={[
{
coordinates: [extentViewState.longitude, extentViewState.latitude],
},
]}
/>
</DeckGL>
);
};

export default Minimap;
52 changes: 39 additions & 13 deletions website/src/pages/mutations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ import * as turf from "@turf/turf";
import { FlyToInterpolator } from "@deck.gl/core";
import { parse } from "path";
import { useQuery } from "react-query";
import { GeoJsonLayer } from "@deck.gl/layers";
import DeckGL from "@deck.gl/react";

const MutationsMap = dynamic(() => import("../components/Mutations/Map"), {
ssr: false,
});
const MutationsMinimap = dynamic(
() => import("../components/Mutations/Minimap"),
{
ssr: false,
}
);

const INITIAL_VIEW_STATE = {
latitude: 46.8182,
Expand Down Expand Up @@ -209,7 +217,11 @@ export default function Page() {
>
<div>
<Typography variant="h5">{year1}</Typography>
<Box height="90%" position="relative" border="1px solid #ccc">
<Box
height="calc(100% - 2rem)"
position="relative"
border="1px solid #ccc"
>
<MutationsMap
viewState={viewState}
geoData={geoData1}
Expand All @@ -230,7 +242,11 @@ export default function Page() {
</div>
<div>
<Typography variant="h5">{year2}</Typography>
<Box height="90%" position="relative" border="1px solid #ccc">
<Box
height="calc(100% - 2rem)"
position="relative"
border="1px solid #ccc"
>
<MutationsMap
geoData={geoData2}
viewState={viewState}
Expand All @@ -246,19 +262,29 @@ export default function Page() {
/>
</Box>
</div>
<div
style={{
position: "absolute",
bottom: "2rem",
right: "1.5rem",
width: 220,
height: 180,
border: "1px solid #ccc",
backgroundColor: "rgba(255, 255, 255, 1)",
}}
>
<MutationsMinimap
extentViewState={viewState}
viewState={{
/** Switzerland */
latitude: 46.8182,
longitude: 8.2275,
zoom: 5,
}}
/>
</div>
</Box>
</Box>
</Box>
);
}

const SAMPLE_HTML = `
<table class="table table-bordered text-right dataTable no-footer dtr-inline" width="100%" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info" style="width: 100%;"><thead><tr class="text-left" role="row"><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 0px;">N° d'hist.</th><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 0px;">Canton</th><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 0px;">N° du district</th><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 0px;">Nom du district</th><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 0px;">N° OFS commune</th><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 0px;">Nom de la commune</th><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 0px;">Raison de la radiation</th><th class="sorting_disabled" rowspan="1" colspan="1" style="width: 0px;">Raison de l'inscription</th></tr>
</thead>
<tbody>
<tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3964</em>, Type de mutation : <em>Inclusion de commune</em>, Entrée en vigueur : <em>01.01.2023</em></td></tr><tr role="row" class="odd"><td tabindex="0">11735</td><td>ZH</td><td>102</td><td>Bezirk Andelfingen</td><td>21</td><td>Adlikon</td><td>Radiation</td><td></td></tr><tr role="row" class="even"><td tabindex="0">12173</td><td>ZH</td><td>102</td><td>Bezirk Andelfingen</td><td>32</td><td>Humlikon</td><td>Radiation</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">13214</td><td>ZH</td><td>102</td><td>Bezirk Andelfingen</td><td>30</td><td>Andelfingen</td><td>Modification du territoire</td><td></td></tr><tr role="row" class="even"><td tabindex="0">16621</td><td>ZH</td><td>102</td><td>Bezirk Andelfingen</td><td>291</td><td>Andelfingen</td><td></td><td>Modification du territoire</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3965</em>, Type de mutation : <em>Inclusion de commune</em>, Entrée en vigueur : <em>01.01.2023</em></td></tr><tr role="row" class="odd"><td tabindex="0">15116</td><td>BE</td><td>246</td><td>Verwaltungskreis Bern-Mittelland</td><td>536</td><td>Diemerswil</td><td>Radiation</td><td></td></tr><tr role="row" class="even"><td tabindex="0">15125</td><td>BE</td><td>246</td><td>Verwaltungskreis Bern-Mittelland</td><td>546</td><td>Münchenbuchsee</td><td>Modification du territoire</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">16622</td><td>BE</td><td>246</td><td>Verwaltungskreis Bern-Mittelland</td><td>546</td><td>Münchenbuchsee</td><td></td><td>Modification du territoire</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3966</em>, Type de mutation : <em>Inclusion de commune</em>, Entrée en vigueur : <em>01.01.2023</em></td></tr><tr role="row" class="even"><td tabindex="0">14441</td><td>SG</td><td>1727</td><td>Wahlkreis Toggenburg</td><td>3372</td><td>Hemberg</td><td>Radiation</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">14444</td><td>SG</td><td>1727</td><td>Wahlkreis Toggenburg</td><td>3375</td><td>Oberhelfenschwil</td><td>Radiation</td><td></td></tr><tr role="row" class="even"><td tabindex="0">14950</td><td>SG</td><td>1727</td><td>Wahlkreis Toggenburg</td><td>3378</td><td>Neckertal</td><td>Modification du territoire</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">16623</td><td>SG</td><td>1727</td><td>Wahlkreis Toggenburg</td><td>3396</td><td>Neckertal</td><td></td><td>Modification du territoire</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3967</em>, Type de mutation : <em>Inclusion de commune</em>, Entrée en vigueur : <em>01.01.2023</em></td></tr><tr role="row" class="even"><td tabindex="0">13301</td><td>JU</td><td>2602</td><td>District des Franches-Montagnes</td><td>6743</td><td>Les Breuleux</td><td>Modification du territoire</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">13302</td><td>JU</td><td>2602</td><td>District des Franches-Montagnes</td><td>6744</td><td>La Chaux-des-Breuleux</td><td>Radiation</td><td></td></tr><tr role="row" class="even"><td tabindex="0">16624</td><td>JU</td><td>2602</td><td>District des Franches-Montagnes</td><td>6743</td><td>Les Breuleux</td><td></td><td>Modification du territoire</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3968</em>, Type de mutation : <em>Inclusion de commune</em>, Entrée en vigueur : <em>01.01.2023</em></td></tr><tr role="row" class="odd"><td tabindex="0">11503</td><td>AG</td><td>1905</td><td>Bezirk Kulm</td><td>4133</td><td>Burg (AG)</td><td>Radiation</td><td></td></tr><tr role="row" class="even"><td tabindex="0">12397</td><td>AG</td><td>1905</td><td>Bezirk Kulm</td><td>4139</td><td>Menziken</td><td>Modification du territoire</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">16625</td><td>AG</td><td>1905</td><td>Bezirk Kulm</td><td>4139</td><td>Menziken</td><td></td><td>Modification du territoire</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3969</em>, Type de mutation : <em>Fusion de communes</em>, Entrée en vigueur : <em>01.01.2023</em></td></tr><tr role="row" class="even"><td tabindex="0">10849</td><td>AG</td><td>1906</td><td>Bezirk Laufenburg</td><td>4179</td><td>Ueken</td><td>Radiation</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">12317</td><td>AG</td><td>1906</td><td>Bezirk Laufenburg</td><td>4166</td><td>Herznach</td><td>Radiation</td><td></td></tr><tr role="row" class="even"><td tabindex="0">16626</td><td>AG</td><td>1906</td><td>Bezirk Laufenburg</td><td>4186</td><td>Herznach-Ueken</td><td></td><td>Création</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3970</em>, Type de mutation : <em>Fusion de communes</em>, Entrée en vigueur : <em>01.01.2023</em></td></tr><tr role="row" class="odd"><td tabindex="0">13334</td><td>JU</td><td>2603</td><td>District de Porrentruy</td><td>6787</td><td>Damphreux</td><td>Radiation</td><td></td></tr><tr role="row" class="even"><td tabindex="0">13340</td><td>JU</td><td>2603</td><td>District de Porrentruy</td><td>6793</td><td>Lugnez</td><td>Radiation</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">16627</td><td>JU</td><td>2603</td><td>District de Porrentruy</td><td>6811</td><td>Damphreux-Lugnez</td><td></td><td>Création</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3983</em>, Type de mutation : <em>Inclusion de commune</em>, Entrée en vigueur : <em>01.01.2024</em></td></tr><tr role="row" class="even"><td tabindex="0">15266</td><td>BE</td><td>247</td><td>Verwaltungskreis Thun</td><td>767</td><td>Reutigen</td><td>Modification du territoire</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">15344</td><td>BE</td><td>247</td><td>Verwaltungskreis Thun</td><td>947</td><td>Zwieselberg</td><td>Radiation</td><td></td></tr><tr role="row" class="even"><td tabindex="0">16651</td><td>BE</td><td>247</td><td>Verwaltungskreis Thun</td><td>767</td><td>Reutigen</td><td></td><td>Modification du territoire</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3984</em>, Type de mutation : <em>Inclusion de commune</em>, Entrée en vigueur : <em>01.01.2024</em></td></tr><tr role="row" class="odd"><td tabindex="0">15375</td><td>BE</td><td>244</td><td>Verwaltungskreis Oberaargau</td><td>992</td><td>Wangen an der Aare</td><td>Modification du territoire</td><td></td></tr><tr role="row" class="even"><td tabindex="0">15376</td><td>BE</td><td>244</td><td>Verwaltungskreis Oberaargau</td><td>993</td><td>Wangenried</td><td>Radiation</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">16652</td><td>BE</td><td>244</td><td>Verwaltungskreis Oberaargau</td><td>992</td><td>Wangen an der Aare</td><td></td><td>Modification du territoire</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3985</em>, Type de mutation : <em>Inclusion de commune</em>, Entrée en vigueur : <em>01.01.2024</em></td></tr><tr role="row" class="even"><td tabindex="0">14067</td><td>SO</td><td>1103</td><td>Bezirk Bucheggberg</td><td>2456</td><td>Lüterswil-Gächliwil</td><td>Radiation</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">15642</td><td>SO</td><td>1103</td><td>Bezirk Bucheggberg</td><td>2465</td><td>Buchegg</td><td>Modification du territoire</td><td></td></tr><tr role="row" class="even"><td tabindex="0">16653</td><td>SO</td><td>1103</td><td>Bezirk Bucheggberg</td><td>2465</td><td>Buchegg</td><td></td><td>Modification du territoire</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3986</em>, Type de mutation : <em>Fusion de communes</em>, Entrée en vigueur : <em>01.01.2024</em></td></tr><tr role="row" class="odd"><td tabindex="0">13320</td><td>JU</td><td>2603</td><td>District de Porrentruy</td><td>6773</td><td>Beurnevésin</td><td>Radiation</td><td></td></tr><tr role="row" class="even"><td tabindex="0">13322</td><td>JU</td><td>2603</td><td>District de Porrentruy</td><td>6775</td><td>Bonfol</td><td>Radiation</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">16654</td><td>JU</td><td>2603</td><td>District de Porrentruy</td><td>6812</td><td>Basse-Vendline</td><td></td><td>Création</td></tr><tr><td colspan="9" class="text-left mutation-detail">Numéro de mutation : <em>3987</em>, Type de mutation : <em>Inclusion de commune</em>, Entrée en vigueur : <em>01.01.2024</em></td></tr><tr role="row" class="even"><td tabindex="0">10886</td><td>AG</td><td>1902</td><td>Bezirk Baden</td><td>4042</td><td>Turgi</td><td>Radiation</td><td></td></tr><tr role="row" class="odd"><td tabindex="0">13189</td><td>AG</td><td>1902</td><td>Bezirk Baden</td><td>4021</td><td>Baden</td><td>Modification du territoire</td><td></td></tr><tr role="row" class="even"><td tabindex="0">16655</td><td>AG</td><td>1902</td><td>Bezirk Baden</td><td>4021</td><td>Baden</td><td></td><td>Modification du territoire</td></tr></tbody></table>
`;

0 comments on commit 8de56fc

Please sign in to comment.