Skip to content

qazsato/maplibre-gl-layer

Repository files navigation

maplibre-gl-layer

A layer control for MapLibre GL JS.

maplibre-gl-layer

Installation

npm install maplibre-gl-layer

Usage

import { Map } from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";
import { LayerControl } from "maplibre-gl-layer";
import 'maplibre-gl-layer/style.css'

const map = new Map({ /* YOUR_MAP_OPTIONS */ });

/**
 * Parameters for LayerControl
 * {
 *   layers: Array<{
 *     name: string;
 *     style: string | StyleSpecification;
 *     checked?: boolean;
 *   }>;
 * }
 */
const layerControl = new LayerControl({
  layers: [
    {
      name: 'STYLE 1',
      style: YOUR_AWESOME_STYLE
    },
    {
      name: 'STYLE 2',
      style: YOUR_AWESOME_STYLE
    }
  ]
})
layerControl.on('layerchange', (layer) => {
  console.log('Layer changed to:', layer.name)
})
map.addControl(layerControl)

License

This project is licensed under the terms of the MIT license.

About

A layer control for MapLibre GL JS.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors