|
1 | 1 | <script lang="ts"> |
2 | | - import { geoAlbersUsa } from 'd3-geo'; |
| 2 | + import { geoAlbersUsa, geoNaturalEarth1 } from 'd3-geo'; |
3 | 3 | import { feature } from 'topojson-client'; |
4 | 4 |
|
5 | 5 | import Preview from '$lib/docs/Preview.svelte'; |
|
8 | 8 | import GeoPoint from '$lib/components/GeoPoint.svelte'; |
9 | 9 | import Text from '$lib/components/Text.svelte'; |
10 | 10 |
|
11 | | - import capitals from '../_data/geo/us-state-capitals.csv'; |
12 | | -
|
13 | 11 | 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); |
15 | 15 | </script> |
16 | 16 |
|
17 | 17 | <h1>Examples</h1> |
18 | 18 |
|
19 | | -<h2>SVG</h2> |
| 19 | +<h2>US State Capitals</h2> |
20 | 20 |
|
21 | 21 | <Preview data={states}> |
22 | 22 | <div class="h-[600px]"> |
|
36 | 36 | {/each} |
37 | 37 | </g> |
38 | 38 | <g class="points pointer-events-none"> |
39 | | - {#each capitals as capital} |
| 39 | + {#each data.us.stateCaptitals as capital} |
40 | 40 | <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" /> |
42 | 42 | <Text |
43 | 43 | y="-6" |
44 | 44 | value={capital.description} |
|
53 | 53 | </div> |
54 | 54 | </Preview> |
55 | 55 |
|
| 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 | + |
56 | 84 | <h2>Canvas</h2> |
57 | 85 |
|
58 | 86 | <Preview data={states}> |
|
66 | 94 | <Canvas> |
67 | 95 | <GeoPath geojson={states} fill="#e5e7eb" stroke="white" /> |
68 | 96 | </Canvas> |
69 | | - {#each capitals as capital} |
| 97 | + {#each data.us.stateCaptitals as capital} |
70 | 98 | <Canvas> |
71 | 99 | <GeoPoint |
72 | 100 | lat={capital.latitude} |
|
0 commit comments