Skip to content

alantgeo/style-switcher

 
 

Repository files navigation

Mapbox GL JS Style Switcher

Adds a style switcher to mapbox-gl

Installation:

npm i mapbox-gl-style-switcher --save

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"
    }
];

map.addControl(new MapboxStyleSwitcherControl(styles));

Screenshots

Closed

Open

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 57.9%
  • CSS 42.1%