|
8 | 8 | geoNaturalEarth1, |
9 | 9 | geoOrthographic, |
10 | 10 | } from 'd3-geo'; |
| 11 | + import { range } from 'd3-array'; |
11 | 12 | import { feature } from 'topojson-client'; |
12 | 13 |
|
13 | | - import { RangeField, SelectField } from 'svelte-ux'; |
| 14 | + import { Field, RangeField, SelectField, ToggleGroup, ToggleOption } from 'svelte-ux'; |
14 | 15 |
|
15 | 16 | import Chart, { Svg } from '$lib/components/Chart.svelte'; |
16 | 17 | import GeoCircle from '$lib/components/GeoCircle.svelte'; |
|
20 | 21 |
|
21 | 22 | export let data; |
22 | 23 |
|
| 24 | + let example: 'single' | 'multi' = 'single'; |
23 | 25 | let latitude = 0; |
24 | 26 | let longitude = 0; |
25 | 27 | let radius = 600; |
|
41 | 43 | projection === geoAlbersUsa |
42 | 44 | ? geojson.features.filter((f) => f.properties.name === 'United States of America') |
43 | 45 | : 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 | + }); |
44 | 53 | </script> |
45 | 54 |
|
46 | 55 | <div class="grid grid-cols-2 gap-2 my-2"> |
|
51 | 60 | clearable={false} |
52 | 61 | toggleIcon={null} |
53 | 62 | stepper |
54 | | - class="col-span-2" |
55 | 63 | /> |
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'} /> |
60 | 87 | </div> |
61 | 88 |
|
62 | 89 | <h1>Examples</h1> |
|
76 | 103 | <GeoPath geojson={{ type: 'Sphere' }} class="stroke-surface-content/30" id="globe" /> |
77 | 104 | <Graticule class="stroke-surface-content/20" /> |
78 | 105 |
|
79 | | - <GeoPath {geojson} id="clip" /> |
80 | | - |
81 | 106 | {#each features as feature} |
82 | 107 | <GeoPath |
83 | 108 | 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" |
85 | 110 | /> |
86 | 111 | {/each} |
87 | 112 |
|
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} |
94 | 125 | </Svg> |
95 | 126 | </Chart> |
96 | 127 | </div> |
|
0 commit comments