# Search this area

A switch above the list: every place, or only those in view as the map moves.

## How it works

The list on the map, top left, has a switch above it: every place, or only those in view as the map moves.

- **HTML**: `list-scope="viewport"` on `<maplace-map>`, beside `list` and `list-position`, with `area-only-label`, `show-all-label` and `empty-area-label` for its wording ([Map attributes](/element/#map-attributes)).
- **Script** and **Bundler**: `list: { scope: "viewport", position: "top-left" }` in the map's options, with `areaOnlyLabel`, `showAllLabel` and `emptyAreaLabel` ([List view options](/store/#list-view-options); `position`, [on Google](/google/#creategooglemap), [on MapLibre](/maplibre/#createmaplibremap)).
- **React**: `<LocationList scope="viewport" position="top-left" />` inside the `<MaplaceMap>` ([`<LocationList>`](/react/#locationlist)).
- **Its corner**: any of the four, `top-left` here. Left of the map is where a list has the most room on Google, which stacks its fullscreen button, camera control and Pegman on the right ([On-map controls](/google/#on-map-controls)). Without a `position`, the list goes top right.

## Code

### HTML on MapLibre

`packages/maplace/examples/this-area/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- A list on the map that follows it: its switch lists "All", or in "This area" what is in view as the map moves. -->
<maplace-map id="this-area-maplibre-map" list list-position="top-left" list-scope="viewport">
  <maplace-location location-id="lisbon" lat="38.7223" lng="-9.1393" title="Lisbon"></maplace-location>
  <maplace-location location-id="madrid" lat="40.4168" lng="-3.7038" title="Madrid"></maplace-location>
  <maplace-location location-id="paris" lat="48.8566" lng="2.3522" title="Paris"></maplace-location>
  <maplace-location location-id="brussels" lat="50.8503" lng="4.3517" title="Brussels"></maplace-location>
  <maplace-location location-id="amsterdam" lat="52.3676" lng="4.9041" title="Amsterdam"></maplace-location>
  <maplace-location location-id="berlin" lat="52.52" lng="13.405" title="Berlin"></maplace-location>
  <maplace-location location-id="copenhagen" lat="55.6761" lng="12.5683" title="Copenhagen"></maplace-location>
  <maplace-location location-id="vienna" lat="48.2082" lng="16.3738" title="Vienna"></maplace-location>
  <maplace-location location-id="prague" lat="50.0755" lng="14.4378" title="Prague"></maplace-location>
  <maplace-location location-id="warsaw" lat="52.2297" lng="21.0122" title="Warsaw"></maplace-location>
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome"></maplace-location>
  <maplace-location location-id="athens" lat="37.9838" lng="23.7275" title="Athens"></maplace-location>
</maplace-map>
```

### HTML on Google

`packages/maplace/examples/this-area/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- A list on the map that follows it: its switch lists "All", or in "This area" what is in view as the map moves. -->
<maplace-map id="this-area-map" api-key="YOUR_KEY" list list-position="top-left" list-scope="viewport">
  <maplace-location location-id="lisbon" lat="38.7223" lng="-9.1393" title="Lisbon"></maplace-location>
  <maplace-location location-id="madrid" lat="40.4168" lng="-3.7038" title="Madrid"></maplace-location>
  <maplace-location location-id="paris" lat="48.8566" lng="2.3522" title="Paris"></maplace-location>
  <maplace-location location-id="brussels" lat="50.8503" lng="4.3517" title="Brussels"></maplace-location>
  <maplace-location location-id="amsterdam" lat="52.3676" lng="4.9041" title="Amsterdam"></maplace-location>
  <maplace-location location-id="berlin" lat="52.52" lng="13.405" title="Berlin"></maplace-location>
  <maplace-location location-id="copenhagen" lat="55.6761" lng="12.5683" title="Copenhagen"></maplace-location>
  <maplace-location location-id="vienna" lat="48.2082" lng="16.3738" title="Vienna"></maplace-location>
  <maplace-location location-id="prague" lat="50.0755" lng="14.4378" title="Prague"></maplace-location>
  <maplace-location location-id="warsaw" lat="52.2297" lng="21.0122" title="Warsaw"></maplace-location>
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome"></maplace-location>
  <maplace-location location-id="athens" lat="37.9838" lng="23.7275" title="Athens"></maplace-location>
</maplace-map>
```

### Script on MapLibre

`packages/maplace/examples/this-area/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 mounts on, and the map made with Maplace. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  #this-area-maplibre-script-map { height: 24rem; }
</style>
<div id="this-area-maplibre-script-map"></div>
<script type="module">
  Maplace.createMapLibreMap("#this-area-maplibre-script-map", {
    locations: [
      { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
      { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
      { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
      { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
      { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
      { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
      { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
      { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
      { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
      { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
      { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
      { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
    ],
    list: { scope: "viewport", position: "top-left" },
  });
</script>
```

### Script on Google

`packages/maplace/examples/this-area/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script, what the map mounts on, and the map made with Maplace, which adds Maps JS with your key. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  #this-area-script-map { height: 24rem; }
</style>
<div id="this-area-script-map"></div>
<script type="module">
  Maplace.createGoogleMap("#this-area-script-map", {
    apiKey: "YOUR_KEY",
    locations: [
      { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
      { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
      { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
      { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
      { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
      { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
      { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
      { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
      { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
      { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
      { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
      { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
    ],
    list: { scope: "viewport", position: "top-left" },
  });
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/this-area/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. -->
<style>
  #this-area-maplibre-vanilla-map { height: 24rem; }
</style>
<div id="this-area-maplibre-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/this-area/maplibre/vanilla.ts`

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

createMapLibreMap("#this-area-maplibre-vanilla-map", {
  locations: [
    { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
    { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
    { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
    { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
    { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
    { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
    { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
    { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
    { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
    { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
    { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
    { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
  ],
  // On the map, top-left: a list switched between "All" and "This area", what is in view.
  list: { scope: "viewport", position: "top-left" },
});
```

### Bundler on Google

`packages/maplace/examples/this-area/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>
<style>
  #this-area-vanilla-map { height: 24rem; }
</style>
<div id="this-area-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/this-area/vanilla.ts`

```ts
import { createGoogleMap } from "@maplacejs/maplace/google";

createGoogleMap("#this-area-vanilla-map", {
  locations: [
    { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
    { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
    { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
    { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
    { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
    { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
    { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
    { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
    { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
    { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
    { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
    { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
  ],
  // On the map, top-left: a list switched between "All" and "This area", what is in view.
  list: { scope: "viewport", position: "top-left" },
});
```

### React on MapLibre

`packages/maplace/examples/this-area/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. -->
<style>
  #this-area-maplibre-react-root .map { height: 24rem; }
</style>
<div id="this-area-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/this-area/maplibre/react.tsx`

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

const capitals: Location[] = [
  { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
  { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
  { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
  { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
  { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
  { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
  { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
  { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
  { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
  { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
  { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
  { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
];

function ThisArea() {
  return (
    <MaplaceProvider locations={capitals}>
      <MaplaceMap createAdapter={createMapLibreAdapter} className="map">
        {/* A list switched between "All" and "This area", what is in view as the map moves. */}
        <LocationList scope="viewport" position="top-left" />
      </MaplaceMap>
    </MaplaceProvider>
  );
}

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

### React on Google

`packages/maplace/examples/this-area/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>
<style>
  #this-area-react-root .map { height: 24rem; }
</style>
<div id="this-area-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/this-area/react.tsx`

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

const capitals: Location[] = [
  { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
  { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
  { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
  { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
  { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
  { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
  { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
  { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
  { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
  { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
  { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
  { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
];

function ThisArea() {
  return (
    <MaplaceProvider locations={capitals}>
      <MaplaceMap createAdapter={createGoogleAdapter} className="map">
        {/* A list switched between "All" and "This area", what is in view as the map moves. */}
        <LocationList scope="viewport" position="top-left" />
      </MaplaceMap>
    </MaplaceProvider>
  );
}

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