import*as tslib_1 from"../polyfills/tslib.js";var Map$1=function(){function e(){this.drawing=!1,this.zoom=10,this.minzoom=0,this.maxzoom=22}return e.prototype.componentWillLoad=function(){var e=this;this._style=this.loadStyle(),this.map=new mapboxgl.Map({container:this.el,center:[this.longitude,this.latitude],zoom:this.zoom,minZoom:this.minzoom,maxZoom:this.maxzoom,style:this._style}),window.addEventListener("resize",this.resizeMap.bind(this)),this.map.on("draw.create",function(t){return e.glDrawCreate.emit({mapId:e.id,features:t.features})}),this.map.on("draw.delete",function(t){return e.glDrawDelete.emit({mapId:e.id,features:t.features})})},e.prototype.componentDidUpdate=function(){this.resizeMap()},e.prototype.updateStyle=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){var e=this;return tslib_1.__generator(this,function(t){return this._updateStyleTimeout?[2]:(this._updateStyleTimeout=window.setTimeout(function(){return tslib_1.__awaiter(e,void 0,void 0,function(){var e;return tslib_1.__generator(this,function(t){switch(t.label){case 0:return this._updateStyleTimeout=null,e=this,[4,this.loadStyle()];case 1:return e._style=t.sent(),this.map.setStyle(this._style),this.glStyleUpdated.emit(this._style),[2]}})})},66),[2])})})},e.prototype.handleStyleAdded=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(e){return this.updateStyle(),[2]})})},e.prototype.handleStyleModified=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(e){return this.updateStyle(),[2]})})},e.prototype.handleStyleRemoved=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(e){return this.updateStyle(),[2]})})},e.prototype.updateDrawing=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(e){return this.drawing?(this.draw=new MapboxDraw(this.drawOptions),this.map.addControl(this.draw),this.glDrawEnter.emit({mapId:this.id})):(this.map.removeControl(this.draw),this.draw=null,this.glDrawExit.emit({mapId:this.id})),[2]})})},e.prototype.resizeMap=function(){var e=this;this._resizeMapTimeout||(this._resizeMapTimeout=window.setTimeout(function(){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){return this._resizeMapTimeout=null,this.map&&this.map.resize(),[2]})})},66))},e.prototype.getStyleLayers=function(e,t){if(!t.layers)return[];for(var r=[],i=0,n=t.layers;i<n.length;i++){var o=n[i],a=Object.assign({},o,{id:this.prefix(e,o.id)});o.source&&(a.source=this.prefix(e,o.source)),r.push(a)}return r},e.prototype.getStyleSources=function(e,t){if(!t.sources)return[];var r={};for(var i in t.sources)r[this.prefix(e,i)]=t.sources[i];return r},e.prototype.loadStyle=function(){var e=this,t={version:8,metadata:{},sources:{},layers:[]};return Array.from(this.el.querySelectorAll("gl-style")).forEach(function(r){if(r.enabled){var i=r.id,n=r.json;n&&(t.layers=e.getStyleLayers(i,n).concat(t.layers),t.sources=Object.assign({},t.sources,e.getStyleSources(i,n)),n.glyphs&&(t.glyphs=n.glyphs),n.sprite&&(t.sprite=n.sprite))}}),t},e.prototype.prefix=function(e,t){return e+":"+t},Object.defineProperty(e,"is",{get:function(){return"gl-map"},enumerable:!0,configurable:!0}),Object.defineProperty(e,"properties",{get:function(){return{draw:{type:"Any",attr:"draw",mutable:!0},drawing:{type:Boolean,attr:"drawing",watchCallbacks:["updateDrawing"]},drawOptions:{type:"Any",attr:"draw-options"},el:{elementRef:!0},id:{type:String,attr:"id"},latitude:{type:Number,attr:"latitude"},longitude:{type:Number,attr:"longitude"},map:{type:"Any",attr:"map",mutable:!0},maxzoom:{type:Number,attr:"maxzoom"},minzoom:{type:Number,attr:"minzoom"},resizeMap:{method:!0},zoom:{type:Number,attr:"zoom"}}},enumerable:!0,configurable:!0}),Object.defineProperty(e,"events",{get:function(){return[{name:"glDrawCreate",method:"glDrawCreate",bubbles:!0,cancelable:!0,composed:!0},{name:"glDrawDelete",method:"glDrawDelete",bubbles:!0,cancelable:!0,composed:!0},{name:"glDrawEnter",method:"glDrawEnter",bubbles:!0,cancelable:!0,composed:!0},{name:"glDrawExit",method:"glDrawExit",bubbles:!0,cancelable:!0,composed:!0},{name:"glStyleUpdated",method:"glStyleUpdated",bubbles:!0,cancelable:!0,composed:!0}]},enumerable:!0,configurable:!0}),Object.defineProperty(e,"listeners",{get:function(){return[{name:"glStyleElementAdded",method:"handleStyleAdded"},{name:"glStyleElementModified",method:"handleStyleModified"},{name:"glStyleElementRemoved",method:"handleStyleRemoved"}]},enumerable:!0,configurable:!0}),Object.defineProperty(e,"style",{get:function(){return"gl-map{display:block;height:100%;width:100%}"},enumerable:!0,configurable:!0}),e}();export{Map$1 as GlMap};