Add Mapbox GL Inspect plugin
This commit is contained in:
1 parent
d4ddbec45d
commit
b2dcf97d9a
2 files changed
+41
No files matched your search
@@ -0,0 +1,40 @@
|
||||
.mapbox-gl-inspect_popup {
|
||||
color: #333;
|
||||
display: table;
|
||||
}
|
||||
|
||||
.mapbox-gl-inspect_feature:not(:last-child) {
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.mapbox-gl-inspect_layer:before {
|
||||
content: '#';
|
||||
}
|
||||
|
||||
.mapbox-gl-inspect_layer {
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.mapbox-gl-inspect_property {
|
||||
display: table-row;
|
||||
}
|
||||
|
||||
.mapbox-gl-inspect_property-value {
|
||||
display: table-cell;
|
||||
|
||||
}
|
||||
|
||||
.mapbox-gl-inspect_property-name {
|
||||
display: table-cell;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
.mapboxgl-ctrl-inspect {
|
||||
background-image: url('data:image/svg+xml;charset=utf8,<svg%20xmlns="http://www.w3.org/2000/svg"%20fill="#333333%22%20preserveAspectRatio=%22xMidYMid%20meet%22%20viewBox=%22-10%20-10%2060%2060%22%3E%3Cg%3E%3Cpath%20d=%22m15%2021.6q0-2%201.5-3.5t3.5-1.5%203.5%201.5%201.5%203.5-1.5%203.6-3.5%201.4-3.5-1.4-1.5-3.6z%20m18.4%2011.1l-6.4-6.5q1.4-2.1%201.4-4.6%200-3.4-2.5-5.8t-5.9-2.4-5.9%202.4-2.5%205.8%202.5%205.9%205.9%202.5q2.4%200%204.6-1.4l7.4%207.4q-0.9%200.6-2%200.6h-20q-1.3%200-2.3-0.9t-1.1-2.3l0.1-26.8q0-1.3%201-2.3t2.3-0.9h13.4l10%2010v19.3z%22%3E%3C/path%3E%3C/g%3E%3C/svg%3E');
|
||||
}
|
||||
|
||||
.mapboxgl-ctrl-map {
|
||||
background-image: url('data:image/svg+xml;charset=utf8,<svg%20xmlns="http://www.w3.org/2000/svg"%20fill="#333333%22%20viewBox=%22-10%20-10%2060%2060%22%20preserveAspectRatio=%22xMidYMid%20meet%22%3E%3Cg%3E%3Cpath%20d=%22m25%2031.640000000000004v-19.766666666666673l-10-3.511666666666663v19.766666666666666z%20m9.140000000000008-26.640000000000004q0.8599999999999923%200%200.8599999999999923%200.8600000000000003v25.156666666666666q0%200.625-0.625%200.783333333333335l-9.375%203.1999999999999993-10-3.5133333333333354-8.906666666666668%203.4383333333333326-0.2333333333333334%200.07833333333333314q-0.8616666666666664%200-0.8616666666666664-0.8599999999999994v-25.156666666666663q0-0.625%200.6233333333333331-0.7833333333333332l9.378333333333334-3.198333333333334%2010%203.5133333333333336%208.905000000000001-3.4383333333333344z%22%3E%3C/path%3E%3C/g%3E%3C/svg%3E');
|
||||
}
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.MapboxInspect=t()}}(function(){var t;return function t(e,n,r){function o(i,s){if(!n[i]){if(!e[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(a)return a(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[i]={exports:{}};e[i][0].call(l.exports,function(t){var n=e[i][1][t];return o(n?n:t)},l,l.exports,t,e,n,r)}return n[i].exports}for(var a="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(t,e,n){var r=t("./lib/MapboxInspect");e.exports=r},{"./lib/MapboxInspect":3}],2:[function(t,e,n){function r(t,e){var n=document.createElement("div");return n.className="mapboxgl-ctrl mapboxgl-ctrl-group",n.appendChild(t),e||(n.style.display="none"),n}function o(){var t=document.createElement("button");return t.className="mapboxgl-ctrl-icon mapboxgl-ctrl-inspect",t.type="button",t["aria-label"]="Inspect",t}function a(t){t=Object.assign({show:!0,onToggle:function(){}},t),this._btn=o(),this._btn.onclick=t.onToggle,this.elem=r(this._btn,t.show)}a.prototype.setInspectIcon=function(){this._btn.className="mapboxgl-ctrl-icon mapboxgl-ctrl-inspect"},a.prototype.setMapIcon=function(){this._btn.className="mapboxgl-ctrl-icon mapboxgl-ctrl-map"},e.exports=a},{}],3:[function(t,e,n){function r(t){return t.metadata&&t.metadata.inspect}function o(t){return t.metadata=t.metadata||{},t.metadata.inspect=!0,t}function a(t){return"raster"===t.type&&t.tileSize&&t.tiles?{type:t.type,tileSize:t.tileSize,tiles:t.tiles}:"raster"===t.type&&t.url?{type:t.type,url:t.url}:t}function i(t){return Object.keys(t.sources).forEach(function(e){t.sources[e]=a(t.sources[e])}),t}function s(t){var e=t.version.split(".").map(parseFloat);e[0]<1&&e[1]<29&&console.error("MapboxInspect only supports Mapbox GL JS >= v0.29.0. Please upgrade your Mapbox GL JS version.")}function u(t){if(!(this instanceof u))throw new Error("MapboxInspect needs to be called with the new keyword");var e=null;window.mapboxgl?(s(window.mapboxgl),e=new window.mapboxgl.Popup({closeButton:!1,closeOnClick:!1})):t.popup||console.error("Mapbox GL JS can not be found. Make sure to include it or pass an initialized MapboxGL Popup to MapboxInspect if you are using moduleis."),this.options=Object.assign({showInspectMap:!1,showInspectButton:!0,showInspectMapPopup:!0,showMapPopup:!1,backgroundColor:"#fff",assignLayerColor:h.brightColor,buildInspectStyle:c.generateInspectStyle,renderPopup:f,popup:e},t),this.sources={},this.assignLayerColor=this.options.assignLayerColor,this.toggleInspector=this.toggleInspector.bind(this),this._popup=this.options.popup,this._showInspectMap=this.options.showInspectMap,this._onSourceChange=this._onSourceChange.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onStyleChange=this._onStyleChange.bind(this),this._originalStyle=null,this._toggle=new l({show:this.options.showInspectButton,onToggle:this.toggleInspector.bind(this)})}var c=t("./stylegen"),l=t("./InspectButton"),p=t("lodash.isequal"),f=t("./renderPopup"),h=t("./colors");u.prototype.toggleInspector=function(){this._showInspectMap=!this._showInspectMap,this.render()},u.prototype._inspectStyle=function(){var t=c.generateColoredLayers(this.sources,this.assignLayerColor);return this.options.buildInspectStyle(this._map.getStyle(),t,{backgroundColor:this.options.backgroundColor})},u.prototype.render=function(){this._showInspectMap?(this._map.setStyle(i(o(this._inspectStyle()))),this._toggle.setMapIcon()):this._originalStyle&&(this._popup&&this._popup.remove(),this._map.setStyle(i(this._originalStyle)),this._toggle.setInspectIcon())},u.prototype._onSourceChange=function(){var t=this.sources,e=this._map,n=Object.assign({},t);Object.keys(e.style.sourceCaches).forEach(function(n){var r=e.style.sourceCaches[n]._source.vectorLayerIds;r&&(t[n]=r)}),p(n,t)||this.render()},u.prototype._onStyleChange=function(){var t=this._map.getStyle();r(t)||(this._originalStyle=t)},u.prototype._onMousemove=function(t){if((this.options.showInspectMapPopup||!this._showInspectMap)&&(this.options.showMapPopup||this._showInspectMap)){var e=this._map.queryRenderedFeatures(t.point);this._map.getCanvas().style.cursor=e.length?"pointer":"",!e.length&&this._popup?this._popup.remove():this._popup&&this._popup.setLngLat(t.lngLat).setHTML(this.options.renderPopup(e)).addTo(this._map)}},u.prototype.onAdd=function(t){return this._map=t,t.on("styledata",this._onStyleChange),t.on("load",this._onStyleChange),t.on("tiledata",this._onSourceChange),t.on("sourcedata",this._onSourceChange),t.on("mousemove",this._onMousemove),this._toggle.elem},u.prototype.onRemove=function(){this._map.off("styledata",this._onStyleChange),this._map.off("load",this._onStyleChange),this._map.off("tiledata",this._onSLine truncated
|
||||
Reference in new issue
Block a user