Code Monkey home page Code Monkey logo

mapbox-gl-inspect's Introduction

Mapbox GL Inspect Build Status

Add an inspect control to Mapbox GL JS to view all features of the vector sources and allows hovering over features to see their properties.

Requires mapbox-gl-js (version 0.29.0 โ€“ 0.31.x).

Mapbox GL Inspect Preview

Usage

mapbox-gl-inspect is a Mapbox GL JS plugin that you can easily add on top of your map. Check index.html for a complete example.

Make sure to include the CSS and JS files.

When using a CDN

<script src='http://mapbox-gl-inspect.lukasmartinelli.ch/dist/mapbox-gl-inspect.min.js'></script>
<link href='http://mapbox-gl-inspect.lukasmartinelli.ch/dist/mapbox-gl-inspect.css' rel='stylesheet' />

When using modules

require('mapbox-gl-inspect/dist/mapbox-gl-inspect.css');
var mapboxgl = require('mapbox-gl');
var MapboxInspect = require('mapbox-gl-inspect');

// Pass an initialized popup to Mapbox GL
map.addControl(new MapboxInspect({
  popup: new mapboxgl.Popup({
    closeButton: false,
    closeOnClick: false
  })
}));

Add the inspector control to your map.

map.addControl(new MapboxInspect());

Switch to the inspection map by default.

map.addControl(new MapboxInspect({
  showInspectMap: true
}));

Switch to the inspection map by default and hide the inspect button to switch back to the normal map. Check examples/inspect-only.html.

map.addControl(new MapboxInspect({
  showInspectMap: true,
  showInspectButton: false
}));

Disable the feature Popup in inspection mode and in map mode. Check examples/no-popup.html.

map.addControl(new MapboxInspect({
  showInspectMapPopup: false,
  showMapPopup: false
}));

You can also control the Popup output. Check examples/custom-popup.html.

map.addControl(new MapboxInspect({
  renderPopup: function(features) {
    return '<h1>' + features.length + '</h1>';
  }
}));

You are able to control the generated colors and background of the inspection style. Check examples/custom-color-1.html and examples/custom-color-2.html.

var colors = ['#FC49A3', '#CC66FF', '#66CCFF', '#66FFCC'];
map.addControl(new MapboxInspect({
  backgroundColor: '#000',
  assignLayerColor: function(layerId, alpha) {
    var randomNumber = parseInt(Math.random() * colors.length);
    return colors[randomNumber];
   }
}));

Develop

Run the linter and watch for changes to rebuild with browserify.

npm install
npm run test
npm run watch

Create a minified standalone build.

npm install
npm run build

mapbox-gl-inspect's People

Contributors

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