---
title: "SplatAnnotation | Geosplats sdk"
description: "Documentation for MapTiler GeoSplats SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Class SplatAnnotation

An annotation on a SplatModel, as returned by `SplatModel.addAnnotation()`, and included in the SplatModel's "annotation:click", "annotation:active" and "annotation:inactive" events. Its position, label, icon, color, popup and custom data can be changed at any time, including while the popup is open - e.g. from within those event listeners. It can also be hidden, removed, and have its popup opened and closed from code:

#### Example[](#example)

```typescript
splatModel.on("annotation:click", ({ annotation }) => {
  annotation.setColor("#e69439"); // mark as visited
});
splatModel.on("annotation:active", ({ annotation }) => {
  annotation.setPopup(`<p>Open until ${closingTime()}</p>`);
});
splatModel.on("annotation:inactive", ({ annotation }) => {
  annotation.setIcon("✔️");
});
document.querySelector("#show-pool")!.addEventListener("click", () => {
  pool.openPopup();
});
```

##### Index

### Methods[](#methods)

[closePopup](#closepopup) [getColor](#getcolor) [getData](#getdata) [getIcon](#geticon) [getLabel](#getlabel) [getPopup](#getpopup) [getPosition](#getposition) [isActive](#isactive) [isRemoved](#isremoved) [isVisible](#isvisible) [openPopup](#openpopup) [remove](#remove) [setColor](#setcolor) [setData](#setdata) [setIcon](#seticon) [setLabel](#setlabel) [setPopup](#setpopup) [setPosition](#setposition) [setVisible](#setvisible)

## Methods[](#methods-1)

### closePopup[](#closepopup)

-   closePopup(): void[](#closepopup-1)
    
    Closes the annotation's popup, if it is open.
    
    #### Returns void
    

### getColor[](#getcolor)

-   getColor(): [Color](https://docs.maptiler.com/geosplats-sdk/api/types/Color/) | undefined[](#getcolor-1)
    
    Returns the annotation body's color, if one was set.
    
    #### Returns [Color](https://docs.maptiler.com/geosplats-sdk/api/types/Color/) | undefined
    

### getData[](#getdata)

-   getData(): unknown[](#getdata-1)
    
    Returns the custom data attached to the annotation (see `AnnotationOptions.data`), if any. It is returned as is - not copied - so modifying it in place modifies the annotation's data.
    
    #### Returns unknown
    
    #### Example[](#example-1)
    
    ```typescript
    splatModel.on("annotation:click", ({ annotation }) => {
      const { rowId } = annotation.getData() as { rowId: number };
    });
    ```
    

### getIcon[](#geticon)

-   getIcon(): string | undefined[](#geticon-1)
    
    Returns the emoji shown in the annotation, if any.
    
    #### Returns string | undefined
    

### getLabel[](#getlabel)

-   getLabel(): string[](#getlabel-1)
    
    Returns the short string displayed in the annotation body (empty if none).
    
    #### Returns string
    

### getPopup[](#getpopup)

-   getPopup(): string | undefined[](#getpopup-1)
    
    Returns the HTML string of the annotation's popup, if it has one.
    
    #### Returns string | undefined
    

### getPosition[](#getposition)

-   getPosition(): [AnnotationPosition](https://docs.maptiler.com/geosplats-sdk/api/types/AnnotationPosition/)[](#getposition-1)
    
    Returns the annotation's position, in the form it was given in: relative to the SplatModel, or geographic (with its longitude as `lng`, even if it was given as `lon`). See [AnnotationPosition](https://docs.maptiler.com/geosplats-sdk/api/types/AnnotationPosition/).
    
    #### Returns [AnnotationPosition](https://docs.maptiler.com/geosplats-sdk/api/types/AnnotationPosition/)
    

### isActive[](#isactive)

-   isActive(): boolean[](#isactive-1)
    
    Returns whether the annotation is currently active, i.e. its popup is open.
    
    #### Returns boolean
    

### isRemoved[](#isremoved)

-   isRemoved(): boolean[](#isremoved-1)
    
    Returns whether the annotation was removed, by `remove()` or along with its SplatModel.
    
    #### Returns boolean
    

### isVisible[](#isvisible)

-   isVisible(): boolean[](#isvisible-1)
    
    Returns whether the annotation is visible, i.e. not hidden with `setVisible(false)`. This is unaffected by whether it is currently on screen.
    
    #### Returns boolean
    

### openPopup[](#openpopup)

-   openPopup(): void[](#openpopup-1)
    
    Opens the annotation's popup, as if the annotation was clicked, but without firing "annotation:click". Like a click, it closes any other open popup on the map first. Does nothing if the annotation has no popup, is already active, hidden or removed. The popup is only shown while the annotation is on screen.
    
    #### Returns void
    

### remove[](#remove)

-   remove(): void[](#remove-1)
    
    Removes the annotation for good, closing its popup first if it is open. Afterwards, it is no longer shown, nor fires events, and this handle has no further effect. Does nothing if the annotation was already removed, including along with its SplatModel.
    
    #### Returns void
    

### setColor[](#setcolor)

-   setColor(color?: [Color](https://docs.maptiler.com/geosplats-sdk/api/types/Color/)): void[](#setcolor-1)
    
    Sets the annotation body's color, e.g. to mark annotations the user has already seen. `undefined` restores the default color. An unsupported color string is ignored (with a console warning), keeping the current color.
    
    #### Parameters
    
    -   `Optional`color: [Color](https://docs.maptiler.com/geosplats-sdk/api/types/Color/)
    
    #### Returns void
    

### setData[](#setdata)

-   setData(data?: unknown): void[](#setdata-1)
    
    Replaces the custom data attached to the annotation, which may be anything.
    
    #### Parameters
    
    -   `Optional`data: unknown
    
    #### Returns void
    

### setIcon[](#seticon)

-   setIcon(icon?: string): void[](#seticon-1)
    
    Sets the single emoji shown by itself while the annotation is collapsed (active), and prepended to the label text while it's expanded. `undefined` or an empty string shows no icon.
    
    #### Parameters
    
    -   `Optional`icon: string
    
    #### Returns void
    

### setLabel[](#setlabel)

-   setLabel(label?: string): void[](#setlabel-1)
    
    Sets the short string displayed in the annotation body; the annotation resizes to fit it. `undefined` or an empty string shows no label.
    
    #### Parameters
    
    -   `Optional`label: string
    
    #### Returns void
    

### setPopup[](#setpopup)

-   setPopup(html?: string): void[](#setpopup-1)
    
    Sets the HTML string of the popup that pops up when one clicks the annotation. If the popup is currently open, its content is replaced in place. `undefined` or an empty string removes the popup, closing it if it's open, so clicking the annotation no longer opens one.
    
    #### Parameters
    
    -   `Optional`html: string
    
    #### Returns void
    

### setPosition[](#setposition)

-   setPosition(pos: [AnnotationPosition](https://docs.maptiler.com/geosplats-sdk/api/types/AnnotationPosition/)): void[](#setposition-1)
    
    Moves the annotation, to a position relative to the SplatModel or a geographic one (see [AnnotationPosition](https://docs.maptiler.com/geosplats-sdk/api/types/AnnotationPosition/)) - either way, regardless of which kind it had before. An open popup moves along with it.
    
    #### Parameters
    
    -   pos: [AnnotationPosition](https://docs.maptiler.com/geosplats-sdk/api/types/AnnotationPosition/)
    
    #### Returns void
    
    #### Throws[](#throws)
    
    Error for an invalid position, like `SplatModel.addAnnotation()`.
    

### setVisible[](#setvisible)

-   setVisible(visible: boolean): void[](#setvisible-1)
    
    Shows or hides the annotation. Hiding it closes its popup if it is open, and a hidden annotation can't be clicked, nor its popup opened. Unlike `remove()`, it can be shown again at any time.
    
    #### Parameters
    
    -   visible: boolean
    
    #### Returns void
