Skip to content

Area Slider Map Pin

Drop a pin on a rounded map and read the grid square under it. follow-shape and warp-background bend the grid with the rounded map, the thumb slot holds the pin, and valueLabelHandler names the column and row for screen readers.

A B C D E F G H I J

Code

The following example assumes that you have imported the component and set up the theme.

Map Pin
<div class="map-pin">
46 collapsed lines
<sv-area-slider
id="map-pin-picker"
class="map"
aria-label="Map location"
follow-shape
step="5 5"
value="72 68"
warp-background
x-label="Column"
y-label="Row"
>
<svg class="paper" preserveAspectRatio="none" slot="background" viewBox="0 0 100 100">
<defs>
<pattern
id="map-pin-major"
height="10"
patternUnits="userSpaceOnUse"
width="10"
x="-5"
y="-5"
>
<path d="M5 0V10M0 5H10" stroke="currentColor" stroke-opacity="0.5" stroke-width="0.5" />
</pattern>
</defs>
<rect fill="url(#map-pin-major)" height="99.4" width="99.4" x="0.3" y="0.3" />
<g fill="currentColor" font-size="5" opacity="0.6" transform="translate(0 45)">
<text x="4" y="4">A</text>
<text x="14" y="4">B</text>
<text x="24" y="4">C</text>
<text x="34" y="4">D</text>
<text x="44" y="4">E</text>
<text x="54" y="4">F</text>
<text x="64" y="4">G</text>
<text x="74" y="4">H</text>
<text x="84" y="4">I</text>
<text x="94" y="4">J</text>
</g>
</svg>
<svg class="pin" slot="thumb" viewBox="0 0 24 32">
<path d="M12 31s10-11 10-19a10 10 0 0 0-20 0c0 8 10 19 10 19z" />
<circle cx="12" cy="12" r="4" />
</svg>
</sv-area-slider>
<output id="map-pin-output"></output>
</div>
<script type="application/x-typescript" module>
16 collapsed lines
const picker = document.querySelector<AreaSlider>("#map-pin-picker")!;
const squareOutput = document.querySelector<HTMLOutputElement>("#map-pin-output")!;
const getColumnName = (x: number) => "ABCDEFGHIJ"[Math.min(9, Math.floor(x / 10))];
const getRowName = (y: number) => String(Math.min(10, Math.floor((100 - y) / 10) + 1));
picker.valueLabelHandler = (value, axis) =>
axis === "x" ? `column ${getColumnName(value)}` : `row ${getRowName(value)}`;
updateSquare();
picker.addEventListener("valuechange", updateSquare);
function updateSquare() {
const [x, y] = picker.valueXY;
squareOutput.value = `Square ${getColumnName(x)}${getRowName(y)}`;
}
</script>
<style>
37 collapsed lines
.map-pin {
display: grid;
gap: 0.75em;
justify-items: center;
.map {
--sv-area-slider-width: min(100%, 20em);
--sv-area-slider-bdr-rad: 30%;
--sv-area-slider-thumb-sz: 1.6em;
}
.paper {
display: block;
inline-size: 100%;
block-size: 100%;
color: var(--sv-gray-1);
}
.pin {
inline-size: 1.6em;
block-size: 2.1em;
filter: drop-shadow(0 2px 2px rgb(0 0 0 / 35%));
translate: 0 -50%;
path {
fill: var(--sv-accent);
}
circle {
fill: var(--sv-accent-content);
}
}
output {
font-variant-numeric: tabular-nums;
}
}
</style>