• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created almost 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Inspection plugin for Mapbox GL JS

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='https://github.com/lukasmartinelli/mapbox-gl-inspect/releases/download/v1.3.1/mapbox-gl-inspect.js'></script>
<link href='https://github.com/lukasmartinelli/mapbox-gl-inspect/releases/download/v1.3.1/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 Inspect Control

Add the inspect control to your map.

map.addControl(new MapboxInspect());

Show Inspection Map

Switch to the inspection map by default.

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

Show only Inspection Mode

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 Popup

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

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

Custom Popup Function

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

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

Custom Color Function

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];
   }
}));

Show just Popup but no Inspect Style

You can also hide the inspect button and enable the popup on the map if just want the popup hovering feature in your normal map but no inspect style. Check examples/no-inspect-style.html.

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

Show Popup only for certain Features

You can pass a queryParameters object structured like the parameters object documented for map.queryRenderedFeatures. This let's you show the inspect popup for only certain layers. Check examples/query-params.html.

map.addControl(new MapboxInspect({
  queryParameters: {
    layers: ['composite_road_line']
  }
}));

You can also use this feature to do custom layer filtering.

map.addControl(new MapboxInspect({
  queryParameters: {
    filter: ['>', 'height', 10]
  }
}));

Less Fidly Popup

If inspecting features is too fiddly for thin lines you can optionally set a custom pixel buffer around the pointer when querying for features to make inspection a bit more forgiving. Check examples/less-fidly.html.

map.addControl(new MapboxInspect({
  selectThreshold: 50
});

Show Popup only on Click not on Hovering

Do not show the inspect popup when hovering over the map but only when clicking on the map. Check examples/popup-on-click.html.

map.addControl(new MapboxInspect({
  showMapPopup: true,
  showMapPopupOnHover: false,
  showInspectMapPopupOnHover: false
});

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

More Repositories

1

pgfutter

Import CSV and JSON into PostgreSQL the easy way
Go
1,311
star
2

py14

Python to C++ 14 transpiler
C++
573
star
3

pipecat

Connect UNIX pipes and message queues
Go
435
star
4

pgclimb

Export data from PostgreSQL into different data formats
Go
386
star
5

nigit

Web server that wraps around programs and shell scripts and exposes them as API
Go
383
star
6

redis-pipe

Treat Redis Lists like Unix Pipes
Go
283
star
7

postgis-editor

An accessible PostGIS query editor and visualizer.
JavaScript
192
star
8

naturalearthtiles

Natural Earth vector tiles (MVT) and raster tiles free and ready to use.
PLpgSQL
89
star
9

hwk

A Haskell based awk and sed alternative
Haskell
67
star
10

osm-noise-pollution

Approximate global noise pollution with OSM data and very simple noise model
Shell
66
star
11

php-dos-attack

Exploit json_decode vulnerability of PHP
PHP
35
star
12

osm-activity

Show global OpenStreetMap activity on a map
JavaScript
30
star
13

swissdem

Digital Elevation Model for Switzerland from SRTM (1 arc second / 25m) as download
Shell
17
star
14

osm-lakelines

Calculate nice centered linestrings for labelling OpenStreetMap lakes
Shell
15
star
15

px-to-csv

Convert PC-Axis files to CSV
JavaScript
14
star
16

mbtoolbox

MBTiles tools for optimizing and verifying MBTiles files
Python
13
star
17

push-it

Plays an encouraging sound when you do a git push
Shell
13
star
18

ghrr

Create realtime apps on top of GitHub
JavaScript
12
star
19

sharpen

Solve algorithmic Python challenges to sharpen the tools.
Python
11
star
20

detectivegit

Detective git takes a look at your repo and shows the hotspots and possible bugs.
JavaScript
9
star
21

osm-qa-filter

Extract GeoJSON features from OSM QA tiles
JavaScript
9
star
22

osm-simple-features

Defines an opinionated mapping from OSM to simple GeoJSON features with multiple layers and defined schemas.
JavaScript
7
star
23

swissnames

Curated extracts from the free swissNAMES3D data set from swisstopo.
Shell
5
star
24

delptr

Informs the world about people who still use naked pointers in C++
JavaScript
5
star
25

location-history-to-geojson

Turn your Google Location History into a GeoJSON feature collection
JavaScript
3
star
26

lukasmartinelli.github.io

Personal blog and portfolio.
HTML
2
star
27

battle-of-britain-map

A Mapbox GL map showcasing the air battle of Britain
CSS
2
star
28

biketour

Tracking my bike tour from Switzerland to Greece
HTML
1
star