---
title: getSpaces
slug: viewer-2d/methods/getSpaces
docTags: 
createdAt: 2024-02-21T14:33:53.989Z
---

Returns the list of spaces.

:::hint{type="info"}
By default returns spaces for the active building if applicable otherwise returns all spaces.
:::

## Example

::codepen{url="https://codepen.io/Catenda/embed/JjQMGyV"}

## Usage

```javascript
const options = {
  all: true
};

const spaces = viewer2d.getSpaces(options);
```

## Parameters

### options

Options for getting spaces.

| **Type** | **Required** |
| -------- | ------------ |
| Object   | No           |

**Properties**

| **Name**     | **Type** | **Required** | **Description**                           |
| ------------ | -------- | ------------ | ----------------------------------------- |
| `all`        | Boolean  | No           | Get spaces from all models                |
| `buildingId` | String   | No           | Get spaces for a specific building        |
| `storeyId`   | String   | No           | Get spaces for a specific storey          |
| `visible`    | Boolean  | No           | Don't include spaces that are not visible |

## Return Value

List of spaces.

| **Type**      |
| ------------- |
| Array\[Space] |

**Space**

| **Name**      | **Type** | **Description**                     |
| ------------- | -------- | ----------------------------------- |
| `boundingBox` | Object   | Bounding box of the space           |
| `buildingId`  | String   | Id of the building space belongs to |
| `guid`        | String   | Guid of the space                   |
| `id`          | String   | Id of the space                     |
| `longName`    | String   | Long name of the space              |
| `name`        | String   | Short name of the space             |
| `modelId`     | String   | Id of the model space belongs to    |
| `storey`      | String   | Name of the storey space belongs to |
| `storeyId`    | String   | Id of the storey space belongs to   |

**boundingBox**

| **Name** | **Type** | **Description**                  |
| -------- | -------- | -------------------------------- |
| `height` | Number   | Height of the bounding box       |
| `width`  | Number   | Width of the bounding box        |
| `x`      | Number   | X coordinate of the bounding box |
| `y`      | Number   | Y coordinate of the bounding box |

### Example

```javascript
[
  {
    boundingBox: {
      height: 10,
      width: 5,
      x: 0,
      y: 0
    },
    buildingId: "0.rp9o7e4sjl",
    guid: "3gw3QKtyuBThLITx3QSRY2",
    id: "2772343120",
    longName: "CENTRAL WAITING",
    modelId: "0.vo5kl3grto",
    name: "1E16",
    storey: "First Floor",
    storeyId: "2776467125"
  }
];
```

