MapPoints.svelte component
Generates SVG dots onto a map using d3-geo.
| Param | Default | Required | Description |
|---|---|---|---|
projection Function |
None | A D3 projection function. Pass this in as an uncalled function, e.g. projection={geoAlbersUsa}. |
|
r number |
3.5 |
The point's radius. | |
fill string |
'yellow' |
The point's fill color. | |
stroke string |
'#000' |
The point's stroke color. | |
strokeWidth number |
1 |
The point's stroke width in pixels. | |
opacity number |
1 |
The point's opacity. | |
features (Array<Object> | undefined) |
None | A list of GeoJSON features to plot. If unset, the plotted features will default to those in k.data.features, assuming this field is a list of GeoJSON features. |
<!--
@component
Generates SVG dots onto a map using [d3-geo](https://github.com/d3/d3-geo).
-->
<script>
import { getLayerCakeContext } from 'layercake';
/** @type {import('layercake').LayerCakeContext<any, { features: Array<any> }>} */
const k = getLayerCakeContext();
/**
* @typedef {Object} Props
* @property {Function} projection - A D3 projection function. Pass this in as an uncalled function, e.g. `projection={geoAlbersUsa}`.
* @property {number} [r=3.5] - The point's radius.
* @property {string} [fill='yellow'] - The point's fill color.
* @property {string} [stroke='#000'] - The point's stroke color.
* @property {number} [strokeWidth=1] - The point's stroke width in pixels.
* @property {number} [opacity=1] - The point's opacity.
* @property {Array<Object>|undefined} [features] - A list of GeoJSON features to plot. If unset, the plotted features will default to those in `k.data.features`, assuming this field is a list of GeoJSON features.
*/
/** @type {Props} */
let {
projection,
r = 3.5,
fill = 'yellow',
stroke = '#000',
strokeWidth = 1,
opacity = 1,
features
} = $props();
let projectionFn = $derived(projection().fitSize([k.width, k.height], k.data));
</script>
<g class="points">
{#each features || k.data.features as d}
<!-- To size each circle from an r scale, set r to k.rGet(d.properties) -->
<circle
cx={projectionFn(d.geometry.coordinates)[0]}
cy={projectionFn(d.geometry.coordinates)[1]}
{r}
{fill}
{stroke}
stroke-width={strokeWidth}
{opacity}
/>
{/each}
</g>