diff --git a/dist/mapbox-gl-indoorequal.cjs.js b/dist/mapbox-gl-indoorequal.cjs.js index 47ccccc..e942dd2 100644 --- a/dist/mapbox-gl-indoorequal.cjs.js +++ b/dist/mapbox-gl-indoorequal.cjs.js @@ -110,7 +110,7 @@ const commonPoi = { } }; -const rank2Class = ["waste_basket", "information", "vending_machine"]; +const rank2Class = ["waste_basket", "information", "vending_machine", "bench", "photo_booth", "ticket_validator"]; const layers = [ { @@ -602,11 +602,11 @@ class IndoorEqual { this.events = {}; if (this.map.isStyleLoaded()) { - this._addSource(); + this._init(); this.setHeatmapVisible(opts.heatmap); } else { this.map.once('load', () => { - this._addSource(); + this._init(); this.setHeatmapVisible(opts.heatmap); }); } @@ -723,9 +723,9 @@ class IndoorEqual { } } - _addSource() { + _init() { this.source.addSource(); - this._addLayers(); + this.source.addLayers(); this._updateFilters(); this._updateLevelsDebounce = debounce__default["default"](this._updateLevels.bind(this), 1000); @@ -737,10 +737,6 @@ class IndoorEqual { }); } - _addLayers() { - this.source.addLayers(); - } - _updateFilters() { this.source.layers .filter(layer => layer.type !== 'heatmap') diff --git a/dist/mapbox-gl-indoorequal.esm.js b/dist/mapbox-gl-indoorequal.esm.js index 1f39df4..cfb5c22 100644 --- a/dist/mapbox-gl-indoorequal.esm.js +++ b/dist/mapbox-gl-indoorequal.esm.js @@ -103,7 +103,7 @@ const commonPoi = { } }; -const rank2Class = ["waste_basket", "information", "vending_machine"]; +const rank2Class = ["waste_basket", "information", "vending_machine", "bench", "photo_booth", "ticket_validator"]; const layers = [ { @@ -595,11 +595,11 @@ class IndoorEqual { this.events = {}; if (this.map.isStyleLoaded()) { - this._addSource(); + this._init(); this.setHeatmapVisible(opts.heatmap); } else { this.map.once('load', () => { - this._addSource(); + this._init(); this.setHeatmapVisible(opts.heatmap); }); } @@ -716,9 +716,9 @@ class IndoorEqual { } } - _addSource() { + _init() { this.source.addSource(); - this._addLayers(); + this.source.addLayers(); this._updateFilters(); this._updateLevelsDebounce = debounce(this._updateLevels.bind(this), 1000); @@ -730,10 +730,6 @@ class IndoorEqual { }); } - _addLayers() { - this.source.addLayers(); - } - _updateFilters() { this.source.layers .filter(layer => layer.type !== 'heatmap') diff --git a/dist/mapbox-gl-indoorequal.umd.min.js b/dist/mapbox-gl-indoorequal.umd.min.js index 01698d5..db4564e 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 r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;n=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":""}))}))}},{key:"remove",value:function(){var e=this;this.layers.forEach((function(t){e.map.removeLayer(t.id)})),Object.keys(this.geojson).forEach((function(t){e.map.removeSource("".concat(e.baseSourceId,"_").concat(t))}))}}]),e}(),_=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))}))}},{key:"remove",value:function(){var e=this;this.layers.forEach((function(t){e.map.removeLayer(t.id)})),this.map.removeSource(this.sourceId)}}]),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:_,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.once("load",(function(){i._addSource(),i.setHeatmapVisible(s.heatmap)}))}return i(e,[{key:"remove",value:function(){this.source.remove(),this._updateLevelsDebounce.clear(),this.map.off("load",this._updateLevelsDebounce),this.map.off("data",this._updateLevelsDebounce),this.map.off("move",this._updateLevelsDebounce),this._control&&this.onRemove()}},{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(){var e=this;this.source.addSource(),this._addLayers(),this._updateFilters(),this._updateLevelsDebounce=u(this._updateLevels.bind(this),1e3),this.map.on("load",this._updateLevelsDebounce),this.map.on("data",this._updateLevelsDebounce),this.map.on("move",this._updateLevelsDebounce),this.map.on("remove",(function(){e.remove()}))}},{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=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 u=c;var h=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","bench","photo_booth","ticket_validator"],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 v(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 y(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,u=a.sdf,h=a.pixelRatio,f=a.stretchX,d=a.stretchY,p=a.content,v=new m({width:o,height:l});m.copy(e,v,{x:s,y:c},{x:0,y:0},{width:o,height:l}),i[r]={data:v,pixelRatio:h,sdf:u,stretchX:f,stretchY:d,content:p}}return i}))}var b=["data"],w=function(){function e(i){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e);var a={layers:p,geojson:{}},o=t(t({},a),r);this.map=i,this.geojson=o.geojson,this.layers=o.layers,this.baseSourceId="indoorequal",this.sourceId="".concat(this.baseSourceId,"_area")}return r(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),i=this.layers;this.layers=i.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":""}))}))}},{key:"remove",value:function(){var e=this;this.layers.forEach((function(t){e.map.removeLayer(t.id)})),Object.keys(this.geojson).forEach((function(t){e.map.removeSource("".concat(e.baseSourceId,"_").concat(t))}))}}]),e}(),_=function(){function e(i){var r=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),r);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=i,this.url=o.url,this.apiKey=o.apiKey,this.layers=o.layers,this.sourceId="indoorequal"}return r(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))}))}},{key:"remove",value:function(){var e=this;this.layers.forEach((function(t){e.map.removeLayer(t.id)})),this.map.removeSource(this.sourceId)}}]),e}();return function(){function e(i){var r=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,e);var o=a.geojson?w:_,l={heatmap:!0},s=t(t({},l),a);this.source=new o(i,a),this.map=i,this.levels=[],this.level="0",this.events={},this.map.isStyleLoaded()?(this._init(),this.setHeatmapVisible(s.heatmap)):this.map.once("load",(function(){r._init(),r.setHeatmapVisible(s.heatmap)}))}return r(e,[{key:"remove",value:function(){this.source.remove(),this._updateLevelsDebounce.clear(),this.map.off("load",this._updateLevelsDebounce),this.map.off("data",this._updateLevelsDebounce),this.map.off("move",this._updateLevelsDebounce),this._control&&this.onRemove()}},{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,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,b);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.getLayer("indoor-heat")&&this.map.setLayoutProperty("indoor-heat","visibility",e?"visible":"none")}},{key:"_init",value:function(){var e=this;this.source.addSource(),this.source.addLayers(),this._updateFilters(),this._updateLevelsDebounce=u(this._updateLevels.bind(this),1e3),this.map.on("load",this._updateLevelsDebounce),this.map.on("data",this._updateLevelsDebounce),this.map.on("move",this._updateLevelsDebounce),this.map.on("remove",(function(){e.remove()}))}},{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),i=1;i