Data displayMapSplit
Searchastronomic.dev# MapSplit
For a search page: the list and the map side by side, with a Show map button on a phone.
Interactive: inline script.
## Usage
```astro
import MapSplit from "@astronomic/ui-pro/components/MapSplit.astro";
```
## Examples
### Homes for sale
FilterBar over MapSplit with the demo listings, the full width of the page: the map runs to the edge on its side and the list keeps the page gutter. Pick a filter: the list, the count and the pins follow. Point at a card or tab to it and its pin lights; a pin lights its card. Narrow the frame to see one view at a time and the Show map button.
```astro
---
import Container from "@astronomic-dev/ui/components/Container.astro";
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import MapSplit from "@astronomic/ui-pro/components/MapSplit.astro";
// Your own listings, fields and index. The points are the server's matches, for the map's first draw.
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { denver, exampleStyle, points } from "../_data/map.ts";
import { exampleIndex, firstPage } from "../_data/search.ts";
const listings = firstPage("buy");
const ids = new Set(listings.map((listing) => listing.id));
---
<!-- A search page: the filters over the list and the map, the full width of the page. The split keeps the page gutter itself; the filters sit in a full-width Container. Pick a filter: the list, the count and the pins follow. Hover a card to light its pin. -->
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks pt-6">
<Container size="full">
<FilterBar id="split-main-filters" label="Filter homes" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={defaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
</Container>
<MapSplit
heading="Homes in Denver"
headingTag="h2"
count={listings.length}
countText={{ one: "home", other: "homes" }}
sorts={sorts}
filtersId="split-main-filters"
source={{ index: exampleIndex }}
fields={fields}
listings={listings}
page={1}
pages={1}
pageHref={() => "?"}
mode="buy"
imageSizes="(min-width: 64rem) 25vw, (min-width: 42rem) 50vw, 100vw"
mapLabel="Map of homes"
mapStyle={exampleStyle}
center={denver}
points={points.filter((point) => ids.has(point.id))}
clusterLabel="{count} homes here. Zoom in."
/>
</div>
```
### Rentals in rows
card is row, and the button's texts are "Map" and "List". Rent pins take the second color.
```astro
---
import Container from "@astronomic-dev/ui/components/Container.astro";
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import MapSplit from "@astronomic/ui-pro/components/MapSplit.astro";
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { denver, exampleStyle, points } from "../_data/map.ts";
import { exampleIndex, firstPage } from "../_data/search.ts";
const rentDefaults = { ...defaults, mode: "rent" };
const listings = firstPage("rent");
const ids = new Set(listings.map((listing) => listing.id));
---
<!-- Rentals in rows beside the map: rent pins take the second color. The button's texts are your own. -->
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks pt-6">
<Container size="full">
<FilterBar id="split-rent-filters" label="Filter rentals" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={rentDefaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
</Container>
<MapSplit
heading="Homes for rent in Denver"
headingTag="h2"
count={listings.length}
countText={{ one: "rental", other: "rentals" }}
sorts={sorts}
filtersId="split-rent-filters"
source={{ index: exampleIndex }}
fields={fields}
listings={listings}
page={1}
pages={1}
pageHref={() => "?"}
mode="rent"
card="row"
imageSizes="(min-width: 36rem) 20rem, 100vw"
mapLabel="Map of rentals"
mapStyle={exampleStyle}
center={denver}
points={points.filter((point) => ids.has(point.id))}
clusterLabel="{count} rentals here. Zoom in."
showMapText="Map"
showListText="List"
/>
</div>
```
## Props
### MapSplit
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `heading` | `string` | None | The heading over the list (ResultsHead's). |
| `headingTag` | `"h1" \| "h2" \| "h3"` | `"h1"` | The heading's element: h1 where the search is the page. |
| `headingId` | `string` | None | The heading's id. Default: a page-unique id. It names the list, and Skip the map and Show list move focus to it. |
| `count` | `number` | None | The count the server knows; the search writes it after. |
| `countText` | `{ one: string; other: string }` | None | The count's noun. Default { one: "listing", other: "listings" }. |
| `sorts` | `ResultsSort[]` | None | The sorts, as passed to Filters. |
| `sort` | `string` | None | The sort picked at first. Default: the first. |
| `sortLabel` | `string` | None | The sort's visible label. Default "Sort". |
| `sortPicker` | `boolean` | None | Draws the sort as a Select with picker: pass it with Filters' dropdown. |
| `filtersId` | `string` | None | The id of the Filters (or FilterBar) form the list follows. Place the filters yourself, over the split. |
| `source` | `{ index: string } \| { endpoint: string }` | None | Where the search reads (ListingResults'). |
| `fields` | `ListingField[]` | None | Your fields list: the cards' facts and the pin cards' facts line. |
| `listings` | `ListingCardData[]` | None | The first page, rendered on the server. |
| `page` | `number` | None | The server list's page, from 1. |
| `pages` | `number` | None | The server list's page count. |
| `pageHref` | `(n: number) => string` | None | Each page's path. Give Filters the same pageHref and pages. |
| `pageSize` | `number` | None | Cards per page. Default 24. |
| `mode` | `string` | None | The mode the server cards show ("buy"). |
| `card` | `"inset" \| "row"` | None | The card recipe (ListingResults'). Default "inset". |
| `itemHeadingTag` | `"h2" \| "h3" \| "h4"` | None | Each card's title element. Default "h3". |
| `imageSizes` | `string` | None | The card photos' sizes attribute. The list is about half the width beside the map. |
| `save` | `boolean` | None | Shows each card's Save button. Default true. |
| `saveList` | `string` | None | The Save buttons' list. |
| `emptyTitle` | `string` | None | The empty state's title (ListingResults'). |
| `emptyText` | `string` | None | The note over the nearest results (ListingResults'). |
| `clearText` | `string` | None | The empty state's button (ListingResults'). |
| `failedText` | `string` | None | The list's note when the search cannot run (ListingResults'). |
| `mapLabel` | `string` | None | The map region's name, such as "Map of homes" (MapView's label). |
| `mapStyle` | `"astronomic" \| "liberty" \| "bright" \| "positron" \| "dark" \| "fiord" \| string` | None | The map's style (MapView's). Default "astronomic". |
| `center` | `{ lat: number; lng: number }` | None | Where the map opens before it fits the points. |
| `zoom` | `number` | None | The zoom it opens at. Default 11. |
| `points` | `MapPoint[]` | None | The server's matches as points, for the map's first draw (toMapPoint from @astronomic/ui-pro/lib/listing-record.ts). Each search replaces them with every match's point. Default []. |
| `skipText` | `string` | None | The map's skip link text. Default "Skip the map". |
| `clusterLabel` | `string` | None | A cluster's name; {count} is filled in. Default "{count} listings here. Zoom in." |
| `mapFailedText` | `string` | None | The map's note when it cannot load (MapView's failedText). Default "The map is not available. The list shows every listing." |
| `linkText` | `string` | None | The pin card's action. Default "See the listing". |
| `closeLabel` | `string` | None | The pin card's close button name. Default "Close". |
| `mapSide` | `"start" \| "end"` | `"end"` | Which side the map takes from the split's wide size. The page order stays the list, then the map, so the Tab order does not change. |
| `showMapText` | `string` | `"Show map"` | The Map/List button's text in the list view. |
| `showListText` | `string` | `"Show list"` | The Map/List button's text in the map view. |
| `class` | `string` | None | More classes for the split, merged with cn(), so yours win on conflicts. Place the split outside your page container: it spans its box and keeps the page gutter itself. |
Any other attribute goes on the split's <div>. The list and the map get their own ids, which the button's aria-controls names.
## Accessibility
| Key | Action |
| --- | --- |
| Enter or Space on Show map | Shows the map in place of the list and moves focus to the map's region (on a narrow screen) |
| Enter or Space on Show list | Shows the list where it was and moves focus to the results heading |
| Tab | Moves from Skip the map to the map, its zoom buttons, the clusters and the pins |
| Enter or Space on a pin | Opens its card and moves focus to the card, with no ring. The next Tab goes to Close, then the title link |
| Escape in the card | Closes the card and returns focus to its pin |
| Enter or Space on a cluster | Zooms in until its listings split apart |
| Arrow keys and + or - on the map | Pan and zoom the map (MapLibre's own keys) |
- In the page the head comes first, then the list, then the map. The Map/List button comes right after the head, and floats at the bottom center while the split is on screen. It shows only with the script (with no script there is no map) and only below the split's wide size; from there both views show side by side.
- Below the wide size the view not shown is hidden from everyone (display none), not only moved: it leaves the Tab order and the accessibility tree.
- The button is a plain button, not a toggle: its text says what it shows next ("Show map", "Show list"), and its aria-controls names both the list and the map.
- Pointing at a card or moving focus into it lights its pin, and the pin lights its card. A pin's click brings its card into view beside the map.
- When a search leaves out the listing whose card is open, the card closes; if focus was on it, focus moves to the results heading.
- The map is a region named by label. "Skip the map" comes first, shows when it has focus, and moves focus to skipToId (give that heading tabindex="-1").
- Each pin is a button named by the full price and the address ("$1,125,000, 3721 Grove St"), with aria-expanded and aria-controls naming its card. One card is open at a time; it has a Close button first, then the listing's link.
- A cluster is a button named by clusterLabel ("14 listings here. Zoom in.").
- When the pin with focus or an open card joins a cluster as you zoom out, or leaves the map, focus moves to the cluster that holds it, else to the map's region, never to the page's start.
- While MapLibre and the style load, the map box is aria-busy. If the map cannot load (no WebGL, a failed download, a style that errors or takes over 8 seconds, a worker that cannot load), the note shows in its place. It takes focus only when the reader asked for the map (Show map); a map that fails as it scrolls into view stays quiet.
- Pins, clusters, the zoom buttons and the card's Close are at least 44px on a touch screen. The attribution stays visible, as OpenFreeMap and OpenStreetMap require.
- Under reduced motion or the theme's calm setting the map jumps instead of glides, and pins do not grow.
MapSplit
ProFor a search page: the list and the map side by side, with a Show map button on a phone.
- File
- MapSplit.astro
- Group
- Data display
- Kind
- Interactive: inline script
- Examples
- 2
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Homes for sale
FilterBar over MapSplit with the demo listings, the full width of the page: the map runs to the edge on its side and the list keeps the page gutter. Pick a filter: the list, the count and the pins follow. Point at a card or tab to it and its pin lights; a pin lights its card. Narrow the frame to see one view at a time and the Show map button.
This preview did not load.
main.astro
examples/mapsplit/main.astro
---
import Container from "@astronomic-dev/ui/components/Container.astro";
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import MapSplit from "@astronomic/ui-pro/components/MapSplit.astro";
// Your own listings, fields and index. The points are the server's matches, for the map's first draw.
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { denver, exampleStyle, points } from "../_data/map.ts";
import { exampleIndex, firstPage } from "../_data/search.ts";
const listings = firstPage("buy");
const ids = new Set(listings.map((listing) => listing.id));
---
<!-- A search page: the filters over the list and the map, the full width of the page. The split keeps the page gutter itself; the filters sit in a full-width Container. Pick a filter: the list, the count and the pins follow. Hover a card to light its pin. -->
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks pt-6">
<Container size="full">
<FilterBar id="split-main-filters" label="Filter homes" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={defaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
</Container>
<MapSplit
heading="Homes in Denver"
headingTag="h2"
count={listings.length}
countText={{ one: "home", other: "homes" }}
sorts={sorts}
filtersId="split-main-filters"
source={{ index: exampleIndex }}
fields={fields}
listings={listings}
page={1}
pages={1}
pageHref={() => "?"}
mode="buy"
imageSizes="(min-width: 64rem) 25vw, (min-width: 42rem) 50vw, 100vw"
mapLabel="Map of homes"
mapStyle={exampleStyle}
center={denver}
points={points.filter((point) => ids.has(point.id))}
clusterLabel="{count} homes here. Zoom in."
/>
</div>Rentals in rows
card is row, and the button's texts are "Map" and "List". Rent pins take the second color.
This preview did not load.
rent.astro
examples/mapsplit/rent.astro
---
import Container from "@astronomic-dev/ui/components/Container.astro";
import FilterBar from "@astronomic-dev/ui/components/FilterBar.astro";
import MapSplit from "@astronomic/ui-pro/components/MapSplit.astro";
import { defaults, fields, modes, sorts } from "../_data/vega.ts";
import { denver, exampleStyle, points } from "../_data/map.ts";
import { exampleIndex, firstPage } from "../_data/search.ts";
const rentDefaults = { ...defaults, mode: "rent" };
const listings = firstPage("rent");
const ids = new Set(listings.map((listing) => listing.id));
---
<!-- Rentals in rows beside the map: rent pins take the second color. The button's texts are your own. -->
<div class="grid grid-cols-[minmax(0,1fr)] gap-blocks pt-6">
<Container size="full">
<FilterBar id="split-rent-filters" label="Filter rentals" fields={fields} modes={modes} modesLabel="Buy or rent" sorts={sorts} defaults={rentDefaults} textLabel="Where" textPlaceholder="Street or neighborhood" />
</Container>
<MapSplit
heading="Homes for rent in Denver"
headingTag="h2"
count={listings.length}
countText={{ one: "rental", other: "rentals" }}
sorts={sorts}
filtersId="split-rent-filters"
source={{ index: exampleIndex }}
fields={fields}
listings={listings}
page={1}
pages={1}
pageHref={() => "?"}
mode="rent"
card="row"
imageSizes="(min-width: 36rem) 20rem, 100vw"
mapLabel="Map of rentals"
mapStyle={exampleStyle}
center={denver}
points={points.filter((point) => ids.has(point.id))}
clusterLabel="{count} rentals here. Zoom in."
showMapText="Map"
showListText="List"
/>
</div>Minimal · Light