Vizzuality / layer-manager

A library to get a layer depending on provider and layer spec
https://layer-manager-docs.vercel.app
MIT License
18 stars 12 forks source link

Run tests

Layer Manager

This library will help you to manage the addition and removal of layers. It also provides methods to set opacity, visibility and zIndex.

We currently only supports Mapbox spec. Leaflet or Google Maps Plugin are not supported yet.

Docs

Quick start with MapboxGL

import mapboxgl from 'mapbox-gl';
import MapboxGLPlugin from '@vizzuality/layer-manager-plugin-mapboxgl';
import CartoProvider from '@vizzuality/layer-manager-provider-carto';
import LayerManager from '@vizzuality/layer-manager';

mapboxgl.accessToken = '<your access token here>';

const map = new mapboxgl.Map({
    container: 'map', // container ID
    style: 'mapbox://styles/mapbox/streets-v11', // style URL
    center: [-74.5, 40], // starting position [lng, lat]
    zoom: 9 // starting zoom
});

const plugin = new MapboxGLPlugin(map, pluginOptions); // required
const layerManager = new LayerManager(plugin);

// Optionally you can add additional providers
const provider = new CartoProvider();
LayerManager.registerProvider(provider); // optional

layerManager.add(layerSpec); // see docs/LAYER-SPEC.md
layerManager.remove(1);