From 47339d4af2bfd13032d0ad5eff4d8f1d10e4e0ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= Date: Thu, 9 Dec 2021 21:12:54 +0100 Subject: [PATCH] Release version 0.2.9. --- dist/mapbox-gl-indoorequal.cjs.js | 116 +++++++++++++++++++------- dist/mapbox-gl-indoorequal.esm.js | 114 +++++++++++++++++++------ dist/mapbox-gl-indoorequal.umd.min.js | 2 +- package.json | 2 +- 4 files changed, 177 insertions(+), 57 deletions(-) diff --git a/dist/mapbox-gl-indoorequal.cjs.js b/dist/mapbox-gl-indoorequal.cjs.js index d1e711b..c941b92 100644 --- a/dist/mapbox-gl-indoorequal.cjs.js +++ b/dist/mapbox-gl-indoorequal.cjs.js @@ -491,13 +491,80 @@ function loadSprite(baseUrl) { }); } -const SOURCE_ID = 'indoorequal'; +class GeoJSONSource { + constructor(map, options = {}) { + const defaultOpts = { layers, geojson: {} }; + const opts = { ...defaultOpts, ...options }; + this.map = map; + this.geojson = opts.geojson; + this.layers = opts.layers; + this.baseSourceId = 'indoorequal'; + this.sourceId = `${this.baseSourceId}_area`; + } + + addSource() { + Object.keys(this.geojson).forEach((layerName) => { + this.map.addSource(`${this.baseSourceId}_${layerName}`, { + type: 'geojson', + data: this.geojson[layerName] + }); + }); + } + + addLayers() { + const sourceLayers = Object.keys(this.geojson); + const layers = this.layers; + this.layers = layers.filter((layer) => { + return sourceLayers.includes(layer['source-layer']); + }); + this.layers.forEach((layer) => { + this.map.addLayer({ + source: `${this.baseSourceId}_${layer['source-layer']}`, + ...layer, + 'source-layer': '' + }); + }); + } +} + +class VectorTileSource { + constructor(map, options = {}) { + const defaultOpts = { url: 'https://tiles.indoorequal.org/', layers }; + const opts = { ...defaultOpts, ...options }; + if (opts.url === defaultOpts.url && !opts.apiKey) { + throw 'You must register your apiKey at https://indoorequal.com before and set it as apiKey param.'; + } + this.map = map; + this.url = opts.url; + this.apiKey = opts.apiKey; + this.layers = opts.layers; + this.sourceId = 'indoorequal'; + } + + addSource() { + const queryParams = this.apiKey ? `?key=${this.apiKey}` : ''; + this.map.addSource(this.sourceId, { + type: 'vector', + url: `${this.url}${queryParams}` + }); + } + + addLayers() { + this.layers.forEach((layer) => { + this.map.addLayer({ + source: this.sourceId, + ...layer + }); + }); + } +} /** * Load the indoor= source and layers in your map. * @param {object} map the mapbox-gl instance of the map * @param {object} options - * @param {url} [options.url] Override the default tiles URL (https://tiles.indoorequal.org/). + * @param {string} [options.url] Override the default tiles URL (https://tiles.indoorequal.org/). + * @param {object} [options.geojson] GeoJSON data with with key as layer name and value with geojson features * @param {string} [options.apiKey] The API key if you use the default tile URL (get your free key at [indoorequal.com](https://indoorequal.com)). * @param {array} [options.layers] The layers to be used to style indoor= tiles. Take a look a the [layers.js file](https://github.com/indoorequal/mapbox-gl-indoorequal/blob/master/src/layers.js) file and the [vector schema](https://indoorequal.com/schema) * @param {boolean} [options.heatmap] Should the heatmap layer be visible at start (true : visible, false : hidden). Defaults to true/visible. @@ -509,15 +576,11 @@ const SOURCE_ID = 'indoorequal'; */ class IndoorEqual { constructor(map, options = {}) { - const defaultOpts = { url: 'https://tiles.indoorequal.org/', layers, heatmap: true }; + const SourceKlass = options.geojson ? GeoJSONSource : VectorTileSource; + const defaultOpts = { heatmap: true }; const opts = { ...defaultOpts, ...options }; - if (opts.url === defaultOpts.url && !opts.apiKey) { - throw 'You must register your apiKey at https://indoorequal.com before and set it as apiKey param.'; - } + this.source = new SourceKlass(map, options); this.map = map; - this.url = opts.url; - this.apiKey = opts.apiKey; - this.layers = opts.layers; this.levels = []; this.level = '0'; this.events = {}; @@ -601,7 +664,7 @@ class IndoorEqual { * Load a sprite and add all images to the map * @param {string} baseUrl the baseUrl where to load the sprite * @param {object} options - * @param {url} [options.update] Update existing image (default false) + * @param {boolean} [options.update] Update existing image (default false) * @return {Promise} It resolves an hash of images. */ loadSprite(baseUrl, options = {}) { @@ -625,31 +688,28 @@ class IndoorEqual { * @param {boolean} visible True to make it visible, false to hide it */ setHeatmapVisible(visible) { - this.map.setLayoutProperty('indoor-heat', 'visibility', visible ? 'visible' : 'none'); + if (this.map.getLayer('indoor-heat')) { + this.map.setLayoutProperty('indoor-heat', 'visibility', visible ? 'visible' : 'none'); + } } _addSource() { - const queryParams = this.apiKey ? `?key=${this.apiKey}` : ''; - this.map.addSource(SOURCE_ID, { - type: 'vector', - url: `${this.url}${queryParams}` - }); - this.layers.forEach((layer) => { - this.map.addLayer({ - source: SOURCE_ID, - ...layer - }); - }); + this.source.addSource(); + this._addLayers(); this._updateFilters(); - const updateLevels = debounce__default['default'](this._updateLevels.bind(this), 1000); + const updateLevels = debounce__default["default"](this._updateLevels.bind(this), 1000); this.map.on('load', updateLevels); this.map.on('data', updateLevels); this.map.on('move', updateLevels); } + _addLayers() { + this.source.addLayers(); + } + _updateFilters() { - this.layers + this.source.layers .filter(layer => layer.type !== 'heatmap') .forEach((layer) => { this.map.setFilter(layer.id, [ ...layer.filter || ['all'], ['==', 'level', this.level]]); @@ -663,10 +723,10 @@ class IndoorEqual { } _updateLevels() { - if (this.map.isSourceLoaded(SOURCE_ID)) { - const features = this.map.querySourceFeatures(SOURCE_ID, { sourceLayer: 'area' }); + if (this.map.isSourceLoaded(this.source.sourceId)) { + const features = this.map.querySourceFeatures(this.source.sourceId, { sourceLayer: 'area' }); const levels = findAllLevels(features); - if (!arrayEqual__default['default'](levels, this.levels)) { + if (!arrayEqual__default["default"](levels, this.levels)) { this.levels = levels; this._emitLevelsChange(); this._refreshAfterLevelsUpdate(); @@ -695,7 +755,7 @@ class IndoorEqual { */ /** - * Emitted when the list of available levels has been updated + * Emitted when the current level has been updated * * @event IndoorEqual#levelchange * @type {string} always emitted when the level displayed has changed diff --git a/dist/mapbox-gl-indoorequal.esm.js b/dist/mapbox-gl-indoorequal.esm.js index 193518c..52327c2 100644 --- a/dist/mapbox-gl-indoorequal.esm.js +++ b/dist/mapbox-gl-indoorequal.esm.js @@ -484,13 +484,80 @@ function loadSprite(baseUrl) { }); } -const SOURCE_ID = 'indoorequal'; +class GeoJSONSource { + constructor(map, options = {}) { + const defaultOpts = { layers, geojson: {} }; + const opts = { ...defaultOpts, ...options }; + this.map = map; + this.geojson = opts.geojson; + this.layers = opts.layers; + this.baseSourceId = 'indoorequal'; + this.sourceId = `${this.baseSourceId}_area`; + } + + addSource() { + Object.keys(this.geojson).forEach((layerName) => { + this.map.addSource(`${this.baseSourceId}_${layerName}`, { + type: 'geojson', + data: this.geojson[layerName] + }); + }); + } + + addLayers() { + const sourceLayers = Object.keys(this.geojson); + const layers = this.layers; + this.layers = layers.filter((layer) => { + return sourceLayers.includes(layer['source-layer']); + }); + this.layers.forEach((layer) => { + this.map.addLayer({ + source: `${this.baseSourceId}_${layer['source-layer']}`, + ...layer, + 'source-layer': '' + }); + }); + } +} + +class VectorTileSource { + constructor(map, options = {}) { + const defaultOpts = { url: 'https://tiles.indoorequal.org/', layers }; + const opts = { ...defaultOpts, ...options }; + if (opts.url === defaultOpts.url && !opts.apiKey) { + throw 'You must register your apiKey at https://indoorequal.com before and set it as apiKey param.'; + } + this.map = map; + this.url = opts.url; + this.apiKey = opts.apiKey; + this.layers = opts.layers; + this.sourceId = 'indoorequal'; + } + + addSource() { + const queryParams = this.apiKey ? `?key=${this.apiKey}` : ''; + this.map.addSource(this.sourceId, { + type: 'vector', + url: `${this.url}${queryParams}` + }); + } + + addLayers() { + this.layers.forEach((layer) => { + this.map.addLayer({ + source: this.sourceId, + ...layer + }); + }); + } +} /** * Load the indoor= source and layers in your map. * @param {object} map the mapbox-gl instance of the map * @param {object} options - * @param {url} [options.url] Override the default tiles URL (https://tiles.indoorequal.org/). + * @param {string} [options.url] Override the default tiles URL (https://tiles.indoorequal.org/). + * @param {object} [options.geojson] GeoJSON data with with key as layer name and value with geojson features * @param {string} [options.apiKey] The API key if you use the default tile URL (get your free key at [indoorequal.com](https://indoorequal.com)). * @param {array} [options.layers] The layers to be used to style indoor= tiles. Take a look a the [layers.js file](https://github.com/indoorequal/mapbox-gl-indoorequal/blob/master/src/layers.js) file and the [vector schema](https://indoorequal.com/schema) * @param {boolean} [options.heatmap] Should the heatmap layer be visible at start (true : visible, false : hidden). Defaults to true/visible. @@ -502,15 +569,11 @@ const SOURCE_ID = 'indoorequal'; */ class IndoorEqual { constructor(map, options = {}) { - const defaultOpts = { url: 'https://tiles.indoorequal.org/', layers, heatmap: true }; + const SourceKlass = options.geojson ? GeoJSONSource : VectorTileSource; + const defaultOpts = { heatmap: true }; const opts = { ...defaultOpts, ...options }; - if (opts.url === defaultOpts.url && !opts.apiKey) { - throw 'You must register your apiKey at https://indoorequal.com before and set it as apiKey param.'; - } + this.source = new SourceKlass(map, options); this.map = map; - this.url = opts.url; - this.apiKey = opts.apiKey; - this.layers = opts.layers; this.levels = []; this.level = '0'; this.events = {}; @@ -594,7 +657,7 @@ class IndoorEqual { * Load a sprite and add all images to the map * @param {string} baseUrl the baseUrl where to load the sprite * @param {object} options - * @param {url} [options.update] Update existing image (default false) + * @param {boolean} [options.update] Update existing image (default false) * @return {Promise} It resolves an hash of images. */ loadSprite(baseUrl, options = {}) { @@ -618,21 +681,14 @@ class IndoorEqual { * @param {boolean} visible True to make it visible, false to hide it */ setHeatmapVisible(visible) { - this.map.setLayoutProperty('indoor-heat', 'visibility', visible ? 'visible' : 'none'); + if (this.map.getLayer('indoor-heat')) { + this.map.setLayoutProperty('indoor-heat', 'visibility', visible ? 'visible' : 'none'); + } } _addSource() { - const queryParams = this.apiKey ? `?key=${this.apiKey}` : ''; - this.map.addSource(SOURCE_ID, { - type: 'vector', - url: `${this.url}${queryParams}` - }); - this.layers.forEach((layer) => { - this.map.addLayer({ - source: SOURCE_ID, - ...layer - }); - }); + this.source.addSource(); + this._addLayers(); this._updateFilters(); const updateLevels = debounce(this._updateLevels.bind(this), 1000); @@ -641,8 +697,12 @@ class IndoorEqual { this.map.on('move', updateLevels); } + _addLayers() { + this.source.addLayers(); + } + _updateFilters() { - this.layers + this.source.layers .filter(layer => layer.type !== 'heatmap') .forEach((layer) => { this.map.setFilter(layer.id, [ ...layer.filter || ['all'], ['==', 'level', this.level]]); @@ -656,8 +716,8 @@ class IndoorEqual { } _updateLevels() { - if (this.map.isSourceLoaded(SOURCE_ID)) { - const features = this.map.querySourceFeatures(SOURCE_ID, { sourceLayer: 'area' }); + if (this.map.isSourceLoaded(this.source.sourceId)) { + const features = this.map.querySourceFeatures(this.source.sourceId, { sourceLayer: 'area' }); const levels = findAllLevels(features); if (!arrayEqual(levels, this.levels)) { this.levels = levels; @@ -688,10 +748,10 @@ class IndoorEqual { */ /** - * Emitted when the list of available levels has been updated + * Emitted when the current level has been updated * * @event IndoorEqual#levelchange * @type {string} always emitted when the level displayed has changed */ -export default IndoorEqual; +export { IndoorEqual as default }; diff --git a/dist/mapbox-gl-indoorequal.umd.min.js b/dist/mapbox-gl-indoorequal.umd.min.js index 809c3fe..735f73f 100644 --- a/dist/mapbox-gl-indoorequal.umd.min.js +++ b/dist/mapbox-gl-indoorequal.umd.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).IndoorEqual=t()}(this,(function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function t(t){for(var n=1;n=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}function l(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n=0?i=setTimeout(s,t-c):(i=null,n||(l=e.apply(a,r),a=r=null))}null==t&&(t=100);var c=function(){a=this,r=arguments,o=Date.now();var c=n&&!i;return i||(i=setTimeout(s,t)),c&&(l=e.apply(a,r),a=r=null),l};return c.clear=function(){i&&(clearTimeout(i),i=null)},c.flush=function(){i&&(l=e.apply(a,r),a=r=null,clearTimeout(i),i=null)},c}c.debounce=c;var h=c;var u=function(){function e(t){var i=this;n(this,e),this.indoorequal=t,this._cbRefresh=function(){return i._refresh()},this.indoorequal.on("levelschange",this._cbRefresh),this.indoorequal.on("levelchange",this._cbRefresh),this.$el=document.createElement("div"),this.$el.classList.add("mapboxgl-ctrl","mapboxgl-ctrl-group","mapboxgl-ctrl-indoorequal"),this._refresh()}return r(e,[{key:"destroy",value:function(){this.$el.remove(),this.indoorequal.off("levelschange",this._cbRefresh),this.indoorequal.off("levelchange",this._cbRefresh)}},{key:"_refresh",value:function(){var e=this;this.$el.innerHTML="",this.indoorequal.levels.forEach((function(t){var n=document.createElement("button"),i=document.createElement("strong");i.textContent=t,n.appendChild(i),t==e.indoorequal.level&&n.classList.add("mapboxgl-ctrl-active"),n.addEventListener("click",(function(){e.indoorequal.setLevel(t)})),e.$el.appendChild(n)}))}}]),e}(),f={type:"symbol","source-layer":"poi",layout:{"icon-image":["coalesce",["image",["concat",["literal","indoorequal-"],["get","subclass"]]],["image",["concat",["literal","indoorequal-"],["get","class"]]]],"text-anchor":"top","text-field":"{name:latin}\n{name:nonlatin}","text-max-width":9,"text-offset":[0,.6],"text-padding":2,"text-size":12},paint:{"text-color":"#666","text-halo-blur":.5,"text-halo-color":"#ffffff","text-halo-width":1}},d=["waste_basket","information","vending_machine"],p=[{id:"indoor-polygon",type:"fill","source-layer":"area",filter:["all",["==","$type","Polygon"],["!=","class","level"]],paint:{"fill-color":["case",["all",["has","access"],["in",["get","access"],["literal",["no","private"]]]],"#F2F1F0",["all",["==",["get","is_poi"],!0],["!=",["get","class"],"corridor"]],"#D4EDFF",["==",["get","class"],"room"],"#fefee2","#fdfcfa"]}},{id:"indoor-area",type:"line","source-layer":"area",filter:["all",["in","class","area","corridor","platform"]],paint:{"line-color":"#bfbfbf","line-width":1}},{id:"indoor-column",type:"fill","source-layer":"area",filter:["all",["==","class","column"]],paint:{"fill-color":"#bfbfbf"}},{id:"indoor-lines",type:"line","source-layer":"area",filter:["all",["in","class","room","wall"]],paint:{"line-color":"gray","line-width":2}},{id:"indoor-transportation",type:"line","source-layer":"transportation",filter:["all"],paint:{"line-color":"gray","line-dasharray":[.4,.75],"line-width":{base:1.4,stops:[[17,2],[20,10]]}}},{id:"indoor-transportation-poi",type:"symbol","source-layer":"transportation",filter:["all",["in","$type","Point","LineString"],["in","class","steps","elevator","escalator"]],layout:{"icon-image":["case",["has","conveying"],"indoorequal-escalator",["concat",["literal","indoorequal-"],["get","class"]]],"symbol-placement":"line-center","icon-rotation-alignment":"viewport"}},t(t({id:"indoor-poi-rank1"},f),{},{filter:["all",["==","$type","Point"],["!in","class"].concat(d)]}),t(t({id:"indoor-poi-rank2"},f),{},{minzoom:19,filter:["all",["==","$type","Point"],["in","class"].concat(d)]}),{id:"indoor-heat",type:"heatmap","source-layer":"heat",filter:["all"],paint:{"heatmap-color":["interpolate",["linear"],["heatmap-density"],0,"rgba(102, 103, 173, 0)",.1,"rgba(102, 103, 173, 0.2)",1,"rgba(102, 103, 173, 0.7)"],"heatmap-radius":["interpolate",["linear"],["zoom"],0,3,13,20,17,40],"heatmap-intensity":1,"heatmap-opacity":["interpolate",["linear"],["zoom"],16,1,17.1,0]}},{id:"indoor-name",type:"symbol","source-layer":"area_name",filter:["all"],layout:{"text-field":["get","name"],"text-max-width":5,"text-size":14},paint:{"text-color":"#666","text-halo-color":"#ffffff","text-halo-width":1}}];function y(e,t,n,i){var r=t.width,a=t.height;if(i){if(i instanceof Uint8ClampedArray)i=new Uint8Array(i.buffer);else if(i.length!==r*a*n)throw new RangeError("mismatched image size")}else i=new Uint8Array(r*a*n);return e.width=r,e.height=a,e.data=i,e}function v(e,t,n,i,r,a){if(0===r.width||0===r.height)return t;if(r.width>e.width||r.height>e.height||n.x>e.width-r.width||n.y>e.height-r.height)throw new RangeError("out of range source coordinates for image copy");if(r.width>t.width||r.height>t.height||i.x>t.width-r.width||i.y>t.height-r.height)throw new RangeError("out of range destination coordinates for image copy");for(var o=e.data,l=t.data,s=0;s1?"@2x":"",r=fetch("".concat(e).concat(i,".json")).then((function(e){return e.json()})).then((function(e){return t=e})),a=fetch("".concat(e).concat(i,".png")).then((function(e){return e.blob()})).then((function(e){return(n=new Image).src=URL.createObjectURL(e),new Promise((function(e,t){n.onload=function(){return e()},n.onerror=function(){return t()}}))}));return Promise.all([r,a]).then((function(){var e=function(e,t){var n=window.document.createElement("canvas"),i=n.getContext("2d");if(!i)throw new Error("failed to create canvas 2d context");return n.width=e.width,n.height=e.height,i.drawImage(e,0,0,e.width,e.height),i.getImageData(0,0,e.width,e.height)}(n),i={};for(var r in t){var a=t[r],o=a.width,l=a.height,s=a.x,c=a.y,h=a.sdf,u=a.pixelRatio,f=a.stretchX,d=a.stretchY,p=a.content,y=new m({width:o,height:l});m.copy(e,y,{x:s,y:c},{x:0,y:0},{width:o,height:l}),i[r]={data:y,pixelRatio:u,sdf:h,stretchX:f,stretchY:d,content:p}}return i}))}var b="indoorequal";return function(){function e(i){var r=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e);var o={url:"https://tiles.indoorequal.org/",layers:p,heatmap:!0},l=t(t({},o),a);if(l.url===o.url&&!l.apiKey)throw"You must register your apiKey at https://indoorequal.com before and set it as apiKey param.";this.map=i,this.url=l.url,this.apiKey=l.apiKey,this.layers=l.layers,this.levels=[],this.level="0",this.events={},this.map.isStyleLoaded()?(this._addSource(),this.setHeatmapVisible(l.heatmap)):this.map.on("load",(function(){r._addSource(),r.setHeatmapVisible(l.heatmap)}))}return r(e,[{key:"on",value:function(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}},{key:"off",value:function(e,t){this.events[e]||(this.events[e]=[]),this.events[e]=this.events[e].filter((function(e){return e!==t}))}},{key:"onAdd",value:function(){return this._control=new u(this),this._control.$el}},{key:"onRemove",value:function(){this._control.destroy(),this._control=null}},{key:"setLevel",value:function(e){this.level=e,this._updateFilters(),this._emitLevelChange()}},{key:"updateLevel",value:function(e){console.log("The updateLevel method is deprecated. Please use setLevel instead."),this.setLevel(e)}},{key:"loadSprite",value:function(e){var n=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t({update:!1},i);return g(e).then((function(e){for(var t in e){var i=e[t],a=i.data,l=o(i,["data"]);n.map.hasImage(t)?r.update&&n.map.updateImage(t,a):n.map.addImage(t,a,l)}return e}))}},{key:"setHeatmapVisible",value:function(e){this.map.setLayoutProperty("indoor-heat","visibility",e?"visible":"none")}},{key:"_addSource",value:function(){var e=this,n=this.apiKey?"?key=".concat(this.apiKey):"";this.map.addSource(b,{type:"vector",url:"".concat(this.url).concat(n)}),this.layers.forEach((function(n){e.map.addLayer(t({source:b},n))})),this._updateFilters();var i=h(this._updateLevels.bind(this),1e3);this.map.on("load",i),this.map.on("data",i),this.map.on("move",i)}},{key:"_updateFilters",value:function(){var e=this;this.layers.filter((function(e){return"heatmap"!==e.type})).forEach((function(t){e.map.setFilter(t.id,[].concat(l(t.filter||["all"]),[["==","level",e.level]]))}))}},{key:"_refreshAfterLevelsUpdate",value:function(){this.levels.includes(this.level)||this.setLevel("0")}},{key:"_updateLevels",value:function(){if(this.map.isSourceLoaded(b)){var e=function(e){for(var t=[],n=0;n1?t-1:0),i=1;i=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function l(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=0?r=setTimeout(s,t-c):(r=null,n||(l=e.apply(a,i),a=i=null))}null==t&&(t=100);var c=function(){a=this,i=arguments,o=Date.now();var c=n&&!r;return r||(r=setTimeout(s,t)),c&&(l=e.apply(a,i),a=i=null),l};return c.clear=function(){r&&(clearTimeout(r),r=null)},c.flush=function(){r&&(l=e.apply(a,i),a=i=null,clearTimeout(r),r=null)},c}c.debounce=c;var u=c;var h=function(){function e(t){var r=this;n(this,e),this.indoorequal=t,this._cbRefresh=function(){return r._refresh()},this.indoorequal.on("levelschange",this._cbRefresh),this.indoorequal.on("levelchange",this._cbRefresh),this.$el=document.createElement("div"),this.$el.classList.add("mapboxgl-ctrl","mapboxgl-ctrl-group","mapboxgl-ctrl-indoorequal"),this._refresh()}return i(e,[{key:"destroy",value:function(){this.$el.remove(),this.indoorequal.off("levelschange",this._cbRefresh),this.indoorequal.off("levelchange",this._cbRefresh)}},{key:"_refresh",value:function(){var e=this;this.$el.innerHTML="",this.indoorequal.levels.forEach((function(t){var n=document.createElement("button"),r=document.createElement("strong");r.textContent=t,n.appendChild(r),t==e.indoorequal.level&&n.classList.add("mapboxgl-ctrl-active"),n.addEventListener("click",(function(){e.indoorequal.setLevel(t)})),e.$el.appendChild(n)}))}}]),e}(),f={type:"symbol","source-layer":"poi",layout:{"icon-image":["coalesce",["image",["concat",["literal","indoorequal-"],["get","subclass"]]],["image",["concat",["literal","indoorequal-"],["get","class"]]]],"text-anchor":"top","text-field":"{name:latin}\n{name:nonlatin}","text-max-width":9,"text-offset":[0,.6],"text-padding":2,"text-size":12},paint:{"text-color":"#666","text-halo-blur":.5,"text-halo-color":"#ffffff","text-halo-width":1}},d=["waste_basket","information","vending_machine"],p=[{id:"indoor-polygon",type:"fill","source-layer":"area",filter:["all",["==","$type","Polygon"],["!=","class","level"]],paint:{"fill-color":["case",["all",["has","access"],["in",["get","access"],["literal",["no","private"]]]],"#F2F1F0",["all",["==",["get","is_poi"],!0],["!=",["get","class"],"corridor"]],"#D4EDFF",["==",["get","class"],"room"],"#fefee2","#fdfcfa"]}},{id:"indoor-area",type:"line","source-layer":"area",filter:["all",["in","class","area","corridor","platform"]],paint:{"line-color":"#bfbfbf","line-width":1}},{id:"indoor-column",type:"fill","source-layer":"area",filter:["all",["==","class","column"]],paint:{"fill-color":"#bfbfbf"}},{id:"indoor-lines",type:"line","source-layer":"area",filter:["all",["in","class","room","wall"]],paint:{"line-color":"gray","line-width":2}},{id:"indoor-transportation",type:"line","source-layer":"transportation",filter:["all"],paint:{"line-color":"gray","line-dasharray":[.4,.75],"line-width":{base:1.4,stops:[[17,2],[20,10]]}}},{id:"indoor-transportation-poi",type:"symbol","source-layer":"transportation",filter:["all",["in","$type","Point","LineString"],["in","class","steps","elevator","escalator"]],layout:{"icon-image":["case",["has","conveying"],"indoorequal-escalator",["concat",["literal","indoorequal-"],["get","class"]]],"symbol-placement":"line-center","icon-rotation-alignment":"viewport"}},t(t({id:"indoor-poi-rank1"},f),{},{filter:["all",["==","$type","Point"],["!in","class"].concat(d)]}),t(t({id:"indoor-poi-rank2"},f),{},{minzoom:19,filter:["all",["==","$type","Point"],["in","class"].concat(d)]}),{id:"indoor-heat",type:"heatmap","source-layer":"heat",filter:["all"],paint:{"heatmap-color":["interpolate",["linear"],["heatmap-density"],0,"rgba(102, 103, 173, 0)",.1,"rgba(102, 103, 173, 0.2)",1,"rgba(102, 103, 173, 0.7)"],"heatmap-radius":["interpolate",["linear"],["zoom"],0,3,13,20,17,40],"heatmap-intensity":1,"heatmap-opacity":["interpolate",["linear"],["zoom"],16,1,17.1,0]}},{id:"indoor-name",type:"symbol","source-layer":"area_name",filter:["all"],layout:{"text-field":["get","name"],"text-max-width":5,"text-size":14},paint:{"text-color":"#666","text-halo-color":"#ffffff","text-halo-width":1}}];function y(e,t,n,r){var i=t.width,a=t.height;if(r){if(r instanceof Uint8ClampedArray)r=new Uint8Array(r.buffer);else if(r.length!==i*a*n)throw new RangeError("mismatched image size")}else r=new Uint8Array(i*a*n);return e.width=i,e.height=a,e.data=r,e}function v(e,t,n,r,i,a){if(0===i.width||0===i.height)return t;if(i.width>e.width||i.height>e.height||n.x>e.width-i.width||n.y>e.height-i.height)throw new RangeError("out of range source coordinates for image copy");if(i.width>t.width||i.height>t.height||r.x>t.width-i.width||r.y>t.height-i.height)throw new RangeError("out of range destination coordinates for image copy");for(var o=e.data,l=t.data,s=0;s1?"@2x":"",i=fetch("".concat(e).concat(r,".json")).then((function(e){return e.json()})).then((function(e){return t=e})),a=fetch("".concat(e).concat(r,".png")).then((function(e){return e.blob()})).then((function(e){return(n=new Image).src=URL.createObjectURL(e),new Promise((function(e,t){n.onload=function(){return e()},n.onerror=function(){return t()}}))}));return Promise.all([i,a]).then((function(){var e=function(e,t){var n=window.document.createElement("canvas"),r=n.getContext("2d");if(!r)throw new Error("failed to create canvas 2d context");return n.width=e.width,n.height=e.height,r.drawImage(e,0,0,e.width,e.height),r.getImageData(0,0,e.width,e.height)}(n),r={};for(var i in t){var a=t[i],o=a.width,l=a.height,s=a.x,c=a.y,u=a.sdf,h=a.pixelRatio,f=a.stretchX,d=a.stretchY,p=a.content,y=new m({width:o,height:l});m.copy(e,y,{x:s,y:c},{x:0,y:0},{width:o,height:l}),r[i]={data:y,pixelRatio:h,sdf:u,stretchX:f,stretchY:d,content:p}}return r}))}var b=["data"],w=function(){function e(r){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e);var a={layers:p,geojson:{}},o=t(t({},a),i);this.map=r,this.geojson=o.geojson,this.layers=o.layers,this.baseSourceId="indoorequal",this.sourceId="".concat(this.baseSourceId,"_area")}return i(e,[{key:"addSource",value:function(){var e=this;Object.keys(this.geojson).forEach((function(t){e.map.addSource("".concat(e.baseSourceId,"_").concat(t),{type:"geojson",data:e.geojson[t]})}))}},{key:"addLayers",value:function(){var e=this,n=Object.keys(this.geojson),r=this.layers;this.layers=r.filter((function(e){return n.includes(e["source-layer"])})),this.layers.forEach((function(n){e.map.addLayer(t(t({source:"".concat(e.baseSourceId,"_").concat(n["source-layer"])},n),{},{"source-layer":""}))}))}}]),e}(),x=function(){function e(r){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e);var a={url:"https://tiles.indoorequal.org/",layers:p},o=t(t({},a),i);if(o.url===a.url&&!o.apiKey)throw"You must register your apiKey at https://indoorequal.com before and set it as apiKey param.";this.map=r,this.url=o.url,this.apiKey=o.apiKey,this.layers=o.layers,this.sourceId="indoorequal"}return i(e,[{key:"addSource",value:function(){var e=this.apiKey?"?key=".concat(this.apiKey):"";this.map.addSource(this.sourceId,{type:"vector",url:"".concat(this.url).concat(e)})}},{key:"addLayers",value:function(){var e=this;this.layers.forEach((function(n){e.map.addLayer(t({source:e.sourceId},n))}))}}]),e}();return function(){function e(r){var i=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e);var o=a.geojson?w:x,l={heatmap:!0},s=t(t({},l),a);this.source=new o(r,a),this.map=r,this.levels=[],this.level="0",this.events={},this.map.isStyleLoaded()?(this._addSource(),this.setHeatmapVisible(s.heatmap)):this.map.on("load",(function(){i._addSource(),i.setHeatmapVisible(s.heatmap)}))}return i(e,[{key:"on",value:function(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}},{key:"off",value:function(e,t){this.events[e]||(this.events[e]=[]),this.events[e]=this.events[e].filter((function(e){return e!==t}))}},{key:"onAdd",value:function(){return this._control=new h(this),this._control.$el}},{key:"onRemove",value:function(){this._control.destroy(),this._control=null}},{key:"setLevel",value:function(e){this.level=e,this._updateFilters(),this._emitLevelChange()}},{key:"updateLevel",value:function(e){console.log("The updateLevel method is deprecated. Please use setLevel instead."),this.setLevel(e)}},{key:"loadSprite",value:function(e){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=t({update:!1},r);return g(e).then((function(e){for(var t in e){var r=e[t],a=r.data,l=o(r,b);n.map.hasImage(t)?i.update&&n.map.updateImage(t,a):n.map.addImage(t,a,l)}return e}))}},{key:"setHeatmapVisible",value:function(e){this.map.getLayer("indoor-heat")&&this.map.setLayoutProperty("indoor-heat","visibility",e?"visible":"none")}},{key:"_addSource",value:function(){this.source.addSource(),this._addLayers(),this._updateFilters();var e=u(this._updateLevels.bind(this),1e3);this.map.on("load",e),this.map.on("data",e),this.map.on("move",e)}},{key:"_addLayers",value:function(){this.source.addLayers()}},{key:"_updateFilters",value:function(){var e=this;this.source.layers.filter((function(e){return"heatmap"!==e.type})).forEach((function(t){e.map.setFilter(t.id,[].concat(l(t.filter||["all"]),[["==","level",e.level]]))}))}},{key:"_refreshAfterLevelsUpdate",value:function(){this.levels.includes(this.level)||this.setLevel("0")}},{key:"_updateLevels",value:function(){if(this.map.isSourceLoaded(this.source.sourceId)){var e=function(e){for(var t=[],n=0;n1?t-1:0),r=1;r