GithubHelp home page GithubHelp logo

isabella232 / mapbox-gl-layers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from developmentseed/mapbox-gl-layers

0.0 0.0 0.0 22 KB

Layer toggle control for Mapbox GL JS

Home Page: https://developmentseed.github.io/mapbox-gl-layers/example.html

License: MIT License

CSS 1.17% JavaScript 94.86% HTML 3.98%

mapbox-gl-layers's Introduction

Circle CI

mapbox-gl-layers

Layer toggle for Mapbox GL JS

Install

npm install mapbox-gl-layers

(Note the peer dependency on mapbox-gl!)

Use

CommonJS

var Layers = require('mapbox-gl-layers')

new Layers({
  layers: {
    'ALL PARKS': ['national_park', 'parks'],
    'National Parks': 'national_park',
    'Other Parks': 'parks'
  }
}).addTo(map) // map is the mapbox gl map instance

Standalone script

Add to <head>:

<script src='dist/mapbox-gl-layers.js'></script>
<link href='dist/mapbox-gl-layers.css' rel='stylesheet' />

And then:

<script>
map.on('style.load', function () {
  new MapboxGLLayers({
    layers: {
      'ALL PARKS': ['national_park', 'parks'],
      'National Parks': 'national_park',
      'Other Parks': 'parks'
    }
  }).addTo(map) // map is the mapbox gl map instance
})
</script>

API

Layers

Creates a layer toggle control

Parameters

  • options Object=
    • options.type string= Selection type: multiple to allow independently toggling each layer/group, single to only choose one at a time. (optional, default 'multiple')
    • options.layers Object= An object determining which layers to include. Each key is a display name (what's shown in the UI), and each value is the corresponding layer id in the map style (or an array of layer ids).
    • options.position string= A string indicating position on the map. Options are top-right, top-left, bottom-right, bottom-left. (optional, default 'top-right')
    • options.onChange function= Optional callback called with {name: dispayName, layerIds: [...], active: true|false } for the clicked layer

Examples

(new Layers({ 'National Parks': 'national_park', 'Other Parks': 'parks' }))
.addTo(map)

Contributing

This is an OPEN open source project. Contributions are welcome!

Steps:

  1. Clone the repo and run npm install.
  2. Start test server with npm start, open http://localhost:9966/example.html, and start make changes to index.js and friends.

mapbox-gl-layers's People

Contributors

anandthakker 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.