import{r as t,h as e}from"./p-5ab6b26f.js";import{_ as s}from"./p-a41b3114.js";import{g as i}from"./p-b01cb482.js";class r{constructor(e){t(this,e),this.data={},this.batchSize=20,this.display="visible",this.features=[],this.item=!0,this.loadingSpinner="bubbles",this.loadingText=s("webmapgl.feature-list.loading"),this.order="asc"}componentWillLoad(){this.handleSourceId();const t=this.getMap();t&&t.on("moveend",()=>this.filter())}handleInfiniteScroll(t){this.limit+=this.batchSize,t.target.complete()}handleStyleUpdated(t){t.detail.id===this.styleId&&this.handleSourceId()}async handleSourceId(){const t=document.querySelector(`#${this.styleId}`);if(!t||!t.json.sources)return;const e=t.json.sources[this.sourceId].data;if("string"==typeof e){let t=await fetch(e);this.data=await t.json()}else this.data=e;this.filter()}getMap(){return i(this.mapId).map}async filter(){if(!this.data.features)return;let t;if("all"===this.display)t=this.data.features;else{let e=this.getMap().getBounds();t=this.data.features.filter(t=>{let[s,i]=t.geometry.coordinates;return s>=e.getWest()&&s<=e.getEast()&&i>=e.getSouth()&&i<=e.getNorth()})}this.limit=this.batchSize,this.features=this.sort(t)}sort(t){return"none"!==this.order&&this.orderBy?(t.sort((t,e)=>{const s=t.properties[this.orderBy],i=e.properties[this.orderBy];return s<i?"asc"===this.order?-1:1:s>i?"asc"===this.order?1:-1:0}),t):t}render(){let t=this.component,s=this.limit?this.features.slice(0,this.limit):this.features,i=s.length<this.features.length,r=s.map(s=>{let i=e(t,Object.assign({feature:s},this.componentOptions));return this.item?e("ion-item",null,i):i});return[e("ion-list",null,e("slot",{name:"start"}),r,e("slot",{name:"end"})),e("ion-infinite-scroll",{disabled:!i},e("ion-infinite-scroll-content",{"loading-spinner":this.loadingSpinner,"loading-text":this.loadingText}))]}static get watchers(){return{styleId:["handleSourceId"],sourceId:["handleSourceId"]}}}export{r as gl_feature_list};