Skip to content

Commit 8e85e0d

Browse files
committed
Add single/multi GeoCircle example toggle to visualize projection distortion
1 parent ac05228 commit 8e85e0d

1 file changed

Lines changed: 46 additions & 15 deletions

File tree

  • packages/layerchart/src/routes/docs/components/GeoCircle

packages/layerchart/src/routes/docs/components/GeoCircle/+page.svelte

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
geoNaturalEarth1,
99
geoOrthographic,
1010
} from 'd3-geo';
11+
import { range } from 'd3-array';
1112
import { feature } from 'topojson-client';
1213
13-
import { RangeField, SelectField } from 'svelte-ux';
14+
import { Field, RangeField, SelectField, ToggleGroup, ToggleOption } from 'svelte-ux';
1415
1516
import Chart, { Svg } from '$lib/components/Chart.svelte';
1617
import GeoCircle from '$lib/components/GeoCircle.svelte';
@@ -20,6 +21,7 @@
2021
2122
export let data;
2223
24+
let example: 'single' | 'multi' = 'single';
2325
let latitude = 0;
2426
let longitude = 0;
2527
let radius = 600;
@@ -41,6 +43,13 @@
4143
projection === geoAlbersUsa
4244
? geojson.features.filter((f) => f.properties.name === 'United States of America')
4345
: geojson.features;
46+
47+
const step = 10;
48+
const coordinates = range(-80, 80 + step, step).flatMap((y) => {
49+
return range(-180, 180 + step, step).map((x) => {
50+
return [x, y];
51+
});
52+
});
4453
</script>
4554

4655
<div class="grid grid-cols-2 gap-2 my-2">
@@ -51,12 +60,30 @@
5160
clearable={false}
5261
toggleIcon={null}
5362
stepper
54-
class="col-span-2"
5563
/>
56-
<RangeField label="Latitude" bind:value={latitude} min={-90} max={90} />
57-
<RangeField label="Longitude" bind:value={longitude} min={-180} max={180} />
58-
<RangeField label="Radius (km)" bind:value={radius} max={6371} />
59-
<RangeField label="Precision" bind:value={precision} max={90} />
64+
<Field label="Example">
65+
<ToggleGroup bind:value={example} variant="outline" inset class="w-full">
66+
<ToggleOption value="single">Single</ToggleOption>
67+
<ToggleOption value="multi">Multi</ToggleOption>
68+
</ToggleGroup>
69+
</Field>
70+
71+
<RangeField
72+
label="Latitude"
73+
bind:value={latitude}
74+
min={-90}
75+
max={90}
76+
disabled={example != 'single'}
77+
/>
78+
<RangeField
79+
label="Longitude"
80+
bind:value={longitude}
81+
min={-180}
82+
max={180}
83+
disabled={example != 'single'}
84+
/>
85+
<RangeField label="Radius (km)" bind:value={radius} max={6371} disabled={example != 'single'} />
86+
<RangeField label="Precision" bind:value={precision} max={90} disabled={example != 'single'} />
6087
</div>
6188

6289
<h1>Examples</h1>
@@ -76,21 +103,25 @@
76103
<GeoPath geojson={{ type: 'Sphere' }} class="stroke-surface-content/30" id="globe" />
77104
<Graticule class="stroke-surface-content/20" />
78105

79-
<GeoPath {geojson} id="clip" />
80-
81106
{#each features as feature}
82107
<GeoPath
83108
geojson={feature}
84-
class="stroke-gray-900/10 fill-gray-900/20 pointer-events-none"
109+
class="stroke-surface-content/30 fill-surface-content/20 pointer-events-none"
85110
/>
86111
{/each}
87112

88-
<GeoCircle
89-
center={[longitude, latitude]}
90-
radius={(radius / (6371 * Math.PI * 2)) * 360}
91-
{precision}
92-
class="fill-danger stroke-none"
93-
/>
113+
{#if example === 'single'}
114+
<GeoCircle
115+
center={[longitude, latitude]}
116+
radius={(radius / (6371 * Math.PI * 2)) * 360}
117+
{precision}
118+
class="fill-danger stroke-none"
119+
/>
120+
{:else if example === 'multi'}
121+
{#each coordinates as coords}
122+
<GeoCircle center={coords} radius={step / 4} {precision} class="stroke-danger" />
123+
{/each}
124+
{/if}
94125
</Svg>
95126
</Chart>
96127
</div>

0 commit comments

Comments
 (0)