import{b as e}from"./chunk-e494a432.js";class t{constructor(){this.drawing=!1,this.zoom=10,this.minzoom=0,this.maxzoom=22}componentWillLoad(){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",e=>this.glDrawCreate.emit({mapId:this.id,features:e.features})),this.map.on("draw.delete",e=>this.glDrawDelete.emit({mapId:this.id,features:e.features}))}componentDidUpdate(){this.resizeMap()}async updateStyle(){this._updateStyleTimeout||(this._updateStyleTimeout=window.setTimeout(async()=>{this._updateStyleTimeout=null,this._style=await this.loadStyle(),this.map.setStyle(this._style),this.glStyleUpdated.emit(this._style)},66))}async handleStyleAdded(){this.updateStyle()}async handleStyleModified(){this.updateStyle()}async handleStyleRemoved(){this.updateStyle()}async updateDrawing(){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}))}resizeMap(){this._resizeMapTimeout||(this._resizeMapTimeout=window.setTimeout(async()=>{this._resizeMapTimeout=null,this.map&&this.map.resize()},66))}getStyleLayers(e,t){if(!t.layers)return[];let s=[];for(let a of t.layers){let t=Object.assign({},a,{id:this.prefix(e,a.id)});a.source&&(t.source=this.prefix(e,a.source)),s.push(t)}return s}getStyleSources(e,t){if(!t.sources)return[];let s={};for(let a in t.sources)s[this.prefix(e,a)]=t.sources[a];return s}loadStyle(){let t={version:8,metadata:{},sources:{},layers:[]};return this.glyphs&&(t.glyphs=this.glyphs),this.sprite&&(t.sprite=this.sprite),Array.from(this.el.querySelectorAll("gl-style")).forEach(e=>{if(!e.enabled)return;let s=e.id,a=e.json;a&&(t.layers=this.getStyleLayers(s,a).concat(t.layers),t.sources=Object.assign({},t.sources,this.getStyleSources(s,a)),a.glyphs&&!t.glyphs&&(t.glyphs=a.glyphs),a.sprite&&!t.sprite&&(t.sprite=a.sprite))}),t.glyphs&&(t.glyphs=e(t.glyphs).replace("%7Bfontstack%7D","{fontstack}").replace("%7Brange%7D","{range}")),t.sprite&&(t.sprite=e(t.sprite)),t}prefix(e,t){return`${e}:${t}`}static get is(){return"gl-map"}static get properties(){return{draw:{type:"Any",attr:"draw",mutable:!0},drawing:{type:Boolean,attr:"drawing",watchCallbacks:["updateDrawing"]},drawOptions:{type:"Any",attr:"draw-options"},el:{elementRef:!0},glyphs:{type:String,attr:"glyphs"},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},sprite:{type:String,attr:"sprite"},zoom:{type:Number,attr:"zoom"}}}static get events(){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}]}static get listeners(){return[{name:"glStyleElementAdded",method:"handleStyleAdded"},{name:"glStyleElementModified",method:"handleStyleModified"},{name:"glStyleElementRemoved",method:"handleStyleRemoved"}]}static get style(){return"gl-map{display:block;height:100%;width:100%}"}}export{t as GlMap};