1.0.18 • Published 2 months ago

maplibre-gl-style-switcher v1.0.18

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
2 months ago

Mapbox GL JS Style Switcher binding for Maplibre GL JS

Adds a style switcher to mapbox-gl

npm.io npm.io npm.io npm.io

Installation:

npm i maplibre-gl-style-switcher

Demo:

Usage:

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.

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.

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

Screenshots

Closed

Open

1.0.18

2 months ago

1.0.19

3 months ago

1.0.17

4 months ago

1.0.16

4 months ago

1.0.15

4 months ago

1.0.14

4 months ago

1.0.13

4 months ago

1.0.12

4 months ago

1.0.11

4 months ago