import{b as e}from"./chunk-853b4351.js";let t=0;class l{constructor(){this.handlers={click:e=>this.handleClick(e),mouseenter:()=>this.handleMouseenter(),mouseleave:()=>this.handleMouseleave()},this.basemap=!1,this.clickableLayers=[],this.enabled=!0,this.json={}}componentWillLoad(){void 0===this.id&&(this.id="style-"+t.toString(),t+=1),this.url&&this.fetchJSON()}componentDidLoad(){this.clickableLayers&&this.clickableLayers.length&&this.updateClickable(this.clickableLayers),this.glStyleElementAdded.emit(this)}componentDidUpdate(){this.glStyleElementModified.emit(this)}componentDidUnload(){this.glStyleElementRemoved.emit(this)}getMap(){return this.el.closest("gl-map").map}async fetchJSON(){let e=await fetch(this.url);if(this.json=await e.json(),this.token&&this.json.sources)for(let e in this.json.sources){let t=this.json.sources[e];t.data&&(t.data=t.data.replace(/\$\{TOKEN\}/g,this.token))}}updateClickable(t,l){const s=this.getMap();t=e(t),l=e(l);for(let e of t){const t=l.indexOf(e);if(-1===t){let t=`${this.id}:${e}`;s.on("click",t,this.handlers.click),s.on("mouseenter",t,this.handlers.mouseenter),s.on("mouseleave",t,this.handlers.mouseleave)}else l.splice(t,1)}for(let e of l){let t=`${this.id}:${e}`;s.off("click",t,this.handlers.click),s.off("mouseenter",t,this.handlers.mouseenter),s.off("mouseleave",t,this.handlers.mouseleave)}}handleClick(e){this.glFeatureClick.emit(e)}handleMouseenter(){this.getMap().getCanvas().style.cursor="pointer"}handleMouseleave(){this.getMap().getCanvas().style.cursor=""}static get is(){return"gl-style"}static get properties(){return{basemap:{type:Boolean,attr:"basemap"},clickableLayers:{type:String,attr:"clickable-layers",watchCallbacks:["updateClickable"]},el:{elementRef:!0},enabled:{type:Boolean,attr:"enabled"},id:{type:String,attr:"id",reflectToAttr:!0,mutable:!0},json:{type:"Any",attr:"json",mutable:!0},name:{type:String,attr:"name"},thumbnail:{type:String,attr:"thumbnail"},token:{type:String,attr:"token"},url:{type:String,attr:"url"}}}static get events(){return[{name:"glFeatureClick",method:"glFeatureClick",bubbles:!0,cancelable:!0,composed:!0},{name:"glStyleElementAdded",method:"glStyleElementAdded",bubbles:!0,cancelable:!0,composed:!0},{name:"glStyleElementModified",method:"glStyleElementModified",bubbles:!0,cancelable:!0,composed:!0},{name:"glStyleElementRemoved",method:"glStyleElementRemoved",bubbles:!0,cancelable:!0,composed:!0}]}}export{l as GlStyle};