|
6 | 6 | geoEquirectangular, |
7 | 7 | geoMercator, |
8 | 8 | geoNaturalEarth1, |
9 | | - geoOrthographic, |
10 | 9 | } from 'd3-geo'; |
11 | 10 | import { extent } from 'd3-array'; |
12 | 11 | import { scaleSequential } from 'd3-scale'; |
13 | 12 | import { interpolateRdBu } from 'd3-scale-chromatic'; |
14 | 13 | import { feature } from 'topojson-client'; |
| 14 | + import { century, equationOfTime, declination } from 'solar-calculator'; |
15 | 15 |
|
16 | 16 | import { Field, SelectField, Switch, timerStore } from 'svelte-ux'; |
17 | 17 |
|
|
24 | 24 | import TooltipItem from '$lib/components/TooltipItem.svelte'; |
25 | 25 | import ClipPath from '$lib/components/ClipPath.svelte'; |
26 | 26 | import Graticule from '$lib/components/Graticule.svelte'; |
| 27 | + import GeoCircle from '$lib/components/GeoCircle.svelte'; |
| 28 | + import { antipode } from '$lib/utils/geo.js'; |
27 | 29 |
|
28 | 30 | export let data; |
29 | 31 |
|
30 | 32 | let enableClip = false; |
| 33 | + let showDaylight = false; |
31 | 34 |
|
32 | 35 | let projection = geoNaturalEarth1; |
33 | 36 | const projections = [ |
|
69 | 72 |
|
70 | 73 | return result; |
71 | 74 | } |
| 75 | +
|
| 76 | + const now = new Date(); |
| 77 | + const day = new Date(+now).setUTCHours(0, 0, 0, 0); |
| 78 | + const t = century(now); |
| 79 | + const longitude = ((day - now) / 864e5) * 360 - 180; |
| 80 | + const sun = [longitude - equationOfTime(t) / 4, declination(t)]; |
72 | 81 | </script> |
73 | 82 |
|
74 | | -<div class="grid grid-cols-[1fr,auto,2fr] gap-2 my-2"> |
| 83 | +<div class="grid grid-cols-[1fr,auto,auto,2fr] gap-2 my-2"> |
75 | 84 | <SelectField |
76 | 85 | label="Projections" |
77 | 86 | options={projections} |
|
80 | 89 | toggleIcon={null} |
81 | 90 | stepper |
82 | 91 | /> |
| 92 | + |
83 | 93 | <Field label="Clip" let:id> |
84 | 94 | <Switch bind:checked={enableClip} {id} size="md" /> |
85 | 95 | </Field> |
| 96 | + |
| 97 | + <Field label="Daylight" let:id> |
| 98 | + <Switch bind:checked={showDaylight} {id} size="md" /> |
| 99 | + </Field> |
86 | 100 | </div> |
87 | 101 |
|
88 | 102 | <h1>Examples</h1> |
|
101 | 115 | let:tooltip |
102 | 116 | > |
103 | 117 | <Svg> |
104 | | - <GeoPath geojson={{ type: 'Sphere' }} class="_fill-surface-200 stroke-surface-content/30" /> |
| 118 | + <GeoPath geojson={{ type: 'Sphere' }} class="stroke-surface-content/30" /> |
105 | 119 | <Graticule class="stroke-surface-content/20" /> |
106 | 120 |
|
107 | 121 | <GeoPath {geojson} id="clip" /> |
|
122 | 136 | class="stroke-gray-900/10 fill-gray-900/20 pointer-events-none" |
123 | 137 | /> |
124 | 138 | {/each} |
| 139 | + |
| 140 | + {#if showDaylight} |
| 141 | + <GeoCircle center={antipode(sun)} class="stroke-none fill-black/50 pointer-events-none" /> |
| 142 | + {/if} |
125 | 143 | </Svg> |
126 | 144 |
|
127 | 145 | <Tooltip let:data> |
|
0 commit comments