|
| 1 | +<script module lang="ts"> |
| 2 | + import { getCountriesTopology } from '$lib/geo.remote'; |
| 3 | + const topology = await getCountriesTopology(); |
| 4 | +</script> |
| 5 | + |
| 6 | +<script lang="ts"> |
| 7 | + import { geoNaturalEarth1 } from 'd3-geo'; |
| 8 | + import { feature } from 'topojson-client'; |
| 9 | +
|
| 10 | + import { AnnotationPoint, Chart, GeoPath, Layer } from 'layerchart'; |
| 11 | + import type { ComponentProps } from 'svelte'; |
| 12 | +
|
| 13 | + const countries = feature(topology, topology.objects.countries); |
| 14 | +
|
| 15 | + const annotations: Array< |
| 16 | + { |
| 17 | + lon: number; |
| 18 | + lat: number; |
| 19 | + } & ComponentProps<typeof AnnotationPoint> |
| 20 | + > = [ |
| 21 | + { |
| 22 | + label: 'Statue of Liberty', |
| 23 | + lon: -74.0445, |
| 24 | + lat: 40.6892, |
| 25 | + labelPlacement: 'left', |
| 26 | + labelXOffset: 10, |
| 27 | + props: { |
| 28 | + circle: { class: 'fill-secondary stroke-surface-100' }, |
| 29 | + label: { class: 'fill-surface-content text-xs font-bold' } |
| 30 | + } |
| 31 | + }, |
| 32 | + { |
| 33 | + label: 'Machu Picchu', |
| 34 | + lon: -72.545, |
| 35 | + lat: -13.1631, |
| 36 | + labelPlacement: 'bottom-left', |
| 37 | + labelXOffset: 10, |
| 38 | + labelYOffset: 10, |
| 39 | + props: { |
| 40 | + circle: { class: 'fill-secondary stroke-surface-100' }, |
| 41 | + label: { class: 'fill-surface-content text-xs font-bold' } |
| 42 | + } |
| 43 | + }, |
| 44 | + { |
| 45 | + label: 'Eiffel Tower', |
| 46 | + lon: 2.2945, |
| 47 | + lat: 48.8584, |
| 48 | + labelPlacement: 'top-right', |
| 49 | + labelXOffset: 10, |
| 50 | + labelYOffset: 10, |
| 51 | + props: { |
| 52 | + circle: { class: 'fill-secondary stroke-surface-100' }, |
| 53 | + label: { class: 'fill-surface-content text-xs font-bold' } |
| 54 | + } |
| 55 | + }, |
| 56 | + { |
| 57 | + label: 'Pyramids of Giza', |
| 58 | + lon: 31.1342, |
| 59 | + lat: 29.9792, |
| 60 | + labelPlacement: 'bottom-left', |
| 61 | + labelXOffset: 10, |
| 62 | + labelYOffset: 10, |
| 63 | + props: { |
| 64 | + circle: { class: 'fill-secondary stroke-surface-100' }, |
| 65 | + label: { class: 'fill-surface-content text-xs font-bold' } |
| 66 | + } |
| 67 | + }, |
| 68 | + { |
| 69 | + label: 'Mt. Everest', |
| 70 | + lon: 86.925, |
| 71 | + lat: 27.9881, |
| 72 | + labelPlacement: 'top', |
| 73 | + labelYOffset: 10, |
| 74 | + props: { |
| 75 | + circle: { class: 'fill-secondary stroke-surface-100' }, |
| 76 | + label: { class: 'fill-surface-content text-xs font-bold' } |
| 77 | + } |
| 78 | + }, |
| 79 | + { |
| 80 | + label: 'Great Wall', |
| 81 | + lon: 117.2381, |
| 82 | + lat: 40.3587, |
| 83 | + labelPlacement: 'top-right', |
| 84 | + labelXOffset: 10, |
| 85 | + labelYOffset: 10, |
| 86 | + props: { |
| 87 | + circle: { class: 'fill-secondary stroke-surface-100' }, |
| 88 | + label: { class: 'fill-surface-content text-xs font-bold' } |
| 89 | + } |
| 90 | + }, |
| 91 | + { |
| 92 | + label: 'Sydney Opera House', |
| 93 | + lon: 151.2153, |
| 94 | + lat: -33.8568, |
| 95 | + labelPlacement: 'bottom', |
| 96 | + labelYOffset: 10, |
| 97 | + props: { |
| 98 | + circle: { class: 'fill-secondary stroke-surface-100' }, |
| 99 | + label: { class: 'fill-surface-content text-xs font-bold' } |
| 100 | + } |
| 101 | + } |
| 102 | + ]; |
| 103 | +
|
| 104 | + const data = { topology, countries }; |
| 105 | + export { data }; |
| 106 | +</script> |
| 107 | + |
| 108 | +<Chart geo={{ projection: geoNaturalEarth1, fitGeojson: countries }} height={500}> |
| 109 | + <Layer> |
| 110 | + {#each countries.features as f, i (i)} |
| 111 | + <GeoPath geojson={f} class="fill-surface-content/10 stroke-surface-100" /> |
| 112 | + {/each} |
| 113 | + |
| 114 | + {#each annotations as annotation (annotation.label)} |
| 115 | + <AnnotationPoint {...annotation} x={annotation.lon} y={annotation.lat} r={4} link /> |
| 116 | + {/each} |
| 117 | + </Layer> |
| 118 | +</Chart> |
0 commit comments