GithubHelp home page GithubHelp logo

lukasmartinelli / mapbox-gl-inspect Goto Github PK

View Code? Open in Web Editor NEW
142.0 12.0 22.0 315 KB

Inspection plugin for Mapbox GL JS

Home Page: http://mapbox-gl-inspect.lukasmartinelli.ch/

License: BSD 3-Clause "New" or "Revised" License

HTML 6.58% JavaScript 93.42%

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='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

mapbox-gl-inspect's People

Contributors

aaronlidman avatar gregwolanski avatar lukasmartinelli avatar mabhub avatar orangemug avatar tcql avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapbox-gl-inspect's Issues

Mablibre attempt help

Hi lukasmartinelli,

I am trying to make a version of mapbox-gl-inspect that works with the new maplibre-gl-js fork.

For my first attempt I took the already built mapbox-gl-inspect.min.js and did a string replace on all mapbox text (except classes). This was successful and that version is here https://raw.githubusercontent.com/acalcutt/maplibre-gl-inspect/master/dist/maplibre-gl-inspect.min.js

However, I noticed the version I had modified was a bit out of date so I wanted to make a newer version. I made this fork here ( https://raw.githubusercontent.com/acalcutt/maplibre-gl-inspect/ ). It is mostly working except I can't seem to get the popup to work.

I see the following error, which seems to be trying to append html into the popup, which seems to be null...I'm guessing this is because the popup does not exists.

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
    at o.setDOMContent (popup.js:426)
    at u._onMousemove (maplibre-gl-inspect.min.js:177)
    at r.Ct.fire (evented.js:119)
    at Fo.mousemove (map_event.js:118)
    at gr.handleEvent (handler_manager.js:325)

However as far as i can tell I have changed what would be needed to make a popup in maplibere ( window.maplibregl.Popup ).

I'm not seeing any errors and I was wondering if you have any ideas why the popup piece is not working (everything else seemed to be working as far as I can tell)

This is the version I compiled from the source at https://raw.githubusercontent.com/acalcutt/maplibre-gl-inspect that is not working
maplibre-gl-inspect_broken.zip

Wondering if you might have any tips for what the issue may be... its mostly working so maybe I changed something obvious.

Edit: the one I modified by hand can be seen working here ( https://wifidb.net/wifidb/opt/map.php?func=wifidbmap&labeled=0&sig_label=none ).

OSM QA TILES - minzoom

I don't know it is a problem or not ...

Mapbox QA tiles is very special, because minzoom: 12 and maxzoom: 12
see more:

so I downloaded and tested via tileserver-gl ( which is containing the mapbox-gl-inspect )

my simple test script :

mkdir qatiles
cd ./qatiles
wget https://s3.amazonaws.com/mapbox/osm-qa-tiles/latest.country/iceland.mbtiles.gz
gunzip iceland.mbtiles.gz
docker run -it --rm -v $(pwd):/data -p 8080:80 klokantech/tileserver-gl

The over zooming is fine:
image

but no warning when z < minzoom: 12 ,

image

so my theoretical questions:

  • it is possible to show minzoom: maxzoom: info
  • detect if z < minzoom:

Bonus: A picture of a cute animal: idea

image
foto : Jan Truter on Flickr https://flic.kr/p/iBaEkQ

Plugin recognizes DOM node type only as 'undefined.'

While using the plugin after adding it to a layer of point geometry type, we observed that the user would click on a point, but the hover would not appear. The plugin checks the type of the object it attempts to add to as a parent. If it's of type 'string', then it adds the hover as HTML. Otherwise as a DOM content (near line 216 of MaboxInspect.js).

Only after allowing for a type of 'undefined' could the popup actually be added to the data structure by invoking this._popup.setHTML(). So the new proposed code would be

if (type === 'string' || type === 'undefined') { this._popup.setHTML(this.options.renderPopup(features)); } else { this._popup.setDOMContent(this.options.renderPopup(features)); }

v1.9 is the HIGHEST COMPATIBLE mapbox-gl version. Please update the MapboxInspect to work with latest mapbox v2.6!

When I change mapbox-gl version from v1.9 to v2.6, I got this error in MapboxInspect.js:


  <link href="https://api.mapbox.com/mapbox-gl-js/v2.6.0/mapbox-gl.css" rel="stylesheet">
  <script src="https://api.mapbox.com/mapbox-gl-js/v2.6.0/mapbox-gl.js"></script>
  <!-- <link href="https://api.mapbox.com/mapbox-gl-js/v1.9.0/mapbox-gl.css" rel="stylesheet"> -->
  <!-- <script src="https://api.mapbox.com/mapbox-gl-js/v1.9.0/mapbox-gl.js"></script> -->

MapboxInspect.js:135 Uncaught TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at MapboxInspect._onSourceChange (MapboxInspect.js:135)
    at Map.fire (evented.js:129)
    at Map.<anonymous> (map.js:548)
    at Map.fire (evented.js:129)
    at je.fire (evented.js:144)
    at vector.fire (evented.js:144)
    at je.update (style.js:553)
    at Map._render (map.js:2865)
    at map.js:3217

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.