JSPM

@watergis/mapbox-gl-style-switcher

1.0.11
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q43043F
  • License GPL-3.0

Mapbox GL JS Style Switcher

Package Exports

  • @watergis/mapbox-gl-style-switcher

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@watergis/mapbox-gl-style-switcher) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Mapbox GL JS Style Switcher

Adds a style switcher to mapbox-gl

Installation:

npm i @watergis/mapbox-gl-style-switcher --save

Demo:

Usage:

import { MapboxStyleSwitcherControl } from "@watergis/mapbox-gl-style-switcher";
import { Map as MapboxMap } from "mapbox-gl";

import "@watergis/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 "@watergis/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));

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

Development

# install npm packages
npm i
# build source code
npm run build
# launch application with server
npm run dev