Skip to content

Commit f489400

Browse files
committed
Add World Airports example to GeoPoint
1 parent f6a19c0 commit f489400

4 files changed

Lines changed: 3035 additions & 11 deletions

File tree

packages/layerchart/src/routes/docs/examples/GeoPoint/+page.svelte

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { geoAlbersUsa } from 'd3-geo';
2+
import { geoAlbersUsa, geoNaturalEarth1 } from 'd3-geo';
33
import { feature } from 'topojson-client';
44
55
import Preview from '$lib/docs/Preview.svelte';
@@ -8,15 +8,15 @@
88
import GeoPoint from '$lib/components/GeoPoint.svelte';
99
import Text from '$lib/components/Text.svelte';
1010
11-
import capitals from '../_data/geo/us-state-capitals.csv';
12-
1311
export let data;
14-
const states = feature(data.geojson, data.geojson.objects.states);
12+
13+
const states = feature(data.us.geojson, data.us.geojson.objects.states);
14+
const countries = feature(data.world.geojson, data.world.geojson.objects.countries);
1515
</script>
1616

1717
<h1>Examples</h1>
1818

19-
<h2>SVG</h2>
19+
<h2>US State Capitals</h2>
2020

2121
<Preview data={states}>
2222
<div class="h-[600px]">
@@ -36,9 +36,9 @@
3636
{/each}
3737
</g>
3838
<g class="points pointer-events-none">
39-
{#each capitals as capital}
39+
{#each data.us.stateCaptitals as capital}
4040
<GeoPoint lat={capital.latitude} long={capital.longitude}>
41-
<circle r="2" class="fill-white stroke-red-500" />
41+
<circle r="2" class="fill-white stroke-danger" />
4242
<Text
4343
y="-6"
4444
value={capital.description}
@@ -53,6 +53,34 @@
5353
</div>
5454
</Preview>
5555

56+
<h2>World Airports</h2>
57+
58+
<Preview data={states}>
59+
<div class="h-[600px]">
60+
<Chart
61+
geo={{
62+
projection: geoNaturalEarth1,
63+
fitGeojson: countries,
64+
}}
65+
>
66+
<Svg>
67+
<g class="states">
68+
{#each countries.features as feature}
69+
<GeoPath geojson={feature} class="fill-surface-content/10 stroke-surface-100" />
70+
{/each}
71+
</g>
72+
<g class="points pointer-events-none">
73+
{#each data.world.airports as airport}
74+
<GeoPoint lat={airport.latitude} long={airport.longitude}>
75+
<circle r="1" class="fill-primary" />
76+
</GeoPoint>
77+
{/each}
78+
</g>
79+
</Svg>
80+
</Chart>
81+
</div>
82+
</Preview>
83+
5684
<h2>Canvas</h2>
5785

5886
<Preview data={states}>
@@ -66,7 +94,7 @@
6694
<Canvas>
6795
<GeoPath geojson={states} fill="#e5e7eb" stroke="white" />
6896
</Canvas>
69-
{#each capitals as capital}
97+
{#each data.us.stateCaptitals as capital}
7098
<Canvas>
7199
<GeoPoint
72100
lat={capital.latitude}

packages/layerchart/src/routes/docs/examples/GeoPoint/+page.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
import { autoType, csvParse } from 'd3-dsv';
12
import pageSource from './+page.svelte?raw';
23

34
export async function load() {
45
return {
5-
geojson: await fetch('https://cdn.jsdelivr.net/npm/us-atlas@3/states-10m.json').then((r) =>
6-
r.json()
7-
),
6+
us: {
7+
geojson: await fetch('https://cdn.jsdelivr.net/npm/us-atlas@3/states-10m.json').then((r) =>
8+
r.json()
9+
),
10+
stateCaptitals: await fetch('/data/examples/geo/us-state-capitals.csv').then(async (r) =>
11+
csvParse(await r.text(), autoType)
12+
),
13+
},
14+
world: {
15+
geojson: await fetch('https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json').then(
16+
(r) => r.json()
17+
),
18+
19+
airports: await fetch('/data/examples/geo/world-airports.csv').then(async (r) =>
20+
csvParse(await r.text(), autoType)
21+
),
22+
},
823
meta: {
924
pageSource,
1025
},

packages/layerchart/src/routes/docs/examples/_data/geo/us-state-capitals.csv renamed to packages/layerchart/static/data/examples/geo/us-state-capitals.csv

File renamed without changes.

0 commit comments

Comments
 (0)