# maplibre-gl-style-switcher

> Mapbox GL JS Style Switcher fork for Maplibre GL

Latest version **1.0.18** (published 2024-03-26) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install maplibre-gl-style-switcher
pnpm add maplibre-gl-style-switcher
yarn add maplibre-gl-style-switcher
bun add maplibre-gl-style-switcher
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.18 |
| Published | 2024-03-26 |
| First published | 2024-01-24 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 57.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 90 |
| Author | Eliz Kilic |
| Maintainers | denysthebest |
| Keywords | maplibre, maplibre-gl-js, style-switcher |

## Links

- npm: https://www.npmjs.com/package/maplibre-gl-style-switcher
- Repository: https://github.com/el/style-switcher
- Homepage: https://github.com/el/style-switcher#readme
- Issues: https://github.com/el/style-switcher/issues
- npm.io page: https://npm.io/package/maplibre-gl-style-switcher

## Dependencies (1)

- [maplibre-gl](https://npm.io/package/maplibre-gl.md) ^3.6.2

## Recent versions

- 1.0.18 (latest) — 2024-03-26
- 1.0.19 — 2024-02-21
- 1.0.17 — 2024-01-30
- 1.0.16 — 2024-01-29
- 1.0.15 — 2024-01-26
- 1.0.14 — 2024-01-25
- 1.0.13 — 2024-01-24
- 1.0.12 — 2024-01-24
- 1.0.11 — 2024-01-24

## README

# Mapbox GL JS Style Switcher binding for Maplibre GL JS

Adds a style switcher to `mapbox-gl`

![](https://img.shields.io/bundlephobia/min/mapbox-gl-style-switcher) <a href="https://www.npmjs.com/package/mapbox-gl-style-switcher">![](https://img.shields.io/npm/v/mapbox-gl-style-switcher)</a> ![](https://img.shields.io/npm/types/mapbox-gl-style-switcher) ![](https://img.shields.io/npm/l/mapbox-gl-style-switcher)


## Installation:

```bash
npm i maplibre-gl-style-switcher
```

## Demo:

- [codesandbox](https://codesandbox.io/s/elegant-night-wi9v4)

## Usage:

```ts
import { MapboxStyleSwitcherControl } from "mapbox-gl-style-switcher";
import { Map as MapboxMap } from "mapbox-gl";

import "mapbox-gl-style-switcher/styles.css";

const map = new MapboxMap();
map.addControl(new MapboxStyleSwitcherControl());
```

## Options:
If you want to supply your own list of styles, pass them in the constructor.

```ts
import { MapboxStyleDefinition, MapboxStyleSwitcherControl } from "mapbox-gl-style-switcher";

const styles: MapboxStyleDefinition[] = [
    {
        title: "Dark",
        uri:"mapbox://styles/mapbox/dark-v9"
    },
    {
        title: "Light",
        uri:"mapbox://styles/mapbox/light-v9"
    }
];

// Pass options (optional)
const options: MapboxStyleSwitcherOptions = {
    defaultStyle: "Dark",
    eventListeners: {
 // return true if you want to stop execution
 //           onOpen: (event: MouseEvent) => boolean;
 //           onSelect: (event: MouseEvent) => boolean;
 //           onChange: (event: MouseEvent, style: string) => boolean;
    }
};

map.addControl(new MapboxStyleSwitcherControl(styles, options));
```

If you want to specify a default style, pass them in the constructor as second argument.

```ts
map.addControl(new MapboxStyleSwitcherControl(styles, 'Dark'));
```

## Screenshots

![Closed](assets/closed.png)

![Open](assets/open.png)

---
_Source: https://npm.io/package/maplibre-gl-style-switcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
