Skip to content

Commit ac05228

Browse files
committed
Flesh out GeoCircle docs page
1 parent f22f35d commit ac05228

3 files changed

Lines changed: 97 additions & 1 deletion

File tree

packages/layerchart/src/lib/components/GeoCircle.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/** sets the circle precision to the specified angle in degrees */
1313
export let precision = 6;
1414
15-
$: geojson = geoCircle().radius(radius).center(center)();
15+
$: geojson = geoCircle().radius(radius).center(center).precision(precision)();
1616
</script>
1717

1818
<GeoPath {geojson} {...$$restProps} />
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,97 @@
11
<script lang="ts">
2+
import {
3+
geoAlbersUsa,
4+
geoAlbers,
5+
geoEqualEarth,
6+
geoEquirectangular,
7+
geoMercator,
8+
geoNaturalEarth1,
9+
geoOrthographic,
10+
} from 'd3-geo';
11+
import { feature } from 'topojson-client';
12+
13+
import { RangeField, SelectField } from 'svelte-ux';
14+
215
import Chart, { Svg } from '$lib/components/Chart.svelte';
16+
import GeoCircle from '$lib/components/GeoCircle.svelte';
17+
import GeoPath from '$lib/components/GeoPath.svelte';
18+
import Graticule from '$lib/components/Graticule.svelte';
319
import Preview from '$lib/docs/Preview.svelte';
20+
21+
export let data;
22+
23+
let latitude = 0;
24+
let longitude = 0;
25+
let radius = 600;
26+
let precision = 6;
27+
28+
let projection = geoNaturalEarth1;
29+
const projections = [
30+
{ label: 'Albers', value: geoAlbers },
31+
{ label: 'Albers USA', value: geoAlbersUsa },
32+
{ label: 'Equal Earth', value: geoEqualEarth },
33+
{ label: 'Equirectangular', value: geoEquirectangular },
34+
{ label: 'Mercator', value: geoMercator },
35+
{ label: 'Natural Earth', value: geoNaturalEarth1 },
36+
{ label: 'Orthographic', value: geoOrthographic },
37+
];
38+
39+
$: geojson = feature(data.geojson, data.geojson.objects.countries);
40+
$: features =
41+
projection === geoAlbersUsa
42+
? geojson.features.filter((f) => f.properties.name === 'United States of America')
43+
: geojson.features;
444
</script>
45+
46+
<div class="grid grid-cols-2 gap-2 my-2">
47+
<SelectField
48+
label="Projections"
49+
options={projections}
50+
bind:value={projection}
51+
clearable={false}
52+
toggleIcon={null}
53+
stepper
54+
class="col-span-2"
55+
/>
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} />
60+
</div>
61+
62+
<h1>Examples</h1>
63+
64+
<h2>SVG</h2>
65+
66+
<Preview data={geojson}>
67+
<div class="h-[600px] overflow-hidden">
68+
<Chart
69+
geo={{
70+
projection,
71+
fitGeojson: geojson,
72+
}}
73+
padding={{ left: 100, right: 100 }}
74+
>
75+
<Svg>
76+
<GeoPath geojson={{ type: 'Sphere' }} class="stroke-surface-content/30" id="globe" />
77+
<Graticule class="stroke-surface-content/20" />
78+
79+
<GeoPath {geojson} id="clip" />
80+
81+
{#each features as feature}
82+
<GeoPath
83+
geojson={feature}
84+
class="stroke-gray-900/10 fill-gray-900/20 pointer-events-none"
85+
/>
86+
{/each}
87+
88+
<GeoCircle
89+
center={[longitude, latitude]}
90+
radius={(radius / (6371 * Math.PI * 2)) * 360}
91+
{precision}
92+
class="fill-danger stroke-none"
93+
/>
94+
</Svg>
95+
</Chart>
96+
</div>
97+
</Preview>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import pageSource from './+page.svelte?raw';
44

55
export async function load() {
66
return {
7+
geojson: await fetch('https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json').then(
8+
(r) => r.json()
9+
),
710
meta: {
811
api,
912
source,

0 commit comments

Comments
 (0)