# A team around the world

Faces for markers, list entries of your own with each person's local time, filtered by team.

## How it works

Each person is a face on the map, their initials on their team's colour, and the list beside it is the page's own: their name, role and city, and the time where they are next to how far that is from yours, turning as each minute begins.

- **HTML**: `src` names `team.json`, the same people the other versions load ([Data](/element/#data)), and the page's script sets `markerIcon`, which draws each person's face from their `data.initials` and their group ([Properties and methods](/element/#properties-and-methods)). The list is a view of the page's own, `Maplace.defineListView` around `Maplace.createListView` with `render`, which reads the role, city and time zone from `location.data` and draws the face the same way ([List views](/element/#list-views)); `group-filter`, `group-counts` and `search` on the map still reach it as its `options`.
- **Script** and **Bundler**: the people from `team.json`, each given an `icon` that draws the face from its `data` ([Icons](/locations/#icons)), and `list.render` building each entry ([List view options](/store/#list-view-options)). The times are written into each entry's own span, and a timeout set to the next minute writes them again, so no location changes for the clock.
- **React**: `markerIcon` on `<MaplaceMap>` and the entry as `<LocationList>`'s children ([`<LocationList>`](/react/#locationlist)); each entry's `<LocalTime>` keeps the minute in its state, so only the times render again as each minute begins.
- **Styling**: each team's colour, and the rings a face takes while pointed at or picked (`[data-hovered]`, `[data-selected]`), in the examples' `styles/team.css` ([Styling](/styling/)).
- **On MapLibre, a globe**: `globe` on the map (`globe: true` in the options; in React, `createAdapter={() => createMapLibreAdapter({ globe: true })}`) ([Globe](/maplibre/#globe)). Google's map has no globe.

## Code

### HTML on MapLibre

`packages/maplace/examples/team/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- A team around the world, from team.json: each person's face on the map, their initials on
     their team's colour, and the list beside it, each entry their role and city and the time
     where they are, which turns as each minute begins; filtered by team, or searched by name,
     city or role. On MapLibre, the earth as a globe, with a toggle on the map to flatten it. -->
<!-- This example's look lives in the examples' styles/team.css, which every version links. -->
<link rel="stylesheet" href="../../styles/team.css">
<style>
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #team-maplibre-map { height: 36rem; }
    #team-maplibre-map > .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<maplace-map id="team-maplibre-map" list="maplibre-team-members" list-heading="The team" group-counts
  group-filter search search-label="Find someone" globe
  src="/examples/data/team.json"></maplace-map>
<script>
  {
    const map = document.getElementById("team-maplibre-map");
    const viewerZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
    // How long until the next minute begins, and a little past it, so the clock reads the new one.
    const untilNextMinute = () => 60_050 - (Date.now() % 60_000);

    // The time on a zone's clock: "17:30".
    const localTimeOf = (timeZone, now) =>
      new Intl.DateTimeFormat("en-GB", { timeZone, hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).format(now);
    // How far a zone's clock is ahead of UTC, in minutes: Kolkata's 330 ("GMT" alone is 0).
    const minutesFromUtc = (timeZone, now) => {
      const name = new Intl.DateTimeFormat("en-GB", { timeZone, timeZoneName: "longOffset" })
        .formatToParts(now).find(({ type }) => type === "timeZoneName")?.value ?? "";
      const [, sign = "+", hours = "0", minutes = "0"] = /GMT([+\-−])(\d\d):(\d\d)/.exec(name) ?? [];
      return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes));
    };
    // "+5h30", "−8h" or "same time": how far a zone's clock is ahead of yours, or behind.
    const offsetFromYou = (timeZone, now) => {
      const minutes = minutesFromUtc(timeZone, now) - minutesFromUtc(viewerZone, now);
      if (minutes === 0) return "same time";
      const sign = minutes > 0 ? "+" : "−";
      const hours = Math.floor(Math.abs(minutes) / 60);
      const rest = Math.abs(minutes) % 60;
      return `${sign}${hours}h${rest ? String(rest).padStart(2, "0") : ""}`;
    };
    const writeLocalTime = (time) => {
      const now = new Date();
      time.textContent = `${localTimeOf(time.dataset.timeZone, now)} · ${offsetFromYou(time.dataset.timeZone, now)}`;
    };
    // A span showing the time on a zone's clock beside how far it is from yours.
    const localTime = (timeZone) => {
      const time = document.createElement("span");
      time.className = "team-member-time";
      time.dataset.timeZone = timeZone;
      writeLocalTime(time);
      return time;
    };
    const span = (className, ...children) => {
      const element = document.createElement("span");
      element.className = className;
      element.append(...children);
      return element;
    };

    // A person's marker, and their face in the list: their initials on their team's colour.
    const avatarOf = ({ group, data }) => {
      const avatar = span("team-avatar", data.initials);
      avatar.dataset.team = group;
      return avatar;
    };
    map.markerIcon = avatarOf;

    // A person's entry in the list, the page's own: their face, name, role and city from their
    // data in team.json, and the time where they are.
    const memberItem = ({ location }) => {
      const person = location.data;
      const face = avatarOf(location);
      face.setAttribute("aria-hidden", "true");
      return span("team-member", face, span("team-member-text",
        span("team-member-name", location.title),
        span("team-member-detail", `${person.role} · ${person.city}`),
        localTime(person.timeZone)));
    };
    Maplace.defineListView("maplibre-team-members", (maplace, { options }) =>
      Maplace.createListView(maplace, { ...options, render: memberItem }));

    // Every time shown turns as each minute begins.
    const showLocalTimes = () => {
      for (const time of map.querySelectorAll(".team-member-time")) writeLocalTime(time);
      setTimeout(showLocalTimes, untilNextMinute());
    };
    setTimeout(showLocalTimes, untilNextMinute());
  }
</script>
```

### HTML on Google

`packages/maplace/examples/team/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- A team around the world, from team.json: each person's face on the map, their initials on
     their team's colour, and the list beside it, each entry their role and city and the time
     where they are, which turns as each minute begins; filtered by team, or searched by name,
     city or role. -->
<!-- This example's look lives in the examples' styles/team.css, which every version links. -->
<link rel="stylesheet" href="../styles/team.css">
<style>
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #team-map { height: 36rem; }
    #team-map > .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<maplace-map id="team-map" api-key="YOUR_KEY" list="team-members" list-heading="The team" group-counts
  group-filter search search-label="Find someone"
  src="/examples/data/team.json"></maplace-map>
<script>
  {
    const map = document.getElementById("team-map");
    const viewerZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
    // How long until the next minute begins, and a little past it, so the clock reads the new one.
    const untilNextMinute = () => 60_050 - (Date.now() % 60_000);

    // The time on a zone's clock: "17:30".
    const localTimeOf = (timeZone, now) =>
      new Intl.DateTimeFormat("en-GB", { timeZone, hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).format(now);
    // How far a zone's clock is ahead of UTC, in minutes: Kolkata's 330 ("GMT" alone is 0).
    const minutesFromUtc = (timeZone, now) => {
      const name = new Intl.DateTimeFormat("en-GB", { timeZone, timeZoneName: "longOffset" })
        .formatToParts(now).find(({ type }) => type === "timeZoneName")?.value ?? "";
      const [, sign = "+", hours = "0", minutes = "0"] = /GMT([+\-−])(\d\d):(\d\d)/.exec(name) ?? [];
      return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes));
    };
    // "+5h30", "−8h" or "same time": how far a zone's clock is ahead of yours, or behind.
    const offsetFromYou = (timeZone, now) => {
      const minutes = minutesFromUtc(timeZone, now) - minutesFromUtc(viewerZone, now);
      if (minutes === 0) return "same time";
      const sign = minutes > 0 ? "+" : "−";
      const hours = Math.floor(Math.abs(minutes) / 60);
      const rest = Math.abs(minutes) % 60;
      return `${sign}${hours}h${rest ? String(rest).padStart(2, "0") : ""}`;
    };
    const writeLocalTime = (time) => {
      const now = new Date();
      time.textContent = `${localTimeOf(time.dataset.timeZone, now)} · ${offsetFromYou(time.dataset.timeZone, now)}`;
    };
    // A span showing the time on a zone's clock beside how far it is from yours.
    const localTime = (timeZone) => {
      const time = document.createElement("span");
      time.className = "team-member-time";
      time.dataset.timeZone = timeZone;
      writeLocalTime(time);
      return time;
    };
    const span = (className, ...children) => {
      const element = document.createElement("span");
      element.className = className;
      element.append(...children);
      return element;
    };

    // A person's marker, and their face in the list: their initials on their team's colour.
    const avatarOf = ({ group, data }) => {
      const avatar = span("team-avatar", data.initials);
      avatar.dataset.team = group;
      return avatar;
    };
    map.markerIcon = avatarOf;

    // A person's entry in the list, the page's own: their face, name, role and city from their
    // data in team.json, and the time where they are.
    const memberItem = ({ location }) => {
      const person = location.data;
      const face = avatarOf(location);
      face.setAttribute("aria-hidden", "true");
      return span("team-member", face, span("team-member-text",
        span("team-member-name", location.title),
        span("team-member-detail", `${person.role} · ${person.city}`),
        localTime(person.timeZone)));
    };
    Maplace.defineListView("team-members", (maplace, { options }) =>
      Maplace.createListView(maplace, { ...options, render: memberItem }));

    // Every time shown turns as each minute begins.
    const showLocalTimes = () => {
      for (const time of map.querySelectorAll(".team-member-time")) writeLocalTime(time);
      setTimeout(showLocalTimes, untilNextMinute());
    };
    setTimeout(showLocalTimes, untilNextMinute());
  }
</script>
```

### Script on MapLibre

`packages/maplace/examples/team/maplibre/script.html`

```html
<!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet, what the map and its list mount on, and the map made with Maplace; each person's face on the map, and the list with the time where each one is. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- This example's look lives in the examples' styles/team.css, which every version links. -->
<link rel="stylesheet" href="../../styles/team.css">
<style>
  #team-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #team-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #team-maplibre-script-list { display: contents; }
  #team-maplibre-script-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #team-maplibre-script-map-and-list { flex-direction: column; height: 36rem; }
    #team-maplibre-script-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="team-maplibre-script-map-and-list">
  <div id="team-maplibre-script-map"></div>
  <div id="team-maplibre-script-list"></div>
</div>
<script type="module">
  // Each person, in their team's group: their role, city, clock and initials in their data.
  const team = await fetch("/examples/data/team.json").then((response) => response.json());
  const viewerZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
  // How long until the next minute begins, and a little past it, so the clock reads the new one.
  const untilNextMinute = () => 60_050 - (Date.now() % 60_000);

  // The time on a zone's clock: "17:30".
  const localTimeOf = (timeZone, now) =>
    new Intl.DateTimeFormat("en-GB", { timeZone, hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).format(now);
  // How far a zone's clock is ahead of UTC, in minutes: Kolkata's 330 ("GMT" alone is 0).
  const minutesFromUtc = (timeZone, now) => {
    const name = new Intl.DateTimeFormat("en-GB", { timeZone, timeZoneName: "longOffset" })
      .formatToParts(now).find(({ type }) => type === "timeZoneName")?.value ?? "";
    const [, sign = "+", hours = "0", minutes = "0"] = /GMT([+\-−])(\d\d):(\d\d)/.exec(name) ?? [];
    return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes));
  };
  // "+5h30", "−8h" or "same time": how far a zone's clock is ahead of yours, or behind.
  const offsetFromYou = (timeZone, now) => {
    const minutes = minutesFromUtc(timeZone, now) - minutesFromUtc(viewerZone, now);
    if (minutes === 0) return "same time";
    const sign = minutes > 0 ? "+" : "−";
    const hours = Math.floor(Math.abs(minutes) / 60);
    const rest = Math.abs(minutes) % 60;
    return `${sign}${hours}h${rest ? String(rest).padStart(2, "0") : ""}`;
  };
  const writeLocalTime = (time) => {
    const now = new Date();
    time.textContent = `${localTimeOf(time.dataset.timeZone, now)} · ${offsetFromYou(time.dataset.timeZone, now)}`;
  };
  // A span showing the time on a zone's clock beside how far it is from yours.
  const localTime = (timeZone) => {
    const time = document.createElement("span");
    time.className = "team-member-time";
    time.dataset.timeZone = timeZone;
    writeLocalTime(time);
    return time;
  };
  const span = (className, ...children) => {
    const element = document.createElement("span");
    element.className = className;
    element.append(...children);
    return element;
  };

  // A face: the person's initials on their team's colour, the marker and the entry's lead.
  const avatar = ({ group, data }) => {
    const face = span("team-avatar", data.initials);
    face.dataset.team = group;
    return face;
  };
  // A person's entry in the list, the page's own: their face, name, role and city, and the time
  // where they are.
  const memberItem = ({ location }) => {
    const face = avatar(location);
    face.setAttribute("aria-hidden", "true");
    return span("team-member", face, span("team-member-text",
      span("team-member-name", location.title),
      span("team-member-detail", `${location.data.role} · ${location.data.city}`),
      localTime(location.data.timeZone)));
  };

  Maplace.createMapLibreMap("#team-maplibre-script-map", {
    // The earth as a globe, with a toggle on the map to flatten it.
    globe: true,
    locations: team.map((person) => ({ ...person, icon: avatar })),
    list: {
      container: "#team-maplibre-script-list",
      heading: "The team",
      render: memberItem,
      groupCounts: true,
      groupFilter: true,
      search: true,
      searchLabel: "Find someone",
    },
  });

  // Every time shown turns as each minute begins.
  const list = document.getElementById("team-maplibre-script-list");
  const showLocalTimes = () => {
    for (const time of list.querySelectorAll(".team-member-time")) writeLocalTime(time);
    setTimeout(showLocalTimes, untilNextMinute());
  };
  setTimeout(showLocalTimes, untilNextMinute());
</script>
```

### Script on Google

`packages/maplace/examples/team/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script, what the map and its list mount on, and the map made with Maplace, which adds Maps JS with your key; each person's face on the map, and the list with the time where each one is. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- This example's look lives in the examples' styles/team.css, which every version links. -->
<link rel="stylesheet" href="../styles/team.css">
<style>
  #team-script-map-and-list { display: flex; height: 24rem; }
  #team-script-map { flex: 1 1 auto; min-width: 0; }
  #team-script-list { display: contents; }
  #team-script-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #team-script-map-and-list { flex-direction: column; height: 36rem; }
    #team-script-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="team-script-map-and-list">
  <div id="team-script-map"></div>
  <div id="team-script-list"></div>
</div>
<script type="module">
  // Each person, in their team's group: their role, city, clock and initials in their data.
  const team = await fetch("/examples/data/team.json").then((response) => response.json());
  const viewerZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
  // How long until the next minute begins, and a little past it, so the clock reads the new one.
  const untilNextMinute = () => 60_050 - (Date.now() % 60_000);

  // The time on a zone's clock: "17:30".
  const localTimeOf = (timeZone, now) =>
    new Intl.DateTimeFormat("en-GB", { timeZone, hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).format(now);
  // How far a zone's clock is ahead of UTC, in minutes: Kolkata's 330 ("GMT" alone is 0).
  const minutesFromUtc = (timeZone, now) => {
    const name = new Intl.DateTimeFormat("en-GB", { timeZone, timeZoneName: "longOffset" })
      .formatToParts(now).find(({ type }) => type === "timeZoneName")?.value ?? "";
    const [, sign = "+", hours = "0", minutes = "0"] = /GMT([+\-−])(\d\d):(\d\d)/.exec(name) ?? [];
    return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes));
  };
  // "+5h30", "−8h" or "same time": how far a zone's clock is ahead of yours, or behind.
  const offsetFromYou = (timeZone, now) => {
    const minutes = minutesFromUtc(timeZone, now) - minutesFromUtc(viewerZone, now);
    if (minutes === 0) return "same time";
    const sign = minutes > 0 ? "+" : "−";
    const hours = Math.floor(Math.abs(minutes) / 60);
    const rest = Math.abs(minutes) % 60;
    return `${sign}${hours}h${rest ? String(rest).padStart(2, "0") : ""}`;
  };
  const writeLocalTime = (time) => {
    const now = new Date();
    time.textContent = `${localTimeOf(time.dataset.timeZone, now)} · ${offsetFromYou(time.dataset.timeZone, now)}`;
  };
  // A span showing the time on a zone's clock beside how far it is from yours.
  const localTime = (timeZone) => {
    const time = document.createElement("span");
    time.className = "team-member-time";
    time.dataset.timeZone = timeZone;
    writeLocalTime(time);
    return time;
  };
  const span = (className, ...children) => {
    const element = document.createElement("span");
    element.className = className;
    element.append(...children);
    return element;
  };

  // A face: the person's initials on their team's colour, the marker and the entry's lead.
  const avatar = ({ group, data }) => {
    const face = span("team-avatar", data.initials);
    face.dataset.team = group;
    return face;
  };
  // A person's entry in the list, the page's own: their face, name, role and city, and the time
  // where they are.
  const memberItem = ({ location }) => {
    const face = avatar(location);
    face.setAttribute("aria-hidden", "true");
    return span("team-member", face, span("team-member-text",
      span("team-member-name", location.title),
      span("team-member-detail", `${location.data.role} · ${location.data.city}`),
      localTime(location.data.timeZone)));
  };

  Maplace.createGoogleMap("#team-script-map", {
    apiKey: "YOUR_KEY",
    locations: team.map((person) => ({ ...person, icon: avatar })),
    list: {
      container: "#team-script-list",
      heading: "The team",
      render: memberItem,
      groupCounts: true,
      groupFilter: true,
      search: true,
      searchLabel: "Find someone",
    },
  });

  // Every time shown turns as each minute begins.
  const list = document.getElementById("team-script-list");
  const showLocalTimes = () => {
    for (const time of list.querySelectorAll(".team-member-time")) writeLocalTime(time);
    setTimeout(showLocalTimes, untilNextMinute());
  };
  setTimeout(showLocalTimes, untilNextMinute());
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/team/maplibre/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<!-- This example's look lives in the examples' styles/team.css, which every version links. -->
<link rel="stylesheet" href="../../styles/team.css">
<style>
  #team-maplibre-vanilla-map-and-list { display: flex; height: 24rem; }
  #team-maplibre-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #team-maplibre-vanilla-list { display: contents; }
  #team-maplibre-vanilla-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #team-maplibre-vanilla-map-and-list { flex-direction: column; height: 36rem; }
    #team-maplibre-vanilla-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="team-maplibre-vanilla-map-and-list">
  <div id="team-maplibre-vanilla-map"></div>
  <div id="team-maplibre-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/team/maplibre/vanilla.ts`

```ts
import "maplibre-gl/dist/maplibre-gl.css";
import type { ListEntry, Location } from "@maplacejs/maplace";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";

/** What each person's location carries: their role, city, clock and initials. */
interface Member {
  readonly role: string;
  readonly city: string;
  readonly timeZone: string;
  readonly initials: string;
}

// Each person, in their team's group.
const team: Location<Member>[] = await (await fetch("/examples/data/team.json")).json();
const viewerZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

/** How long until the next minute begins, and a little past it, so the clock reads the new one. */
const untilNextMinute = () => 60_050 - (Date.now() % 60_000);

/** The time on a zone's clock: "17:30". */
function localTimeOf(timeZone: string, now: Date): string {
  const clock = { timeZone, hour: "2-digit", minute: "2-digit", hourCycle: "h23" } as const;
  return new Intl.DateTimeFormat("en-GB", clock).format(now);
}

/** How far a zone's clock is ahead of UTC, in minutes: Kolkata's 330 ("GMT" alone is 0). */
function minutesFromUtc(timeZone: string, now: Date): number {
  const name = new Intl.DateTimeFormat("en-GB", { timeZone, timeZoneName: "longOffset" })
    .formatToParts(now)
    .find(({ type }) => type === "timeZoneName")?.value;
  const [, sign = "+", hours = "0", minutes = "0"] =
    /GMT([+\-−])(\d\d):(\d\d)/.exec(name ?? "") ?? [];
  return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes));
}

/** "+5h30", "−8h" or "same time": how far a zone's clock is ahead of yours, or behind. */
function offsetFromYou(timeZone: string, now: Date): string {
  const minutes = minutesFromUtc(timeZone, now) - minutesFromUtc(viewerZone, now);
  if (minutes === 0) return "same time";
  const sign = minutes > 0 ? "+" : "−";
  const hours = Math.floor(Math.abs(minutes) / 60);
  const rest = Math.abs(minutes) % 60;
  return `${sign}${hours}h${rest ? String(rest).padStart(2, "0") : ""}`;
}

function writeLocalTime(time: HTMLElement): void {
  const now = new Date();
  const zone = time.dataset.timeZone ?? viewerZone;
  time.textContent = `${localTimeOf(zone, now)} · ${offsetFromYou(zone, now)}`;
}

/** A span showing the time on a zone's clock beside how far it is from yours. */
function localTime(timeZone: string): HTMLElement {
  const time = document.createElement("span");
  time.className = "team-member-time";
  time.dataset.timeZone = timeZone;
  writeLocalTime(time);
  return time;
}

function span(className: string, ...children: (Node | string)[]): HTMLSpanElement {
  const element = document.createElement("span");
  element.className = className;
  element.append(...children);
  return element;
}

/** A face: the person's initials on their team's colour, the marker and the entry's lead. */
function avatar({ group, data }: Location<Member>): HTMLElement {
  const face = span("team-avatar", data?.initials ?? "");
  face.dataset.team = String(group);
  return face;
}

/** A person's entry in the list: their face, name, role and city, and the time where they are. */
function memberItem({ location }: ListEntry<Member>): Node {
  const face = avatar(location);
  face.setAttribute("aria-hidden", "true");
  return span(
    "team-member",
    face,
    span(
      "team-member-text",
      span("team-member-name", location.title ?? ""),
      span("team-member-detail", `${location.data?.role} · ${location.data?.city}`),
      localTime(location.data?.timeZone ?? viewerZone),
    ),
  );
}

createMapLibreMap<Member>("#team-maplibre-vanilla-map", {
  // The earth as a globe, with a toggle on the map to flatten it.
  globe: true,
  locations: team.map((person) => ({ ...person, icon: avatar })),
  list: {
    container: "#team-maplibre-vanilla-list",
    heading: "The team",
    render: memberItem,
    groupCounts: true,
    groupFilter: true,
    search: true,
    searchLabel: "Find someone",
  },
});

/** Every time shown turns as each minute begins. */
function showLocalTimes(): void {
  for (const time of document.querySelectorAll<HTMLElement>(
    "#team-maplibre-vanilla-list .team-member-time",
  )) {
    writeLocalTime(time);
  }
  setTimeout(showLocalTimes, untilNextMinute());
}
setTimeout(showLocalTimes, untilNextMinute());
```

### Bundler on Google

`packages/maplace/examples/team/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<!-- This example's look lives in the examples' styles/team.css, which every version links. -->
<link rel="stylesheet" href="../styles/team.css">
<style>
  #team-vanilla-map-and-list { display: flex; height: 24rem; }
  #team-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #team-vanilla-list { display: contents; }
  #team-vanilla-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #team-vanilla-map-and-list { flex-direction: column; height: 36rem; }
    #team-vanilla-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="team-vanilla-map-and-list">
  <div id="team-vanilla-map"></div>
  <div id="team-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/team/vanilla.ts`

```ts
import type { ListEntry, Location } from "@maplacejs/maplace";
import { createGoogleMap } from "@maplacejs/maplace/google";

/** What each person's location carries: their role, city, clock and initials. */
interface Member {
  readonly role: string;
  readonly city: string;
  readonly timeZone: string;
  readonly initials: string;
}

// Each person, in their team's group.
const team: Location<Member>[] = await (await fetch("/examples/data/team.json")).json();
const viewerZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

/** How long until the next minute begins, and a little past it, so the clock reads the new one. */
const untilNextMinute = () => 60_050 - (Date.now() % 60_000);

/** The time on a zone's clock: "17:30". */
function localTimeOf(timeZone: string, now: Date): string {
  const clock = { timeZone, hour: "2-digit", minute: "2-digit", hourCycle: "h23" } as const;
  return new Intl.DateTimeFormat("en-GB", clock).format(now);
}

/** How far a zone's clock is ahead of UTC, in minutes: Kolkata's 330 ("GMT" alone is 0). */
function minutesFromUtc(timeZone: string, now: Date): number {
  const name = new Intl.DateTimeFormat("en-GB", { timeZone, timeZoneName: "longOffset" })
    .formatToParts(now)
    .find(({ type }) => type === "timeZoneName")?.value;
  const [, sign = "+", hours = "0", minutes = "0"] =
    /GMT([+\-−])(\d\d):(\d\d)/.exec(name ?? "") ?? [];
  return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes));
}

/** "+5h30", "−8h" or "same time": how far a zone's clock is ahead of yours, or behind. */
function offsetFromYou(timeZone: string, now: Date): string {
  const minutes = minutesFromUtc(timeZone, now) - minutesFromUtc(viewerZone, now);
  if (minutes === 0) return "same time";
  const sign = minutes > 0 ? "+" : "−";
  const hours = Math.floor(Math.abs(minutes) / 60);
  const rest = Math.abs(minutes) % 60;
  return `${sign}${hours}h${rest ? String(rest).padStart(2, "0") : ""}`;
}

function writeLocalTime(time: HTMLElement): void {
  const now = new Date();
  const zone = time.dataset.timeZone ?? viewerZone;
  time.textContent = `${localTimeOf(zone, now)} · ${offsetFromYou(zone, now)}`;
}

/** A span showing the time on a zone's clock beside how far it is from yours. */
function localTime(timeZone: string): HTMLElement {
  const time = document.createElement("span");
  time.className = "team-member-time";
  time.dataset.timeZone = timeZone;
  writeLocalTime(time);
  return time;
}

function span(className: string, ...children: (Node | string)[]): HTMLSpanElement {
  const element = document.createElement("span");
  element.className = className;
  element.append(...children);
  return element;
}

/** A face: the person's initials on their team's colour, the marker and the entry's lead. */
function avatar({ group, data }: Location<Member>): HTMLElement {
  const face = span("team-avatar", data?.initials ?? "");
  face.dataset.team = String(group);
  return face;
}

/** A person's entry in the list: their face, name, role and city, and the time where they are. */
function memberItem({ location }: ListEntry<Member>): Node {
  const face = avatar(location);
  face.setAttribute("aria-hidden", "true");
  return span(
    "team-member",
    face,
    span(
      "team-member-text",
      span("team-member-name", location.title ?? ""),
      span("team-member-detail", `${location.data?.role} · ${location.data?.city}`),
      localTime(location.data?.timeZone ?? viewerZone),
    ),
  );
}

createGoogleMap<Member>("#team-vanilla-map", {
  locations: team.map((person) => ({ ...person, icon: avatar })),
  list: {
    container: "#team-vanilla-list",
    heading: "The team",
    render: memberItem,
    groupCounts: true,
    groupFilter: true,
    search: true,
    searchLabel: "Find someone",
  },
});

/** Every time shown turns as each minute begins. */
function showLocalTimes(): void {
  for (const time of document.querySelectorAll<HTMLElement>(
    "#team-vanilla-list .team-member-time",
  )) {
    writeLocalTime(time);
  }
  setTimeout(showLocalTimes, untilNextMinute());
}
setTimeout(showLocalTimes, untilNextMinute());
```

### React on MapLibre

`packages/maplace/examples/team/maplibre/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<!-- This example's look lives in the examples' styles/team.css, which every version links. -->
<link rel="stylesheet" href="../../styles/team.css">
<style>
  #team-maplibre-react-root .map-and-list { display: flex; height: 24rem; }
  #team-maplibre-react-root .map { flex: 1 1 auto; min-width: 0; }
  #team-maplibre-react-root .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #team-maplibre-react-root .map-and-list { flex-direction: column; height: 36rem; }
    #team-maplibre-react-root .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="team-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/team/maplibre/react.tsx`

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import type { ListEntry, Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode, useEffect, useState } from "react";
import { createRoot } from "react-dom/client";

/** What each person's location carries: their role, city, clock and initials. */
interface Member {
  readonly role: string;
  readonly city: string;
  readonly timeZone: string;
  readonly initials: string;
}

const viewerZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

/** The time on a zone's clock: "17:30". */
function localTimeOf(timeZone: string, now: Date): string {
  const clock = { timeZone, hour: "2-digit", minute: "2-digit", hourCycle: "h23" } as const;
  return new Intl.DateTimeFormat("en-GB", clock).format(now);
}

/** How far a zone's clock is ahead of UTC, in minutes: Kolkata's 330 ("GMT" alone is 0). */
function minutesFromUtc(timeZone: string, now: Date): number {
  const name = new Intl.DateTimeFormat("en-GB", { timeZone, timeZoneName: "longOffset" })
    .formatToParts(now)
    .find(({ type }) => type === "timeZoneName")?.value;
  const [, sign = "+", hours = "0", minutes = "0"] =
    /GMT([+\-−])(\d\d):(\d\d)/.exec(name ?? "") ?? [];
  return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes));
}

/** "+5h30", "−8h" or "same time": how far a zone's clock is ahead of yours, or behind. */
function offsetFromYou(timeZone: string, now: Date): string {
  const minutes = minutesFromUtc(timeZone, now) - minutesFromUtc(viewerZone, now);
  if (minutes === 0) return "same time";
  const sign = minutes > 0 ? "+" : "−";
  const hours = Math.floor(Math.abs(minutes) / 60);
  const rest = Math.abs(minutes) % 60;
  return `${sign}${hours}h${rest ? String(rest).padStart(2, "0") : ""}`;
}

/** The time now, turning as each minute begins (a little past it, so the clock reads the new one). */
function useMinute(): Date {
  const [now, setNow] = useState(() => new Date());
  useEffect(() => {
    const turn = setTimeout(() => setNow(new Date()), 60_050 - (now.getTime() % 60_000));
    return () => clearTimeout(turn);
  }, [now]);
  return now;
}

/** The time on a zone's clock beside how far it is from yours, turning as each minute begins. */
function LocalTime({ timeZone }: { readonly timeZone: string }) {
  const now = useMinute();
  return (
    <span className="team-member-time">
      {localTimeOf(timeZone, now)} · {offsetFromYou(timeZone, now)}
    </span>
  );
}

/** A face: the person's initials on their team's colour, the marker and the entry's lead. */
function Avatar({ location: { group, data } }: { readonly location: Location<Member> }) {
  return (
    <span className="team-avatar" data-team={String(group)}>
      {data?.initials}
    </span>
  );
}

// The earth as a globe, with a toggle on the map to flatten it.
const onTheGlobe = () => createMapLibreAdapter({ globe: true });

const markerIcon = (location: Location<Member>) => <Avatar location={location} />;

/** A person's entry in the list: their face, name, role and city, and the time where they are. */
const memberItem = ({ location }: ListEntry<Member>) => (
  <span className="team-member">
    <span aria-hidden="true">
      <Avatar location={location} />
    </span>
    <span className="team-member-text">
      <span className="team-member-name">{location.title}</span>
      <span className="team-member-detail">
        {location.data?.role} · {location.data?.city}
      </span>
      <LocalTime timeZone={location.data?.timeZone ?? viewerZone} />
    </span>
  </span>
);

function Team() {
  // Each person, in their team's group.
  const [team, setTeam] = useState<readonly Location<Member>[]>([]);
  useEffect(() => {
    fetch("/examples/data/team.json")
      .then((response) => response.json())
      .then(setTeam);
  }, []);
  return (
    <MaplaceProvider locations={team}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={onTheGlobe} className="map" markerIcon={markerIcon} />
        <LocationList heading="The team" groupCounts groupFilter search searchLabel="Find someone">
          {memberItem}
        </LocationList>
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("team-maplibre-react-root") as HTMLElement).render(
  <StrictMode>
    <Team />
  </StrictMode>,
);
```

### React on Google

`packages/maplace/examples/team/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<!-- This example's look lives in the examples' styles/team.css, which every version links. -->
<link rel="stylesheet" href="../styles/team.css">
<style>
  #team-react-root .map-and-list { display: flex; height: 24rem; }
  #team-react-root .map { flex: 1 1 auto; min-width: 0; }
  #team-react-root .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #team-react-root .map-and-list { flex-direction: column; height: 36rem; }
    #team-react-root .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="team-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/team/react.tsx`

```tsx
import type { ListEntry, Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode, useEffect, useState } from "react";
import { createRoot } from "react-dom/client";

/** What each person's location carries: their role, city, clock and initials. */
interface Member {
  readonly role: string;
  readonly city: string;
  readonly timeZone: string;
  readonly initials: string;
}

const viewerZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

/** The time on a zone's clock: "17:30". */
function localTimeOf(timeZone: string, now: Date): string {
  const clock = { timeZone, hour: "2-digit", minute: "2-digit", hourCycle: "h23" } as const;
  return new Intl.DateTimeFormat("en-GB", clock).format(now);
}

/** How far a zone's clock is ahead of UTC, in minutes: Kolkata's 330 ("GMT" alone is 0). */
function minutesFromUtc(timeZone: string, now: Date): number {
  const name = new Intl.DateTimeFormat("en-GB", { timeZone, timeZoneName: "longOffset" })
    .formatToParts(now)
    .find(({ type }) => type === "timeZoneName")?.value;
  const [, sign = "+", hours = "0", minutes = "0"] =
    /GMT([+\-−])(\d\d):(\d\d)/.exec(name ?? "") ?? [];
  return (sign === "+" ? 1 : -1) * (Number(hours) * 60 + Number(minutes));
}

/** "+5h30", "−8h" or "same time": how far a zone's clock is ahead of yours, or behind. */
function offsetFromYou(timeZone: string, now: Date): string {
  const minutes = minutesFromUtc(timeZone, now) - minutesFromUtc(viewerZone, now);
  if (minutes === 0) return "same time";
  const sign = minutes > 0 ? "+" : "−";
  const hours = Math.floor(Math.abs(minutes) / 60);
  const rest = Math.abs(minutes) % 60;
  return `${sign}${hours}h${rest ? String(rest).padStart(2, "0") : ""}`;
}

/** The time now, turning as each minute begins (a little past it, so the clock reads the new one). */
function useMinute(): Date {
  const [now, setNow] = useState(() => new Date());
  useEffect(() => {
    const turn = setTimeout(() => setNow(new Date()), 60_050 - (now.getTime() % 60_000));
    return () => clearTimeout(turn);
  }, [now]);
  return now;
}

/** The time on a zone's clock beside how far it is from yours, turning as each minute begins. */
function LocalTime({ timeZone }: { readonly timeZone: string }) {
  const now = useMinute();
  return (
    <span className="team-member-time">
      {localTimeOf(timeZone, now)} · {offsetFromYou(timeZone, now)}
    </span>
  );
}

/** A face: the person's initials on their team's colour, the marker and the entry's lead. */
function Avatar({ location: { group, data } }: { readonly location: Location<Member> }) {
  return (
    <span className="team-avatar" data-team={String(group)}>
      {data?.initials}
    </span>
  );
}

const markerIcon = (location: Location<Member>) => <Avatar location={location} />;

/** A person's entry in the list: their face, name, role and city, and the time where they are. */
const memberItem = ({ location }: ListEntry<Member>) => (
  <span className="team-member">
    <span aria-hidden="true">
      <Avatar location={location} />
    </span>
    <span className="team-member-text">
      <span className="team-member-name">{location.title}</span>
      <span className="team-member-detail">
        {location.data?.role} · {location.data?.city}
      </span>
      <LocalTime timeZone={location.data?.timeZone ?? viewerZone} />
    </span>
  </span>
);

function Team() {
  // Each person, in their team's group.
  const [team, setTeam] = useState<readonly Location<Member>[]>([]);
  useEffect(() => {
    fetch("/examples/data/team.json")
      .then((response) => response.json())
      .then(setTeam);
  }, []);
  return (
    <MaplaceProvider locations={team}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createGoogleAdapter} className="map" markerIcon={markerIcon} />
        <LocationList heading="The team" groupCounts groupFilter search searchLabel="Find someone">
          {memberItem}
        </LocationList>
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("team-react-root") as HTMLElement).render(
  <StrictMode>
    <Team />
  </StrictMode>,
);
```

### The stylesheet every version links

`packages/maplace/examples/styles/team.css`

```css
/* The team example's look, which every version links: page, script, vanilla and React, on either
   map. */
/* Each team's colour, which its people's avatars take: white initials read on each at 5.4:1 or
   more. */
[data-team="Design"] {
  --team: #7b2cbf;
}
[data-team="Engineering"] {
  --team: #1d4ed8;
}
[data-team="Growth"] {
  --team: #b42318;
}
[data-team="Support"] {
  --team: #047857;
}
/* A face: the person's initials on their team's colour, the marker on the map and the lead of
   their entry in the list. */
.team-avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2rem;
  height: 2rem;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--team, #111);
  color: #fff;
  font:
    700 0.75rem / 1 system-ui,
    sans-serif;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.35);
}
/* A marker pointed at, or picked: ringed, the picked one in red. The marks are on the avatar, or on
   the node around it when the map wraps it. */
.team-avatar[data-hovered],
[data-hovered] > .team-avatar {
  outline: 2px solid #111;
}
.team-avatar[data-selected],
[data-selected] > .team-avatar {
  outline: 3px solid #e4322b;
}
/* A person in the list: their face, then their name, role and city, and the time where they are. */
.team-member {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}
.team-member-text {
  display: grid;
  gap: 0.125rem;
}
.team-member-name {
  font-weight: 600;
}
.team-member-detail,
.team-member-time {
  font-size: 0.875em;
}
.team-member-detail {
  color: #55554f;
}
```
