Giter Club home page Giter Club logo

mapbox-layerswitcher's Introduction

Mapbox LayerSwitcher

Grouped layer list control for a Mapbox map.

index

install

npm

npm i mb-layerswitcher --save-dev

cdn

<!-- min -->
<script src="https://unpkg.com/[email protected]/mapbox-layerswitcher.min.js"></script>

<!-- Unminified -->
<script src="https://unpkg.com/[email protected]/mapbox-layerswitcher.js"></script>

Usage

let layers = [
    {
        id: "museums-group",
        name: "museums-group",
        children: [
            {
                id: "museums",
                name: "museums",
            }
        ]
    },
    {
        id: "contours",
        name: "contours"
    },
    {
        id: "mapbox://styles/mapbox/streets-v11",
        name: "streets",
        type: "base"
    },
    {
        id: "mapbox://styles/mapbox/satellite-v9",
        name: "satellite",
        type: "base"
    }
];

let layerswitcher = new MapboxLayerSwitcher({
    layers: layers,
    template: 'tree1',
    activemode: 'mouseover'
});
map.addControl(layerswitcher, "top-right");

Developing

build

npm run build

examples

npm run start & http://localhost:3000

You also need to store an access token in localstorage. Open developer tools, locate the console tab and insert:

localStorage.setItem('accessToken', {your token});

API

MapboxLayerSwitcher constructor options:
  • layers

    ​ We use JSON to configure layer groups and layers. We divide the layers into two types: Basemap and Overlays.

    Basemap

       {
            id: "mapbox://styles/mapbox/streets-v11", // basemap's url
            name: "streets", // The name of the layer displayed on the panel
            type: "base" // The basemap must have this attribute
        }

    Overlays

    {
        id: "museums-group",
        name: "museums-group",
        children: [ // Child node layer group or layer
            {
                id: "museums", 
                name: "museums",
            }
        ]
    }
  • template

    The following three style templates are currently available:

    simple1 simple2 tree1
    simple1 simple2 tree1
  • activemode

    Event to use on the button to collapse or expand the panel. Defaults to "mouseover".

    Type: ("mouseover" | "click"|"none").

mapbox-layerswitcher's People

Contributors

felix0917 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.